decidim-core 0.0.1.alpha7 → 0.0.1.alpha8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +619 -0
  3. data/README.md +1 -1
  4. data/app/assets/javascripts/decidim.js.es6 +13 -0
  5. data/app/assets/stylesheets/decidim/_variables.scss +23 -0
  6. data/app/assets/stylesheets/decidim/application.sass +2 -0
  7. data/app/assets/stylesheets/decidim/extras/_turbolinks.scss +3 -0
  8. data/app/assets/stylesheets/decidim/modules/_cards.scss +0 -5
  9. data/app/assets/stylesheets/decidim/utils/_settings.scss +5 -11
  10. data/app/commands/decidim/authorize_user.rb +37 -0
  11. data/app/controllers/concerns/decidim/needs_authorization.rb +36 -0
  12. data/app/controllers/decidim/account_controller.rb +26 -0
  13. data/app/controllers/decidim/application_controller.rb +5 -0
  14. data/app/controllers/decidim/authorizations_controller.rb +76 -0
  15. data/app/controllers/decidim/devise/registrations_controller.rb +1 -1
  16. data/app/controllers/decidim/devise/sessions_controller.rb +8 -0
  17. data/app/controllers/decidim/locales_controller.rb +2 -0
  18. data/app/controllers/decidim/pages_controller.rb +10 -0
  19. data/app/controllers/decidim/participatory_processes_controller.rb +32 -0
  20. data/app/helpers/decidim/authorization_form_helper.rb +25 -0
  21. data/app/helpers/decidim/humanize_booleans_helper.rb +14 -0
  22. data/app/mailers/decidim/application_mailer.rb +1 -1
  23. data/app/models/decidim/abilities/everyone.rb +16 -0
  24. data/app/models/decidim/ability.rb +32 -0
  25. data/app/models/decidim/authorization.rb +25 -0
  26. data/app/models/decidim/participatory_process.rb +25 -0
  27. data/app/models/decidim/participatory_process_step.rb +38 -0
  28. data/app/models/decidim/user.rb +19 -0
  29. data/app/services/decidim/authorization_handler.rb +94 -0
  30. data/app/uploaders/decidim/application_uploader.rb +0 -2
  31. data/app/views/decidim/account/_authorizations.html.erb +52 -0
  32. data/app/views/decidim/account/show.html.erb +32 -0
  33. data/app/views/decidim/authorizations/index.html.erb +22 -0
  34. data/app/views/decidim/authorizations/new.html.erb +29 -0
  35. data/app/views/decidim/devise/confirmations/new.html.erb +27 -11
  36. data/app/views/decidim/devise/invitations/edit.html.erb +25 -10
  37. data/app/views/decidim/devise/passwords/edit.html.erb +30 -15
  38. data/app/views/decidim/devise/passwords/new.html.erb +25 -11
  39. data/app/views/decidim/devise/registrations/new.html.erb +48 -20
  40. data/app/views/decidim/devise/sessions/new.html.erb +40 -21
  41. data/app/views/decidim/devise/shared/_links.html.erb +18 -6
  42. data/app/views/decidim/participatory_processes/_no_processes_yet.html.erb +3 -0
  43. data/app/views/decidim/participatory_processes/_order_by_processes.html.erb +3 -0
  44. data/app/views/decidim/participatory_processes/_participatory_process.html.erb +26 -0
  45. data/app/views/decidim/participatory_processes/_process_header_home.html.erb +18 -0
  46. data/app/views/decidim/participatory_processes/_promoted_process.html.erb +32 -0
  47. data/app/views/decidim/participatory_processes/index.html.erb +15 -0
  48. data/app/views/decidim/participatory_processes/show.html.erb +15 -0
  49. data/app/views/devise/mailer/organization_admin_invitation_instructions.html.erb +1 -1
  50. data/app/views/devise/mailer/organization_admin_invitation_instructions.text.erb +1 -1
  51. data/app/views/layouts/decidim/_footer.html.erb +3 -3
  52. data/app/views/layouts/decidim/_header.html.erb +5 -2
  53. data/app/views/pages/404.html.erb +13 -0
  54. data/app/views/pages/500.html.erb +10 -0
  55. data/app/views/{decidim/home/show.html.erb → pages/home.html.erb} +0 -0
  56. data/app/views/pages/terms.ca.html.erb +4 -0
  57. data/app/views/pages/terms.en.html.erb +4 -0
  58. data/app/views/pages/terms.es.html.erb +4 -0
  59. data/config/i18n-tasks.yml +3 -0
  60. data/config/initializers/devise.rb +1 -1
  61. data/config/locales/ca.yml +84 -10
  62. data/config/locales/en.yml +84 -10
  63. data/config/locales/es.yml +84 -10
  64. data/config/routes.rb +14 -1
  65. data/db/migrate/20161013134732_add_promoted_flag_to_processes.rb +5 -0
  66. data/db/migrate/20161017085822_add_participatory_process_steps.rb +16 -0
  67. data/db/migrate/20161018091013_create_decidim_authorizations.rb +13 -0
  68. data/db/migrate/20161019072016_add_active_flag_to_step.rb +7 -0
  69. data/db/migrate/20161020080756_add_position_to_steps.rb +7 -0
  70. data/db/migrate/20161025125300_add_published_at_to_processes.rb +5 -0
  71. data/db/seeds.rb +81 -27
  72. data/lib/decidim/authorization_form_builder.rb +70 -0
  73. data/lib/decidim/core.rb +23 -5
  74. data/lib/decidim/core/engine.rb +21 -0
  75. data/lib/decidim/core/version.rb +1 -1
  76. data/lib/decidim/faker/localized.rb +162 -0
  77. data/lib/decidim/form_builder.rb +1 -1
  78. data/lib/tasks/decidim_tasks.rake +1 -1
  79. metadata +121 -15
  80. data/MIT-LICENSE +0 -20
  81. data/app/assets/javascripts/decidim.js +0 -23
  82. data/app/assets/stylesheets/decidim.scss +0 -16
  83. data/app/assets/stylesheets/decidim/utils/_variables.scss +0 -25
  84. data/app/controllers/decidim/home_controller.rb +0 -7
