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 39 before_filter :detect_stuff_by_domain
40 40 attr_reader :environment
41 41  
  42 + before_filter :load_terminology
  43 +
42 44 # declares that the given <tt>actions</tt> cannot be accessed by other HTTP
43 45 # method besides POST.
44 46 def self.post_only(actions, redirect = { :action => 'index'})
... ... @@ -64,6 +66,10 @@ class ApplicationController &lt; ActionController::Base
64 66 end
65 67 end
66 68  
  69 + def load_terminology
  70 + Noosfero.terminology = environment.terminology
  71 + end
  72 +
67 73 def render_not_found(path = nil)
68 74 @path ||= request.path
69 75 # raise "#{@path} not found"
... ...
app/models/environment.rb
... ... @@ -204,6 +204,22 @@ class Environment &lt; ActiveRecord::Base
204 204 self.settings[:description] = value
205 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 224 # Validations
209 225 # #################################################
... ...
lib/noosfero.rb
... ... @@ -34,7 +34,7 @@ module Noosfero
34 34 self.terminology.get(t)
35 35 end
36 36 def self.terminology
37   - @terminology ||= Noosfero::Terminology::Default.new
  37 + @terminology ||= Noosfero::Terminology::Default.instance
38 38 end
39 39 def self.terminology=(term)
40 40 @terminology = term
... ...
lib/noosfero/terminology.rb
... ... @@ -7,12 +7,14 @@ module Noosfero
7 7  
8 8 # the default terminology. Just returns the same message as is.
9 9 class Default
  10 + include Singleton
10 11 def get(x)
11 12 x
12 13 end
13 14 end
14 15  
15 16 class Custom
  17 + include Singleton
16 18 def initialize(hash)
17 19 @messages = hash
18 20 end
... ...
lib/zen3_terminology.rb
... ... @@ -10,7 +10,7 @@ class Zen3Terminology &lt; Noosfero::Terminology::Custom
10 10 'Homepage' => N_('ePortfolio'),
11 11 'Communities' => N_('Groups'),
12 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 14 'The communities in which the user is a member' => N_('The groups in which the user is a member'),
15 15 'All communities' => N_('All groups'),
16 16 'Community' => N_('Group'),
... ...
test/functional/application_controller_test.rb
... ... @@ -214,4 +214,14 @@ class ApplicationControllerTest &lt; Test::Unit::TestCase
214 214 assert_no_tag :tag => 'div', :attributes => { :id => 'theme-test-panel' }
215 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 227 end
... ...