decidim-core 0.0.1.alpha9 → 0.0.1

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.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -25
  3. data/app/assets/config/decidim_core_manifest.js +1 -0
  4. data/app/assets/fonts/decidim/Source_Sans_Pro_400.eot +0 -0
  5. data/app/assets/fonts/decidim/Source_Sans_Pro_400.svg +345 -0
  6. data/app/assets/fonts/decidim/Source_Sans_Pro_400.ttf +0 -0
  7. data/app/assets/fonts/decidim/Source_Sans_Pro_400.woff +0 -0
  8. data/app/assets/fonts/decidim/Source_Sans_Pro_400.woff2 +0 -0
  9. data/app/assets/fonts/decidim/Source_Sans_Pro_600.eot +0 -0
  10. data/app/assets/fonts/decidim/Source_Sans_Pro_600.svg +339 -0
  11. data/app/assets/fonts/decidim/Source_Sans_Pro_600.ttf +0 -0
  12. data/app/assets/fonts/decidim/Source_Sans_Pro_600.woff +0 -0
  13. data/app/assets/fonts/decidim/Source_Sans_Pro_600.woff2 +0 -0
  14. data/app/assets/fonts/decidim/Source_Sans_Pro_900.eot +0 -0
  15. data/app/assets/fonts/decidim/Source_Sans_Pro_900.svg +342 -0
  16. data/app/assets/fonts/decidim/Source_Sans_Pro_900.ttf +0 -0
  17. data/app/assets/fonts/decidim/Source_Sans_Pro_900.woff +0 -0
  18. data/app/assets/fonts/decidim/Source_Sans_Pro_900.woff2 +0 -0
  19. data/app/assets/images/decidim/default-avatar.svg +14 -0
  20. data/app/assets/javascripts/decidim.js.es6 +5 -5
  21. data/app/assets/javascripts/decidim/editor.js.es6 +46 -0
  22. data/app/assets/stylesheets/decidim/_variables.scss +12 -13
  23. data/app/assets/stylesheets/decidim/application.sass +4 -1
  24. data/app/assets/stylesheets/decidim/editor.sass +4 -0
  25. data/app/assets/stylesheets/decidim/modules/_card-grid.scss +4 -1
  26. data/app/assets/stylesheets/decidim/modules/_cards.scss +5 -0
  27. data/app/assets/stylesheets/decidim/modules/_navbar.scss +1 -0
  28. data/app/assets/stylesheets/decidim/modules/_process-header.scss +24 -75
  29. data/app/assets/stylesheets/decidim/modules/_process-nav.scss +0 -1
  30. data/app/assets/stylesheets/decidim/modules/_process-phase.scss +80 -0
  31. data/app/assets/stylesheets/decidim/utils/_fontface.scss +39 -1
  32. data/app/assets/stylesheets/decidim/utils/_helpers.scss +25 -0
  33. data/app/assets/stylesheets/decidim/utils/_keyframes.scss +21 -0
  34. data/app/assets/stylesheets/decidim/utils/_mixins.scss +37 -0
  35. data/app/assets/stylesheets/decidim/utils/_settings.scss +11 -5
  36. data/app/commands/decidim/authorize_user.rb +2 -2
  37. data/app/constraints/decidim/current_feature.rb +48 -0
  38. data/app/controllers/concerns/decidim/form_factory.rb +80 -0
  39. data/app/controllers/concerns/decidim/locale_switcher.rb +17 -10
  40. data/app/controllers/concerns/decidim/needs_participatory_process.rb +33 -0
  41. data/app/controllers/decidim/application_controller.rb +1 -1
  42. data/app/controllers/decidim/devise/confirmations_controller.rb +1 -1
  43. data/app/controllers/decidim/devise/passwords_controller.rb +1 -1
  44. data/app/controllers/decidim/devise/registrations_controller.rb +1 -1
  45. data/app/controllers/decidim/devise/sessions_controller.rb +16 -2
  46. data/app/controllers/decidim/pages_controller.rb +14 -0
  47. data/app/controllers/decidim/participatory_processes_controller.rb +7 -0
  48. data/app/forms/decidim/form.rb +15 -0
  49. data/app/forms/translatable_presence_validator.rb +31 -0
  50. data/app/helpers/decidim/application_helper.rb +17 -2
  51. data/app/helpers/decidim/layout_helper.rb +8 -1
  52. data/app/helpers/decidim/localized_locales_helper.rb +43 -0
  53. data/app/helpers/decidim/participatory_process_helper.rb +16 -0
  54. data/app/helpers/decidim/translations_helper.rb +17 -0
  55. data/app/models/decidim/category.rb +35 -0
  56. data/app/models/decidim/component.rb +51 -0
  57. data/app/models/decidim/feature.rb +30 -0
  58. data/app/models/decidim/organization.rb +20 -1
  59. data/app/models/decidim/participatory_process.rb +43 -4
  60. data/app/models/decidim/participatory_process_attachment.rb +56 -0
  61. data/app/models/decidim/scope.rb +14 -0
  62. data/app/models/decidim/static_page.rb +56 -0
  63. data/app/models/decidim/user.rb +2 -0
  64. data/app/queries/decidim/organization_participatory_processes.rb +17 -0
  65. data/app/services/decidim/authorization_handler.rb +2 -2
  66. data/app/types/decidim/process_step_type.rb +24 -0
  67. data/app/types/decidim/process_type.rb +16 -0
  68. data/app/types/decidim/user_type.rb +14 -0
  69. data/app/uploaders/decidim/attachment_uploader.rb +70 -0
  70. data/app/uploaders/decidim/avatar_uploader.rb +14 -0
  71. data/app/uploaders/decidim/banner_image_uploader.rb +1 -1
  72. data/app/uploaders/decidim/hero_image_uploader.rb +1 -1
  73. data/app/uploaders/decidim/homepage_image_uploader.rb +11 -0
  74. data/app/uploaders/decidim/image_uploader.rb +46 -0
  75. data/app/uploaders/decidim/organization_logo_uploader.rb +9 -0
  76. data/app/views/decidim/devise/registrations/new.html.erb +1 -1
  77. data/app/views/decidim/participatory_processes/_documents.html.erb +26 -0
  78. data/app/views/decidim/participatory_processes/_photos.html.erb +16 -0
  79. data/app/views/decidim/participatory_processes/_promoted_process.html.erb +1 -1
  80. data/app/views/decidim/participatory_processes/show.html.erb +16 -11
  81. data/app/views/kaminari/decidim/_first_page.html.erb +11 -0
  82. data/app/views/kaminari/decidim/_gap.html.erb +8 -0
  83. data/app/views/kaminari/decidim/_last_page.html.erb +11 -0
  84. data/app/views/kaminari/decidim/_next_page.html.erb +11 -0
  85. data/app/views/kaminari/decidim/_page.html.erb +12 -0
  86. data/app/views/kaminari/decidim/_paginator.html.erb +25 -0
  87. data/app/views/kaminari/decidim/_prev_page.html.erb +11 -0
  88. data/app/views/layouts/decidim/_application.html.erb +17 -0
  89. data/app/views/layouts/decidim/_footer.html.erb +5 -3
  90. data/app/views/layouts/decidim/_header.html.erb +8 -21
  91. data/app/views/layouts/decidim/_language_chooser.html.erb +14 -0
  92. data/app/views/layouts/decidim/_logo.html.erb +17 -13
  93. data/app/views/layouts/decidim/_process_header.html.erb +34 -0
  94. data/app/views/layouts/decidim/_process_header_steps.html.erb +26 -0
  95. data/app/views/layouts/decidim/_user_menu.html.erb +2 -0
  96. data/app/views/layouts/decidim/application.html.erb +3 -0
  97. data/app/views/layouts/decidim/participatory_process.html.erb +15 -0
  98. data/app/views/pages/decidim_page.html.erb +12 -0
  99. data/app/views/pages/home.html.erb +106 -2
  100. data/config/i18n-tasks.yml +3 -1
  101. data/config/locales/ca.yml +40 -10
  102. data/config/locales/en.yml +39 -4
  103. data/config/locales/es.yml +44 -14
  104. data/config/routes.rb +14 -1
  105. data/db/migrate/20160919104837_create_decidim_organizations.rb +4 -0
  106. data/db/migrate/20161005153007_add_description_to_organizations.rb +1 -3
  107. data/db/migrate/20161010102356_translate_processes.rb +4 -4
  108. data/db/migrate/20161017085822_add_participatory_process_steps.rb +3 -3
  109. data/db/migrate/20161107152228_remove_not_null_on_step_position.rb +5 -0
  110. data/db/migrate/20161108093802_create_decidim_static_pages.rb +11 -0
  111. data/db/migrate/20161110092735_add_index_for_process_slug_organization.rb +8 -0
  112. data/db/migrate/20161110105712_create_decidim_features.rb +9 -0
  113. data/db/migrate/20161116115156_create_attachments.rb +18 -0
  114. data/db/migrate/20161123085134_add_categories.rb +10 -0
  115. data/db/migrate/20161130105257_create_decidim_scopes.rb +9 -0
  116. data/db/migrate/20161209134715_make_organization_description_optional.rb +5 -0
  117. data/db/migrate/20161213094244_add_avatar_to_users.rb +5 -0
  118. data/db/migrate/20161214152811_add_logo_to_organizations.rb +5 -0
  119. data/db/seeds.rb +36 -6
  120. data/db/seeds/Exampledocument.pdf +0 -0
  121. data/{app/assets/images/decidim/hero-home.jpg → db/seeds/homepage_image.jpg} +0 -0
  122. data/lib/decidim/core.rb +55 -2
  123. data/lib/decidim/core/engine.rb +16 -2
  124. data/lib/decidim/core/version.rb +11 -2
  125. data/lib/decidim/feature_manifest.rb +71 -0
  126. data/lib/decidim/features.rb +8 -0
  127. data/lib/decidim/features/base_controller.rb +32 -0
  128. data/lib/decidim/features/namer.rb +35 -0
  129. data/lib/decidim/form_builder.rb +140 -6
  130. data/lib/decidim/page_finder.rb +48 -0
  131. data/lib/decidim/query_extensions.rb +33 -0
  132. data/lib/decidim/translatable_attributes.rb +1 -24
  133. data/vendor/assets/javascripts/quill.min.js +14 -0
  134. data/vendor/assets/javascripts/quill.min.js.map +1 -0
  135. data/vendor/assets/stylesheets/quill.bubble.css +843 -0
  136. data/vendor/assets/stylesheets/quill.core.css +362 -0
  137. data/vendor/assets/stylesheets/quill.snow.css +881 -0
  138. metadata +164 -32
  139. data/LICENSE.txt +0 -619
  140. data/app/views/decidim/participatory_processes/_process_header_home.html.erb +0 -18
  141. data/app/views/pages/terms.ca.html.erb +0 -4
  142. data/app/views/pages/terms.en.html.erb +0 -4
  143. data/app/views/pages/terms.es.html.erb +0 -4
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ # A factory to build forms. This is done to add a context when possible, so
7
+ # that forms can act based on data that varies between requests. This is
8
+ # mostly done so that i18n form fields can be properly validated with the
9
+ # `current_organization` available locales, instead of doing so against all
10
+ # the available locales in the platform. The `current_organization` varies
11
+ # between requests, so the form need some way to access this data.
12
+ #
13
+ # Examples:
14
+ #
15
+ # # in a controller, mostly in a `create` action:
16
+ # form(MyFormClass).form_params(params)
17
+ #
18
+ # # in a controller, mostly in a `new` action:
19
+ # form(MyFormClass).instance
20
+ #
21
+ # # in a controller, mostly in an `edit` action:
22
+ # form(MyFormClass).form_model(@my_resource)
23
+ #
24
+ module FormFactory
25
+ extend ActiveSupport::Concern
26
+
27
+ included do
28
+ # Initializes a factory for the given Form Object class.
29
+ #
30
+ # klass - a Form object class name. Must be a constant, not a String.
31
+ def form(klass)
32
+ Class.new do
33
+ # Initializes the form factory object.
34
+ #
35
+ # klass - the class name of the Form object that will be initialized
36
+ # context - the Controller where the form is built.
37
+ def initialize(klass, context)
38
+ @klass = klass
39
+ @context = context
40
+ end
41
+
42
+ # Returns a simple instance of the form klass.
43
+ def instance(context = {})
44
+ @klass.new(context)
45
+ end
46
+
47
+ # Initializes a form object from a model. Delegates the functionality
48
+ # to the form object class method.
49
+ #
50
+ # model - the model instance from which the form object will be
51
+ # initialized.
52
+ # context - a Hash with optional context data.
53
+ def from_model(model, context = {})
54
+ from_params(model.attributes, context)
55
+ end
56
+
57
+ # Initializes a form object instance from params, and it
58
+ # automatically adds some context. Context can be extended.
59
+ #
60
+ # params - a Hash with params. Mostly a set of params from a form.
61
+ # context - a Hash with optional context data.
62
+ def from_params(params, context = {})
63
+ @klass.from_params(params, context_hash.merge(context))
64
+ end
65
+
66
+ # Sets a base context from the current controller. Since this can be
67
+ # used from some controllers that do not respond to the helper
68
+ # methods used here, this Hash can have different keys depending on
69
+ # the controller that uses it.
70
+ def context_hash
71
+ {
72
+ current_organization: @context.try(:current_organization),
73
+ current_user: @context.try(:current_user)
74
+ }.compact
75
+ end
76
+ end.new(klass, self)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -9,19 +9,19 @@ module Decidim
9
9
 