data/config/routes.rb CHANGED
@@ -12,6 +12,19 @@ Decidim::Core::Engine.routes.draw do
12
12
  registrations: "decidim/devise/registrations",
13
13
  passwords: "decidim/devise/passwords"
14
14
  }
15
+
15
16
  resource :locale, only: [:create]
16
- root to: "home#show"
17
+ resources :participatory_processes, only: [:index, :show]
18
+
19
+ authenticate(:user) do
20
+ resources :authorizations, only: [:new, :create, :destroy, :index]
21
+ resource :account, only: [:show], controller: "account"
22
+ end
23
+
24
+ get "/pages/*id" => "pages#show", as: :page, format: false
25
+
26
+ match "/404", to: "pages#show", id: "404", via: :all
27
+ match "/500", to: "pages#show", id: "500", via: :all
28
+
29
+ root to: "pages#show", id: "home"
17
30
  end
@@ -0,0 +1,5 @@
1
+ class AddPromotedFlagToProcesses < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :decidim_participatory_processes, :promoted, :boolean, default: false, index: true
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ class AddParticipatoryProcessSteps < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :decidim_participatory_process_steps do |t|
4
+ t.hstore :title, null: false
5
+ t.hstore :short_description, null: false
6
+ t.hstore :description, null: false
7
+ t.datetime :start_date
8
+ t.datetime :end_date
9
+ t.references :decidim_participatory_process,
10
+ foreign_key: true,
11
+ index: { name: 'index_decidim_processes_steps__on_decidim_process_id' }
12
+
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ class CreateDecidimAuthorizations < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :decidim_authorizations do |t|
4
+ t.string :name, null: false
5
+ t.jsonb :metadata
6
+ t.references :decidim_user, null: false, foreign_key: true, index: true
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :decidim_authorizations, [:decidim_user_id, :name], unique: true
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ class AddActiveFlagToStep < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :decidim_participatory_process_steps, :active, :boolean, default: false
4
+
5
+ add_index :decidim_participatory_process_steps, [:decidim_participatory_process_id, :active], unique: true, where: "active = 't'", name: "unique_index_to_avoid_duplicate_active_steps"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class AddPositionToSteps < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :decidim_participatory_process_steps, :position, :integer, null: false
4
+ add_index :decidim_participatory_process_steps, :position, order: { position: :asc }, name: "index_order_by_position_for_steps"
5
+ add_index :decidim_participatory_process_steps, [:decidim_participatory_process_id, :position], unique: true, name: "index_unique_position_for_process"
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class AddPublishedAtToProcesses < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :decidim_participatory_processes, :published_at, :datetime, index: true
4
+ end
5
+ end
data/db/seeds.rb CHANGED
@@ -1,57 +1,111 @@
1
1
  if !Rails.env.production? || ENV["SEED"]
