decidim 0.24.3 → 0.25.0.rc4

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.

Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +28 -8
  3. data/babel.config.json +30 -0
  4. data/decidim-core/lib/decidim/webpacker/configuration.rb +89 -0
  5. data/decidim-core/lib/decidim/webpacker/postcss.config.js +16 -0
  6. data/decidim-core/lib/decidim/webpacker/runner.rb +24 -0
  7. data/decidim-core/lib/decidim/webpacker/webpack/base.js +6 -0
  8. data/decidim-core/lib/decidim/webpacker/webpack/custom.js +97 -0
  9. data/decidim-core/lib/decidim/webpacker/webpack/development.js +7 -0
  10. data/decidim-core/lib/decidim/webpacker/webpack/production.js +7 -0
  11. data/decidim-core/lib/decidim/webpacker/webpack/test.js +7 -0
  12. data/decidim-core/lib/decidim/webpacker/webpacker.yml +65 -0
  13. data/docs/README.adoc +1 -1
  14. data/docs/modules/configure/pages/initializer.adoc +31 -0
  15. data/docs/modules/customize/assets/images/modified_user_menu.png +0 -0
  16. data/docs/modules/customize/assets/images/original_user_menu.png +0 -0
  17. data/docs/modules/customize/pages/code.adoc +4 -1
  18. data/docs/modules/customize/pages/images.adoc +2 -2
  19. data/docs/modules/customize/pages/javascript.adoc +8 -3
  20. data/docs/modules/customize/pages/menu.adoc +56 -0
  21. data/docs/modules/customize/pages/styles.adoc +6 -3
  22. data/docs/modules/develop/pages/components.adoc +30 -0
  23. data/docs/modules/develop/pages/guide_migrate_webpacker_app.adoc +175 -0
  24. data/docs/modules/develop/pages/guide_migrate_webpacker_module.adoc +121 -0
  25. data/docs/modules/develop/pages/maps.adoc +2 -2
  26. data/docs/modules/develop/pages/newsletter_templates.adoc +1 -1
  27. data/docs/modules/develop/pages/releases.adoc +3 -1
  28. data/docs/modules/develop/pages/testing.adoc +11 -0
  29. data/docs/modules/develop/pages/view_models_aka_cells.adoc +1 -12
  30. data/docs/modules/install/pages/manual.adoc +46 -43
  31. data/docs/modules/services/pages/elections_bulletin_board.adoc +19 -16
  32. data/docs/modules/services/pages/social_providers.adoc +1 -1
  33. data/lib/decidim/gem_manager.rb +39 -18
  34. data/lib/decidim/version.rb +1 -1
  35. data/lib/decidim.rb +0 -4
  36. data/lib/tasks/decidim_tasks.rake +92 -0
  37. data/package-lock.json +36038 -0
  38. data/package.json +71 -0
  39. data/packages/browserslist-config/index.js +7 -0
  40. data/packages/browserslist-config/package.json +13 -0
  41. data/packages/core/node_modules/uuid/AUTHORS +5 -0
  42. data/packages/core/node_modules/uuid/CHANGELOG.md +119 -0
  43. data/packages/core/node_modules/uuid/LICENSE.md +21 -0
  44. data/packages/core/node_modules/uuid/README.md +276 -0
  45. data/packages/core/node_modules/uuid/bin/uuid +65 -0
  46. data/packages/core/node_modules/uuid/index.js +8 -0
  47. data/packages/core/node_modules/uuid/lib/bytesToUuid.js +26 -0
  48. data/packages/core/node_modules/uuid/lib/md5-browser.js +216 -0
  49. data/packages/core/node_modules/uuid/lib/md5.js +25 -0
  50. data/packages/core/node_modules/uuid/lib/rng-browser.js +34 -0
  51. data/packages/core/node_modules/uuid/lib/rng.js +8 -0
  52. data/packages/core/node_modules/uuid/lib/sha1-browser.js +89 -0
  53. data/packages/core/node_modules/uuid/lib/sha1.js +25 -0
  54. data/packages/core/node_modules/uuid/lib/v35.js +57 -0
  55. data/packages/core/node_modules/uuid/package.json +49 -0
  56. data/packages/core/node_modules/uuid/v1.js +109 -0
  57. data/packages/core/node_modules/uuid/v3.js +4 -0
  58. data/packages/core/node_modules/uuid/v4.js +29 -0
  59. data/packages/core/node_modules/uuid/v5.js +3 -0
  60. data/packages/core/package.json +53 -0
  61. data/packages/dev/package.json +15 -0
  62. data/packages/elections/package.json +17 -0
  63. data/packages/eslint-config/index.js +278 -0
  64. data/packages/eslint-config/package.json +24 -0
  65. data/packages/stylelint-config/index.js +160 -0
  66. data/packages/stylelint-config/package.json +16 -0
  67. data/packages/webpacker/index.js +6 -0
  68. data/packages/webpacker/package.json +50 -0
  69. data/packages/webpacker/src/override-config.js +52 -0
  70. metadata +92 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7503d95371a406035b6bb81ded1ca7b8debf8d5257845430467bee73401cee20