10
10
  included do
11
11
  before_action :set_locale
12
- helper_method :current_locale, :available_locales
12
+ helper_method :current_locale, :available_locales, :default_locale
13
13
 
14
14
  # Sets the locale for the current session.
15
15
  #
16
16
  # Returns nothing.
17
17
  def set_locale
18
- I18n.locale = if params["locale"] && available_locales.include?(params["locale"])
19
- params["locale"]
20
- elsif current_user && current_user.locale.present?
21
- current_user.locale
22
- else
23
- I18n.default_locale
24
- end
18
+ locale = if params["locale"]
19
+ params["locale"]
20
+ elsif current_user && current_user.locale.present?
21
+ current_user.locale
22
+ end
23
+
24
+ I18n.locale = available_locales.include?(locale) ? locale : default_locale
25
25
  end
26
26
 
27
27
  # Adds the current locale to all the URLs generated by url_for so users
@@ -29,7 +29,7 @@ module Decidim
29
29
  #
30
30
  # Returns a Hash.
31
31
  def default_url_options
32
- return {} if current_locale == I18n.default_locale.to_s
32
+ return {} if current_locale == default_locale.to_s
33
33
 
34
34
  { locale: current_locale }
35
35
  end
@@ -46,7 +46,14 @@ module Decidim
46
46
  #
