typus 0.9.25 → 0.9.26

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.25
1
+ 0.9.26
@@ -6,7 +6,7 @@ class Admin::MasterController < ApplicationController
6
6
 
7
7
  include Typus::Authentication
8
8
  include Typus::Format
9
- include Typus::Locale
9
+ include Typus::Preferences
10
10
  include Typus::Reloader
11
11
 
12
12
  if Typus::Configuration.options[:ssl]
@@ -20,7 +20,7 @@ class Admin::MasterController < ApplicationController
20
20
 
21
21
  before_filter :require_login
22
22
 
23
- before_filter :set_locale
23
+ before_filter :set_typus_preferences
24
24
 
25
25
  before_filter :set_resource
26
26
  before_filter :find_item,
@@ -5,24 +5,21 @@ class TypusController < ApplicationController
5
5
  layout :select_layout
6
6
 
7
7
  include Typus::Authentication
8
- include Typus::Locale
9
8
  include Typus::QuickEdit
9
+ include Typus::Preferences
10
10
  include Typus::Reloader
11
11
 
12
12
  if Typus::Configuration.options[:ssl]
13
13
  include SslRequirement
14
14
  ssl_required :sign_in, :sign_out,
15
15
  :dashboard,
16
- :recover_password, :reset_password,
17
- :set_locale
16
+ :recover_password, :reset_password
18
17
  end
19
18
 
20
19
  filter_parameter_logging :password
21
20
 
22
21
  before_filter :verify_typus_users_table_schema
23
22
 
24
- before_filter :set_default_locale, :except => [ :dashboard ]
25
-
26
23
  before_filter :reload_config_et_roles
27
24
  before_filter :require_login,
28
25
  :except => [ :sign_up, :sign_in, :sign_out,
@@ -33,15 +30,19 @@ class TypusController < ApplicationController
33
30
  :except => [ :sign_up, :sign_in, :sign_out,
34
31
  :dashboard,
35
32
  :recover_password, :reset_password,
36
- :quick_edit, :set_locale ]
33
+ :quick_edit ]
37
34
 
38
35
  before_filter :recover_password_disabled?,
39
36
  :only => [ :recover_password, :reset_password ]
40
37
 
41
- before_filter :set_locale, :only => [ :dashboard ]
42
-
43
38
  def dashboard
44
- flash[:notice] = _("There are not defined applications in config/typus/*.yml.") if Typus.applications.empty?
39
+ begin
40
+ I18n.locale = @current_user.preferences[:locale]
41
+ flash[:notice] = _("There are not defined applications in config/typus/*.yml.") if Typus.applications.empty?
42
+ rescue
43
+ @current_user.update_attributes :preferences => { :locale => Typus::Configuration.options[:default_locale] }
44
+ retry
45
+ end
45
46
  end
46
47
 
47
48
  def sign_in
@@ -185,16 +185,4 @@ module TypusHelper
185
185
  HTML
186
186
  end
187
187
 
188
- def locales(uri = admin_set_locale_path)
189
-
190
- return unless Typus.locales.many?
191
-
192
- locale_links = Typus.locales.map { |l| "<a href=\"#{uri}?locale=#{l.last}\">#{l.first.downcase}</a>" }
193
-
194
- <<-HTML
195
- <p>#{_("Set language to")} #{locale_links.join(', ')}.</p>
196
- HTML
197
-
198
- end
199
-
200
188
  end
@@ -61,7 +61,6 @@
61
61
  <%= typus_block :location => 'shared', :partial => 'footer' %>
62
62
  </div>
63
63
  <div class="right">
64
- <%= locales %>
65
64
  </div>
66
65
  <div class="clear"></div>
67
66
  </div>
@@ -96,7 +96,6 @@ de:
96
96
  "Remove entry?": "Eintrag entfernen?"
97
97
  "Unrelate {{unrelate_model}} from {{unrelate_model_from}}?": "Verkn&uuml;pfung zwischen {{unrelate_model}} und {{unrelate_model_from}}entfernen?"
98
98
  "Change {{attribute}}?": "{{attribute}}&auml;ndern?"
99
- "Set language": "Sprache einstellen"
100
99
  "Today": "Heute"
