potassium 1.3.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/.rubocop.yml +1 -1
- data/.ruby_style.yml +6 -2
- data/CHANGELOG.md +19 -1
- data/README.md +79 -74
- data/circle.yml +9 -0
- data/docs/CONTRIBUTING.md +132 -0
- data/docs/{dsl.md → DSL.md} +146 -18
- data/lib/potassium/{templates/application/assets → assets}/.bowerrc +0 -0
- data/lib/potassium/assets/.buildpacks +3 -0
- data/lib/potassium/{templates/application/assets → assets}/.editorconfig +0 -0
- data/lib/potassium/assets/.env.example.erb +8 -0
- data/lib/potassium/assets/.hound.yml +2 -0
- data/lib/potassium/{templates/application/assets → assets}/.pryrc +0 -0
- data/lib/potassium/assets/.rubocop.yml +3 -0
- data/lib/potassium/assets/.ruby_style.yml +0 -0
- data/lib/potassium/assets/Dockerfile.ci +4 -0
- data/lib/potassium/assets/Procfile +1 -0
- data/lib/potassium/assets/README.md.erb +2 -0
- data/lib/potassium/assets/README.yml +83 -0
- data/lib/potassium/{templates/application/assets → assets}/active_admin/active_admin.js.coffee +0 -0
- data/lib/potassium/{templates/application/assets → assets}/active_admin/admin_user_policy.rb +0 -0
- data/lib/potassium/{templates/application/assets → assets}/active_admin/comment_policy.rb +0 -0
- data/lib/potassium/{templates/application/assets → assets}/active_admin/init_activeadmin_angular.rb +0 -0
- data/lib/potassium/{templates/application/assets → assets}/active_admin/pundit_page_policy.rb +0 -0
- data/lib/potassium/{templates/application/assets → assets}/api/api_error_concern.rb +0 -0
- data/lib/potassium/{templates/application/assets → assets}/api/base_controller.rb +0 -0
- data/lib/potassium/{templates/application/assets → assets}/api/responder.rb +0 -0
- data/lib/potassium/assets/bin/cibuild.erb +27 -0
- data/lib/potassium/assets/bin/setup.erb +22 -0
- data/lib/potassium/assets/bin/setup_heroku.erb +21 -0
- data/lib/potassium/{templates/application/assets → assets}/bower.json +0 -0
- data/lib/potassium/assets/circle.yml +16 -0
- data/lib/potassium/assets/config/database_mysql.yml.erb +25 -0
- data/lib/potassium/assets/config/database_postgresql.yml.erb +25 -0
- data/lib/potassium/assets/config/environments/staging.rb +5 -0
- data/lib/potassium/assets/config/puma.rb +29 -0
- data/lib/potassium/assets/config/secrets.yml.erb +14 -0
- data/lib/potassium/assets/docker-compose.ci.yml +6 -0
- data/lib/potassium/{templates/application/assets → assets}/es.yml +0 -0
- data/lib/potassium/{templates/application/assets → assets}/testing/.rspec +0 -0
- data/lib/potassium/{templates/application/assets → assets}/testing/rails_helper.rb +0 -0
- data/lib/potassium/cli/commands/create.rb +55 -4
- data/lib/potassium/cli/commands/install.rb +27 -13
- data/lib/potassium/{templates/application/generator.rb → generators/application.rb} +7 -2
- data/lib/potassium/{templates/application/recipe_generator.rb → generators/recipe.rb} +11 -2
- data/lib/potassium/helpers/answer-helpers.rb +21 -0
- data/lib/potassium/{templates/application/helpers → helpers}/callback-helpers.rb +0 -0
- data/lib/potassium/helpers/docker-helpers.rb +37 -0
- data/lib/potassium/{templates/application/helpers → helpers}/environment-helpers.rb +0 -0
- data/lib/potassium/{templates/application/helpers → helpers}/gem-helpers.rb +6 -2
- data/lib/potassium/helpers/info-helpers.rb +16 -0
- data/lib/potassium/helpers/readme-helpers.rb +85 -0
- data/lib/potassium/{templates/application/helpers → helpers}/template-dsl.rb +8 -0
- data/lib/potassium/helpers/template-helpers.rb +97 -0
- data/lib/potassium/{templates/application/helpers → helpers}/variable-helpers.rb +0 -0
- data/lib/potassium/recipe.rb +2 -0
- data/lib/potassium/{templates/application/recipes → recipes}/admin.rb +36 -6
- data/lib/potassium/recipes/angular_admin.rb +56 -0
- data/lib/potassium/recipes/api.rb +43 -0
- data/lib/potassium/recipes/aws_sdk.rb +5 -0
- data/lib/potassium/recipes/bower.rb +13 -0
- data/lib/potassium/recipes/ci.rb +42 -0
- data/lib/potassium/recipes/cleanup.rb +10 -0
- data/lib/potassium/recipes/database.rb +42 -0
- data/lib/potassium/recipes/delayed_job.rb +41 -0
- data/lib/potassium/recipes/devise.rb +64 -0
- data/lib/potassium/recipes/editorconfig.rb +5 -0
- data/lib/potassium/recipes/env.rb +10 -0
- data/lib/potassium/recipes/git.rb +13 -0
- data/lib/potassium/recipes/github.rb +27 -0
- data/lib/potassium/recipes/heroku.rb +138 -0
- data/lib/potassium/recipes/i18n.rb +26 -0
- data/lib/potassium/recipes/paperclip.rb +37 -0
- data/lib/potassium/recipes/production.rb +7 -0
- data/lib/potassium/recipes/pry.rb +10 -0
- data/lib/potassium/recipes/puma.rb +19 -0
- data/lib/potassium/recipes/pundit.rb +61 -0
- data/lib/potassium/recipes/rack_cors.rb +21 -0
- data/lib/potassium/recipes/readme.rb +7 -0
- data/lib/potassium/recipes/ruby.rb +23 -0
- data/lib/potassium/recipes/script.rb +16 -0
- data/lib/potassium/recipes/secrets.rb +5 -0
- data/lib/potassium/recipes/staging.rb +5 -0
- data/lib/potassium/recipes/style.rb +13 -0
- data/lib/potassium/recipes/testing.rb +37 -0
- data/lib/potassium/templates/application.rb +67 -0
- data/lib/potassium/templates/recipe.rb +12 -0
- data/lib/potassium/text_spinner.rb +0 -5
- data/lib/potassium/version.rb +2 -1
- data/potassium.gemspec +3 -0
- data/spec/fakes/bin/heroku +5 -0
- data/spec/fakes/bin/hub +5 -0
- data/spec/features/ci_spec.rb +14 -0
- data/spec/features/github_spec.rb +22 -0
- data/spec/features/heroku_spec.rb +61 -0
- data/spec/features/new_project_spec.rb +38 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/fake_github.rb +25 -0
- data/spec/support/fake_heroku.rb +77 -0
- data/spec/support/potassium_test_helpers.rb +98 -0
- metadata +149 -62
- data/lib/potassium/templates/application/assets/.rbenv-vars.example +0 -8
- data/lib/potassium/templates/application/assets/config/database_mysql.yml +0 -40
- data/lib/potassium/templates/application/assets/config/database_postgresql.yml +0 -26
- data/lib/potassium/templates/application/helpers/recipe-helpers.rb +0 -5
- data/lib/potassium/templates/application/helpers/template-helpers.rb +0 -35
- data/lib/potassium/templates/application/recipe_template.rb +0 -23
- data/lib/potassium/templates/application/recipes/angular_admin.rb +0 -26
- data/lib/potassium/templates/application/recipes/api.rb +0 -22
- data/lib/potassium/templates/application/recipes/asks/admin.rb +0 -9
- data/lib/potassium/templates/application/recipes/asks/api.rb +0 -2
- data/lib/potassium/templates/application/recipes/asks/database.rb +0 -9
- data/lib/potassium/templates/application/recipes/asks/devise.rb +0 -10
- data/lib/potassium/templates/application/recipes/asks/i18n.rb +0 -8
- data/lib/potassium/templates/application/recipes/asks/paperclip.rb +0 -2
- data/lib/potassium/templates/application/recipes/asks/pundit.rb +0 -4
- data/lib/potassium/templates/application/recipes/aws_sdk.rb +0 -1
- data/lib/potassium/templates/application/recipes/bower.rb +0 -3
- data/lib/potassium/templates/application/recipes/checks/devise.rb +0 -1
- data/lib/potassium/templates/application/recipes/database.rb +0 -22
- data/lib/potassium/templates/application/recipes/dependencies/admin.rb +0 -3
- data/lib/potassium/templates/application/recipes/devise.rb +0 -28
- data/lib/potassium/templates/application/recipes/editorconfig.rb +0 -1
- data/lib/potassium/templates/application/recipes/git.rb +0 -9
- data/lib/potassium/templates/application/recipes/i18n.rb +0 -9
- data/lib/potassium/templates/application/recipes/paperclip.rb +0 -20
- data/lib/potassium/templates/application/recipes/production.rb +0 -3
- data/lib/potassium/templates/application/recipes/pry.rb +0 -6
- data/lib/potassium/templates/application/recipes/pundit.rb +0 -33
- data/lib/potassium/templates/application/recipes/rack-cors.rb +0 -15
- data/lib/potassium/templates/application/recipes/rbenv.rb +0 -23
- data/lib/potassium/templates/application/recipes/readme.rb +0 -2
- data/lib/potassium/templates/application/recipes/testing.rb +0 -32
- data/lib/potassium/templates/application/recipes/unicorn.rb +0 -5
- data/lib/potassium/templates/application/template.rb +0 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e42b19285cfdc9b98d8481a021a68a08dcb7fb6
|
4
|
+
data.tar.gz: faa3f6cefda09e5ca429b7d542b39ffdff80d24a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71899b46a6e1006027a2fa193f3eb802ef6fe0b8cea1be3cb9def2dbb4e9312cdb97ee3dc643893761e7a6a1c29023606ba9e225ef5a5939743c5dcd789a500e
|
7
|
+
data.tar.gz: 95725c1f5db91367b0b85eab121bab9ca47ae49b8f97e17c3b229d98897046eb2712f3cc8a9d134710da8e93abea29854b136129cf56dd95bf8fd21cb417624d
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.rubocop.yml
CHANGED
data/.ruby_style.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,10 +2,28 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
-
|
5
|
+
## 2.0.0
|
6
6
|
|
7
|
+
Features:
|
8
|
+
- Use `.env` instead of `.rbenv-vars`
|
9
|
+
- Use Puma instead of unicorn
|
7
10
|
- Gets ruby version from http://ruby.platan.us/latest
|
8
11
|
- Adds the install command
|
12
|
+
- Adds heroku buildpack support using the [multi buildpack](multi-buildpack)
|
13
|
+
- Adds `rack-timeout` to prevent long running requests
|
14
|
+
- Adds [deploy-tasks buildpack](deploy-tasks) mainly to perform migrations, [#39]
|
15
|
+
- Add Delayed Jobs to handle background processes, [#41]
|
16
|
+
- Adds continuous integration using [CircleCI](https://circleci.com)
|
17
|
+
and docker, [#51]
|
18
|
+
- Adds heroku app creation to the heroku recipe, [#60]
|
19
|
+
- Adds github repo creation through hub
|
20
|
+
- Build a project Readme based on the potassium installed recipes, [#61]
|
21
|
+
|
22
|
+
[multi-buildpack]: http://github.com/ddollar/heroku-buildpack-multi
|
23
|
+
[deploy-tasts]: http://github.com/gunpowderlabs/buildpack-ruby-rake-deploy-tasks
|
24
|
+
[#39]: http://github.com/platanus/potassium/pull/39
|
25
|
+
[#41]: http://github.com/platanus/potassium/pull/41
|
26
|
+
[#51]: http://github.com/platanus/potassium/pull/51
|
9
27
|
|
10
28
|
## 1.3
|
11
29
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Potassium
|
1
|
+
# Potassium [![Circle CI](https://circleci.com/gh/platanus/potassium.svg?style=svg)](https://circleci.com/gh/platanus/potassium)
|
2
2
|
|
3
3
|
A Rails application generator from [Platanus](https://github.com/platanus), inspired by [Suspenders](https://github.com/thoughtbot/suspenders).
|
4
4
|
|
@@ -14,15 +14,19 @@ You have to install Potassium globally:
|
|
14
14
|
|
15
15
|
Use the `potassium create` command to create a new project:
|
16
16
|
|
17
|
-
$ potassium create project-name
|
17
|
+
$ potassium create <project-name>
|
18
18
|
|
19
|
-
It's important to note that it will perform a version check before running to ensure that you're using the latest potassium. Also, if you feel that it's too slow, you may need to update rubygems: `gem update --system`.
|
19
|
+
> It's important to note that it will perform a version check before running to ensure that you're using the latest potassium. Also, if you feel that it's too slow, you may need to update rubygems: `gem update --system`.
|
20
20
|
|
21
21
|
### Adding recipes to an existing project
|
22
22
|
|
23
23
|
Use the `potassium install` command to add a recipe to a project:
|
24
24
|
|
25
|
-
$ potassium install
|
25
|
+
$ potassium install devise
|
26
|
+
|
27
|
+
You can force an already installed recipe by passing the `--force` argument
|
28
|
+
|
29
|
+
$ potassium install devise --force
|
26
30
|
|
27
31
|
You can run the command on its own to view all the available recipes and select one:
|
28
32
|
|
@@ -32,8 +36,8 @@ You can run the command on its own to view all the available recipes and select
|
|
32
36
|
|
33
37
|
Potassium Rails apps includes the following gems and technologies:
|
34
38
|
|
35
|
-
- [
|
36
|
-
- [
|
39
|
+
- [Ruby](https://www.ruby-lang.org) Set the project ruby version based on http://ruby.platan.us/latest
|
40
|
+
- [dotenv](https://github.com/bkeepers/dotenv) load environmental variables in development
|
37
41
|
- [Bower](http://bower.io) for frontend assets packages.
|
38
42
|
- [EditorConfig](http://editorconfig.org) for keeping all our editor configurations the same.
|
39
43
|
- [pry](http://pryrepl.org) and [pry-byebug](https://github.com/deivid-rodriguez/pry-byebug) for a less painful debugging experience.
|
@@ -41,6 +45,9 @@ Potassium Rails apps includes the following gems and technologies:
|
|
41
45
|
- [FactoryGirl](https://github.com/thoughtbot/factory_girl) for test factories.
|
42
46
|
- [Guard](http://guardgem.org) for continuous testing and other watch-related tasks.
|
43
47
|
- [AWS-SDK](https://github.com/aws/aws-sdk-ruby) for file uploads, sdks, etc and because we use AWS.
|
48
|
+
- [Puma](https://github.com/puma/puma) to serve HTTP requests
|
49
|
+
- [Rack Timeout](https://github.com/heroku/rack-timeout) to abort requests that are
|
50
|
+
taking too long
|
44
51
|
|
45
52
|
The following optional integrations are added too:
|
46
53
|
|
@@ -49,95 +56,93 @@ The following optional integrations are added too:
|
|
49
56
|
- [ActiveAdmin](http://activeadmin.info) for admin interfaces.
|
50
57
|
- [ActiveAdminAddons](https://github.com/platanus/activeadmin_addons) for some help with ActiveAdmin.
|
51
58
|
- [Pundit](https://github.com/elabs/pundit) for role-based authorization.
|
59
|
+
- [DelayedJob](https://github.com/collectiveidea/delayed_job) to execute longer tasks in the background.
|
52
60
|
|
53
|
-
|
54
|
-
|
55
|
-
- [Responders](https://github.com/plataformatec/responders) for dry-ing our api controllers.
|
56
|
-
- [Versionist](https://github.com/bploetz/versionist) for some flexible api versioning.
|
57
|
-
- [ActiveModel::Serializers](https://github.com/rails-api/active_model_serializers) for record serialization.
|
58
|
-
- [Simple Token Authentication](https://github.com/gonzalo-bulnes/simple_token_authentication) for stateless API authentication.
|
59
|
-
|
60
|
-
## Contributing
|
61
|
-
|
62
|
-
### How do I add something new to Potassium?
|
63
|
-
|
64
|
-
In the [lib/potassium/templates/application](lib/potassium/templates/application) folder, you will find [the template](lib/potassium/templates/application/template.rb). You should follow the next conventions to add something:
|
65
|
-
|
66
|
-
*__NOTE:__ If you only want to use Potassium but not to add something new, the next parts can be easily skipped.*
|
61
|
+
A few more things are added to the project:
|
67
62
|
|
68
|
-
|
63
|
+
- A [low database connection pool limit][pool]
|
64
|
+
- Setup [Rubocop][rubocop] configuration with Platanus [style guides][rubocop-platanus]
|
65
|
+
- Setup [Hound CI][platanus-hound] configuration, with Platanus flavour
|
66
|
+
- Setup continuous integration in [CircleCI](circle-ci) to run tests.
|
67
|
+
- Create the github repository for the project (it used `hub` under the hood)
|
68
|
+
- A `bin/setup` script to setup things on a newly cloned project
|
69
|
+
- A `bin/cibuild` script to run continuous integration build on CI
|
69
70
|
|
70
|
-
|
71
|
+
[pool]: https://devcenter.heroku.com/articles/concurrency-and-database-connections
|
72
|
+
[rubocop]: https://github.com/bbatsov/rubocop
|
73
|
+
[rubocop-platanus]: https://raw.githubusercontent.com/platanus/hound/platanus/config/style_guides/platanus/ruby.yml
|
74
|
+
[platanus-hound]: http://monkeyci.platan.us
|
71
75
|
|
72
|
-
|
73
|
-
2. Then, ask something using the methods defined in [Inquirer](https://github.com/arlimus/inquirer.rb), that we use by default. Use the [DSL](docs/dsl.md) to store some information.
|
74
|
-
3. Finally, register the **ask** you created in [the template](lib/potassium/templates/application/template.rb):
|
76
|
+
### API support
|
75
77
|
|
76
|
-
|
77
|
-
run_action(:asking) do
|
78
|
-
# ...
|
79
|
-
eval_file "recipes/asks/my_ask.rb"
|
80
|
-
end
|
81
|
-
```
|
78
|
+
The optional API support includes:
|
82
79
|
|
83
|
-
|
84
|
-
|
85
|
-
|
80
|
+
- [Responders](https://github.com/plataformatec/responders) for dry-ing our api controllers.
|
81
|
+
- [Versionist](https://github.com/bploetz/versionist) for some flexible api versioning.
|
82
|
+
- [ActiveModel::Serializers](https://github.com/rails-api/active_model_serializers) for record serialization.
|
83
|
+
- [Simple Token Authentication](https://github.com/gonzalo-bulnes/simple_token_authentication) for stateless API authentication.
|
86
84
|
|
87
|
-
|
88
|
-
2. Run all the **asks** recipes.
|
89
|
-
3. Execute all the **recipes**, that are ruby files stored on the [recipes](lib/potassium/templates/application/recipes) folder. They specify what gems are needed and registers callbacks based on this process, usually to execute things after the gem installation happened or after some other recipe finished his work.
|
90
|
-
4. Install the gems, filling the Gemfile before with all the gathered gems.
|
91
|
-
5. Finally, create the database.
|
85
|
+
### Heroku
|
92
86
|
|
93
|
-
|
87
|
+
When you choose to deploy to heroku a few extra things are added for the project.
|
94
88
|
|
95
|
-
|
89
|
+
- Adds the [Rails Stdout Logging][logging-gem] gem
|
90
|
+
to configure the app to log to standard out,
|
91
|
+
which is how [Heroku's logging][heroku-logging] works.
|
92
|
+
- Adds a [Procfile][procfile] to define the processes to run in heroku
|
93
|
+
- Setup continuous integration using docker and herokuish to maintain better
|
94
|
+
parity between testing and production environments
|
95
|
+
- Adds a `.buildpacks` file with the default buildpacks to use. It use the
|
96
|
+
following buildpacks:
|
96
97
|
|
97
|
-
|
98
|
+
| index | buildpack | description |
|
99
|
+
|-------|-----------|-------------|
|
100
|
+
| 1. | [bower][heroku-buildpack-bower] | to make sure `bower install` run before the assets precompilation task |
|
101
|
+
| 2. | [ruby-version][heroku-buildpack-ruby-version] | to support the use of `.ruby-version` file to instruct heroku which ruby version to use |
|
102
|
+
| 3. | [ruby][heroku-buildpack-ruby] | the base buildpack to run ruby applications |
|
103
|
+
| 4. | [ruby-deploy-tasks][buildpack-deploy-tasks] | to run rake task after the deployment is complete, for example `db:migrate` |
|
98
104
|
|
99
|
-
|
100
|
-
# application/recipes/ask/banana_split.rb
|
101
|
-
use_banana_split = Ask.confirm("Do you want to use Banana Split?")
|
102
|
-
set(:use_banana_split, true) if use_banana_split
|
103
|
-
```
|
105
|
+
Also the heroku applications are created
|
104
106
|
|
105
|
-
|
107
|
+
- Creates a `staging` and `production` applications
|
108
|
+
- Creates a pipeline and assign the above application to the `staging`
|
109
|
+
and `production` stages.
|
110
|
+
- Setup initial configuration variables
|
111
|
+
- Set the application buildpack to the [multi-buildpack][heroku-buildpack-multi]
|
112
|
+
- Set **deploy-tasks** buildpack is setup to run `rake db:migrate` after each deploy
|
106
113
|
|
107
|
-
|
108
|
-
run_action(:asking) do
|
109
|
-
# ...
|
110
|
-
eval_file "recipes/asks/banana_split.rb"
|
111
|
-
end
|
112
|
-
```
|
114
|
+
You'll need to manually
|
113
115
|
|
114
|
-
|
116
|
+
- Connect the pipeline with the github repository
|
117
|
+
- Assign a branch to each stage for auto deployments
|
118
|
+
- Enable deploy after CI pass
|
115
119
|
|
116
|
-
|
117
|
-
# application/recipes/banana_split.rb
|
118
|
-
if get(:use_banana_split)
|
119
|
-
gather_gem('banana_split', '~> 1.2')
|
120
|
+
### Continuous Integration
|
120
121
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
125
|
-
```
|
122
|
+
In order to CicleCI start building the project on each push you need tell circle ci.
|
123
|
+
Go to https://circleci.com/add-projects, choose the repository from the list and hit
|
124
|
+
**Build Project**
|
126
125
|
|
127
|
-
|
126
|
+
### Hound CI
|
128
127
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
eval_file "recipes/banana_split.rb"
|
133
|
-
end
|
134
|
-
```
|
128
|
+
In order to Hound start checking your project's PRs you need enable that repository.
|
129
|
+
Go to https://monkeyci.platan.us, choose the repository from the list and hit
|
130
|
+
**Activate**
|
135
131
|
|
136
|
-
|
132
|
+
[logging-gem]: https://github.com/heroku/rails_stdout_logging
|
133
|
+
[heroku-logging]: https://devcenter.heroku.com/articles/logging#writing-to-your-log
|
134
|
+
[procfile]: https://devcenter.heroku.com/articles/procfile
|
135
|
+
[heroku-buildpack-ruby-version]: http://github.com/platanus/heroku-buildpack-ruby-version
|
136
|
+
[heroku-buildpack-bower]: http://github.com/platanus/heroku-buildpack-bower
|
137
|
+
[heroku-buildpack-ruby]: http://github.com/heroku/heroku-buildpack-ruby
|
138
|
+
[heroku-buildpack-multi]: http://github.com/ddollar/heroku-buildpack-multi
|
139
|
+
[buildpack-deploy-tasks]: http://github.com/gunpowderlabs/buildpack-ruby-rake-deploy-tasks
|
140
|
+
[circle-ci]: https://circleci.com
|
137
141
|
|
138
|
-
|
142
|
+
## Contributing
|
139
143
|
|
140
|
-
|
144
|
+
If you want to add functionality please go to
|
145
|
+
the [contributing](/docs/CONTRIBUTING.md)
|
141
146
|
|
142
147
|
## Credits
|
143
148
|
|
data/circle.yml
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
## How do I add something new to Potassium?
|
4
|
+
|
5
|
+
### Template
|
6
|
+
|
7
|
+
In the [lib/potassium/templates](/lib/potassium/templates) folder, you will find [the template][the-template].
|
8
|
+
|
9
|
+
Now, to add some behavior, thanks to the [DSL](/docs/DSL.md) we have a kind of standard flow of what happens when a new project is created. To understand this better, please read [the template][the-template]. The structure looks like this:
|
10
|
+
|
11
|
+
1. Clean the `Gemfile` and add the base gems that rails needs to work.
|
12
|
+
2. Run all the `ask` methods from the recipes.
|
13
|
+
3. Execute all the `create` methods from the recipes, that are ruby classes stored on the [recipes](/lib/potassium/recipes) folder. Here you can specify what gems are needed and register callbacks based on this process, usually to execute things after the gem installation happened or after some other recipe finished his work.
|
14
|
+
4. Install the gems, filling the `Gemfile` before with all the gathered gems.
|
15
|
+
5. Finally, create the database.
|
16
|
+
|
17
|
+
The main step is the 3rd, when we call the `create` methods from the recipes. A recipe can do anything (because is a ruby script) but their responsability should be to gather gems and register callbacks for the process.
|
18
|
+
|
19
|
+
### Recipe
|
20
|
+
|
21
|
+
The recipes are classes defined in the `Recipes` module that inherit from
|
22
|
+
`Rails::AppBuilder` and by convention can implement some of the following
|
23
|
+
methods `ask`, `create` and `install`. So they took this form.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class Recipes::MyRecipe < Rails::AppBuilder
|
27
|
+
def ask
|
28
|
+
#...
|
29
|
+
end
|
30
|
+
|
31
|
+
def create
|
32
|
+
#...
|
33
|
+
end
|
34
|
+
|
35
|
+
def install
|
36
|
+
#...
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
The recipes should be created in the `lib/potassium/recipes` folder.
|
42
|
+
|
43
|
+
#### Methods
|
44
|
+
|
45
|
+
For example, if we want to create an optional recipe to add a gem called
|
46
|
+
`banana_split` that needs to run a generator, we can do the following.
|
47
|
+
|
48
|
+
##### | `ask`
|
49
|
+
|
50
|
+
This method is used if you need to ask something to the user before doing something.
|
51
|
+
|
52
|
+
1. Use the [answer method](DSL.md#answer-helpers) to ask something using the methods defined in [Inquirer](https://github.com/arlimus/inquirer.rb), that we use by default. Use the [DSL](/docs/dsl.md) to store some information.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
def ask
|
56
|
+
use_banana_split = answer(:banana_split) do
|
57
|
+
Ask.confirm("Do you wan to use Banana Split?")
|
58
|
+
end
|
59
|
+
set(:use_banana_split, true) if use_banana_split
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
2. Then, register the question you created in [the template][the-template]:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
run_action(:asking) do
|
67
|
+
# ...
|
68
|
+
ask :myRecipe
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
##### | `create`
|
73
|
+
|
74
|
+
We'll call this method to add specific functionality to the rails project.
|
75
|
+
|
76
|
+
1. In the `create` method register a gem using `gather_gem` and create a callback to be called after the `gem_install` action succeded to run the generator. `gem_install` is one of the main actions that should be easily visible with a sneak peek in [the template][the-template].
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
def create
|
80
|
+
if get(:use_banana_split)
|
81
|
+
gather_gem('banana_split', '~> 1.2')
|
82
|
+
|
83
|
+
after(:gem_install) do
|
84
|
+
generate('banana_split:install')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
2. Then, register the recipe creation in [the template][the-template]:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
run_action(:recipe_loading) do
|
94
|
+
# ...
|
95
|
+
create :banana_split
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
##### | `install`
|
100
|
+
|
101
|
+
The install method will be called when you use the `install` command from potassium.
|
102
|
+
For example if you run `portassium install devise` this will use
|
103
|
+
[the recipe template](/lib/potassium/templates/recipe.rb) to load an execute the
|
104
|
+
`install` method for the **devise** recipe.
|
105
|
+
|
106
|
+
You can defined the main functionallity of a recipe in a private method and call
|
107
|
+
it from the `create` and `install` methods.
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
def install
|
111
|
+
if gem_exists?(/banana_split/)
|
112
|
+
info "Banana Split is already installed"
|
113
|
+
else
|
114
|
+
install_banana
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
|
120
|
+
def install_banana
|
121
|
+
#...
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
|
126
|
+
## The DSL
|
127
|
+
|
128
|
+
To see further documentation of what we added to the rails template's DSL, check the [DSL documentation](/docs/DSL.md).
|
129
|
+
|
130
|
+
> Remember that the DSL we are documenting is an extension over the [Rails Application Template DSL](http://edgeguides.rubyonrails.org/rails_application_templates.html), that itself is a dsl based on [Thor](https://github.com/erikhuda/thor/wiki).
|
131
|
+
|
132
|
+
[the-template]: /lib/potassium/templates/application.rb
|
data/docs/{dsl.md → DSL.md}
RENAMED
@@ -1,10 +1,56 @@
|
|
1
|
-
|
1
|
+
# The DSL
|
2
|
+
|
2
3
|
|
3
4
|
The DSL to extend and add recipes defines methods divided in mixins called helpers.
|
4
5
|
|
6
|
+
## The helpers
|
7
|
+
|
8
|
+
- [Templates](#template-helpers)
|
9
|
+
- [Answers](#answer-helpers)
|
10
|
+
- [Variable](#variable-helpers)
|
11
|
+
- [Environment](#environment-helpers)
|
12
|
+
- [Callback](#callback-helpers)
|
13
|
+
- [Gem](#gem-helpers)
|
14
|
+
- [Info](#info-helpers)
|
15
|
+
- [Readme](#readme-helpers)
|
16
|
+
|
5
17
|
### Template Helpers
|
6
18
|
|
7
|
-
|
19
|
+
##### | `ask(recipe_name)`
|
20
|
+
|
21
|
+
Loads the recipe and execute its `ask` method.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
ask :devise
|
25
|
+
```
|
26
|
+
|
27
|
+
##### | `create(recipe_name)`
|
28
|
+
|
29
|
+
Loads the recipe and execute its `create` method.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
create :devise
|
33
|
+
```
|
34
|
+
|
35
|
+
##### | `install(recipe_name)`
|
36
|
+
|
37
|
+
Loads the recipe and execute its `install` method. If the recipe implements
|
38
|
+
a `installed?` method it will check first if it is already installed. You can
|
39
|
+
force the installation by passing the `--force` argument on the cli.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
install :devise
|
43
|
+
```
|
44
|
+
|
45
|
+
##### | `load_recipe(recipe_name)`
|
46
|
+
|
47
|
+
Loads and return the recipe.
|
48
|
+
|
49
|
+
##### | `force?`
|
50
|
+
|
51
|
+
Whether the `--force` argument was passed from the cli.
|
52
|
+
|
53
|
+
##### | `eval_file(file)`
|
8
54
|
|
9
55
|
Just evals a file from the source path of this folder. Example:
|
10
56
|
|
@@ -14,7 +60,7 @@ eval_file('recipes/database.rb')
|
|
14
60
|
|
15
61
|
You can use any variable name you want in the body of the recipe because all the code loaded in each recipe is wrapped inside a method that is executed thereafter.
|
16
62
|
|
17
|
-
|
63
|
+
##### | `erase_comments(file)`
|
18
64
|
|
19
65
|
Erase the comments from a file in the rails application created. Example:
|
20
66
|
|
@@ -22,9 +68,22 @@ Erase the comments from a file in the rails application created. Example:
|
|
22
68
|
erase_comments('Gemfile')
|
23
69
|
```
|
24
70
|
|
71
|
+
### Answer Helpers
|
72
|
+
|
73
|
+
##### | `answer(key, &block)`
|
74
|
+
|
75
|
+
Defines a key to store the answers. In the fallback you can pass a block
|
76
|
+
with the code that will make the question.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
answer(:devise) do
|
80
|
+
Ask.confirm("Do you want to install devise")
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
25
84
|
### Variable Helpers
|
26
85
|
|
27
|
-
|
86
|
+
##### | `set(key, value)`
|
28
87
|
|
29
88
|
Defines a variable to use in different parts of the template. It's important to note that this was preferred over using standard instance variables because the rails template context is not fully controlled by us and to use arbitrary standard instance variables can lead to name clashing. Example:
|
30
89
|
|
@@ -32,7 +91,7 @@ Defines a variable to use in different parts of the template. It's important to
|
|
32
91
|
set('fruit', 'platanus')
|
33
92
|
```
|
34
93
|
|
35
|
-
|
94
|
+
##### | `get(key)`
|
36
95
|
|
37
96
|
Retrieves a variable that was defined with `set`. Example:
|
38
97
|
|
@@ -40,7 +99,7 @@ Retrieves a variable that was defined with `set`. Example:
|
|
40
99
|
get('fruit') == 'platanus'
|
41
100
|
```
|
42
101
|
|
43
|
-
|
102
|
+
##### | `equals?(key, value)`
|
44
103
|
|
45
104
|
Wrapps the pattern `get(key) == value`. Example:
|
46
105
|
|
@@ -52,7 +111,7 @@ equals?('fruit', 'platanus') # true
|
|
52
111
|
|
53
112
|
### Environment Helpers
|
54
113
|
|
55
|
-
|
114
|
+
##### | `set_env(key, value)`
|
56
115
|
|
57
116
|
Stores a future environment helper in the key `default_env` to be used in some way (the `.rbenv-vars` file is the only use right now). To help ensure that the execution of some rake commands in the end of the installation is correct, this sets the value as a real environment variable too. In this way, running `rake db:create` within the template will use the same environment variables that will use later, while running. Example:
|
58
117
|
|
@@ -60,7 +119,7 @@ Stores a future environment helper in the key `default_env` to be used in some w
|
|
60
119
|
set_env('DB_USER', 'root')
|
61
120
|
```
|
62
121
|
|
63
|
-
|
122
|
+
##### | `get_env(key)`
|
64
123
|
|
65
124
|
Get the previously stored variable stored with `set_env` with the name of the key. Example:
|
66
125
|
|
@@ -68,7 +127,7 @@ Get the previously stored variable stored with `set_env` with the name of the ke
|
|
68
127
|
get_env('DB_USER')
|
69
128
|
```
|
70
129
|
|
71
|
-
|
130
|
+
##### | `default_env(hash = {})`
|
72
131
|
|
73
132
|
This stores all the pairs of a hash as environment variables. Example:
|
74
133
|
|
@@ -84,7 +143,7 @@ default_env({
|
|
84
143
|
|
85
144
|
This helpers helps to organize the flow inside the template between multiple recipes. They ensure that the template runs in order and help injecting callbacks before and after important actions. For example, a recipe may want to register something to happen after the gem installation and something to happen after the database creation.
|
86
145
|
|
87
|
-
|
146
|
+
##### | `run_action(action_name, &block)`
|
88
147
|
|
89
148
|
Runs a block with the registered callbacks for the action named as the action_name parameter. Example:
|
90
149
|
|
@@ -95,7 +154,7 @@ run_action(:gem_install) do
|
|
95
154
|
end
|
96
155
|
```
|
97
156
|
|
98
|
-
|
157
|
+
##### | `after(action_name, wrap_in_action: false, &callback)`
|
99
158
|
|
100
159
|
This registers a callback to happen after an action happened. The `wrap_in_action` parameter can be used to wrap the callback in a `run_action` call. Example:
|
101
160
|
|
@@ -124,7 +183,7 @@ after(:gem_install) do
|
|
124
183
|
end
|
125
184
|
```
|
126
185
|
|
127
|
-
|
186
|
+
##### | `before(action_name, wrap_in_action: false, &callback)`
|
128
187
|
|
129
188
|
This registers a callback to happen after an action happened. The `wrap_in_action` parameter can be used to wrap the callback in a `run_action` call. Example:
|
130
189
|
|
@@ -136,7 +195,7 @@ run_action(:gem_install) do
|
|
136
195
|
end
|
137
196
|
|
138
197
|
before(:gem_install) do
|
139
|
-
|
198
|
+
success "We are going to run gem install now"
|
140
199
|
end
|
141
200
|
```
|
142
201
|
|
@@ -149,7 +208,7 @@ The process with the gems installation is different from the standard Rails one.
|
|
149
208
|
3. Through the loading of the recipes, add gems to the same hash.
|
150
209
|
4. Using `build_gemfile` we build the gemfile from that information in a way that makes the Gemfile to be clean.
|
151
210
|
|
152
|
-
|
211
|
+
##### | `gather_gem(name, *attributes)`
|
153
212
|
|
154
213
|
The attributes are the same as the attributes of the `gem` method of the Rails Templates. This adds a gem to the gem information but doesn't add it to the Gemfile yet. Example:
|
155
214
|
|
@@ -157,7 +216,7 @@ The attributes are the same as the attributes of the `gem` method of the Rails T
|
|
157
216
|
gather_gem 'activeadmin', github: 'activeadmin'
|
158
217
|
```
|
159
218
|
|
160
|
-
|
219
|
+
##### | `gather_gems(*environments, &block)`
|
161
220
|
|
162
221
|
Calls the block inside a block with the specified environments. It adds those gems as gems of those environments, so they are added in the correct place in the Gemfile. Again, everything is in memory and it's just stored in a final step, so we don't repeat groups in the final Gemfile. Example:
|
163
222
|
|
@@ -167,7 +226,7 @@ gather_gems(:development, :test) do
|
|
167
226
|
end
|
168
227
|
```
|
169
228
|
|
170
|
-
|
229
|
+
##### | `discard_gem(name)`
|
171
230
|
|
172
231
|
This discard a previously added gem from everywhere. Example:
|
173
232
|
|
@@ -175,7 +234,7 @@ This discard a previously added gem from everywhere. Example:
|
|
175
234
|
discard_gem('sqlite3')
|
176
235
|
```
|
177
236
|
|
178
|
-
|
237
|
+
##### | `clean_gemfile`
|
179
238
|
|
180
239
|
This removes everything from the Gemfile, adds the `source 'https://rubygems.org'` line in the top, reads from the `gemfile_entries` array, which holds the original gems that rails created, and add them to the hash of gems. Example:
|
181
240
|
|
@@ -186,7 +245,7 @@ run_action(:cleaning) do
|
|
186
245
|
end
|
187
246
|
```
|
188
247
|
|
189
|
-
|
248
|
+
##### | `build_gemfile`
|
190
249
|
|
191
250
|
It inserts the gems stored in memory inside the Gemfile, filling it cleanly. Example:
|
192
251
|
|
@@ -196,3 +255,72 @@ run_action(:gem_install) do
|
|
196
255
|
run "bundle install"
|
197
256
|
end
|
198
257
|
```
|
258
|
+
|
259
|
+
### Info Helpers
|
260
|
+
|
261
|
+
##### | `success(message)`
|
262
|
+
|
263
|
+
To show success messages through standard output.
|
264
|
+
|
265
|
+
```ruby
|
266
|
+
success("gem installed!")
|
267
|
+
```
|
268
|
+
|
269
|
+
##### | `error(message)`
|
270
|
+
|
271
|
+
To show error messages through standard output.
|
272
|
+
|
273
|
+
```ruby
|
274
|
+
error("error trying to create installation file")
|
275
|
+
```
|
276
|
+
|
277
|
+
##### | `info(message)`
|
278
|
+
|
279
|
+
To show info messages through standard output.
|
280
|
+
|
281
|
+
|
282
|
+
```ruby
|
283
|
+
info("ActiveAdmin is already installed")
|
284
|
+
```
|
285
|
+
|
286
|
+
### Readme Helpers
|
287
|
+
|
288
|
+
After running the potassium's `create` command, a custom `README.md` file will be generated with recipes you chose.
|
289
|
+
Each recipe defines a "chunk" of that file. To do this, first you need to fill the [README.yml](/lib/potassium/assets/README.yml) file with desired definitions. Then, execute one of the following methods:
|
290
|
+
|
291
|
+
##### | `add_readme_header(header, iterpolation_values)`
|
292
|
+
|
293
|
+
If, for example, you want to add the style guide header, you need to do:
|
294
|
+
|
295
|
+
```yml
|
296
|
+
readme:
|
297
|
+
headers:
|
298
|
+
style_guide:
|
299
|
+
title: "Style Guides"
|
300
|
+
body: "The style guides are enforced through a self hosted version of..."
|
301
|
+
```
|
302
|
+
|
303
|
+
Then, in the recipe:
|
304
|
+
|
305
|
+
```ruby
|
306
|
+
add_readme_header(:style_guide)
|
307
|
+
```
|
308
|
+
|
309
|
+
##### | `add_readme_section(header, section, iterpolation_values)`
|
310
|
+
|
311
|
+
To add header's sections. Paperclip, for example:
|
312
|
+
|
313
|
+
```yml
|
314
|
+
readme:
|
315
|
+
headers:
|
316
|
+
internal_dependencies:
|
317
|
+
title: "Internal dependencies"
|
318
|
+
sections:
|
319
|
+
paperclip:
|
320
|
+
title: "Uploads"
|
321
|
+
body: "For managing uploads, this project uses..."
|
322
|
+
```
|
323
|
+
|
324
|
+
```ruby
|
325
|
+
add_readme_section(:internal_dependencies, :paperclip)
|
326
|
+
```
|