decidim 0.24.0 → 0.25.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of decidim might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Rakefile +1 -6
- data/babel.config.json +30 -0
- data/decidim-core/lib/decidim/webpacker/configuration.rb +89 -0
- data/decidim-core/lib/decidim/webpacker/postcss.config.js +16 -0
- data/decidim-core/lib/decidim/webpacker/runner.rb +24 -0
- data/decidim-core/lib/decidim/webpacker/webpack/base.js +6 -0
- data/decidim-core/lib/decidim/webpacker/webpack/custom.js +97 -0
- data/decidim-core/lib/decidim/webpacker/webpack/development.js +7 -0
- data/decidim-core/lib/decidim/webpacker/webpack/production.js +7 -0
- data/decidim-core/lib/decidim/webpacker/webpack/test.js +7 -0
- data/decidim-core/lib/decidim/webpacker/webpacker.yml +68 -0
- data/docs/README.adoc +1 -1
- data/docs/modules/configure/pages/initializer.adoc +31 -0
- data/docs/modules/customize/assets/images/modified_user_menu.png +0 -0
- data/docs/modules/customize/assets/images/original_user_menu.png +0 -0
- data/docs/modules/customize/pages/code.adoc +4 -1
- data/docs/modules/customize/pages/images.adoc +2 -2
- data/docs/modules/customize/pages/javascript.adoc +8 -3
- data/docs/modules/customize/pages/menu.adoc +56 -0
- data/docs/modules/customize/pages/styles.adoc +6 -3
- data/docs/modules/develop/pages/components.adoc +30 -0
- data/docs/modules/develop/pages/guide_migrate_webpacker_app.adoc +175 -0
- data/docs/modules/develop/pages/guide_migrate_webpacker_module.adoc +121 -0
- data/docs/modules/develop/pages/maps.adoc +2 -2
- data/docs/modules/develop/pages/newsletter_templates.adoc +1 -1
- data/docs/modules/develop/pages/releases.adoc +3 -1
- data/docs/modules/develop/pages/testing.adoc +11 -0
- data/docs/modules/develop/pages/view_models_aka_cells.adoc +1 -12
- data/docs/modules/install/pages/manual.adoc +46 -43
- data/docs/modules/install/pages/update.adoc +1 -1
- data/docs/modules/services/pages/elections_bulletin_board.adoc +19 -16
- data/docs/modules/services/pages/social_providers.adoc +1 -1
- data/lib/decidim.rb +0 -4
- data/lib/decidim/version.rb +1 -1
- data/lib/tasks/decidim_tasks.rake +92 -0
- data/package-lock.json +38919 -0
- data/package.json +67 -0
- data/packages/all/package.json +22 -0
- data/packages/browserslist-config/index.js +7 -0
- data/packages/browserslist-config/package.json +17 -0
- data/packages/core/package.json +53 -0
- data/packages/dev/package.json +21 -0
- data/packages/elections/package.json +21 -0
- data/packages/eslint-config/index.js +278 -0
- data/packages/eslint-config/package.json +28 -0
- data/packages/stylelint-config/index.js +160 -0
- data/packages/stylelint-config/package.json +20 -0
- data/packages/webpacker/index.js +6 -0
- data/packages/webpacker/package.json +55 -0
- data/packages/webpacker/src/override-config.js +50 -0
- metadata +83 -47
Binary file
|
Binary file
|
@@ -12,7 +12,10 @@ Most of the time, you should work with the generated application. That applicati
|
|
12
12
|
decidim DecidimBarcelona
|
13
13
|
----
|
14
14
|
|
15
|
-
If you want to override/change anything
|
15
|
+
If you want to override/change anything, you can just do it with the same name of the file, through Monkey Patching. Some real world examples of this method:
|
16
|
+
|
17
|
+
* https://github.com/gencat/participa/blob/master/app/decorators/decidim/admin/selective_newsletter_form_decorator.rb[Decidim::Admin::SelectiveNewsletterForm]. As it's a decorator you also need to make it available in the https://github.com/gencat/participa/blob/3416992ae095f6ab1e826fee961253514c4ff0ef/config/application.rb#L48[application config]
|
18
|
+
* https://github.com/barcelonaregional/decidim-premet25/blob/master/config/initializers/etiquette_validator.rb[EtiquetteValidator.class_eval]
|
16
19
|
|
17
20
|
If you want to extend Decidim, the prefered way should be by having a Module. This is a Ruby on Rails Engine which provides ruby code (models, views, controllers, assets, etc). You can use it through multiple ways:
|
18
21
|
|
@@ -2,6 +2,6 @@
|
|
2
2
|
|
3
3
|
You can change most of the images (for instance the logo, main banner on homepage, contents of participatory processes, etc) through the Administration panel.
|
4
4
|
|
5
|
-
|
5
|
+
As Decidim uses Webpacker, there's no way to override existing images including in Decidim.
|
6
6
|
|
7
|
-
If you want to add a new image you can do it as any Rails application, leaving it on your image's asset folder and using
|
7
|
+
If you want to add a new image you can do it as any Rails application, leaving it on your image's asset folder (`app/packs/images`) and using image_pack_tag helper (or asset_pack_path). You can see more documentation on http://guides.rubyonrails.org/webpacker.html[Rails guide].
|
@@ -2,9 +2,11 @@
|
|
2
2
|
|
3
3
|
You can add Javascript code by multiple ways in Decidim:
|
4
4
|
|
5
|
-
==
|
5
|
+
== Webpacker
|
6
6
|
|
7
|
-
|
7
|
+
Decidim uses Webpack (via Webpacker) to compile assets, including javascript.
|
8
|
+
|
9
|
+
During the generation of a decidim app, the file `app/packs/src/decidim/decidim_application.js` is created and hooked to Decidim packs, so any javascript written there is compiled within Decidim assets. For example to create a new alert just add:
|
8
10
|
|
9
11
|
[source,javascript]
|
10
12
|
----
|
@@ -13,7 +15,10 @@ $(function(){
|
|
13
15
|
});
|
14
16
|
----
|
15
17
|
|
16
|
-
More information in https://guides.rubyonrails.org/
|
18
|
+
More information in https://guides.rubyonrails.org/webpacker.html[Rails Webpacker documentation].
|
19
|
+
|
20
|
+
If you want to replace a whole file existin in Decidim you can do it by creating a file in your application with the same name and the same path. I.e: to replace `decidim-core/app/packs/src/decidim/editor.js` you should create in your Rails app a file in
|
21
|
+
`app/packs/src/decidim/editor.js` and it will have more priority over the Decidim file.
|
17
22
|
|
18
23
|
== Head extra file
|
19
24
|
|
@@ -19,6 +19,62 @@ Depending in the kind of space and module, then you can see or not some of the s
|
|
19
19
|
- For conferences, you need to enable the module and it appears when there's some published content by an administrator.
|
20
20
|
- For initiatives, you need to enable the module. Every participant can see it, as anyone can create one. That's because is a bottom-up kind of mechanism.
|
21
21
|
|
22
|
+
Starting with 0.25.dev, Decidim Menu Api has been modified, in order to improve developer and administrators experience.
|
23
|
+
The changes on the menu has deprecated the previous `menu.item` call, in favour of `menu.add_item` that has the following structure:
|
24
|
+
[source,ruby]
|
25
|
+
....
|
26
|
+
menu.add_item :identifier, # String or symbol to uniquely define the menu
|
27
|
+
link_caption,
|
28
|
+
link_path or url
|
29
|
+
options: {
|
30
|
+
position: # Optional,
|
31
|
+
if: # Optional,
|
32
|
+
active: # Optional,
|
33
|
+
icon_name: # Optional ,
|
34
|
+
submenu: # Optional,
|
35
|
+
}
|
36
|
+
....
|
37
|
+
|
38
|
+
|
39
|
+
Additionally, the new menu api will allow to interact with the menu in several ways:
|
40
|
+
[source,ruby]
|
41
|
+
....
|
42
|
+
Decidim.menu :user_menu do |menu|
|
43
|
+
menu.remove_item :identifier
|
44
|
+
menu.move :identifier, after: :anchor_identifier
|
45
|
+
menu.move :identifier, before: :anchor_identifier
|
46
|
+
end
|
47
|
+
....
|
48
|
+
|
49
|
+
|
50
|
+
== Example usage:
|
51
|
+
Starting from a default menu like:
|
52
|
+
|
53
|
+
image::original_user_menu.png[Decidim Menu]
|
54
|
+
|
55
|
+
After applying the below initializer, the menu rendering will be modified to:
|
56
|
+
[source,ruby]
|
57
|
+
....
|
58
|
+
# config/initializers/decidim.user_menu.rb
|
59
|
+
|
60
|
+
Decidim.menu :user_menu do |menu|
|
61
|
+
menu.remove_item :user_interests
|
62
|
+
menu.move :own_user_groups, after: :account
|
63
|
+
menu.move :authorizations, before: :notifications_settings
|
64
|
+
end
|
65
|
+
....
|
66
|
+
|
67
|
+
image::modified_user_menu.png[Decidim Menu]
|
68
|
+
|
69
|
+
== The menu Structure
|
70
|
+
Decidim uses internally a number of menus that are being used in various admin sections.
|
71
|
+
Those menus are being defined inside the engine or admin_engine file of a decidim module.
|
72
|
+
The menus are being defined as `Decidim.menu :identifier`. In order to render those menus, there are a number of methods that can be used:
|
73
|
+
|
74
|
+
- main_menu in admin section
|
75
|
+
- sidebar_menu will render the secondary admin section
|
76
|
+
- simple_menu will render any submenus
|
77
|
+
|
22
78
|
There's also a https://github.com/OpenSourcePolitics/decidim-module-navbar_links[NavBar links module] made by the community that you can use to add your custom links.
|
23
79
|
|
24
80
|
Finally if you want to dive in the code that handles this, a good starting point is the https://rubydoc.info/github/decidim/decidim/develop/Decidim/Menu[Menu API].
|
@@ -50,11 +50,14 @@ image::header-snippet.png[Header snippet]
|
|
50
50
|
|
51
51
|
Notice that you can resize this textarea.
|
52
52
|
|
53
|
-
==
|
53
|
+
== Webpacker
|
54
54
|
|
55
|
-
|
55
|
+
Decidim uses Webpacker to compile assets. There are two ways to customize CSS:
|
56
56
|
|
57
|
-
|
57
|
+
1. if you want to redefine just CSS vars or Foundation settings, use _decidim-settings.scss
|
58
|
+
2. if you want to redefine a specific snippet of CSS (let's say a few classes but not a whole file) you can use decidim_application.scss
|
59
|
+
3. and of course you can overwrite whole files by copying them into the application i.e: to replace `decidim-core/app/packs/stylesheets/modules/_cookie-bar.scss` you should create in your Rails app a file in
|
60
|
+
`app/packs/stylesheets/modules/_cookie-bar.scss` and it will have more priority over the Decidim file.
|
58
61
|
|
59
62
|
We use http://sass-lang.com/guide[SASS, with SCSS syntax] as CSS preprocessor.
|
60
63
|
|
@@ -135,3 +135,33 @@ This sections explains how to add dummy content to a development application.
|
|
135
135
|
|
136
136
|
* Take advantage of the Faker gem, already in decidim.
|
137
137
|
* If you need content for i18n fields, you can use https://github.com/decidim/decidim/blob/develop/decidim-core/lib/decidim/faker/localized.rb[Localizaed], which uses `Faker` internally.
|
138
|
+
|
139
|
+
== Assets
|
140
|
+
|
141
|
+
In order to attach the new component assets to Webpacker configuration, you need to follow a few steps. We are considering two scenarios:
|
142
|
+
|
143
|
+
- while the component is being developed, where changes in Webpacker configuration should be done in the development for simplicity
|
144
|
+
- once the component has been completed, change the Webpacker templates for the app generators
|
145
|
+
|
146
|
+
In both cases, changes are the same:
|
147
|
+
|
148
|
+
1. Add the new component `app/packs` folder to webpacker.yml
|
149
|
+
2. Add the new entrypoints of the component to `config/webpack/custom.js`
|
150
|
+
|
151
|
+
=== Updating the development application
|
152
|
+
|
153
|
+
While the component is being developed, it'll be simpler and faster to update Webpacker configuration inside the development app. The new component `app/packs` folder needs to be added to the list of paths that Webpack will use to look for assets.
|
154
|
+
|
155
|
+
Also, components might have one or many entrypoints (for CSSs and javascripts) and images. These entrypoints need to be manually added to `config/webpack/custom.js`. **Any change in both files** requires to restart `webpack-dev-server` process.
|
156
|
+
|
157
|
+
Take into account that generating a new development application **overwrites** Webpacker configuration so these changes might be overwriten. That's why it's necessary, once the changes are stable enough, to update the generators files.
|
158
|
+
|
159
|
+
=== Updating Webpacker configuration for the generators
|
160
|
+
|
161
|
+
Decidim webpacker configuration lives in `decidim-core/lib/decidim/webpacker`. Any change performed in the development app should be replicated in these files.
|
162
|
+
|
163
|
+
Also, any npm package added to package.json should be replicated in Decidim package.json file.
|
164
|
+
|
165
|
+
=== Updating the design app
|
166
|
+
|
167
|
+
These changes should also be translated to the design app `config/webpacker.yml` and `config/webpack/custom.js` files. And if there are changes in the npm packages, these should be moved to.
|
@@ -0,0 +1,175 @@
|
|
1
|
+
= Migrate to Webpacker an instance app
|
2
|
+
|
3
|
+
In order to migrate an existing Decidim app to Webpacker, there are a few changes your need to run in your code.
|
4
|
+
|
5
|
+
Disclaimer: this recipe might not work for all the cases, it tries to cover the generic scenarios. If you find yourself with a complex scenario and want to improve this guide feel free to open a PR to complete the guide.
|
6
|
+
|
7
|
+
== About Webpacker
|
8
|
+
|
9
|
+
It's recommended to understand how Webpacker works. More information:
|
10
|
+
|
11
|
+
* https://github.com/rails/webpacker#usage
|
12
|
+
* https://edgeguides.rubyonrails.org/webpacker.html
|
13
|
+
|
14
|
+
== Requirements
|
15
|
+
|
16
|
+
Before starting the migration, please check you have the following dependencies installed:
|
17
|
+
|
18
|
+
- Node.js version 15.14.0 (this version is mandatory)
|
19
|
+
- Npm version 7.7.0 (it works with other versions, but this is the recommended)
|
20
|
+
|
21
|
+
== Add Webpacker to the application
|
22
|
+
|
23
|
+
Follow the steps described https://github.com/rails/webpacker#installation[here]
|
24
|
+
|
25
|
+
- Install it
|
26
|
+
|
27
|
+
[source,console]
|
28
|
+
----
|
29
|
+
bundle exec rails webpacker:install
|
30
|
+
----
|
31
|
+
|
32
|
+
* Install Decidim webpacker custom code
|
33
|
+
|
34
|
+
[source,console]
|
35
|
+
----
|
36
|
+
bundle exec rails decidim:webpacker:install
|
37
|
+
----
|
38
|
+
|
39
|
+
This task do a few steps to allow the Rails instance to have a webpacker instance sharing the code between itself and Decidim gem.
|
40
|
+
|
41
|
+
This task is automatically performed every time decidim is updated, to get the latest Webpack configuration. This happens when you run the `decidim:upgrade` task.
|
42
|
+
|
43
|
+
== Copy Decidim custom CSS and Javascript
|
44
|
+
|
45
|
+
`webpacker:install` task should have created to you the following dirs structure:
|
46
|
+
|
47
|
+
[source,console]
|
48
|
+
----
|
49
|
+
app/packs:
|
50
|
+
├── entrypoints
|
51
|
+
└── src
|
52
|
+
└── stylesheets
|
53
|
+
└── images
|
54
|
+
----
|
55
|
+
|
56
|
+
If it's not the case you must create it. Then, copy Decidim customizable assets
|
57
|
+
|
58
|
+
* Copy the file https://github.com/decidim/decidim/blob/develop/decidim-generators/lib/decidim/generators/app_templates/decidim_application.js[decidim_application.js] to `app/packs/src/decidim/decidim_application.js`
|
59
|
+
* Copy the file https://github.com/decidim/decidim/blob/develop/decidim-generators/lib/decidim/generators/app_templates/decidim_application.scss[decidim_application.scss] to `app/packs/stylesheets/decidim/decidim_application.scss`
|
60
|
+
* Copy the file https://github.com/decidim/decidim/blob/develop/decidim-generators/lib/decidim/generators/app_templates/_decidim-settings.scss[_decidim-settings.scss] to `app/packs/stylesheets/decidim/_decidim-settings.scss`
|
61
|
+
|
62
|
+
These files are hooked into Decidim packs (specifically into decidim-core pack) and will be automatically included inside that pack when compiled.
|
63
|
+
|
64
|
+
== Migrate images
|
65
|
+
|
66
|
+
Copy the existing images from `app/assets/images` to `app/packs/images`. Images will be available at `/media/images/image.png`
|
67
|
+
|
68
|
+
== Migrate stylesheets
|
69
|
+
|
70
|
+
Existing stylesheets should be moved from `app/assets/stylesheets` to `app/packs/stylesheets` and imported with `@import` into `decidim_application.scss`. Take into account that you might need to adjust a bit the paths of the `@import` to adjust them to the new locations.
|
71
|
+
|
72
|
+
If that CSS file is replacing a Decidim file, there's no need to add it to `decidim_application.scss`.
|
73
|
+
|
74
|
+
If any of the CSS is re-defining CSS vars add them to `_decidim-settings.scss`.
|
75
|
+
|
76
|
+
== Migrate javascripts
|
77
|
+
|
78
|
+
Existing javascripts should be moved from `app/assets/javascsripts` to `app/packs/src` and imported with `import` into `decidim_application.js`. Take into account that you might need to adjust a bit the paths of the `import` to adjust them to the new locations.
|
79
|
+
|
80
|
+
If that JS file is replacing a Decidim file, there's no need to add it to `decidim_application.js`
|
81
|
+
|
82
|
+
== Update Rails helpers
|
83
|
+
|
84
|
+
`javascript_include_tag` and `stylesheet_link_tag` have been replaced by `javascript_pack_tag` and `stylesheet_pack_tag`.
|
85
|
+
|
86
|
+
For images, if they are in `app/packs/images` you could use `image_pack_tag`.
|
87
|
+
|
88
|
+
== Migrate vendorized files and gems
|
89
|
+
|
90
|
+
Sometimes assets are included in `vendor/assets/` folder or imported from gems. For each specific one you should check:
|
91
|
+
|
92
|
+
1. if the asset is a javascript that is available as npm package the recommendation is to add it to package.json with `npm install`. If it's not available you might want to copy it to `app/packs/src` and import it.
|
93
|
+
2. if the asset is a stylesheet it should be copied to `app/packs/stylesheets` and imported with `@import...` from `_decidim-settings.scss`. Alternatively you can use the optional asset includes as described below to include these in the Decidim main SCSS files.
|
94
|
+
|
95
|
+
== Optional asset includes
|
96
|
+
|
97
|
+
Decidim Webpacker provides a new configuration convention that allows you to add extra configurations for webpacker using a configuration file named `config/assets.rb`. Within this file, you have the following API methods available:
|
98
|
+
|
99
|
+
[source,ruby]
|
100
|
+
----
|
101
|
+
# frozen_string_literal: true
|
102
|
+
# This file is located at `config/assets.rb` of your module.
|
103
|
+
|
104
|
+
# Define the base path of your module. Please note that `Rails.root` may not be
|
105
|
+
# used because we are not inside the Rails environment when this file is loaded.
|
106
|
+
base_path = File.expand_path("..", __dir__)
|
107
|
+
|
108
|
+
# If you want to import some extra SCSS files in the Decidim main SCSS file
|
109
|
+
# without adding any extra stylesheet inclusion tags, you can use the following
|
110
|
+
# method to register the stylesheet import for the main application. This would
|
111
|
+
# include an SCSS file at `app/packs/stylesheets/your_app_extensions.scss` into
|
112
|
+
# the Decidim's main SCSS file.
|
113
|
+
Decidim::Webpacker.register_stylesheet_import("stylesheets/your_app_extensions")
|
114
|
+
|
115
|
+
# If you want to do the same but include the SCSS file for the admin panel's
|
116
|
+
# main SCSS file, you can use the following method.
|
117
|
+
Decidim::Webpacker.register_stylesheet_import("stylesheets/your_app_admin_extensions", group: :admin)
|
118
|
+
----
|
119
|
+
|
120
|
+
== Remove Sprockets references
|
121
|
+
|
122
|
+
The completely remove Sprockets references from your application:
|
123
|
+
|
124
|
+
* Review your Gemfile and remove any reference to `sprockets` and `sassc-rails`
|
125
|
+
* Remove `config/initializers/assets.rb`
|
126
|
+
* Remove `app/assets` folder
|
127
|
+
* In `config/application.rb` replace:
|
128
|
+
|
129
|
+
[source,ruby]
|
130
|
+
----
|
131
|
+
require 'rails/all'
|
132
|
+
----
|
133
|
+
|
134
|
+
with:
|
135
|
+
|
136
|
+
[source,ruby]
|
137
|
+
----
|
138
|
+
require "decidim/rails"
|
139
|
+
# Add the frameworks used by your app that are not loaded by Decidim.
|
140
|
+
# require "action_cable/engine"
|
141
|
+
# require "action_mailbox/engine"
|
142
|
+
# require "action_text/engine"
|
143
|
+
----
|
144
|
+
|
145
|
+
* In `config/environments/*.rb` remove any line containing `config.assets.*` (i.e `config.assets.debug = true`)
|
146
|
+
|
147
|
+
== Deployment
|
148
|
+
|
149
|
+
The deployment needs to be updated to manually run `npm install` before assets are precompiled.
|
150
|
+
|
151
|
+
In the case of Capistrano this can be done with a before hook:
|
152
|
+
|
153
|
+
[source,ruby]
|
154
|
+
----
|
155
|
+
namespace :deploy do
|
156
|
+
desc "Decidim webpacker configuration"
|
157
|
+
task :decidim_webpacker_install do
|
158
|
+
on roles(:all) do
|
159
|
+
within release_path do
|
160
|
+
with rails_env: fetch(:rails_env) do
|
161
|
+
execute "npm ci"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
before "deploy:assets:precompile", "deploy:decidim_webpacker_install"
|
168
|
+
end
|
169
|
+
----
|
170
|
+
|
171
|
+
Also, in the case of Capistrano it's interesting to add to the shared_paths the following folders:
|
172
|
+
|
173
|
+
* `tmp/webpacker-cache`
|
174
|
+
* `node_modules`
|
175
|
+
* `public/decidim-packs`
|
@@ -0,0 +1,121 @@
|
|
1
|
+
= Migrate to Webpacker a Decidim module
|
2
|
+
|
3
|
+
Decidim modules are included to Decidim apps as gems. Since the introduction of Webpacker to manage and compile assets in Decidim, there are some changes required to make modules compatible with Decidim
|
4
|
+
|
5
|
+
== About Webpacker
|
6
|
+
|
7
|
+
It's recommended to understand how Webpacker works. More information:
|
8
|
+
|
9
|
+
* https://github.com/rails/webpacker#usage
|
10
|
+
* https://edgeguides.rubyonrails.org/webpacker.html
|
11
|
+
|
12
|
+
== Overview
|
13
|
+
|
14
|
+
The recommended way to import assets from a gem in a Rails app using Webpacker is to publish a package in npmjs.org and include it in the package.json via `npm install`. Then the assets are available to Webpack via node_modules/ folder
|
15
|
+
|
16
|
+
Once created, you should update the instructions to install the module and add the step to add the assets with npm.
|
17
|
+
|
18
|
+
== Folder migration
|
19
|
+
|
20
|
+
It's recommend to migrate to the new folders structure:
|
21
|
+
|
22
|
+
```
|
23
|
+
app/packs:
|
24
|
+
├── entrypoints
|
25
|
+
└── src
|
26
|
+
└── stylesheets
|
27
|
+
└── images
|
28
|
+
```
|
29
|
+
|
30
|
+
== Update Rails helpers
|
31
|
+
|
32
|
+
`javascript_include_tag` and `stylesheet_link_tag` have been replaced by `javascript_pack_tag` and `stylesheet_pack_tag`
|
33
|
+
|
34
|
+
For images, if they are in `app/packs/images` you could use `image_pack_tag`.
|
35
|
+
|
36
|
+
== Asset compilation
|
37
|
+
|
38
|
+
As all assets are now compiled using Webpacker without ever loading the Rails or Decidim environment, there are some new conventions how to tell Webpacker about the Decidim module's assets.
|
39
|
+
|
40
|
+
To begin with, create a new file named `config/assets.rb` inside your Decidim module.
|
41
|
+
|
42
|
+
After this, add the following contents in that file, depending what kind of assets your module provides:
|
43
|
+
|
44
|
+
[source,ruby]
|
45
|
+
----
|
46
|
+
# frozen_string_literal: true
|
47
|
+
# This file is located at `config/assets.rb` of your module.
|
48
|
+
|
49
|
+
# Define the base path of your module. Please note that `Rails.root` may not be
|
50
|
+
# used because we are not inside the Rails environment when this file is loaded.
|
51
|
+
base_path = File.expand_path("..", __dir__)
|
52
|
+
|
53
|
+
# Register an additional load path for webpack. All the assets within these
|
54
|
+
# directories will be available for inclusion within the Decidim assets. For
|
55
|
+
# example, if you have `app/packs/src/decidim/foo.js`, you can include that file
|
56
|
+
# in your JavaScript entrypoints (or other JavaScript files within Decidim)
|
57
|
+
# using `import "src/decidim/foo"` after you have registered the additional path
|
58
|
+
# as follows.
|
59
|
+
Decidim::Webpacker.register_path("#{base_path}/app/packs")
|
60
|
+
|
61
|
+
# Register the entrypoints for your module. These entrypoints can be included
|
62
|
+
# within your application using `javascript_pack_tag` and if you include any
|
63
|
+
# SCSS files within the entrypoints, they become available for inclusion using
|
64
|
+
# `stylesheet_pack_tag`.
|
65
|
+
Decidim::Webpacker.register_entrypoints(
|
66
|
+
decidim_foo: "#{base_path}/app/packs/entrypoints/decidim_foo.js",
|
67
|
+
decidim_foo_admin: "#{base_path}/app/packs/entrypoints/decidim_foo_admin.js"
|
68
|
+
)
|
69
|
+
|
70
|
+
# If you want to import some extra SCSS files in the Decidim main SCSS file
|
71
|
+
# without adding any extra stylesheet inclusion tags, you can use the following
|
72
|
+
# method to register the stylesheet import for the main application.
|
73
|
+
Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/foo/app")
|
74
|
+
|
75
|
+
# If you want to do the same but include the SCSS file for the admin panel's
|
76
|
+
# main SCSS file, you can use the following method.
|
77
|
+
Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/foo/admin", group: :admin)
|
78
|
+
|
79
|
+
# If you want to override some SCSS variables/settings for Foundation from the
|
80
|
+
# module, you can add the following registered import.
|
81
|
+
Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/foo/settings", type: :settings)
|
82
|
+
|
83
|
+
# If you want to do the same but override the SCSS variables of the admin
|
84
|
+
# panel's styles, you can use the following method.
|
85
|
+
Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/foo/admin_settings", type: :settings, group: :admin)
|
86
|
+
----
|
87
|
+
|
88
|
+
== Component stylesheet migration
|
89
|
+
|
90
|
+
In older Decidim versions your components could define their own stylesheet as follows:
|
91
|
+
|
92
|
+
[source,ruby]
|
93
|
+
----
|
94
|
+
Decidim.register_component(:your_component) do |component|
|
95
|
+
component.engine = Decidim::YourComponent::Engine
|
96
|
+
component.stylesheet = "decidim/your_component/your_component"
|
97
|
+
component.admin_stylesheet = "decidim/your_component/your_component_admin"
|
98
|
+
end
|
99
|
+
----
|
100
|
+
|
101
|
+
These were automatically included in the main application's stylesheet file and also in the admin panel's stylesheet file. These no longer work with Webpacker as the Decidim environment is not loaded when Webpacker compiles the assets.
|
102
|
+
|
103
|
+
What you should do instead is to follow the asset compilation migration guide above and migrate these definitions into your module's `config/assets.rb` file as follows:
|
104
|
+
|
105
|
+
[source,ruby]
|
106
|
+
----
|
107
|
+
# frozen_string_literal: true
|
108
|
+
# This file is located at `config/assets.rb` of your module.
|
109
|
+
|
110
|
+
base_path = File.expand_path("..", __dir__)
|
111
|
+
|
112
|
+
# Register the additonal path for Webpacker in order to make the module's
|
113
|
+
# stylesheets available for inclusion.
|
114
|
+
Decidim::Webpacker.register_path("#{base_path}/app/packs")
|
115
|
+
|
116
|
+
# Register the main application's stylesheet include statement:
|
117
|
+
Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/your_component/your_component")
|
118
|
+
|
119
|
+
# Register the admin panel's stylesheet include statement:
|
120
|
+
Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/your_component/your_component_admin", group: :admin)
|
121
|
+
----
|