101
100
  "Last few days": "Letzten Tage"
102
101
  "Last 7 days": "Letzten 7 Tage"
@@ -104,5 +103,4 @@ de:
104
103
  "{{model}} filtered by {{filtered_by}}": "{{model}} gefiltert nach {{filtered_by}}"
105
104
  "True": "Richtig"
106
105
  "False": "Falsch"
107
- "Set language to": "Sprache wechseln zu"
108
106
  "Are you sure you want to sign out and end your session?": "Wollen Sie sich abmelden und die Sitzung beenden?"
@@ -96,7 +96,6 @@ es:
96
96
  "Remove entry?": "¿Borrar entrada?"
97
97
  "Unrelate {{unrelate_model}} from {{unrelate_model_from}}?": "Unrelate {{unrelate_model}} from {{unrelate_model_from}}?"
98
98
  "Change {{attribute}}?": "Change {{attribute}}?"
99
- "Set language": "Cambiar idioma"
100
99
  "Today": "Hoy"
101
100
  "Last few days": "Últimos dias"
102
101
  "Last 7 days": "Últimos 7 dias"
@@ -104,5 +103,4 @@ es:
104
103
  "{{model}} filtered by {{filtered_by}}": "{{model}} filtrados por {{filtered_by}}"
105
104
  "True": "Verdadero"
106
105
  "False": "Falso"
107
- "Set language to": "Idioma"
108
106
  "Are you sure you want to sign out and end your session?":
@@ -100,7 +100,6 @@
100
100
  "Remove entry?":
101
101
  "Unrelate {{unrelate_model}} from {{unrelate_model_from}}?":
102
102
  "Change {{attribute}}?":
103
- "Set language":
104
103
  "Today":
105
104
  "Last few days":
106
105
  "Last 7 days":
@@ -108,5 +107,4 @@
108
107
  "{{model}} filtered by {{filtered_by}}":
109
108
  "True":
110
109
  "False":
111
- "Set language to":
112
110
  "Are you sure you want to sign out and end your session?":
@@ -96,7 +96,6 @@ pt-BR:
96
96
  "Remove entry?": "Remover entrada?"
97
97
  "Unrelate {{unrelate_model}} from {{unrelate_model_from}}?": "Desvincular {{unrelate_model}} de {{unrelate_model_from}}?"
98
98
  "Change {{attribute}}?": "Mudar {{attribute}}?"
99
- "Set language": "Mudar idioma"
100
99
  "Today": "Hoje"
101
100
  "Last few days": "Últimos dias"
102
101
  "Last 7 days": "Últimos 7 dias"
@@ -106,5 +105,4 @@ pt-BR:
106
105
  "{{model}} filtered by {{filtered_by}}": "{{model}} filtrados por {{filtered_by}}"
107
106
  "True": "Verdadeiro"
108
107
  "False": "Falso"
109
- "Set language to": "Idioma"
110
108
  "Are you sure you want to sign out and end your session?": "Tem certeza que quer sair e encerrar sua sessão?"
@@ -96,7 +96,6 @@ ru:
96
96
  "Remove entry?": "Удалить запись?"
97
97
  "Unrelate {{unrelate_model}} from {{unrelate_model_from}}?": "Отсоединить {{unrelate_model}} от {{unrelate_model_from}}?"
98
98
  "Change {{attribute}}?": "Изменить {{attribute}}?"
99
- "Set language": "Установить язык"
100
99
  "Today": "Сегодня"
101
100
  "Last few days": "Последние дней"
102
101
  "Last 7 days": "Последние 7 дней"
@@ -106,5 +105,4 @@ ru:
106
105
  "{{model}} filtered by {{filtered_by}}":
107
106
  "True":
108
107
  "False":
109
- "Set language to":
110
108
  "Are you sure you want to sign out and end your session?":
data/config/routes.rb CHANGED
@@ -8,7 +8,6 @@ ActionController::Routing::Routes.draw do |map|
8
8
  i.admin_sign_up 'sign_up', :action => 'sign_up'
9
9
  i.admin_recover_password 'recover_password', :action => 'recover_password'
10
10
  i.admin_reset_password 'reset_password', :action => 'reset_password'
