decidim-core 0.0.1.alpha4 → 0.0.1.alpha5

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -5
  3. data/app/assets/images/decidim/icons.svg +1 -1
  4. data/app/assets/javascripts/decidim.js +1 -2
  5. data/app/assets/stylesheets/decidim/email.css +1377 -0
  6. data/app/assets/stylesheets/decidim/modules/_cards.scss +0 -14
  7. data/app/assets/stylesheets/decidim/modules/_navbar.scss +8 -0
  8. data/app/assets/stylesheets/decidim/utils/_settings.scss +3 -4
  9. data/app/controllers/concerns/decidim/locale_switcher.rb +53 -0
  10. data/app/controllers/decidim/application_controller.rb +1 -0
  11. data/app/controllers/decidim/devise/confirmations_controller.rb +1 -0
  12. data/app/controllers/decidim/devise/passwords_controller.rb +1 -0
  13. data/app/controllers/decidim/devise/registrations_controller.rb +6 -0
  14. data/app/controllers/decidim/devise/sessions_controller.rb +1 -0
  15. data/app/controllers/decidim/locales_controller.rb +26 -0
  16. data/app/helpers/decidim/layout_helper.rb +1 -1
  17. data/app/mailers/concerns/decidim/localised_mailer.rb +30 -0
  18. data/app/mailers/decidim/application_mailer.rb +2 -0
  19. data/app/mailers/decidim/decidim_devise_mailer.rb +31 -4
  20. data/app/models/decidim/organization.rb +1 -0
  21. data/app/models/decidim/participatory_process.rb +1 -1
  22. data/app/models/decidim/user.rb +2 -1
  23. data/app/views/decidim/devise/registrations/edit.html.erb +4 -0
  24. data/app/views/decidim/devise/registrations/new.html.erb +4 -0
  25. data/app/views/layouts/decidim/_header.html.erb +47 -7
  26. data/app/views/layouts/decidim/_meta.html.erb +3 -0
  27. data/app/views/layouts/decidim/mailer.html.erb +71 -0
  28. data/config/i18n-tasks.yml +1 -0
  29. data/config/initializers/devise.rb +0 -2
  30. data/config/locales/ca.yml +48 -0
  31. data/config/locales/en.yml +9 -0
  32. data/config/locales/es.yml +48 -0
  33. data/config/routes.rb +1 -0
  34. data/db/migrate/20161010085443_add_name_to_users.rb +5 -0
  35. data/db/migrate/20161010102356_translate_processes.rb +15 -0
  36. data/db/migrate/20161010131544_add_locale_to_users.rb +5 -0
  37. data/db/seeds.rb +26 -6
  38. data/lib/decidim/core.rb +4 -0
  39. data/lib/decidim/core/engine.rb +5 -4
  40. data/lib/decidim/core/version.rb +1 -1
  41. data/lib/decidim/translatable_attributes.rb +4 -3
  42. data/lib/tasks/decidim_tasks.rake +1 -0
  43. metadata +56 -18
@@ -421,20 +421,6 @@ $datetime-bg: $primary;
421
421
  align-items: center;
422
422
  justify-content: center;
423
423
  }
424
- &:after{
425
- content: "";
426
- display: block;
427
- width: 100%;
428
- height: 100%;
429
- position: absolute;
430
- top: 0;
431
- left: 0;
432
- background: linear-gradient(to bottom, rgba($white,1),rgba($white,0) 80%);
433
- z-index: 0;
434
- @include breakpoint(mediumlarge){
435
- background: linear-gradient(to right, rgba($white,1),rgba($white,0) 80%);
436
- }
437
- }
438
424
  > .card__content{
439
425
  position: relative;
440
426
  z-index: 1;
@@ -62,6 +62,10 @@ $navbar-active-shadow-medium: inset 0 4px 0 0 $primary;
62
62
  }
63
63
  img{
64
64
  display: block;
65
+ max-width: 100px;
66
+ @include breakpoint(mediumlarge){
67
+ max-width: 140px;
68
+ }
65
69
  }
66
70
  }