47
47
  # Returns an Array of Strings.
48
48
  def available_locales
49
- @available_locales ||= I18n.available_locales.map(&:to_s)
49
+ @available_locales ||= current_organization.available_locales.map(&:to_s)
50
+ end
51
+
52
+ # The default locale of this organization.
53
+ #
54
+ # Returns a String with the default locale.
55
+ def default_locale
56
+ @default_locale ||= current_organization.default_locale
50
57
  end
51
58
  end
52
59
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ # This module, when injected into a controller, ensures there's a
7
+ # Participatory Process available and deducts it from the context.
8
+ module NeedsParticipatoryProcess
9
+ extend ActiveSupport::Concern
10
+
11
+ include NeedsOrganization
12
+
13
+ included do
14
+ after_action :verify_participatory_process
15
+ helper_method :current_participatory_process
16
+
17
+ # Public: Finds the current Participatory Process given this controller's
18
+ # context.
19
+ #
20
+ # Returns the current ParticipatoryProcess.
21
+ def current_participatory_process
22
+ @current_participatory_process ||=
23
+ current_organization.participatory_processes.find_by(id: params[:participatory_process_id])
24
+ end
25
+
26
+ private
27
+
28
+ def verify_participatory_process
29
+ raise ActionController::RoutingError, "Not Found" unless current_participatory_process
30
+ end
31
+ end
32
+ end
33
+ end
@@ -7,7 +7,7 @@ module Decidim
7
7
  include NeedsAuthorization