11
- i.admin_set_locale 'set_locale', :action => 'set_locale'
12
11
  end
13
12
 
14
13
  end
@@ -4,8 +4,8 @@
4
4
 
5
5
  Typus::Configuration.options[:app_name] = '<%= application %>'
6
6
  # Typus::Configuration.options[:config_folder] = 'config/typus'
7
+ # Typus::Configuration.options[:default_locale] = :en
7
8
  # Typus::Configuration.options[:email] = 'admin@example.com'
8
- # Typus::Configuration.options[:locales] = [ [ "English", :en ], [ "Español", :es ] ]
9
9
  # Typus::Configuration.options[:recover_password] = true
10
10
  # Typus::Configuration.options[:root] = 'admin'
11
11
  # Typus::Configuration.options[:ssl] = false
@@ -1,9 +1,9 @@
1
1
  TypusUser:
2
2
  fields:
3
3
  list: email, role, status
4
- form: first_name, last_name, role, email, password, password_confirmation
4
+ form: first_name, last_name, role, email, password, password_confirmation, language
5
5
  options:
6
- selectors: role
6
+ selectors: role, language
7
7
  booleans:
8
8
  status: Active, Inactive
9
9
  filters: status, role
data/lib/typus.rb CHANGED
@@ -11,11 +11,11 @@ module Typus
11
11
  end
12
12
 
13
13
  def locales
14
- Typus::Configuration.options[:locales]
15
- end
16
-
17
- def default_locale
18
- locales.map(&:last).first
14
+ [ [ "German", 'de' ],
15
+ [ "English", 'en' ],
16
+ [ "Español", 'es' ],
17
+ [ "Portuguese", 'pt-BR' ],
18
+ [ "Russian", 'ru' ] ]
19
19
  end
20
20
 
21
21
  def applications
@@ -103,8 +103,8 @@ module Typus
103
103
  require 'typus/authentication'
104
104
  require 'typus/format'
105
105
  require 'typus/generator'
106
- require 'typus/locale'
107
106
  require 'typus/preview'
107
+ require 'typus/preferences'
108
108
  require 'typus/reloader'
109
109
  require 'typus/quick_edit'
110
110
  require 'typus/user'
@@ -5,9 +5,9 @@ module Typus
5
5
  # Default options which can be overwritten from the initializer.