2
+ require "decidim/faker/localized"
3
+
2
4
  puts "Creating Decidim::Core seeds..."
3
5
 
4
6
  staging_organization = Decidim::Organization.create!(
5
- name: "Decidim Staging",
7
+ name: Decidim::Faker::Localized.company,
6
8
  host: ENV["DECIDIM_HOST"] || "localhost"
7
9
  )
8
10
 
9
11
  Decidim::User.create!(
10
- name: "Organization Admin",
12
+ name: Faker::Name.name,
11
13
  email: "admin@decidim.org",
12
14
  password: "decidim123456",
13
15
  password_confirmation: "decidim123456",
14
16
  organization: staging_organization,
15
17
  confirmed_at: Time.current,
16
18
  locale: I18n.default_locale,
17
- roles: ["admin"]
19
+ roles: ["admin"],
20
+ tos_agreement: true
18
21
  )
19
22
 
20
23
  Decidim::User.create!(
21
- name: "Responsible Citizen",
24
+ name: Faker::Name.name,
22
25
  email: "user@decidim.org",
23
26
  password: "decidim123456",
24
27
  password_confirmation: "decidim123456",
25
28
  confirmed_at: Time.current,
26
29
  locale: I18n.default_locale,
30
+ organization: staging_organization,
31
+ tos_agreement: true
32
+ )
33
+
34
+ participatory_process1 = Decidim::ParticipatoryProcess.create!(
35
+ title: Decidim::Faker::Localized.sentence(5),
36
+ slug: Faker::Internet.slug(nil, '-'),
37
+ subtitle: Decidim::Faker::Localized.sentence(2),
38
+ hashtag: "##{Faker::Lorem.word}",
39
+ short_description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
40
+ Decidim::Faker::Localized.sentence(3)
41
+ end,
42
+ description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
43
+ Decidim::Faker::Localized.paragraph(3)
44
+ end,
45
+ hero_image: File.new(File.join(File.dirname(__FILE__), "seeds", "city.jpeg")),
46
+ banner_image: File.new(File.join(File.dirname(__FILE__), "seeds", "city2.jpeg")),
47
+ promoted: true,
48
+ published_at: 2.weeks.ago,
27
49
  organization: staging_organization
28
50
  )
29
51
 
30
52
  Decidim::ParticipatoryProcess.create!(
31
- title: {
32
- en: 'Urbanistic plan for Newtown neighbourhood',
33
- es: 'Plan urbanístico para el barrio de Villanueva',
34
- ca: 'Pla urbanístic pel barri de Vilanova'
35
- },
36
- slug: 'urbanistic-plan-for-newtown-neighbourhood',
37
- subtitle: {
38
- en: 'Go for it!',
39
- es: 'Vamos!',
40
- ca: 'Som-hi!'
41
- },
42
- hashtag: '#urbaNewtown',
43
- short_description: {
44
- en: 'Short description',
45
- es: 'Descripción corta',
46
- ca: 'Descripció curta'
47
- },
48
- description: {
49
- en: 'Description',
50
- es: 'Descripción',
51
- ca: 'Descripció'
52
- },
53
- hero_image: File.new(File.join(File.dirname(__FILE__), "seeds", "city.jpeg")),
53
+ title: Decidim::Faker::Localized.sentence(5),
54
+ slug: Faker::Internet.slug(nil, '-'),
55
+ subtitle: Decidim::Faker::Localized.sentence(2),
56
+ hashtag: "##{Faker::Lorem.word}",
57
+ short_description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
58
+ Decidim::Faker::Localized.sentence(3)
59
+ end,
60
+ description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
61
+ Decidim::Faker::Localized.paragraph(3)
62
+ end,
63
+ hero_image: File.new(File.join(File.dirname(__FILE__), "seeds", "city2.jpeg")),
64
+ banner_image: File.new(File.join(File.dirname(__FILE__), "seeds", "city3.jpeg")),
65
+ published_at: 1.week.ago,
66
+ organization: staging_organization
67
+ )
68
+
69
+ Decidim::ParticipatoryProcess.create!(
70
+ title: Decidim::Faker::Localized.sentence(5),
71
+ slug: Faker::Internet.slug(nil, '-'),
72
+ subtitle: Decidim::Faker::Localized.sentence(2),
73
+ hashtag: "##{Faker::Lorem.word}",
74
+ short_description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
75
+ Decidim::Faker::Localized.sentence(3)
76
+ end,
77
+ description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
78
+ Decidim::Faker::Localized.paragraph(3)
79
+ end,
80
+ hero_image: File.new(File.join(File.dirname(__FILE__), "seeds", "city3.jpeg")),
54
81
  banner_image: File.new(File.join(File.dirname(__FILE__), "seeds", "city2.jpeg")),
55
82
  organization: staging_organization
56
83
  )