4
- data.tar.gz: bd9c485d073ad5a99c5f5b60e61d552823830a17fc92031ad89a15b9d5d2cd71
3
+ metadata.gz: 669bd9a525ab33dd37ea3b2aa68e644ff34751595edad6c70714f7d73314f3da
4
+ data.tar.gz: 0dda19b573c625137eac6f17764b75abc0067e87ab3eed8bb824c839829a4620
5
5
  SHA512:
6
- metadata.gz: 4db1328d71a3edf2917f36cc269af163cf6fc92d8f8d33dc321c930fa467fcee3a03bdc9aacbfcd70ff7881e27090c81ab409984378afd491f06441f748cee5a
7
- data.tar.gz: d627d0c55e62a530dfcce0b073a0f879dd38304911bf9784853ff01a4c470df58c8b5e533742dff8d4fc44187fef687540b735147311efba03f55879c3feba27
6
+ metadata.gz: 386340222687878a528eac94e36d28e0bcdb5c2f6ed9ea0bd0af2b4b490d9eafa6302580170f56b2d8a3e44d7c7a5c843e0e6f7b086d662f2a06be897fc649a3
7
+ data.tar.gz: e7019090a58beb62bf011681d017ed3c9844b9fbb56a53b5988538e55a096553de478f493e3a0834e8fbccb3d5c69ece06fb874be8af313844898bbef0b2b047
data/Rakefile CHANGED
@@ -56,9 +56,10 @@ task :uninstall_all do
56
56
  Decidim::GemManager.uninstall_all
57
57
  end
58
58
 
59
- desc "Pushes a new build for each gem."
60
- task release_all: [:update_versions, :check_locale_completeness, :webpack] do
59
+ desc "Pushes a new build for each gem and package."
60
+ task release_all: [:update_versions, :check_locale_completeness] do
61
61
  Decidim::GemManager.run_all("rake release")
62
+ Decidim::GemManager.run_packages("npm publish --access public")
62
63
  end
63
64
 
64
65
  desc "Makes sure all official locales are complete and clean."
@@ -74,17 +75,36 @@ task test_app: "decidim:generate_external_test_app"
74
75
  desc "Generates a development app."
75
76
  task development_app: "decidim:generate_external_development_app"
76
77
 
77
- desc "Build webpack bundle files"
78
- task :webpack do
79
- sh "npm install && npm run build:prod"
80
- end
81
-
82
78
  desc "Bundle all Gemfiles"
83
79
  task :bundle do
84
80
  [".", "decidim-generators", "decidim_app-design"].each do |dir|
85
81
  Bundler.with_original_env do
86
82
  puts "Updating #{dir}...\n"
87
- Dir.chdir(dir) { sh "bundle install" }
83
+ system!("bundle install", dir)
88
84
  end
