gist/README.md

303 lines
7.4 KiB
Markdown
Raw Normal View History

2016-09-19 13:08:18 +02:00
Table of Contents
=================
* [GIST](#gist)
* [Requirements](#requirements)
* [Git](#git)
* [Composer](#composer)
* [Bower](#bower)
2016-09-28 00:43:54 +02:00
* [Installation](#installation)
* [Upgrade](#upgrade)
2016-09-19 13:08:18 +02:00
* [Makefile](#makefile)
* [API](#api)
2016-09-28 00:43:54 +02:00
* [Create a new gist](#create-a-new-gist)
* [Update an existing Gist](#update-an-existing-gist)
2016-09-19 13:08:18 +02:00
* [Console](#console)
2016-09-28 00:49:50 +02:00
* [Create and update gists](#create-and-update-gists)
2016-09-28 00:43:54 +02:00
* [Create user](#create-user)
* [Show stats](#show-stats)
2016-09-19 13:08:18 +02:00
* [Configuration](#configuration)
2016-09-28 00:43:54 +02:00
* [API](#api-1)
* [Authentication](#authentication)
* [Debug](#debug)
2016-09-19 13:08:18 +02:00
* [Deployment](#deployment)
2016-10-03 17:41:01 +02:00
* [Contributors](#contributors)
2016-09-19 13:08:18 +02:00
2015-05-06 10:58:55 +02:00
GIST
====
GIST is an open-source application to share code.
2015-05-10 02:32:24 +02:00
https://www.deblan.io/post/517/gist-est-dans-la-place
2015-05-06 10:58:55 +02:00
2015-11-30 01:09:59 +01:00
![Gist](https://upload.deblan.org/u/2015-11/565b93a5.png "Gist")
2015-05-12 11:13:30 +02:00
![Gist](https://upload.deblan.org/u/2016-06/57655dec.png "Gist")
2015-05-06 10:58:55 +02:00
Requirements
------------
* PHP >= 5.4
* GIT
2015-05-09 17:42:53 +02:00
* MySQL, PostgreSQL or SQLite
2015-05-06 11:04:38 +02:00
* Composer (php)
* Bower (node)
2015-05-06 10:58:55 +02:00
2016-09-28 00:43:54 +02:00
### Git
Git can maybe be downloaded from your system's repositories.
$ git config --global user.email "you@example.com"
$ git config --global user.name "Your Name"
### Composer
Composer can maybe be downloaded from your system's repositories.
Else, follow the next instructions:
2016-10-02 20:31:08 +02:00
# With cURL
$ curl -sS https://getcomposer.org/installer | php
2016-09-28 00:43:54 +02:00
2016-10-02 20:31:08 +02:00
# With Wget
$ wget -O - -q https://getcomposer.org/installer | php
2016-09-28 00:43:54 +02:00
2016-10-02 20:31:08 +02:00
$ chmod +x composer.phar
2016-09-28 00:43:54 +02:00
2016-10-02 20:31:08 +02:00
# For a local installation and if the envvar PATH contains "$HOME/bin/"
$ mv composer.phar ~/bin/composer
# For a global installation
$ sudo mv composer.phar /usr/local/bin/composer
2016-09-28 00:43:54 +02:00
2016-10-02 20:31:08 +02:00
### Bower
2016-09-28 00:43:54 +02:00
2016-10-02 20:31:08 +02:00
$ sudo apt-get install npm
$ sudo npm install -g bower
2016-09-28 00:43:54 +02:00
2015-05-06 10:58:55 +02:00
Installation
------------
2016-10-02 20:31:08 +02:00
$ cd /path/to/www/
2016-02-13 09:12:01 +01:00
$ git clone https://gitnet.fr/deblan/gist
2015-05-06 11:10:26 +02:00
$ cd gist
2015-05-06 10:58:55 +02:00
$ make
2015-05-09 17:42:53 +02:00
$ mv propel-dist.yaml propel.yaml
2016-09-28 00:25:47 +02:00
Edit `propel.yaml`. **Use spaces instead of tabulations**.
**MySQL**
propel:
database:
connections:
default:
adapter: mysql
# http://www.php.net/manual/en/ref.pdo-mysql.connection.php
dsn: "mysql:host=DATABASE_SERVER;dbname=DATABASE_NAME"
user: DATEBASE_USER
password: DATEBASE_PASSWORD
settings:
charset: utf8
queries:
utf8: "SET NAMES utf8 COLLATE utf8_unicode_ci, COLLATION_CONNECTION = utf8_unicode_ci, COLLATION_DATABASE = utf8_unicode_ci, COLLATION_SERVER = utf8_unicode_ci"
[...]
**SQLITE**
propel:
database:
connections:
default:
adapter: sqlite
# http://www.php.net/manual/en/ref.pdo-sqlite.connection.php
dsn: "sqlite:/PATH/TO/gist.sqlite"
user: ~
password: ~
[...]
Then `$ make propel`.
2015-05-09 17:42:53 +02:00
2016-09-26 17:41:57 +02:00
Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['token']` with a strong secret phrase.
2015-05-06 10:58:55 +02:00
2016-10-02 20:31:08 +02:00
The web server must have permission to write into `data`.
$ sudo chown -R www-data:www-data data
2016-10-03 23:32:01 +02:00
Your webserver must be configured to serve `web/` as document root. If you use nginx, all virtual paths must be rooted with `web/index.php` or `web/app_dev.php` ([documentation](https://www.nginx.com/resources/wiki/start/topics/recipes/symfony/)). If you use apache, you must enable the `rewrite` module and restart:
$ sudo a2enmod rewrite
$ sudo service apache2 restart
2016-10-03 23:29:49 +02:00
2016-09-28 00:43:54 +02:00
Upgrade
-------
2015-11-24 19:26:58 +01:00
$ make update
$ make propel
2015-05-06 10:58:55 +02:00
Makefile
--------
A Makefile is provided to automate some tasks.
2015-05-09 17:42:53 +02:00
* `make` will install application's dependencies via Composer and Bower,
2015-05-06 10:58:55 +02:00
* `make optimize` will run Composer's autoloader dump script with classmap
2015-05-09 17:42:53 +02:00
* `make update` will update the application
* `make propel` will generate propel's files
2015-09-17 11:41:32 +02:00
* `make run` will run development server on http://127.0.0.1:8080/
2015-07-19 18:39:46 +02:00
API
---
### Create a new gist
**POST** /{locale}/api/create
Params:
2016-09-28 00:43:54 +02:00
* `form[title]`: String (required, can be empty)
* `form[type]`: String (required)
2015-07-19 18:39:46 +02:00
Values: html, css, javascript, php, sql, xml, yaml, perl, c, asp, python, bash, actionscript3, text
2016-09-28 00:43:54 +02:00
* `form[content]`: String (required)
2015-07-19 18:39:46 +02:00
2016-09-28 00:43:54 +02:00
**Responses:**
2015-07-19 18:39:46 +02:00
2016-09-28 00:43:54 +02:00
* Code `200`: A json which contains gist's information. Example:
2015-07-19 18:39:46 +02:00
```javascript
2015-07-19 18:42:22 +02:00
{
2015-09-17 11:41:32 +02:00
"url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/f4afbf72967dd95e3461490dcaa310d728d6a97d",
2015-07-19 18:42:22 +02:00
"gist": {
2015-09-17 11:48:52 +02:00
"Id": 66,
2015-07-19 18:42:22 +02:00
"Title": "test prod",
"Cipher": false,
"Type": "javascript",
"File": "55abcfa7771e0",
"CreatedAt": "2015-07-19T16:26:15Z",
"UpdatedAt": "2015-07-19T16:26:15Z"
}
}
2015-07-19 18:39:46 +02:00
```
2016-09-28 00:43:54 +02:00
* Code `405`: Method Not Allowed
* Code `400`: Bad Request
2015-07-19 18:39:46 +02:00
2015-11-07 22:13:08 +01:00
### Update an existing Gist
**POST** /{locale}/api/update/{id}
Params:
2016-09-28 00:43:54 +02:00
* `{id}`: Gist Id (required)
* `form[content]`: String (required)
2015-11-07 22:13:08 +01:00
2016-09-28 00:43:54 +02:00
**Responses:**
2015-11-07 22:13:08 +01:00
2016-09-28 00:43:54 +02:00
* Code `200`: A json which contains gist's information. Example:
2015-11-07 22:13:08 +01:00
```javascript
{
"url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/abcgi72967dd95e3461490dcaa310d728d6adef",
"gist": {
"Id": 66,
"Title": "test prod",
"Cipher": false,
"Type": "javascript",
"File": "55abcfa7771e0",
"CreatedAt": "2015-07-19T16:26:15Z",
"UpdatedAt": "2015-07-19T16:30:15Z"
}
}
```
2016-09-28 00:43:54 +02:00
* Code `405`: Method Not Allowed
* Code `400`: Bad Request
2015-11-07 22:13:08 +01:00
2015-07-19 18:45:01 +02:00
Console
-------
2016-09-28 00:49:50 +02:00
### Create and update gists
2015-07-19 18:45:01 +02:00
```
2015-11-24 19:14:10 +01:00
$ app/console --help create
$ app/console --help update
2015-07-19 18:45:01 +02:00
```
2015-07-19 18:48:52 +02:00
2015-11-24 19:14:10 +01:00
### Create user
2015-11-21 00:20:44 +01:00
```
2015-11-24 23:00:03 +01:00
$ app/console --help user:create
2015-11-24 19:14:10 +01:00
```
### Show stats
2015-11-21 00:20:44 +01:00
```
2015-11-24 19:14:10 +01:00
$ app/console --help stats
```
Configuration
-------------
2015-11-21 00:20:44 +01:00
2015-11-24 19:14:10 +01:00
### API
2016-09-28 00:49:50 +02:00
**Personal instance**
2015-07-19 18:48:52 +02:00
2016-09-28 00:49:50 +02:00
If you install Gist on your server, you have to modify the `base_uri` of the API.
Edit `app/bootstrap.php.d/60-api.php` and replace `https://gist.deblan.org/`.
2015-11-24 19:14:10 +01:00
### Authentication
2016-09-28 00:49:50 +02:00
**Disabling login**
2015-11-24 19:14:10 +01:00
Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['enable_login']` with `false`.
2016-09-28 00:49:50 +02:00
**Disabling registration**
2015-11-24 19:14:10 +01:00
Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['enable_registration']` with `false`.
2015-11-24 19:18:00 +01:00
2016-09-28 00:49:50 +02:00
**Login required to edit a gist**
2016-09-19 15:12:53 +02:00
Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['login_required_to_edit_gist']` with `true`.
2016-09-28 00:49:50 +02:00
**Login required to view a gist**
2016-09-19 15:12:53 +02:00
Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['login_required_to_view_gist']` with `true`.
2016-09-28 00:49:50 +02:00
**Login required to view an embeded gist**
2016-09-19 15:12:53 +02:00
Edit `app/bootstrap.php.d/70-security.php` and modify the value of `$app['login_required_to_view_embeded_gist']` with `true`.
2015-11-24 19:18:00 +01:00
### Debug
`app_dev.php` is the development router. Access is granted for an IP range defined in the same file.
2016-02-02 19:31:22 +01:00
Deployment
----------
2016-02-02 19:32:08 +01:00
Gist uses [Magallanes](http://magephp.com/) to manage deployment.
2016-02-02 19:43:55 +01:00
2016-09-28 00:49:50 +02:00
**Global installation**
2016-02-02 19:43:55 +01:00
2016-02-02 19:31:22 +01:00
$ composer global require andres-montanez/magallanes
2016-02-02 19:32:27 +01:00
# if the envvar PATH contains "$HOME/bin/"
2016-02-02 19:31:22 +01:00
$ ln -s ~/.composer/vendor/bin/mage ~/bin/mage
2016-09-28 00:49:50 +02:00
**Local installation**
2016-02-02 19:43:55 +01:00
$ composer require andres-montanez/magallanes
2016-02-02 19:31:22 +01:00
There is an example of the configuration of an environment in `.mage/config/environment/prod.yml-dist`.
2016-02-02 19:43:55 +01:00
# global installation
2016-02-02 19:31:22 +01:00
$ mage deploy to:prod
2016-02-02 19:43:55 +01:00
# local installation
2016-02-13 09:12:01 +01:00
$ ./vendor/andres-montanez/magallanes/bin/mage deploy to:prod
2016-10-03 17:41:01 +02:00
Contributors
------------
**Developers**
* Simon Vieille <contact@deblan.fr>
2016-10-03 19:10:34 +02:00
**Translators**
2016-10-03 17:41:01 +02:00
* Simon Vieille <contact@deblan.fr>
2016-10-03 19:10:34 +02:00
* Marion Sanchez
* Marjorie Da Silva