84
+
85
+ Decidim::ParticipatoryProcessStep.create!(
86
+ title: Decidim::Faker::Localized.sentence(5),
87
+ short_description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
88
+ Decidim::Faker::Localized.sentence(3)
89
+ end,
90
+ description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
91
+ Decidim::Faker::Localized.paragraph(3)
92
+ end,
93
+ active: true,
94
+ start_date: 1.month.ago.at_midnight,
95
+ end_date: 2.months.from_now.at_midnight,
96
+ participatory_process: participatory_process1
97
+ )
98
+
99
+ Decidim::ParticipatoryProcessStep.create!(
100
+ title: Decidim::Faker::Localized.sentence(5),
101
+ short_description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
102
+ Decidim::Faker::Localized.sentence(3)
103
+ end,
104
+ description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
105
+ Decidim::Faker::Localized.paragraph(3)
106
+ end,
107
+ start_date: 2.months.from_now.at_midnight,
108
+ end_date: 3.months.from_now.at_midnight,
109
+ participatory_process: participatory_process1
110
+ )
57
111
  end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+ require "decidim/form_builder"
3
+
4
+ module Decidim
5
+ # A customf orm builder to render AuthorizationHandler forms.
6
+ class AuthorizationFormBuilder < Decidim::FormBuilder
7
+ # Renders all form attributes defined by the handler.
8
+ #
9
+ # Returns a String.
10
+ def all_fields
11
+ fields = public_attributes.map do |name, type|
12
+ @template.content_tag(:div, input_field(name, type), class: "field")
13
+ end
14
+
15
+ safe_join(fields)
16
+ end
17
+
18
+ # Renders a single attribute from the form handlers.
19
+ #
20
+ # name - The String name of the attribute.
21
+ # options - An optional Hash, accepted options are:
22
+ # :as - A String name with the type the field to render
23
+ # :input - An optional Hash to pass to the field method.
24
+ #
25
+ # Returns a String.
26
+ def input(name, options = {})
27
+ if options[:as]
28
+ send(options[:as].to_s, name, options[:input] || {})
29
+ else
30
+ type = find_input_type(name.to_s)
31
+ input_field(name, type)
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def input_field(name, type)
38
+ return hidden_field(name) if name.to_s == "handler_name"
39
+
40
+ case type.name
41
+ when "Date"
42
+ date_field name
43
+ else
44
+ text_field name
45
+ end
46
+ end
47
+
48
+ def find_input_type(name)
49
+ found_attribute = object.class.attribute_set.detect do |attribute|
50
+ attribute.name.to_s == name
51
+ end
52
+
53
+ raise "Could not find attribute #{name} in #{object.class.name}" unless found_attribute
54
+
55
+ found_attribute.type.primitive
56
+ end
57
+
58
+ def public_attributes
59
+ form_attributes.inject({}) do |all, attribute|
60
+ all.update(attribute.name => attribute.type.primitive)
61
+ end
62
+ end
63
+
64
+ def form_attributes
65
+ object.class.attribute_set.select do |attribute|
66
+ object.form_attributes.include?(attribute.name)
67
+ end
68
+ end
69
+ end
70
+ end
data/lib/decidim/core.rb CHANGED
@@ -6,15 +6,33 @@ require "decidim/core/version"
6
6
  module Decidim