89
85
  end
90
86
  end
87
+
88
+ desc "Synchronize npm packages files on the whole repo"
89
+ task :webpack do
90
+ FileUtils.rm_rf(decidim_app_design_path.join("package-lock.json"))
91
+ FileUtils.rm_rf(decidim_app_design_path.join("packages"))
92
+ FileUtils.cp_r(root_folder.join("package.json"), decidim_app_design_path)
93
+ FileUtils.cp_r(root_folder.join("package-lock.json"), decidim_app_design_path)
94
+ FileUtils.cp_r(root_folder.join("packages"), decidim_app_design_path)
95
+
96
+ system!("npm install", root_folder)
97
+ system!("npm install", decidim_app_design_path)
98
+ end
99
+
100
+ def root_folder
101
+ @root_folder ||= Pathname.new(__dir__)
102
+ end
103
+
104
+ def decidim_app_design_path
105
+ @decidim_app_design_path ||= Pathname.new(root_folder.join("decidim_app-design"))
106
+ end
107
+
108
+ def system!(command, path)
109
+ system("cd #{path} && #{command}") || abort("\n== Command #{command} failed ==")
110
+ end
data/babel.config.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "@babel/preset-env", {
5
+ "forceAllTransforms": true,
6
+ "useBuiltIns": "entry",
7
+ "corejs": 3,
8
+ "modules": false
9
+ }
10
+ ],
11
+ ["@babel/preset-react"]
12
+ ],
13
+ "plugins": [
14
+ "@babel/plugin-transform-classes",
15
+ [
16
+ "@babel/plugin-transform-runtime",
17
+ {
18
+ "helpers": false,
19
+ "regenerator": true,
20
+ "corejs": false
21
+ }
22
+ ],
23
+ [
24
+ "@babel/plugin-transform-regenerator",
25
+ {
26
+ "async": false
27
+ }
28
+ ]
29
+ ]
30
+ }
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Webpacker
5
+ class Configuration
6
+ attr_reader :additional_paths, :entrypoints, :stylesheet_imports
7
+
8
+ def initialize
9
+ @additional_paths = []
10
+ @entrypoints = {}
11
+ @stylesheet_imports = {}
12
+ end
13
+
14
+ def configuration_file
15
+ # Before webpacker is installed, the original configuration file may not
16
+ # be available yet.
17
+ return unless File.exist?(original_configuration_file_path)
18
+ return configuration_file_path if configurations_loaded?
19
+
20
+ load_asset_configurations
21
+
22
+ # Read the original configuration and append the paths
23
+ config = YAML.load_file(original_configuration_file_path)
24
+ default = config["default"] || {}
25
+ all_additional_paths = default["additional_paths"] || []
26
+ all_additional_paths += additional_paths
27
+ all_stylesheet_imports = default["stylesheet_imports"] || {}
28
+ all_stylesheet_imports.merge!(stylesheet_imports)
29
+ all_entrypoints = default["entrypoints"] || {}
30
+ all_entrypoints.merge!(entrypoints)
31
+ config.each do |environment, env_config|
32
+ config[environment] = env_config.merge(
33
+ "additional_paths" => all_additional_paths,
34
+ "entrypoints" => all_entrypoints,
35
+ "stylesheet_imports" => all_stylesheet_imports
36
+ )
37
+ end
38
+
39
+ # Write the runtime configuration and override the configuration
40
+ File.write(configuration_file_path, config.to_yaml)
41
+
42
+ self.configurations_loaded = true
43
+
44
+ configuration_file_path
45
+ end
46
+
47
+ private
48
+
49
+ attr_writer :configurations_loaded
50
+
51
+ def configurations_loaded?
52
+ @configurations_loaded == true
53
+ end
54
+
55
+ def app_path
56
+ @app_path ||=
57
+ if defined?(Rails)
58
+ Rails.application.root
59
+ else
60
+ # This is used when Rails is not available from the webpacker binstubs
61
+ File.expand_path(".", Dir.pwd)
62
+ end
63
+ end
64
+
65
+ def configuration_file_path
66
+ @configuration_file_path ||= File.join(app_path, "tmp/webpacker_runtime.yml")
67
+ end
68
+
69
+ def original_configuration_file_path
70
+ @original_configuration_file_path = File.join(app_path, "config/webpacker.yml")
71
+ end
72
+
73
+ def load_asset_configurations
74
+ # Decidim gem assets
75
+ decidim_gems = Bundler.load.specs.select { |spec| spec.name =~ /^decidim-/ }
76
+ decidim_gems.each do |gem|
77
+ asset_config_path = File.join(gem.full_gem_path, "config/assets.rb")
78
+ next unless File.exist?(asset_config_path)
79
+
80
+ load asset_config_path
81
+ end
82
+
83
+ # Application assets
84
+ asset_config_path = File.join(app_path, "config/assets.rb")
85
+ load asset_config_path if File.exist?(asset_config_path)
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,16 @@
1
+ /* eslint-disable */
2
+
3
+ module.exports = {
4
+ syntax: 'postcss-scss',
5
+ plugins: [
6
+ require('autoprefixer'),
7
+ require('postcss-import'),
8
+ require('postcss-flexbugs-fixes'),
9
+ require('postcss-preset-env')({
10
+ autoprefixer: {
11
+ flexbox: 'no-2009'
12
+ },
13
+ stage: 3
14
+ })
15
+ ]
16
+ }
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Webpacker
5
+ module Runner
6
+ def self.included(base)
7
+ base.alias_method :original_initialize, :initialize
8
+ base.send :private, :original_initialize
9
+
10
+ base.define_method :initialize do |argv|
11
+ original_initialize(argv)
12
+ decidim_initialize(argv)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def decidim_initialize(_argv)
19
+ # Write the runtime configuration and override the configuration
20
+ @webpacker_config = Decidim::Webpacker.configuration.configuration_file
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ /* eslint-disable */
2
+
3
+ const { webpackConfig, merge } = require("@decidim/webpacker")
4
+ const customConfig = require("./custom")
5
+
6
+ module.exports = merge(webpackConfig, customConfig)
@@ -0,0 +1,97 @@
1
+ /* eslint-disable */
2
+
3
+ const path = require("path");
4
+ const { config } = require("@rails/webpacker");
5
+
6
+ module.exports = {
7
+ module: {
8
+ rules: [
9
+ {
10
+ test: require.resolve("quill"),
11
+ loader: "expose-loader",
12
+ options: {
13
+ exposes: ["Quill"]
14
+ }
15
+ },
16
+ {
17
+ test: require.resolve("jquery"),
18
+ loader: "expose-loader",
19
+ options: {
20
+ exposes: ["$", "jQuery"]
21
+ }
22
+ },
23
+ {
24
+ test: /\.(js|jsx)$/,
25
+ exclude: /node_modules\/(?!tributejs)/,
26
+ loader: "babel-loader"
27
+ },
28
+ {
29
+ test: /\.(graphql|gql)$/,
30
+ loader: "graphql-tag/loader"
31
+ },
32
+ {
33
+ test: require.resolve("react"),
34
+ loader: "expose-loader",
35
+ options: {
36
+ exposes: ["React"]
37
+ }
38
+ },
39
+ {
40
+ test: require.resolve("@rails/ujs"),
41
+ loader: "expose-loader",
42
+ options: {
43
+ exposes: ["Rails"]
44
+ }
45
+ },
46
+ {
47
+ test: [
48
+ /\.md$/,
49
+ /\.odt$/,
50
+ ],
51
+ exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
52
+ type: 'asset/resource',
53
+ generator: {
54
+ filename: 'media/documents/[hash][ext][query]'
55
+ }
56
+ },
57
+ // Overwrite webpacker files rule to amend the filename output
58
+ // and include the name of the file, otherwise some SVGs
59
+ // are not generated because the hash is the same between them
60
+ {
61
+ test: [
62
+ /\.bmp$/,
63
+ /\.gif$/,
64
+ /\.jpe?g$/,
65
+ /\.png$/,
66
+ /\.tiff$/,
67
+ /\.ico$/,
68
+ /\.avif$/,
69
+ /\.webp$/,
70
+ /\.eot$/,
71
+ /\.otf$/,
72
+ /\.ttf$/,
73
+ /\.woff$/,
74
+ /\.woff2$/,
75
+ /\.svg$/
76
+ ],
77
+ exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
78
+ type: 'asset/resource',
79
+ generator: {
80
+ filename: 'media/images/[name]-[hash][ext][query]'
81
+ }
82
+ }
83
+ ]
84
+ },
85
+ resolve: {
86
+ extensions: [".js", ".jsx", ".gql", ".graphql"],
87
+ fallback: {
88
+ crypto: false
89
+ }
90
+ },
91
+ // https://github.com/rails/webpacker/issues/2932
92
+ // As Decidim uses multiple packs, we need to enforce a single runtime, to prevent duplication
93
+ optimization: {
94
+ runtimeChunk: false
95
+ },
96
+ entry: config.entrypoints
97
+ }
@@ -0,0 +1,7 @@
1
+ /* eslint-disable */
2
+
3
+ process.env.NODE_ENV = process.env.NODE_ENV || "development"
4
+
5
+ const webpackConfig = require("./base")
6
+
7
+ module.exports = webpackConfig
@@ -0,0 +1,7 @@
1
+ /* eslint-disable */
2
+
3
+ process.env.NODE_ENV = process.env.NODE_ENV || "production"
4
+
5
+ const webpackConfig = require("./base")
6
+
7
+ module.exports = webpackConfig
@@ -0,0 +1,7 @@
1
+ /* eslint-disable */
2
+
3
+ process.env.NODE_ENV = process.env.NODE_ENV || "development"
4
+
5
+ const webpackConfig = require("./base")
6
+
7
+ module.exports = webpackConfig
@@ -0,0 +1,65 @@
1
+ # File written by Decidim generator
2
+ # Note: You must restart bin/webpack-dev-server for changes to take effect
3
+
4
+ default: &default
5
+ source_path: app/packs
6
+ source_entry_path: entrypoints
7
+ public_output_path: decidim-packs
8
+ public_root_path: public
9
+ webpack_compile_output: true
10
+ cache_path: tmp/webpacker-cache
11
+ extract_css: true
12
+
13
+ additional_paths:
14
+ - node_modules
15
+ - app/packs
16
+
17
+ # Reload manifest.json on all requests so we reload latest compiled packs
18
+ cache_manifest: false
19
+
20
+ development:
21
+ <<: *default
22
+ compile: true
23
+ # Compile test packs to decidim decidim-packs folder
24
+
25
+ # Reference: https://webpack.js.org/configuration/dev-server/
26
+ dev_server:
27
+ https: false
28
+ host: localhost
29
+ # Notice that we use a different port (to prevent blocking the default one) as
30
+ # there will be at least two webpack servers running
31
+ port: 3035
32
+ # Hot Module Replacement updates modules while the application is running without a full reload
33
+ hmr: false
34
+ client:
35
+ # Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
36
+ overlay: true
37
+ # May also be a string
38
+ # webSocketURL:
39
+ # hostname: "0.0.0.0"
40
+ # pathname: "/ws"
41
+ # port: 8080
42
+ # Should we use gzip compression?
43
+ compress: true
44
+ # Note that apps that do not check the host are vulnerable to DNS rebinding attacks
45
+ allowed_hosts: "all"
46
+ pretty: true
47
+ headers:
48
+ 'Access-Control-Allow-Origin': '*'
49
+ static:
50
+ watch:
51
+ ignored: '**/node_modules/**'
52
+
53
+ test:
54
+ <<: *default
55
+ compile: true
56
+ public_output_path: packs-test
57
+
58
+ production:
59
+ <<: *default
60
+
61
+ # Production depends on precompilation of packs prior to booting for performance.
62
+ compile: false
63
+
64
+ # Cache manifest.json for performance
65
+ cache_manifest: true
data/docs/README.adoc CHANGED
@@ -43,7 +43,7 @@ In detail each one of these steps are:
43
43
  # 1. Clone the repository