6
6
  typus_options = { :app_name => 'Typus',
7
7
  :config_folder => 'config/typus',
8
+ :default_locale => :en,
8
9
  :email => 'admin@example.com',
9
10
  :image_preview_size => 'typus',
10
- :locales => [ [ "English", :en ] ],
11
11
  :recover_password => false,
12
12
  :root => 'admin',
13
13
  :ssl => false,
data/lib/typus/locale.rb CHANGED
@@ -1,27 +0,0 @@
1
- module Typus
2
-
3
- module Locale
4
-
5
- def set_locale
6
- if params[:locale]
7
- I18n.locale = params[:locale]
8
- session[:typus_locale] = params[:locale]
9
- @current_user.update_attributes :preferences => { :locale => params[:locale] }
10
- redirect_to request.referer || admin_dashboard_path
11
- else
12
- begin
13
- I18n.locale = @current_user.preferences[:locale]
14
- rescue
15
- @current_user.update_attributes :preferences => { :locale => Typus.default_locale }
16
- retry
17
- end
18
- end
19
- end
20
-
21
- def set_default_locale
22
- I18n.locale = Typus.default_locale
23
- end
24
-
25
- end
26
-
27
- end
@@ -0,0 +1,11 @@
1
+ module Typus
2
+
3
+ module Preferences
4
+
5
+ def set_typus_preferences
6
+ I18n.locale = @current_user.preferences[:locale]
7
+ end
8
+
9
+ end
10
+
11
+ end
data/lib/typus/user.rb CHANGED
@@ -25,7 +25,7 @@ module Typus
25
25
  validates_presence_of :role
26
26
 
27
27
  before_save :initialize_salt, :encrypt_password, :initialize_token
28
- before_create :set_preferences
28
+ before_save :set_preferences
29
29
 
30
30
  serialize :preferences
31
31
 
@@ -41,6 +41,10 @@ module Typus
41
41
  Typus::Configuration.roles.keys.sort
42
42
  end
43
43
 
44
+ def language
45
+ Typus.locales
46
+ end
47
+
44
48
  def authenticate(email, password)
45
49
  user = find_by_email_and_status(email, true)
46
50
  user && user.authenticated?(password) ? user : nil
@@ -99,8 +103,18 @@ module Typus
99
103
 
100
104
  protected
101
105
 
106
+ def language
107
+ preferences[:locale] rescue Typus::Configuration.options[:default_locale]
108
+ end
109
+
110
+ def language=(locale)
111
+ self.preferences = { :locale => locale }
112
+ end
113
+
102
114
  def set_preferences
103
- self.preferences = { :locale => Typus.default_locale }
115
+ if self.preferences.nil? || self.preferences[:locale].nil? || self.preferences[:locale].blank?
116
+ self.preferences = { :locale => Typus::Configuration.options[:default_locale] }
117
+ end
104
118
  end
105
119
 
106
120
  def generate_hash(string)
@@ -8,6 +8,7 @@ admin:
8
8
  token: 1A2B3C4D5E6F
9
9
  salt: admin
10
10
  crypted_password: <%= Digest::SHA1.hexdigest("--admin--#{12345678}") %>
11
+ preferences: { :locale => :en }
11
12
 
12
13
  editor:
13
14
  id: 2
@@ -19,6 +20,7 @@ editor:
19
20
  token: A2B3C4D5E6F1
20
21
  salt: editor
21
22
  crypted_password: <%= Digest::SHA1.hexdigest("--editor--#{12345678}") %>
23
+ preferences: { :locale => :en }
22
24
 
23
25
  disabled_user:
24
26
  id: 3
@@ -30,6 +32,7 @@ disabled_user:
30
32
  token: 2B3C4D5E6F1A
31
33
  salt: disabled_user
32
34
  crypted_password: <%= Digest::SHA1.hexdigest("--disabled_user--#{12345678}") %>
35
+ preferences: { :locale => :en }
33
36
 
34
37
  designer:
35
38
  id: 4
@@ -41,6 +44,7 @@ designer:
41
44
  token: B3C4D5E6F1A2
42
45
  salt: designer
43
46
  crypted_password: <%= Digest::SHA1.hexdigest("--designer--#{12345678}") %>
47
+ preferences: { :locale => :en }
44
48
 
45
49
  removed_role:
46
50
  id: 5
@@ -52,3 +56,4 @@ removed_role:
52
56
  token: 3C4D5E6F1A2B
53
57
  salt: removed_role
54
58
  crypted_password: <%= Digest::SHA1.hexdigest("--removed_role--#{12345678}") %>
59
+ preferences: { :locale => :en }
@@ -101,17 +101,4 @@ class TypusHelperTest < ActiveSupport::TestCase
101
101
  assert_equal expected, output
102
102
  end
103
103
 
104
- def test_locales
105
-
106
- options = { :locales => [ [ "English", :en ], [ "Español", :es ] ] }
107
- Typus::Configuration.stubs(:options).returns(options)
108
-
109
- output = locales('set_locale')
110
- expected = <<-HTML
111
- <p>Set language to <a href=\"set_locale?locale=en\">english</a>, <a href=\"set_locale?locale=es\">español</a>.</p>
112
- HTML
113
- assert_equal expected, output
114
-
115
- end
116
-
117
104
  end
@@ -16,6 +16,7 @@ class ActiveRecordTest < ActiveSupport::TestCase
16
16
  [:token, :string],
17
17
  [:salt, :string],
18
18
  [:crypted_password, :string],
19
+ [:preferences, :string],
19
20
  [:created_at, :datetime],
20
21
  [:updated_at, :datetime]]
21
22
  assert_equal expected_fields.map { |i| i.first }, TypusUser.model_fields.keys
@@ -11,8 +11,8 @@ class ConfigurationTest < ActiveSupport::TestCase
11
11
  return if File.exist?(initializer)
12
12
  assert_equal 'Typus', Typus::Configuration.options[:app_name]
13
13
  assert_equal 'vendor/plugins/typus/test/config/working', Typus::Configuration.options[:config_folder]