8
8
  protect_from_forgery with: :exception, prepend: true
9
9
 
10
- layout "application"
10
+ layout "layouts/decidim/application"
11
11
 
12
12
  def user_not_authorized_path
13
13
  decidim.root_path
@@ -5,7 +5,7 @@ module Decidim
5
5
  class ConfirmationsController < ::Devise::ConfirmationsController
6
6
  include Decidim::NeedsOrganization
7
7
  include Decidim::LocaleSwitcher
8
- layout "application"
8
+ layout "layouts/decidim/application"
9
9
  end
10
10
  end
11
11
  end
@@ -5,7 +5,7 @@ module Decidim
5
5
  class PasswordsController < ::Devise::PasswordsController
6
6
  include Decidim::NeedsOrganization
7
7
  include Decidim::LocaleSwitcher
8
- layout "application"
8
+ layout "layouts/decidim/application"
9
9
  end
10
10
  end
11
11
  end
@@ -6,7 +6,7 @@ module Decidim
6
6
  class RegistrationsController < ::Devise::RegistrationsController
7
7
  include Decidim::NeedsOrganization
8
8
  include Decidim::LocaleSwitcher
9
- layout "application"
9
+ layout "layouts/decidim/application"
10
10
  before_action :configure_permitted_parameters
11
11
 