7
7
  autoload :TranslatableAttributes, "decidim/translatable_attributes"
8
8
  autoload :FormBuilder, "decidim/form_builder"
9
+ autoload :AuthorizationFormBuilder, "decidim/authorization_form_builder"
9
10
  autoload :DeviseFailureApp, "decidim/devise_failure_app"
11
+ include ActiveSupport::Configurable
10
12
 
11
- @config = OpenStruct.new
13
+ # Loads seeds from all engines.
14
+ def self.seed!
15
+ Rails.application.railties.select do |railtie|
16
+ railtie.respond_to?(:load_seed) && railtie.class.name.include?("Decidim::")
17
+ end.each(&:load_seed)
18
+ end
19
+
20
+ # Exposes a configuration option: The application name String.
21
+ config_accessor :application_name
22
+
23
+ # Exposes a configuration option: The email String to use as sender in all
24
+ # the mails.
25
+ config_accessor :mailer_sender
12
26
 
13
- def self.setup
14
- yield(@config)
27
+ # Exposes a configuration option: an Array of `cancancan`'s Ability classes
28
+ # that will be automatically included to the base `Decidim::Ability` class.
29
+ config_accessor :abilities do
30
+ []
15
31
  end
16
32
 
17
- def self.config
18
- @config
33
+ # Exposes a configuration option: an Array of classes that can be used as
34
+ # AuthorizaionHandlers so users can be verified against different systems.
35
+ config_accessor :authorization_handlers do
36
+ []
19
37
  end
20
38
  end
@@ -18,6 +18,11 @@ require "active_link_to"
18
18
  require "rectify"
19
19
  require "roadie-rails"
20
20
  require "carrierwave"
21
+ require "high_voltage"
22
+ require "rails-i18n"
23
+ require "date_validator"
24
+ require "sprockets/es6"
25
+ require "cancancan"
21
26
 
22
27
  module Decidim
23
28
  module Core
@@ -40,9 +45,25 @@ module Decidim
40
45
  app.config.assets.precompile += %w(decidim_core_manifest.js)
41
46
  end
42
47
 
48
+ initializer "decidim.high_voltage" do |_app|
49
+ HighVoltage.configure do |config|
50
+ config.routes = false
51
+ end
52
+ end
53
+
43
54
  initializer "decidim.default_form_builder" do |_app|
44
55
  ActionView::Base.default_form_builder = Decidim::FormBuilder
45
56
  end
57
+
58
+ initializer "decidim.exceptions_app" do |app|
59
+ app.config.exceptions_app = Decidim::Core::Engine.routes
60
+ end
61
+
62
+ initializer "decidim_admin.inject_abilities_to_user" do |_app|
63
+ Decidim.configure do |config|
64
+ config.abilities << Abilities::Everyone
65
+ end
66
+ end
46
67
  end
47
68
  end
48
69
  end
@@ -2,7 +2,7 @@
2
2
  # This holds Decidim's version and the Rails version on which it depends.
3
3
  module Decidim
4
4
  def self.version
5
- "0.0.1.alpha7"
5
+ "0.0.1.alpha8"
6
6
  end
7
7
 
