Commit 9e462a970e1b16ccd597093983cf125b145845a5

Authored by MoisesMachado
1 parent ce19d6fd

ActionItem629: made terminology an environment cofig

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2432 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/application.rb
@@ -39,6 +39,8 @@ class ApplicationController < ActionController::Base @@ -39,6 +39,8 @@ class ApplicationController < ActionController::Base
39 before_filter :detect_stuff_by_domain 39 before_filter :detect_stuff_by_domain
40 attr_reader :environment 40 attr_reader :environment
41 41
  42 + before_filter :load_terminology
  43 +
42 # declares that the given <tt>actions</tt> cannot be accessed by other HTTP 44 # declares that the given <tt>actions</tt> cannot be accessed by other HTTP
43 # method besides POST. 45 # method besides POST.
44 def self.post_only(actions, redirect = { :action => 'index'}) 46 def self.post_only(actions, redirect = { :action => 'index'})
@@ -64,6 +66,10 @@ class ApplicationController &lt; ActionController::Base @@ -64,6 +66,10 @@ class ApplicationController &lt; ActionController::Base
64 end 66 end
65 end 67 end
66 68
  69 + def load_terminology
  70 + Noosfero.terminology = environment.terminology
  71 + end
  72 +
67 def render_not_found(path = nil) 73 def render_not_found(path = nil)
68 @path ||= request.path 74 @path ||= request.path
69 # raise "#{@path} not found" 75 # raise "#{@path} not found"
app/models/environment.rb
@@ -204,6 +204,22 @@ class Environment &lt; ActiveRecord::Base @@ -204,6 +204,22 @@ class Environment &lt; ActiveRecord::Base
204 self.settings[:description] = value 204 self.settings[:description] = value
205 end 205 end
206 206
  207 + def terminology
  208 + if self.settings[:terminology]
  209 + self.settings[:terminology].constantize.instance
  210 + else
  211 + Noosfero.terminology
  212 + end
  213 + end
  214 +
  215 + def terminology=(value)
  216 + if value
  217 + self.settings[:terminology] = value.class.name
  218 + else
  219 + self.settings[:terminology] = nil
  220 + end
  221 + end
  222 +
207 # ################################################# 223 # #################################################
208 # Validations 224 # Validations
209 # ################################################# 225 # #################################################
lib/noosfero.rb
@@ -34,7 +34,7 @@ module Noosfero @@ -34,7 +34,7 @@ module Noosfero
34 self.terminology.get(t) 34 self.terminology.get(t)
35 end 35 end
36 def self.terminology 36 def self.terminology
37 - @terminology ||= Noosfero::Terminology::Default.new 37 + @terminology ||= Noosfero::Terminology::Default.instance
38 end 38 end
39 def self.terminology=(term) 39 def self.terminology=(term)
40 @terminology = term 40 @terminology = term
lib/noosfero/terminology.rb
@@ -7,12 +7,14 @@ module Noosfero @@ -7,12 +7,14 @@ module Noosfero
7 7
8 # the default terminology. Just returns the same message as is. 8 # the default terminology. Just returns the same message as is.
9 class Default 9 class Default
  10 + include Singleton
10 def get(x) 11 def get(x)
11 x 12 x
12 end 13 end
13 end 14 end
14 15
15 class Custom 16 class Custom
  17 + include Singleton
16 def initialize(hash) 18 def initialize(hash)
17 @messages = hash 19 @messages = hash
18 end 20 end
lib/zen3_terminology.rb
@@ -10,7 +10,7 @@ class Zen3Terminology &lt; Noosfero::Terminology::Custom @@ -10,7 +10,7 @@ class Zen3Terminology &lt; Noosfero::Terminology::Custom
10 'Homepage' => N_('ePortfolio'), 10 'Homepage' => N_('ePortfolio'),
11 'Communities' => N_('Groups'), 11 'Communities' => N_('Groups'),
12 'A block that displays your communities' => N_('A block that displays your groups'), 12 'A block that displays your communities' => N_('A block that displays your groups'),
13 - 'A block that displays your friends' => N_('A block that displays your contacts') 13 + 'A block that displays your friends' => N_('A block that displays your contacts'),
14 'The communities in which the user is a member' => N_('The groups in which the user is a member'), 14 'The communities in which the user is a member' => N_('The groups in which the user is a member'),
15 'All communities' => N_('All groups'), 15 'All communities' => N_('All groups'),
16 'Community' => N_('Group'), 16 'Community' => N_('Group'),
test/functional/application_controller_test.rb
@@ -214,4 +214,14 @@ class ApplicationControllerTest &lt; Test::Unit::TestCase @@ -214,4 +214,14 @@ class ApplicationControllerTest &lt; Test::Unit::TestCase
214 assert_no_tag :tag => 'div', :attributes => { :id => 'theme-test-panel' } 214 assert_no_tag :tag => 'div', :attributes => { :id => 'theme-test-panel' }
215 end 215 end
216 216
  217 + should 'load terminology from environment' do
  218 + term = Zen3Terminology.instance
  219 + env = Environment.default
  220 + Environment.stubs(:default).returns(env)
  221 + env.stubs(:terminology).returns(term)
  222 +
  223 + Noosfero.expects(:terminology=).with(term)
  224 + get :index
  225 + end
  226 +
217 end 227 end