67
71
 
@@ -246,6 +250,10 @@ $navbar-active-shadow-medium: inset 0 4px 0 0 $primary;
246
250
  background: $navbar-bg-hover;
247
251
  color: $navbar-color-hover;
248
252
  }
253
+
254
+ @include breakpoint(medium){
255
+ padding: .75em 2em;
256
+ }
249
257
  }
250
258
 
251
259
  .main-nav__link--active{
@@ -49,9 +49,8 @@ $global-font-size: 100%;
49
49
  $global-width: rem-calc(1200);
50
50
  $global-lineheight: 1.5;
51
51
  $foundation-palette: (
52
- primary: #C24B29, //#dc0030,
53
- //secondary: #777777,
54
- secondary: #5295ad,//#74AABE,
52
+ primary: #ef604d,
53
+ secondary: #599aa6,
55
54
  success: #57d685,
56
55
  warning: #ffae00,
57
56
  alert: #ec5840,
@@ -539,7 +538,7 @@ $thumbnail-radius: $global-radius;
539
538
 
540
539
  $titlebar-background: $black;
541
540
  $titlebar-color: $white;
542
- $titlebar-padding: 0.5rem;
541
+ $titlebar-padding: 1rem 0.5rem;
543
542
  $titlebar-text-font-weight: bold;
544
543
  $titlebar-icon-color: $white;
545
544
  $titlebar-icon-color-hover: $medium-gray;
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ # Common logic to switch between locales.
7
+ module LocaleSwitcher
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ before_action :set_locale
12
+ helper_method :current_locale, :available_locales
13
+
14
+ # Sets the locale for the current session.
15
+ #
16
+ # Returns nothing.
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
25
+ end
26
+
27
+ # Adds the current locale to all the URLs generated by url_for so users
28
+ # experience a consistent behaviour if they copy or share links.
29
+ #
30
+ # Returns a Hash.
31
+ def default_url_options
32
+ return {} if current_locale == I18n.default_locale.to_s
33
+
34
+ { locale: current_locale }
35
+ end
36
+
37
+ # The current locale for the user. Available as a helper for the views.
38
+ #
39
+ # Returns a String.
40
+ def current_locale
41
+ @current_locale ||= I18n.locale.to_s
42
+ end
43
+
44
+ # The available locales in the application. Available as a helper for the
45
+ # views.
46
+ #
47
+ # Returns an Array of Strings.
48
+ def available_locales
49
+ @available_locales ||= I18n.available_locales.map(&:to_s)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -3,6 +3,7 @@ module Decidim
3
3
  # The main application controller that inherits from Rails.
4
4
  class ApplicationController < ActionController::Base
5
5
  include Decidim::NeedsOrganization
6
+ include Decidim::LocaleSwitcher
6
7
  protect_from_forgery with: :exception, prepend: true
7
8
 
8
9
  layout "application"
@@ -4,6 +4,7 @@ module Decidim
4
4
  # Custom Devise ConfirmationsController to avoid namespace problems.
5
5
  class ConfirmationsController < ::Devise::ConfirmationsController
6
6
  include Decidim::NeedsOrganization
7
+ include Decidim::LocaleSwitcher
7
8
  layout "application"
8
9
  end
9
10
  end
@@ -4,6 +4,7 @@ module Decidim
4
4
  # Custom Devise PasswordsController to avoid namespace problems.
5
5
  class PasswordsController < ::Devise::PasswordsController
6
6
  include Decidim::NeedsOrganization
7
+ include Decidim::LocaleSwitcher
7
8
  layout "application"
8
9
  end
9
10
  end
@@ -5,10 +5,16 @@ module Decidim
5
5
  # RegistrationsController so we can specify a custom layout.
6
6
  class RegistrationsController < ::Devise::RegistrationsController
7
7
  include Decidim::NeedsOrganization
8
+ include Decidim::LocaleSwitcher
8
9
  layout "application"
10
+ before_action :configure_permitted_parameters
9
11
 
10
12
  protected
11
13
 
14
+ def configure_permitted_parameters
15
+ devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
16
+ end
17
+
12
18
  # Called before resource.save
13
19
  def build_resource(hash = nil)
14
20
  super(hash)
@@ -4,6 +4,7 @@ module Decidim
4
4
  # Custom Devise SessionsController to avoid namespace problems.
5
5
  class SessionsController < ::Devise::SessionsController
6
6
  include Decidim::NeedsOrganization
7
+ include Decidim::LocaleSwitcher
7
8
  layout "application"
8
9
  end
9
10
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ require_dependency "decidim/application_controller"
3
+
4
+ module Decidim
5
+ # A controller to allow users switching their locale.
6
+ class LocalesController < ApplicationController
7
+ def create
8
+ if current_user && params["locale"] && available_locales.include?(params["locale"])
9
+ current_user.update_attribute(:locale, params["locale"])
10
+ end
11
+
12
+ redirect_to referer_with_new_locale
13
+ end
14
+
15
+ private
16
+
17
+ def referer_with_new_locale
18
+ uri = URI(request.referrer || "/")
19
+ query = uri.query.to_s.gsub(/locale\=[a-zA-Z\-]{2,5}/, "")
20
+ params = URI.decode_www_form(query) << ["locale", current_locale]
21
+ uri.query = URI.encode_www_form(params)
22
+
23
+ uri.to_s
24
+ end
25
+ end
26
+ end
@@ -3,7 +3,7 @@ module Decidim
3
3
  # View helpers related to the layout.
4
4
  module LayoutHelper
5
5
  def decidim_page_title
6
- Decidim.config.application_name
6
+ current_organization.name
7
7
  end
8
8
 
9
9
  # Outputs an SVG-based icon.
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Decidim
6
+ # A module to be included in mailers that changes the default behaviour so
7
+ # the emails are rendered in the user's locale instead of the default one.
8
+ module LocalisedMailer
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ # Yields with the I18n locale changed to the user's one.
13
+ #
14
+ # Returns nothing.
15
+ def with_user(user)
16
+ I18n.with_locale(user.locale || I18n.locale) do
17
+ yield
18
+ end
19
+ end
20
+
21
+ # Overwrite default devise_mail method to always render the email with
22
+ # the user's locale.
23
+ def devise_mail(record, action, opts = {})
24
+ with_user(record) do
25
+ super
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -3,6 +3,8 @@ module Decidim
3
3
  # Main application mailer configuration. Inherit from this to create new
4
4
  # mailers.
5
5
  class ApplicationMailer < ActionMailer::Base
6
+ include Roadie::Rails::Automatic
7
+
6
8
  default from: "from@example.com"
7
9
  layout "mailer"
8
10
  end
@@ -1,11 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
  module Decidim
3
3
  # A custom mailer for Devise so we can tweak the invitation instructions for
4
- # each role.
4
+ # each role and use a localised version.
5
5
  class DecidimDeviseMailer < Devise::Mailer
6
- def invitation_instructions(record, token, opts = {})
7
- @token = token
8
- devise_mail(record, opts[:invitation_instructions] || :invitation_instructions, opts)
6
+ include LocalisedMailer
7
+ include Roadie::Rails::Automatic
8
+
9
+ layout "decidim/mailer"
10
+
11
+ # Sends an email with the invitation instructions to a new user.
12
+ #
13
+ # user - The User that has been invited.
14
+ # token - The String to be sent as a token to verify the invitation.
15
+ # opts - A Hash with options to send the email (optional).
16
+ def invitation_instructions(user, token, opts = {})
17
+ with_user(user) do
18
+ @token = token
19
+
20
+ if opts[:invitation_instructions] == "organization_admin_invitation_instructions"
21
+ opts[:subject] = I18n.t("devise.mailer.organization_admin_invitation_instructions.subject", organization: user.organization.name)
22
+ end
23
+ end
24
+
25
+ devise_mail(user, opts[:invitation_instructions] || :invitation_instructions, opts)
26
+ end
27
+
28
+ private
29
+
30
+ # Overwrite devise_mail so we can inject the organization from the user.
31
+ def devise_mail(user, action, opts = {}, &block)
32
+ with_user(user) do
33
+ @organization = user.organization
34
+ super
35
+ end
9
36
  end
10
37
  end
11
38
  end
@@ -4,6 +4,7 @@ module Decidim
4
4
  # installation we can find many organizations and each of them can start
5
5
  # their own participatory processes.
6
6
  class Organization < ApplicationRecord
7
+ has_many :participatory_processes, foreign_key: "decidim_organization_id", class_name: Decidim::ParticipatoryProcess
7
8
  validates :name, :host, uniqueness: true
8
9
  end
9
10
  end
@@ -8,7 +8,7 @@ module Decidim
8
8
  class ParticipatoryProcess < ApplicationRecord
9
9
  belongs_to :organization, foreign_key: "decidim_organization_id", class_name: Decidim::Organization
10
10
 
11
- validates :title, :slug, :subtitle, :short_description, :description, presence: true
11
+ validates :slug, presence: true
12
12
  validates :slug, uniqueness: true
13
13
  end
14
14
  end
@@ -11,7 +11,8 @@ module Decidim
11
11
 
12
12
  ROLES = %w(admin moderator official).freeze
13
13
 
14
- validates :organization, presence: true
14
+ validates :organization, :name, presence: true
15
+ validates :locale, inclusion: { in: I18n.available_locales.map(&:to_s) }, allow_blank: true
15
16
  validate :all_roles_are_valid
16
17
 
17
18
  # Public: Allows customizing the invitation instruction email content when
@@ -25,6 +25,10 @@
25
25
  <%= f.password_field :current_password %>
26
26
  </div>
27
27
 
28
+ <div class="field">
29
+ <%= f.text_field :name %>
30
+ </div>
31
+
28
32
  <div><%= f.submit t("devise.registrations.edit.update") %></div>
29
33
  <% end %>
30
34
 
@@ -15,6 +15,10 @@
15
15
  <%= f.password_field :password_confirmation, autocomplete: "off" %>
16
16
  </div>
17
17
 
18
+ <div class="field">
19
+ <%= f.text_field :name %>
20
+ </div>
21
+
18
22
  <div class="actions">
19
23
  <%= f.submit t("devise.registrations.new.sign_up") %>
20
24
  </div>
@@ -25,22 +25,62 @@
25
25
  <!-- Remove this, use the final SVG logo -->
26
26
  <span><%= current_organization.name %></span>
27
27
  <style>
28
- .logo-wrapper span{ color: white; font-weight: 600;
29
- display: inline-block; text-align: left;
30
- padding-left: 8px; line-height: 1;
31
- position: relative; }
32
- .logo-wrapper span:before{ content: ""; display: block;
33
- position: absolute; border-left: 4px solid white; height: 88%;
34
- top: 6%; left: 0; }
28
+ .logo-wrapper span{ color: white; font-weight: 600;
29
+ font-size: 1.4em;
30
+ display: inline-block; text-align: left;
31
+ padding-left: 8px; line-height: 1;
32
+ position: relative; }
33
+ .logo-wrapper span:before{ content: ""; display: block;
34
+ position: absolute; border-left: 4px solid white; height: 88%;
35
+ top: 6%; left: 0; }
35
36
  </style>
36
37
  <!-- /Remove-->
37
38
  </a>
38
39
  </div>
40
+ <div class="topbar__dropmenu language-choose">
41
+ <ul class="dropdown menu" data-dropdown-menu>
42
+ <li class="is-dropdown-submenu-parent">
43
+ <%= link_to t(current_locale, scope: "locales") %>
44
+ <% if available_locales.length > 1 %>
45
+ <ul class="menu is-dropdown-submenu">
46
+ <% available_locales.each do |locale| %>
47
+ <li><%= link_to t(locale, scope: "locales"), locale_path(locale: locale), method: :post%></li>
48
+ <% end %>
49
+ <% end %>
50
+ </ul>
51
+ </li>
52
+ </ul>
53
+ </div>
39
54
  <div class="hide-for-medium topbar__menu">
40
55
  <button type="button" data-toggle="offCanvas">
41
56
  <%= icon "menu", aria_label: t('.navigation'), role: "img" %>
42
57
  </button>
43
58
  </div>
59
+ <% if current_user %>
60
+ <div class="topbar__dropmenu topbar__user__logged">
61
+ <ul class="dropdown menu" data-dropdown-menu>
62
+ <li class="is-dropdown-submenu-parent show-for-medium">
63
+ <%= link_to current_user.name, root_path %>
64
+ <ul class="menu is-dropdown-subeenu js-append usermenu-off-canvas">
65
+ <li><%= link_to t('.sign_out'), destroy_user_session_path, method: :delete, class: "sign-out-link" %></li>
66
+ </ul>
67
+ <span data-set="nav-login-holder" class="show-for-medium">
68
+ <!-- Repeated due to dropdown limitations -->
69
+ <ul class="menu is-dropdown-submenu js-append usermenu-off-canvas">
70
+ <li><%= link_to t('.sign_out'), destroy_user_session_path, method: :delete, class: "sign-out-link" %></li>
71
+ </ul>
72
+ </span>
73
+ </li>
74
+ </ul>
75
+ </div>
76
+ <% else %>
77
+ <div class="topbar__user show-for-medium" data-set="nav-login-holder">
78
+ <div class="topbar__user__login js-append">
79
+ <%= link_to t('.sign_up'), new_user_registration_path, class: "sign-up-link" %>
80
+ <%= link_to t('.sign_in'), new_user_session_path, class: "sign-in-link" %>
81
+ </div>
82
+ </div>
83
+ <% end %>
44
84
  </div>
45
85
  </div>
46
86
  <div class="show-for-medium" data-set="nav-holder">
@@ -0,0 +1,3 @@
1
+ <% available_locales.each do |locale| %>
2
+ <link rel="alternate" href="<%= url_for(request.parameters.merge(locale: locale)) %>" hreflang="<%= locale %>" />
3
+ <% end %>
@@ -0,0 +1,71 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <meta name="viewport" content="width=device-width" />
6
+ <%= stylesheet_link_tag "decidim/email" %>
7
+ </head>
8
+
9
+ <body>
10
+ <!-- <style> -->
11
+ <table class="body">
12
+ <tr>
13
+ <td class="float-center" align="center" valign="top">
14
+ <center>
15
+ <table class="container">
16
+ <tr>
17
+ <td>
18
+ <table class="row">
19
+ <tr>
20
+ <th class="small-12 first columns decidim-bar">
21
+ <center class="decidim-logo">
22
+ <%= link_to @organization.name, root_url(host: @organization.host) %>
23
+ </center>
24
+ </th>
25
+ <th class="expander"></th>
26
+ </tr>
27
+ </table>
28
+ <table class="spacer">
29
+ <tbody>
30
+ <tr>
31
+ <td height="40px" style="font-size:40px;line-height:40px;"> </td>
32
+ </tr>
33
+ </tbody>
34
+ </table>
35
+
36
+ <table class="row content">
37
+ <tr>
38
+ <th class="small-12 first columns">
39
+ <%= yield %>
40
+ </th>
41
+ <th class="expander"></th>
42
+ </tr>
43
+ </table>
44
+
45
+ <table class="row">
46
+ <tr>
47
+ <th class="small-12 first columns">
48
+ </th>
49
+ <th class="expander"></th>
50
+ </tr>
51
+ </table>
52
+
53
+ <table class="row">
54
+ <tr>
55
+ <th class="expander"></th>
56
+ <th class="small-12 first columns cityhall-bar">
57
+ <div class="decidim-logo" style="float: right; text-align: right; padding-right: 16px">
58
+ <%= link_to @organization.name, root_url(host: @organization.host) %>
59
+ </div>
60
+ </th>
61
+ </tr>
62
+ </table>
63
+ </td>
64
+ </tr>
65
+ </table>
66
+ </center>
67
+ </td>
68
+ </tr>
69
+ </table>
70
+ </body>
71
+ </html>