decidim-generators 0.11.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +26 -0
- data/Gemfile.lock +671 -0
- data/README.md +76 -0
- data/Rakefile +32 -0
- data/exe/decidim +14 -0
- data/lib/decidim/generators/app_generator.rb +161 -0
- data/lib/decidim/generators/app_templates/Dockerfile.erb +1 -0
- data/lib/decidim/generators/app_templates/README.md.erb +22 -0
- data/lib/decidim/generators/app_templates/cable.yml.erb +9 -0
- data/lib/decidim/generators/app_templates/carrierwave.rb +28 -0
- data/lib/decidim/generators/app_templates/database.yml.erb +87 -0
- data/lib/decidim/generators/app_templates/decidim.scss.erb +3 -0
- data/lib/decidim/generators/app_templates/decidim_controller.rb.erb +5 -0
- data/lib/decidim/generators/app_templates/docker-compose.yml.erb +26 -0
- data/lib/decidim/generators/app_templates/example_authorization_handler.rb +55 -0
- data/lib/decidim/generators/app_templates/initializer.rb +47 -0
- data/lib/decidim/generators/app_templates/secrets.yml.erb +61 -0
- data/lib/decidim/generators/app_templates/social_share_button.rb +8 -0
- data/lib/decidim/generators/component_generator.rb +74 -0
- data/lib/decidim/generators/component_templates/Gemfile.erb +26 -0
- data/lib/decidim/generators/component_templates/LICENSE-AGPLv3.txt +661 -0
- data/lib/decidim/generators/component_templates/README.md.erb +30 -0
- data/lib/decidim/generators/component_templates/Rakefile +9 -0
- data/lib/decidim/generators/component_templates/app/assets/config/component_manifest.js +0 -0
- data/lib/decidim/generators/component_templates/app/assets/images/decidim/component/icon.svg +1 -0
- data/lib/decidim/generators/component_templates/app/controllers/decidim/component/admin/application_controller.rb.erb +15 -0
- data/lib/decidim/generators/component_templates/app/controllers/decidim/component/application_controller.rb.erb +13 -0
- data/lib/decidim/generators/component_templates/app/helpers/decidim/component/application_helper.rb.erb +10 -0
- data/lib/decidim/generators/component_templates/app/models/decidim/component/abilities/admin/admin_ability.rb.erb +17 -0
- data/lib/decidim/generators/component_templates/app/models/decidim/component/abilities/current_user_ability.rb.erb +47 -0
- data/lib/decidim/generators/component_templates/app/models/decidim/component/application_record.rb.erb +10 -0
- data/lib/decidim/generators/component_templates/bin/rails.erb +20 -0
- data/lib/decidim/generators/component_templates/config/i18n-tasks.yml.erb +10 -0
- data/lib/decidim/generators/component_templates/config/locales/en.yml.erb +6 -0
- data/lib/decidim/generators/component_templates/decidim-component.gemspec.erb +22 -0
- data/lib/decidim/generators/component_templates/lib/decidim/component.rb.erb +13 -0
- data/lib/decidim/generators/component_templates/lib/decidim/component/admin.rb.erb +10 -0
- data/lib/decidim/generators/component_templates/lib/decidim/component/admin_engine.rb.erb +32 -0
- data/lib/decidim/generators/component_templates/lib/decidim/component/component.rb.erb +40 -0
- data/lib/decidim/generators/component_templates/lib/decidim/component/engine.rb.erb +29 -0
- data/lib/decidim/generators/component_templates/lib/decidim/component/test/factories.rb.erb +13 -0
- data/lib/decidim/generators/component_templates/lib/decidim/component/version.rb.erb +10 -0
- data/lib/decidim/generators/component_templates/spec/factories.rb.erb +3 -0
- data/lib/decidim/generators/component_templates/spec/spec_helper.rb.erb +13 -0
- data/lib/decidim/generators/install_generator.rb +170 -0
- data/lib/decidim/generators/version.rb +10 -0
- metadata +123 -0
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Decidim::Generators
|
2
|
+
|
3
|
+
This gem provides several generators to create decidim applications & components
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```console
|
8
|
+
gem install decidim-generators
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
### Generating decidim applications
|
14
|
+
|
15
|
+
Use the command
|
16
|
+
|
17
|
+
```console
|
18
|
+
decidim my_new_application
|
19
|
+
```
|
20
|
+
|
21
|
+
to generate a fresh new decidim application.
|
22
|
+
|
23
|
+
### Generating decidim components
|
24
|
+
|
25
|
+
This repo helps you generating the scheleton of a decidim component. It will
|
26
|
+
generate a folder with a plugin's code skeleton that you then need to properly
|
27
|
+
require in your final decidim application in order to use it. To do that, you
|
28
|
+
need to include the plugin in your application's `Gemfile`.
|
29
|
+
|
30
|
+
For example, if you generated your component at
|
31
|
+
`~/decidim-module-experimental_component`, you'll need to edit your `Gemfile` like
|
32
|
+
this in order for the component to be used:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
gem "decidim-experimental_plugin", path: "~/decidim-module-experimental_plugin"
|
36
|
+
```
|
37
|
+
|
38
|
+
Once you do that, and boot your application, you'll see the new component being
|
39
|
+
offered in the "New component" selector on the "Components" section of any
|
40
|
+
participatory space in the admin dashboard.
|
41
|
+
|
42
|
+
#### Generate a new component
|
43
|
+
|
44
|
+
```console
|
45
|
+
decidim --component my_component
|
46
|
+
```
|
47
|
+
|
48
|
+
#### Generate a new component in a specific folder
|
49
|
+
|
50
|
+
You may do this when you want to point to an existing folder or give it a custom
|
51
|
+
name.
|
52
|
+
|
53
|
+
```console
|
54
|
+
decidim --component my_component --destination_folder ../decidim-module-my_component
|
55
|
+
```
|
56
|
+
|
57
|
+
#### Generate a new component as a external plugin
|
58
|
+
|
59
|
+
You may do this when your plugin is meant to live outside of decidim's core
|
60
|
+
repo. The generated application has some particularities as opposed to a plugin
|
61
|
+
living in the core repo. For example:
|
62
|
+
|
63
|
+
* It has its own Gemfile.
|
64
|
+
* The dummy application path is different.
|
65
|
+
|
66
|
+
```console
|
67
|
+
decidim --component my_component --external
|
68
|
+
```
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
See [Decidim](https://github.com/decidim/decidim).
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
See [Decidim](https://github.com/decidim/decidim).
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
require_relative "../lib/decidim/gem_manager"
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
task default: :spec
|
10
|
+
|
11
|
+
desc "Installs all gems locally."
|
12
|
+
task :install_all do
|
13
|
+
Decidim::GemManager.run_all(
|
14
|
+
"gem build %name && mv %name-%version.gem ..",
|
15
|
+
include_root: false
|
16
|
+
)
|
17
|
+
|
18
|
+
Decidim::GemManager.new(File.expand_path("..", __dir__)).run(
|
19
|
+
"gem build %name && gem install *.gem"
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Uninstalls all gems locally."
|
24
|
+
task :uninstall_all do
|
25
|
+
Decidim::GemManager.run_all(
|
26
|
+
"gem uninstall %name -v %version --executables --force"
|
27
|
+
)
|
28
|
+
|
29
|
+
Decidim::GemManager.new(File.expand_path("..", __dir__)).run(
|
30
|
+
"rm decidim-*.gem"
|
31
|
+
)
|
32
|
+
end
|
data/exe/decidim
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
if ARGV[0] == "--component"
|
5
|
+
ARGV.replace(["component", *ARGV[1..-1]])
|
6
|
+
|
7
|
+
require "decidim/generators/component_generator"
|
8
|
+
|
9
|
+
Decidim::Generators::ComponentGenerator.start
|
10
|
+
else
|
11
|
+
require "decidim/generators/app_generator"
|
12
|
+
|
13
|
+
Decidim::Generators::AppGenerator.start
|
14
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler"
|
4
|
+
require "rails/generators"
|
5
|
+
require "rails/generators/rails/app/app_generator"
|
6
|
+
require "decidim/generators/version"
|
7
|
+
require_relative "install_generator"
|
8
|
+
|
9
|
+
module Decidim
|
10
|
+
module Generators
|
11
|
+
# Generates a Rails app and installs decidim to it. Uses the default Rails
|
12
|
+
# generator for most of the work.
|
13
|
+
#
|
14
|
+
# Remember that, for how generators work, actions are executed based on the
|
15
|
+
# definition order of the public methods.
|
16
|
+
class AppGenerator < Rails::Generators::AppGenerator
|
17
|
+
hide!
|
18
|
+
|
19
|
+
def source_paths
|
20
|
+
[
|
21
|
+
self.class.source_root,
|
22
|
+
Rails::Generators::AppGenerator.source_root
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
source_root File.expand_path("app_templates", __dir__)
|
27
|
+
|
28
|
+
class_option :path, type: :string,
|
29
|
+
default: nil,
|
30
|
+
desc: "Path to the gem"
|
31
|
+
|
32
|
+
class_option :edge, type: :boolean,
|
33
|
+
default: false,
|
34
|
+
desc: "Use GitHub's edge version from master branch"
|
35
|
+
|
36
|
+
class_option :branch, type: :string,
|
37
|
+
default: nil,
|
38
|
+
desc: "Use a specific branch from GitHub's version"
|
39
|
+
|
40
|
+
class_option :recreate_db, type: :boolean,
|
41
|
+
default: false,
|
42
|
+
desc: "Recreate test database"
|
43
|
+
|
44
|
+
class_option :seed_db, type: :boolean,
|
45
|
+
default: false,
|
46
|
+
desc: "Seed test database"
|
47
|
+
|
48
|
+
class_option :skip_bundle, type: :boolean,
|
49
|
+
default: true,
|
50
|
+
desc: "Don't run bundle install"
|
51
|
+
|
52
|
+
class_option :skip_gemfile, type: :boolean,
|
53
|
+
default: false,
|
54
|
+
desc: "Don't generate a Gemfile for the application"
|
55
|
+
|
56
|
+
class_option :demo, type: :boolean,
|
57
|
+
default: false,
|
58
|
+
desc: "Generate a demo authorization handler"
|
59
|
+
|
60
|
+
def database_yml
|
61
|
+
template "database.yml.erb", "config/database.yml", force: true
|
62
|
+
end
|
63
|
+
|
64
|
+
def decidim_controller
|
65
|
+
template "decidim_controller.rb.erb", "app/controllers/decidim_controller.rb", force: true
|
66
|
+
end
|
67
|
+
|
68
|
+
def docker
|
69
|
+
template "Dockerfile.erb", "Dockerfile"
|
70
|
+
template "docker-compose.yml.erb", "docker-compose.yml"
|
71
|
+
end
|
72
|
+
|
73
|
+
def cable_yml
|
74
|
+
template "cable.yml.erb", "config/cable.yml", force: true
|
75
|
+
end
|
76
|
+
|
77
|
+
def readme
|
78
|
+
template "README.md.erb", "README.md", force: true
|
79
|
+
end
|
80
|
+
|
81
|
+
def gemfile
|
82
|
+
return if options[:skip_gemfile]
|
83
|
+
|
84
|
+
copy_file target_gemfile, "Gemfile", force: true
|
85
|
+
copy_file "#{target_gemfile}.lock", "Gemfile.lock", force: true
|
86
|
+
|
87
|
+
gem_modifier = if options[:path]
|
88
|
+
"path: \"#{options[:path]}\""
|
89
|
+
elsif options[:edge]
|
90
|
+
"git: \"https://github.com/decidim/decidim.git\""
|
91
|
+
elsif options[:branch]
|
92
|
+
"git: \"https://github.com/decidim/decidim.git\", branch: \"#{options[:branch]}\""
|
93
|
+
else
|
94
|
+
"\"#{Decidim::Generators.version}\""
|
95
|
+
end
|
96
|
+
|
97
|
+
gsub_file "Gemfile", /gem "#{current_gem}".*/, "gem \"#{current_gem}\", #{gem_modifier}"
|
98
|
+
gsub_file "Gemfile", /gem "decidim-dev".*/, "gem \"decidim-dev\", #{gem_modifier}" if current_gem == "decidim"
|
99
|
+
gsub_file "Gemfile", /gem "decidim-([A-z]+)".*/, "# gem \"decidim-\\1\", #{gem_modifier}"
|
100
|
+
gsub_file "Gemfile", /(# )?gem "decidim-dev".*/, "gem \"decidim-dev\", #{gem_modifier}" if current_gem == "decidim"
|
101
|
+
|
102
|
+
Bundler.with_original_env { run "bundle install" }
|
103
|
+
end
|
104
|
+
|
105
|
+
def add_ignore_uploads
|
106
|
+
append_file ".gitignore", "\n# Ignore public uploads\npublic/uploads" unless options["skip_git"]
|
107
|
+
end
|
108
|
+
|
109
|
+
def remove_default_error_pages
|
110
|
+
remove_file "public/404.html"
|
111
|
+
remove_file "public/500.html"
|
112
|
+
end
|
113
|
+
|
114
|
+
def authorization_handler
|
115
|
+
copy_file "initializer.rb", "config/initializers/decidim.rb"
|
116
|
+
|
117
|
+
copy_file "example_authorization_handler.rb", "app/services/example_authorization_handler.rb" if options[:demo]
|
118
|
+
end
|
119
|
+
|
120
|
+
def install
|
121
|
+
Decidim::Generators::InstallGenerator.start(
|
122
|
+
[
|
123
|
+
"--recreate_db=#{options[:recreate_db]}",
|
124
|
+
"--seed_db=#{options[:seed_db]}",
|
125
|
+
"--app_name=#{app_name}"
|
126
|
+
]
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def current_gem
|
133
|
+
return "decidim" unless options[:path]
|
134
|
+
|
135
|
+
File.read(gemspec).match(/name\s*=\s*['"](?<name>.*)["']/)[:name]
|
136
|
+
end
|
137
|
+
|
138
|
+
def gemspec
|
139
|
+
File.expand_path(Dir.glob("*.gemspec", base: expanded_path).first, expanded_path)
|
140
|
+
end
|
141
|
+
|
142
|
+
def target_gemfile
|
143
|
+
root = if options[:path]
|
144
|
+
expanded_path
|
145
|
+
else
|
146
|
+
root_path
|
147
|
+
end
|
148
|
+
|
149
|
+
File.join(root, "Gemfile")
|
150
|
+
end
|
151
|
+
|
152
|
+
def expanded_path
|
153
|
+
File.expand_path(options[:path])
|
154
|
+
end
|
155
|
+
|
156
|
+
def root_path
|
157
|
+
File.expand_path(File.join("..", "..", ".."), __dir__)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
FROM decidim/decidim:<%= Decidim::Generators.version %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# <%= app_name %>
|
2
|
+
|
3
|
+
Citizen Participation and Open Government application.
|
4
|
+
|
5
|
+
This is the open-source repository for <%= app_name %>, based on [Decidim](https://github.com/decidim/decidim).
|
6
|
+
|
7
|
+
## Setting up the application
|
8
|
+
|
9
|
+
You will need to do some steps before having the app working properly once you've deployed it:
|
10
|
+
|
11
|
+
1. Open a Rails console in the server: `bundle exec rails console`
|
12
|
+
2. Create a System Admin user:
|
13
|
+
```ruby
|
14
|
+
user = Decidim::System::Admin.new(email: <email>, password: <password>, password_confirmation: <password>)
|
15
|
+
user.save!
|
16
|
+
```
|
17
|
+
3. Visit `<your app url>/system` and login with your system admin credentials
|
18
|
+
4. Create a new organization. Check the locales you want to use for that organization, and select a default locale.
|
19
|
+
5. Set the correct default host for the organization, otherwise the app will not work properly. Note that you need to include any subdomain you might be using.
|
20
|
+
6. Fill the rest of the form and submit it.
|
21
|
+
|
22
|
+
You're good to go!
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Default CarrierWave setup.
|
4
|
+
#
|
5
|
+
CarrierWave.configure do |config|
|
6
|
+
config.permissions = 0o666
|
7
|
+
config.directory_permissions = 0o777
|
8
|
+
config.storage = :file
|
9
|
+
config.enable_processing = !Rails.env.test?
|
10
|
+
end
|
11
|
+
|
12
|
+
# Setup CarrierWave to use Amazon S3. Add `gem "fog-aws" to your Gemfile.
|
13
|
+
#
|
14
|
+
# CarrierWave.configure do |config|
|
15
|
+
# config.storage = :fog
|
16
|
+
# config.fog_provider = 'fog/aws' # required
|
17
|
+
# config.fog_credentials = {
|
18
|
+
# provider: 'AWS', # required
|
19
|
+
# aws_access_key_id: Rails.application.secrets.aws_access_key_id, # required
|
20
|
+
# aws_secret_access_key: Rails.application.secrets.aws_secret_access_key, # required
|
21
|
+
# region: 'eu-west-1', # optional, defaults to 'us-east-1'
|
22
|
+
# host: 's3.example.com', # optional, defaults to nil
|
23
|
+
# endpoint: 'https://s3.example.com:8080' # optional, defaults to nil
|
24
|
+
# }
|
25
|
+
# config.fog_directory = 'name_of_directory' # required
|
26
|
+
# config.fog_public = false # optional, defaults to true
|
27
|
+
# config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" } # optional, defaults to {}
|
28
|
+
# end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# PostgreSQL. Versions 9.1 and up are supported.
|
2
|
+
#
|
3
|
+
# Install the pg driver:
|
4
|
+
# gem install pg
|
5
|
+
# On OS X with Homebrew:
|
6
|
+
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
|
7
|
+
# On OS X with MacPorts:
|
8
|
+
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
|
9
|
+
# On Windows:
|
10
|
+
# gem install pg
|
11
|
+
# Choose the win32 build.
|
12
|
+
# Install PostgreSQL and put its /bin directory on your path.
|
13
|
+
#
|
14
|
+
# Configure Using Gemfile
|
15
|
+
# gem 'pg'
|
16
|
+
#
|
17
|
+
# On Linux, the 'host: "localhost"' line below should be commented out to avoid 'password required' error.
|
18
|
+
#
|
19
|
+
default: &default
|
20
|
+
adapter: postgresql
|
21
|
+
encoding: unicode
|
22
|
+
# For details on connection pooling, see rails configuration guide
|
23
|
+
# http://guides.rubyonrails.org/configuring.html#database-pooling
|
24
|
+
pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
25
|
+
host: <%%= ENV.fetch("DATABASE_HOST") { "localhost" } %>
|
26
|
+
username: <%%= ENV.fetch("DATABASE_USERNAME") { "" } %>
|
27
|
+
password: <%%= ENV.fetch("DATABASE_PASSWORD") { "" } %>
|
28
|
+
|
29
|
+
development:
|
30
|
+
<<: *default
|
31
|
+
database: <%%= ENV.fetch("DEV_DATABASE_NAME") { "<%= app_name %>_development" } %>
|
32
|
+
|
33
|
+
# The specified database role being used to connect to postgres.
|
34
|
+
# To create additional roles in postgres see `$ createuser --help`.
|
35
|
+
# When left blank, postgres will use the default role. This is
|
36
|
+
# the same name as the operating system user that initialized the database.
|
37
|
+
#username: <%= app_name %>
|
38
|
+
|
39
|
+
# The password associated with the postgres role (username).
|
40
|
+
#password:
|
41
|
+
|
42
|
+
# Connect on a TCP socket. Omitted by default since the client uses a
|
43
|
+
# domain socket that doesn't need configuration. Windows does not have
|
44
|
+
# domain sockets, so uncomment these lines.
|
45
|
+
#host: localhost
|
46
|
+
|
47
|
+
# The TCP port the server listens on. Defaults to 5432.
|
48
|
+
# If your server runs on a different port number, change accordingly.
|
49
|
+
#port: 5432
|
50
|
+
|
51
|
+
# Schema search path. The server defaults to $user,public
|
52
|
+
#schema_search_path: myapp,sharedapp,public
|
53
|
+
|
54
|
+
# Minimum log levels, in increasing order:
|
55
|
+
# debug5, debug4, debug3, debug2, debug1,
|
56
|
+
# log, notice, warning, error, fatal, and panic
|
57
|
+
# Defaults to warning.
|
58
|
+
#min_messages: notice
|
59
|
+
|
60
|
+
# Warning: The database defined as "test" will be erased and
|
61
|
+
# re-generated from your development database when you run "rake".
|
62
|
+
# Do not set this db to the same as development or production.
|
63
|
+
test:
|
64
|
+
<<: *default
|
65
|
+
database: <%%= ENV.fetch("TEST_DATABASE_NAME") { "<%= app_name %>_test" } %>
|
66
|
+
|
67
|
+
# As with config/secrets.yml, you never want to store sensitive information,
|
68
|
+
# like your database password, in your source code. If your source code is
|
69
|
+
# ever seen by anyone, they now have access to your database.
|
70
|
+
#
|
71
|
+
# Instead, provide the password as a unix environment variable when you boot
|
72
|
+
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
|
73
|
+
# for a full rundown on how to provide these environment variables in a
|
74
|
+
# production deployment.
|
75
|
+
#
|
76
|
+
# On some platform providers, you may have a full connection URL
|
77
|
+
# available as an environment variable. For example:
|
78
|
+
#
|
79
|
+
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
|
80
|
+
#
|
81
|
+
# You can use this database configuration with:
|
82
|
+
#
|
83
|
+
# production:
|
84
|
+
# url: <%%= ENV['DATABASE_URL'] %>
|
85
|
+
#
|
86
|
+
production:
|
87
|
+
url: <%%= ENV['DATABASE_URL'] %>
|