12
12
  protected
@@ -5,15 +5,29 @@ module Decidim
5
5
  class SessionsController < ::Devise::SessionsController
6
6
  include Decidim::NeedsOrganization
7
7
  include Decidim::LocaleSwitcher
8
- layout "application"
8
+ helper Decidim::TranslationsHelper
9
+
10
+ layout "layouts/decidim/application"
9
11
 
10
12
  def after_sign_in_path_for(user)
11
- if user.is_a?(User) && user.sign_in_count == 1 && Decidim.authorization_handlers.any?
13
+ if !pending_redirect?(user) && first_login_and_not_authorized?(user)
12
14
  authorizations_path
13
15
  else
14
16
  super
15
17
  end
16
18
  end
19
+
20
+ # Calling the `stored_location_for` method removes the key, so in order
21
+ # to check if there's any pending redirect after login I need to call
22
+ # this method and use the value to set a pending redirect. This is the
23
+ # only way to do this without checking the session directly.
24
+ def pending_redirect?(user)
25
+ store_location_for(user, stored_location_for(user))
26
+ end
27
+
28
+ def first_login_and_not_authorized?(user)
29
+ user.is_a?(User) && user.sign_in_count == 1 && Decidim.authorization_handlers.any?
30
+ end
17
31
  end
18
32
  end
19
33
  end
@@ -1,10 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
  require_dependency "decidim/application_controller"
3
+ require_dependency "decidim/page_finder"
3
4
 
4
5
  module Decidim
5
6
  # This controller serves static pages using HighVoltage.
6
7
  class PagesController < ApplicationController
7
8
  include HighVoltage::StaticPage
9
+
10
+ layout "layouts/decidim/application"
11
+
8
12
  authorize_resource :public_pages, class: false
13
+ delegate :page, to: :page_finder
14
+ helper_method :page, :participatory_processes
15
+
16
+ def page_finder
17
+ @page_finder ||= Decidim::PageFinder.new(params[:id], current_organization)
18
+ end
19
+
20
+ def participatory_processes
21
+ @participatory_processes ||= current_organization.participatory_processes.includes(:active_step).published.promoted
22
+ end
9
23
  end
10
24
  end
@@ -6,6 +6,9 @@ module Decidim
6
6
  # public layout.
7
7
  class ParticipatoryProcessesController < ApplicationController
8
8
  helper_method :participatory_processes, :participatory_process, :promoted_processes
9
+ helper_method :current_participatory_process
10
+
11
+ layout "layouts/decidim/participatory_process", only: [:show]
9
12
 
10
13
  def index
11
14
  authorize! :read, ParticipatoryProcess
@@ -17,6 +20,10 @@ module Decidim
17
20
 
18
21
  private
19
22
 
23
+ def current_participatory_process
24
+ participatory_process
25
+ end
26
+
20
27
  def participatory_process
21
28
  @participatory_process ||= ParticipatoryProcess.find(params[:id])
22
29
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # A base form object to hold common logic, like automatically adding as
4
+ # public method the params sent as context by the `FormFactory` concern.
5
+ class Form < Rectify::Form
6
+ attr_reader :current_organization, :current_user, :current_feature
7
+
8
+ def initialize(attributes = {})
9
+ @current_organization = attributes.delete("current_organization") || attributes.delete(:current_organization)
10
+ @current_user = attributes.delete("current_user") || attributes.delete(:current_user)
11
+ @current_feature = attributes.delete("current_feature") || attributes.delete(:current_feature)
12
+ super
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A custom validator to check for presence in I18n-enabled fields. In order to
4
+ # use it do the following:
5
+ #
6
+ # validates :my_i18n_field, translatable_presence: true
7
+ #
8
+ # This will automatically check for presence for each of the
9
+ # `available_locales` of the form object (or the `available_locales` of the
10
+ # form's organization) for the given field.
11
+ class TranslatablePresenceValidator < ActiveModel::EachValidator
12
+ def validate_each(record, attribute, _value)
13
+ available_locales_for(record).each do |locale|
14
+ translated_attr = "#{attribute}_#{locale}"
15
+ record.errors.add(translated_attr, :blank) unless record.send(translated_attr).present?
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def available_locales_for(record)
22
+ return record.available_locales if record.respond_to?(:available_locales)
23
+
24
+ if record.current_organization
25
+ record.current_organization.available_locales
26
+ else
27
+ record.errors.add(:current_organization, :blank)
28
+ []
29
+ end
30
+ end
31
+ end
@@ -1,9 +1,24 @@
1
+ # encoding: utf-8
1
2
  # frozen_string_literal: true