44
44
  git clone https://github.com/decidim/documentation
45
45
  # 2. Install dependencies
46
- npm install
46
+ npm
47
47
  # 3. Change the antora-playbook.yml url key in source
48
48
  # 4. Build the antora playbook
49
49
  npm run build
@@ -79,6 +79,22 @@ Whether SSL should be enabled or not. Recommended for extra security.
79
79
  config.force_ssl = true
80
80
  ....
81
81
 
82
+ == CORS enabled
83
+
84
+ The SVG do not support CORS. When using custom asset host different than root url, set this value to `true`, in order to activate the available workaround.
85
+
86
+ Please refer to:
87
+
88
+ - https://github.com/w3c/svgwg/issues/707
89
+ - https://stackoverflow.com/questions/65811142/how-to-allow-external-images-referenced-within-embedded-svg
90
+ - https://groups.google.com/a/chromium.org/g/blink-dev/c/qemQwRpe2so/m/THi81oodSDgJ.
91
+ - https://www.w3.org/Graphics/SVG/WG/track/actions/3781
92
+
93
+ [source,ruby]
94
+ ....
95
+ config.cors_enabled = true
96
+ ....
97
+
82
98
  == Geocoder configuration
83
99
 
84
100
  Allows to make geographical mapping in some components, like Proposals or Meetings. It must be configured against a OpenStreetMap provider. See xref:services:geocoder.adoc[Geocoder service documentation].
