From 9e462a970e1b16ccd597093983cf125b145845a5 Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Fri, 29 Aug 2008 21:45:53 +0000 Subject: [PATCH] ActionItem629: made terminology an environment cofig --- app/controllers/application.rb | 6 ++++++ app/models/environment.rb | 16 ++++++++++++++++ lib/noosfero.rb | 2 +- lib/noosfero/terminology.rb | 2 ++ lib/zen3_terminology.rb | 2 +- test/functional/application_controller_test.rb | 10 ++++++++++ 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 4fc26dc..f1b1f2c 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -39,6 +39,8 @@ class ApplicationController < ActionController::Base before_filter :detect_stuff_by_domain attr_reader :environment + before_filter :load_terminology + # declares that the given actions cannot be accessed by other HTTP # method besides POST. def self.post_only(actions, redirect = { :action => 'index'}) @@ -64,6 +66,10 @@ class ApplicationController < ActionController::Base end end + def load_terminology + Noosfero.terminology = environment.terminology + end + def render_not_found(path = nil) @path ||= request.path # raise "#{@path} not found" diff --git a/app/models/environment.rb b/app/models/environment.rb index 40af24f..67d2d51 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -204,6 +204,22 @@ class Environment < ActiveRecord::Base self.settings[:description] = value end + def terminology + if self.settings[:terminology] + self.settings[:terminology].constantize.instance + else + Noosfero.terminology + end + end + + def terminology=(value) + if value + self.settings[:terminology] = value.class.name + else + self.settings[:terminology] = nil + end + end + # ################################################# # Validations # ################################################# diff --git a/lib/noosfero.rb b/lib/noosfero.rb index 0220016..b668176 100644 --- a/lib/noosfero.rb +++ b/lib/noosfero.rb @@ -34,7 +34,7 @@ module Noosfero self.terminology.get(t) end def self.terminology - @terminology ||= Noosfero::Terminology::Default.new + @terminology ||= Noosfero::Terminology::Default.instance end def self.terminology=(term) @terminology = term diff --git a/lib/noosfero/terminology.rb b/lib/noosfero/terminology.rb index 23c950e..609d643 100644 --- a/lib/noosfero/terminology.rb +++ b/lib/noosfero/terminology.rb @@ -7,12 +7,14 @@ module Noosfero # the default terminology. Just returns the same message as is. class Default + include Singleton def get(x) x end end class Custom + include Singleton def initialize(hash) @messages = hash end diff --git a/lib/zen3_terminology.rb b/lib/zen3_terminology.rb index 79e449e..cce6216 100644 --- a/lib/zen3_terminology.rb +++ b/lib/zen3_terminology.rb @@ -10,7 +10,7 @@ class Zen3Terminology < Noosfero::Terminology::Custom 'Homepage' => N_('ePortfolio'), 'Communities' => N_('Groups'), 'A block that displays your communities' => N_('A block that displays your groups'), - 'A block that displays your friends' => N_('A block that displays your contacts') + 'A block that displays your friends' => N_('A block that displays your contacts'), 'The communities in which the user is a member' => N_('The groups in which the user is a member'), 'All communities' => N_('All groups'), 'Community' => N_('Group'), diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index a039492..b13a8f2 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -214,4 +214,14 @@ class ApplicationControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'div', :attributes => { :id => 'theme-test-panel' } end + should 'load terminology from environment' do + term = Zen3Terminology.instance + env = Environment.default + Environment.stubs(:default).returns(env) + env.stubs(:terminology).returns(term) + + Noosfero.expects(:terminology=).with(term) + get :index + end + end -- libgit2 0.21.2