2
3
  module Decidim
3
4
  # Main module to add application-wide helpers.
4
5
  module ApplicationHelper
5
- def link_to_organization(organization)
6
- link_to(organization.name, root_url(host: organization.host))
6
+ # Truncates a given text respecting its HTML tags.
7
+ #
8
+ # text - The String text to be truncated.
9
+ # options - A Hash with the options to truncate the text (default: {}):
10
+ # :length - An Integer number with the max length of the text.
11
+ # :separator - A String to append to the text when it's being
12
+ # truncated. See `truncato` gem for more options.
13
+ #
14
+ # Returns a String.
15
+ def html_truncate(text, options = {})
16
+ options[:max_length] = options.delete(:length) || options[:max_length]
17
+ options[:tail] = options.delete(:separator) || options[:tail] || "..."
18
+ options[:count_tags] ||= false
19
+ options[:count_tail] ||= false
20
+
21
+ Truncato.truncate(text, options)
7
22
  end
8
23
  end
9
24
  end
@@ -3,7 +3,8 @@ module Decidim
3
3
  # View helpers related to the layout.
4
4
  module LayoutHelper
5
5
  def decidim_page_title
6
- current_organization.name
6
+ title = content_for(:title)
7
+ title ? "#{title} - #{current_organization.name}" : current_organization.name
7
8
  end
8
9
 
9
10
  # Outputs an SVG-based icon.
@@ -19,6 +20,12 @@ module Decidim
19
20
  #
20
21
  # Returns a String.
21
22
  def icon(name, options = {})
23
+ # Ugly hack to work around the issue of phantomjs not sending js events
24
+ # when clicking on a SVG element.
25
+ if Rails.env.test?
26
+ return content_tag(:span, "?", class: "icon icon--#{name}")
27
+ end
28
+
22
29
  html_properties = {}
23
30
 
24
31
  html_properties["width"] = options[:width]
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # A helper that converts an array of locale IDs (two-letter identifiers, e.g.
4
+ # `"en"`) to an array of Objects that have both the ID and their name in
5
+ # their own language (e.g., `"English"`).
6
+ #
7
+ # This is intended to be used in forms, when selecting the default locale
8
+ # form a given list, or when creating a list of radio buttons, for example.
9
+ #
10
+ # Examples:
11
+ #
12
+ # <%= form.collection_select :default_locale, localized_locales(current_organization.available_locales), :id, :name %>
13
+ #
14
+ # <% localized_locales(current_organization.available_locales).each do |locale| %>
15
+ # <p><%= locale.name %></p>
16
+ # <% end %>
17
+ #
18
+ module LocalizedLocalesHelper
19
+ # Converts a given array of strings to an array of Objects representing
20
+ # locales.
21
+ #
22
+ # collection - an Array of Strings. By default it uses all the available
23
+ # locales in Decidim, but you can passa nother collection of locales (for
24
+ # example, the available locales for an organization)
25
+ def localized_locales(collection = Decidim.available_locales)
26
+ klass = Class.new do
27
+ def initialize(locale)
28
+ @locale = locale
29
+ end
30
+
31
+ def id
32
+ @locale.to_s
33
+ end
34
+
35
+ def name
36
+ I18n.t(id, scope: "locales")
37
+ end
38
+ end
39
+
40
+ collection.map { |locale| klass.new(locale) }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ module Decidim
3
+ # Helpers related to the Participatory Process layout.
4
+ module ParticipatoryProcessHelper
5
+ # Public: Returns the dates for a step in a readable format like
6
+ # "2016-01-01 - 2016-02-05".
7
+ #
8
+ # participatory_process_step - The step to format to
9
+ #
10
+ # Returns a String with the formatted dates.
11
+ def participatory_process_step_dates(participatory_process_step)
12
+ dates = [participatory_process_step.start_date, participatory_process_step.end_date]
13
+ dates.map { |date| date ? localize(date.to_date, format: :default) : "?" }.join(" - ")
14
+ end
15
+ end
16
+ end