8
8
  def self.rails_version
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+ require "faker"
3
+
4
+ module Decidim
5
+ module Faker
6
+ # A Custom Faker wrapper so we can easily generate fake data for each
7
+ # locale in localized attributes.
8
+ module Localized
9
+ # Fakes a company name.
10
+ #
11
+ # Returns a Hash with a value for each locale.
12
+ def self.company
13
+ localized do
14
+ ::Faker::Company.name
15
+ end
16
+ end
17
+
18
+ # Fakes a person name.
19
+ #
20
+ # Returns a Hash with a value for each locale.
21
+ def self.name
22
+ localized do
23
+ ::Faker::Name.name
24
+ end
25
+ end
26
+
27
+ # Builds a Lorem Ipsum word.
28
+ #
29
+ # Returns a Hash with a value for each locale.
30
+ def self.word
31
+ localized do
32
+ ::Faker::Lorem.word
33
+ end
34
+ end
35
+
36
+ # Builds many Lorem Ipsum words. See Faker::Lorem for options.
37
+ #
38
+ # Returns a Hash with a value for each locale.
39
+ def self.words(*args)
40
+ localized do
41
+ ::Faker::Lorem.words(*args)
42
+ end
43
+ end
44
+
45
+ # Builds a Lorem Ipsum character.
46
+ #
47
+ # Returns a Hash with a value for each locale.
48
+ def self.character
49
+ localized do
50
+ ::Faker::Lorem.character
51
+ end
52
+ end
53
+
54
+ # Builds many Lorem Ipsum characters. See Faker::Lorem for options.
55
+ #
56
+ # Returns a Hash with a value for each locale.
57
+ def self.characters(*args)
58
+ localized do
59
+ ::Faker::Lorem.characters(*args)
60
+ end
61
+ end
62
+
63
+ # Builds a sentence with Lorem Ipsum words. See Faker::Lorem for options.
64
+ #
65
+ # Returns a Hash with a value for each locale.
66
+ def self.sentence(*args)
67
+ localized do
68
+ ::Faker::Lorem.sentence(*args)
69
+ end
70
+ end
71
+
72
+ # Builds many sentences with Lorem Ipsum words. See Faker::Lorem for options.
73
+ #
74
+ # Returns a Hash with a value for each locale.
75
+ def self.sentences(*args)
76
+ localized do
77
+ ::Faker::Lorem.sentences(*args)
78
+ end
79
+ end
80
+
81
+ # Builds a paragraph with Lorem Ipsum words. See Faker::Lorem for options.
82
+ #
83
+ # Returns a Hash with a value for each locale.
84
+ def self.paragraph(*args)
85
+ localized do
86
+ ::Faker::Lorem.paragraph(*args)
87
+ end
88
+ end
89
+
90
+ # Builds many paragraphs with Lorem Ipsum words. See Faker::Lorem for options.
91
+ #
92
+ # Returns a Hash with a value for each locale.
93
+ def self.paragraphs(*args)
94
+ localized do
95
+ ::Faker::Lorem.paragraphs(*args)
96
+ end
97
+ end
98
+
99
+ # Builds a question with Lorem Ipsum words. See Faker::Lorem for options.
100
+ #
101
+ # Returns a Hash with a value for each locale.
102
+ def self.question(*args)
103
+ localized do
104
+ ::Faker::Lorem.question(*args)
105
+ end
106
+ end
107
+
108
+ # Builds many questions with Lorem Ipsum words. See Faker::Lorem for options.
109
+ #
110
+ # Returns a Hash with a value for each locale.
111
+ def self.questions(*args)
112
+ localized do
113
+ ::Faker::Lorem.questions(*args)
114
+ end
115
+ end
116
+
117
+ # Sets the given text as the value for each locale.
118
+ #
119
+ # text - The String text to set for each locale.
120
+ #
121
+ # Returns a Hash with a value for each locale.
122
+ def self.literal(text)
123
+ I18n.available_locales.inject({}) do |result, locale|
124
+ result.update(locale => text)
125
+ end
126
+ end
127
+
128
+ # Wrapps a text build by the block with some other text.o
129
+ #
130
+ # before - The String text to inject at the begining of each value.
131
+ # after - The String text to inject at the end of each value.
132
+ # block - A Block that generates a Hash with a text for each locale.
133
+ #
134
+ # Example:
135
+ #
136
+ # Decidim::Faker::Localized.wrapped("<p>", "</p>") do
137
+ # Decidim::Faker::Localized.sentence(5)
138
+ # end
139
+ #
140
+ # Returns a Hash with a value for each locale.
141
+ def self.wrapped(before, after)
142
+ result = yield
143
+ result.inject({}) do |wrapped, (locale, text)|
144
+ wrapped.update(locale => [before, text, after].join)
145
+ end
146
+ end
147
+
148
+ # nodoc
149
+ def self.localized
150
+ I18n.available_locales.inject({}) do |result, locale|
151
+ text = ::Faker::Base.with_locale(locale) do
152
+ yield
153
+ end
154
+
155
+ result.update(locale => text)
156
+ end
157
+ end
158
+
159
+ private_class_method :localized
160
+ end
161
+ end
162
+ end