@@ -374,3 +390,18 @@ step setting :amendments_visibility.
374
390
  ....
375
391
  config.amendments_visibility_options = %w(all participants)
376
392
  ....
393
+
394
+ == Export fields
395
+
396
+ To customize export fields, you can subscribe to any serialize event. Every serializer event has unique event name in format: decidim.serialize.module_here.class_here
397
+
398
+ [source,ruby]
399
+ ....
400
+ initializer "decidim_budgets.serializer_listener" do
401
+ ActiveSupport::Notifications.subscribe("decidim.serialize.budgets.project_serializer") do |_event_name, data|
402
+ # Implement your custom code for new or existing fields.
403
+ data[:serialized_data][:column_title] = "Row data #{data[:resource].class}"
404
+ end
405
+ end
406
+ ....
407
+
@@ -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 (for instance the homepage), you can just do it with the same name of the file, through Monkey Patching.
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
- If you want to override the standard images given by Decidim (for instance the initial image for user's avatars) you can do it by naming it the same way as the original image, in this case it should be `app/assets/images/decidim/default-avatar.svg`
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 image_tag helper. You can see more documentation on http://guides.rubyonrails.org/asset_pipeline.html[Rails guide].
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
- == Asset pipeline
5
+ == Webpacker
6
6
 
7
- Just add it to `app/assets/javascripts/application.js`. For example to create a new alert just add:
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/asset_pipeline.html[Rails Asset Pipeline documentation].
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
- == Asset pipeline
53
+ == Webpacker
54
54
 
55
- You can go to app/assets/stylesheets/application.css.sass on your generated applications. There you can override any class using CSS with SASS.
55
+ Decidim uses Webpacker to compile assets. There are two ways to customize CSS:
56
56
 
57
- In https://github.com/decidim/decidim/blob/develop/decidim-core/app/assets/stylesheets/decidim/_variables.scss[decidim-core/app/assets/stylesheets/decidim/_variables.scss] you can find the `variables` that can be overriden in your `sass`.
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.