14
+ assert_equal :en, Typus::Configuration.options[:default_locale]
14
15
  assert_equal 'admin@example.com', Typus::Configuration.options[:email]
15
- assert_equal [ [ "English", :en] ], Typus::Configuration.options[:locales]
16
16
  assert_equal false, Typus::Configuration.options[:recover_password]
17
17
  assert_equal 'admin', Typus::Configuration.options[:root]
18
18
  assert_equal false, Typus::Configuration.options[:ssl]
@@ -11,7 +11,7 @@ class RoutesTest < ActiveSupport::TestCase
11
11
  expected = [ :admin_sign_up, :admin_sign_in, :admin_sign_out,
12
12
  :admin_recover_password, :admin_reset_password,
13
13
  :admin_dashboard,
14
- :admin_quick_edit, :admin_set_locale ]
14
+ :admin_quick_edit ]
15
15
 
16
16
  expected.each { |route| assert routes.include?(route) }
17
17
 
@@ -62,7 +62,7 @@ class RoutesTest < ActiveSupport::TestCase
62
62
 
63
63
  actions = [ 'sign_up', 'sign_in', 'sign_out',
64
64
  'recover_password', 'reset_password',
65
- 'quick_edit', 'set_locale' ]
65
+ 'quick_edit' ]
66
66
 
67
67
  actions.each { |a| assert_routing "/admin/#{a}", :controller => 'typus', :action => a }
68
68
 
@@ -12,20 +12,6 @@ class TypusTest < ActiveSupport::TestCase
12
12
  assert_equal expected, Typus.root
13
13
  end
14
14
 
15
- def test_should_return_locales
16
- initializer = "#{Rails.root}/config/initializers/typus.rb"
17
- return if File.exist?(initializer)
18
- assert Typus.respond_to?(:locales)
19
- assert Typus.locales.kind_of?(Array)
20
- assert_equal [["English", :en]], Typus.locales
21
- end
22
-
23
- def test_should_return_default_locale
24
- assert Typus.respond_to?(:default_locale)
25
- assert Typus.default_locale.kind_of?(Symbol)
26
- assert_equal :en, Typus.default_locale
27
- end
28
-
29
15
  def test_should_return_applications_and_should_be_sorted
30
16
  assert Typus.respond_to?(:applications)
31
17
  assert Typus.applications.kind_of?(Array)
data/test/schema.rb CHANGED
@@ -50,6 +50,7 @@ ActiveRecord::Schema.define do
50
50
  t.string :token, :null => false
51
51
  t.string :salt, :null => false
52
52
  t.string :crypted_password, :null => false
53
+ t.string :preferences
53
54
  t.timestamps
54
55
  end
55
56
 
@@ -8,7 +8,8 @@ class TypusUserTest < ActiveSupport::TestCase
8
8
  :email => 'test@example.com',
9
9
  :password => '12345678',
10
10
  :password_confirmation => '12345678',
11
- :role => Typus::Configuration.options[:root] }
11
+ :role => Typus::Configuration.options[:root],
12
+ :preferences => { :locale => :en } }
12
13
  @typus_user = TypusUser.new(@data)
13
14
  end
14
15
 
data/typus.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{typus}
8
- s.version = "0.9.25"
8
+ s.version = "0.9.26"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Francesc Esplugas"]
@@ -107,6 +107,7 @@ Gem::Specification.new do |s|
107
107
  "lib/typus/hash.rb",
108
108
  "lib/typus/locale.rb",
109
109
  "lib/typus/object.rb",
110
+ "lib/typus/preferences.rb",
110
111
  "lib/typus/preview.rb",
111
112
  "lib/typus/quick_edit.rb",
112
113
  "lib/typus/reloader.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.25
4
+ version: 0.9.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesc Esplugas
@@ -113,6 +113,7 @@ files:
113
113
  - lib/typus/hash.rb
114
114
  - lib/typus/locale.rb
115
115
  - lib/typus/object.rb
116
+ - lib/typus/preferences.rb
116
117
  - lib/typus/preview.rb
117
118
  - lib/typus/quick_edit.rb
118
119
  - lib/typus/reloader.rb