Commit 2c68eefb65304097a2133ea097d7fe23e6a7ee89

Authored by Joenio Costa
Committed by Daniela Feitosa
1 parent 7590a7c4

Merging web2.0.yml and mail.yml into noosfero.yml

- new config entry: addthis_enabled
- new Rails initializer to load config file

(ActionItem1820)
app/helpers/application_helper.rb
... ... @@ -30,17 +30,6 @@ module ApplicationHelper
30 30 (@page && !@page.language.blank?) ? @page.language : FastGettext.locale
31 31 end
32 32  
33   - def load_web2_conf
34   - if File.exists?( RAILS_ROOT + '/config/web2.0.yml')
35   - YAML.load_file( RAILS_ROOT + '/config/web2.0.yml' )
36   - else
37   - {}
38   - end
39   - end
40   - def web2_conf
41   - @web_conf ||= load_web2_conf
42   - end
43   -
44 33 # Displays context help. You can pass the content of the help message as the
45 34 # first parameter or using template code inside a block passed to this
46 35 # method. *Note*: the block is ignored if <tt>content</tt> is not
... ... @@ -570,12 +559,12 @@ module ApplicationHelper
570 559 :protocol => 'http://',
571 560 :only_path => false,
572 561 :controller => 'avatar.php',
573   - :d => web2_conf['gravatar'] ? web2_conf['gravatar']['default'] : nil
  562 + :d => NOOSFERO_CONF['gravatar'] ? NOOSFERO_CONF['gravatar'] : nil
574 563 }.merge(options) )
575 564 end
576 565  
577 566 def str_gravatar_url_for(email, options = {})
578   - default = web2_conf['gravatar'] ? web2_conf['gravatar']['default'] : nil
  567 + default = NOOSFERO_CONF['gravatar'] ? NOOSFERO_CONF['gravatar'] : nil
579 568 url = 'http://www.gravatar.com/avatar.php?gravatar_id=' +
580 569 Digest::MD5.hexdigest(email)
581 570 {
... ...
app/models/google_maps.rb
... ... @@ -6,14 +6,6 @@ class GoogleMaps
6 6  
7 7 include ApplicationHelper
8 8  
9   - def erase_config
10   - @config = nil
11   - end
12   -
13   - def config
14   - @config ||= (web2_conf['googlemaps'] || {})
15   - end
16   -
17 9 def enabled?(domain)
18 10 domain = Domain.find_by_name(domain)
19 11 domain ? !domain.google_maps_key.nil? : false
... ... @@ -25,7 +17,7 @@ class GoogleMaps
25 17 end
26 18  
27 19 def initial_zoom
28   - config['initial_zoom'] || 4
  20 + NOOSFERO_CONF['googlemaps_initial_zoom'] || 4
29 21 end
30 22  
31 23 def api_url(domain)
... ...
app/models/mail_conf.rb
1 1 class MailConf
2 2 class << self
3 3  
4   - def config_file
5   - File.join(RAILS_ROOT, 'config', 'mail.yml')
6   - end
7   -
8   - def config
9   - if File.exists?(config_file)
10   - YAML.load_file(config_file)
11   - else
12   - { 'webmail_url' => 'http://webmail.example.com' }
13   - end
  4 + def default_webmail_url
  5 + 'http://webmail.example.com'
14 6 end
15 7  
16 8 def enabled?
17   - config['enabled'] || false
  9 + NOOSFERO_CONF['mail_enabled'] || false
18 10 end
19 11  
20 12 def webmail_url(username, domain)
21   - config['webmail_url'] % [username, domain]
  13 + (NOOSFERO_CONF['webmail_url'] || default_webmail_url) % [username, domain]
22 14 end
23 15  
24 16 end
... ...
app/views/content_viewer/view_page.rhtml
... ... @@ -101,21 +101,14 @@
101 101  
102 102 <%= display_source_info(@page) %>
103 103  
104   -<%
105   - # AddThis Button
106   - if block_given? && web2_conf['addthis']
107   - opts = web2_conf['addthis']
108   -%>
  104 +<% if NOOSFERO_CONF['addthis_enabled'] %>
109 105 <div id="addThis">
110 106 <script type="text/javascript">
111 107 addthis_brand = '<%= escape_javascript( @environment.name ) %>';
112   -<%=
113   - str = ''
114   - opts.each { |k, v|
115   - str += ' addthis_'+ k +' = "'+ escape_javascript( v ) +"\";\n"
116   - }
117   - str
118   -%></script>
  108 + addthis_pub = '<%= escape_javascript( NOOSFERO_CONF['addthis_pub'] ) %>';
  109 + addthis_logo = '<%= escape_javascript( NOOSFERO_CONF['addthis_logo'] ) %>';
  110 + addthis_options = '<%= escape_javascript( NOOSFERO_CONF['addthis_options'] ) %>';
  111 +</script>
119 112 <a href="http://www.addthis.com/bookmark.php" id="bt_addThis" target="_blank" onmouseover="return addthis_open(this, '', '[URL]')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="/images/bt-bookmark.gif" width="53" height="16" border="0" alt="" /></a><script type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widget.js"></script>
120 113 </div>
121 114 <% end %>
... ...
config/initializers/load_config.rb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +NOOSFERO_CONF = YAML.load_file("#{RAILS_ROOT}/config/noosfero.yml")[RAILS_ENV]
... ...
config/mail.yml.dist
... ... @@ -1,2 +0,0 @@
1   -enabled: true
2   -webmail_url: "http://mail.yourdomain.net/"
config/noosfero.yml 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +development: &DEVELOPMENT
  2 + mail_enabled: true
  3 + webmail_url: "http://localhost.localdomain/"
  4 + addthis_enabled: true
  5 + addthis_pub: your-user-name
  6 + addthis_logo: http://localhost:3000/images/logo-200x50.png
  7 + addthis_options: favorites, email, digg, delicious, technorati, slashdot, twitter, more
  8 + gravatar: wavatar
  9 + googlemaps_initial_zoom: 4
  10 +
  11 +test: &TEST
  12 + <<: *DEVELOPMENT
  13 +
  14 +production:
... ...
config/web2.0.yml.dist
... ... @@ -1,12 +0,0 @@
1   -# This file configures all Web 2.0 services used by this noosfero instalation
2   -
3   -# You can add (or remove) any addthis option here.
4   -# Know more: http://www.addthis.com/customization.php
5   -addthis:
6   - pub: your-user-name
7   - logo: http://localhost:3000/images/logo-200x50.png
8   - options: favorites, email, digg, delicious, technorati, slashdot, twitter, more
9   -googlemaps:
10   - key: <id google>
11   -gravatar:
12   - default: wavatar
gitignore.example
... ... @@ -5,7 +5,7 @@ doc/plugins
5 5 tmp
6 6 config/database.yml
7 7 config/session.secret
8   -config/mail.yml
  8 +config/noosfero.yml
9 9 config/ferret_server.yml
10 10 config/mongrel_cluster.yml
11 11 index
... ...
test/test_helper.rb
... ... @@ -250,4 +250,16 @@ class ActionController::IntegrationTest
250 250  
251 251 end
252 252  
  253 +def with_constants(constants, &block)
  254 + old_constants = Hash.new
  255 + constants.each do |constant, val|
  256 + old_constants[constant] = Object.const_get(constant)
  257 + silence_stderr{ Object.const_set(constant, val) }
  258 + end
  259 + block.call
  260 + old_constants.each do |constant, val|
  261 + silence_stderr{ Object.const_set(constant, val) }
  262 + end
  263 +end
  264 +
253 265 Profile
... ...
test/unit/application_helper_test.rb
... ... @@ -8,17 +8,6 @@ class ApplicationHelperTest &lt; Test::Unit::TestCase
8 8 self.stubs(:session).returns({})
9 9 end
10 10  
11   - should 'retrieve conf from "web2.0" config file' do
12   - yml = RAILS_ROOT + '/config/web2.0.yml'
13   - conf = {
14   - 'addthis'=>{'pub'=>'mylogin', 'options'=>'favorites, email'},
15   - 'gravatar'=>{'default'=>'wavatar'}
16   - }
17   - File.expects(:exists?).with(yml).returns(true)
18   - YAML.expects(:load_file).with(yml).returns(conf)
19   - assert_equal conf, web2_conf
20   - end
21   -
22 11 should 'calculate correctly partial for object' do
23 12 self.stubs(:params).returns({:controller => 'test'})
24 13  
... ... @@ -436,12 +425,13 @@ class ApplicationHelperTest &lt; Test::Unit::TestCase
436 425 end
437 426  
438 427 should 'generate a gravatar url' do
439   - stubs(:web2_conf).returns({"gravatar" => {"default" => "wavatar"}})
440   - url = str_gravatar_url_for( 'rms@gnu.org', :size => 50 )
441   - assert_match(/^http:\/\/www\.gravatar\.com\/avatar\.php\?/, url)
442   - assert_match(/(\?|&)gravatar_id=ed5214d4b49154ba0dc397a28ee90eb7(&|$)/, url)
443   - assert_match(/(\?|&)d=wavatar(&|$)/, url)
444   - assert_match(/(\?|&)size=50(&|$)/, url)
  428 + with_constants :NOOSFERO_CONF => {'gravatar' => 'crazyvatar'} do
  429 + url = str_gravatar_url_for( 'rms@gnu.org', :size => 50 )
  430 + assert_match(/^http:\/\/www\.gravatar\.com\/avatar\.php\?/, url)
  431 + assert_match(/(\?|&)gravatar_id=ed5214d4b49154ba0dc397a28ee90eb7(&|$)/, url)
  432 + assert_match(/(\?|&)d=crazyvatar(&|$)/, url)
  433 + assert_match(/(\?|&)size=50(&|$)/, url)
  434 + end
445 435 end
446 436  
447 437 should 'use theme passed via param when in development mode' do
... ...
test/unit/google_maps_test.rb
... ... @@ -4,8 +4,6 @@ class GoogleMapsTest &lt; Test::Unit::TestCase
4 4  
5 5 def setup
6 6 @domain = fast_create(Domain, :name => 'example-domain', :google_maps_key => 'DOMAIN_KEY')
7   - # force loading of config at every test
8   - GoogleMaps.erase_config
9 7 end
10 8  
11 9 attr_reader :domain
... ... @@ -19,18 +17,14 @@ class GoogleMapsTest &lt; Test::Unit::TestCase
19 17 assert !GoogleMaps.enabled?('domain-without-key')
20 18 end
21 19  
22   - should 'not crash if config not informed' do
23   - GoogleMaps.stubs(:config).returns({})
24   - assert_equal({}, GoogleMaps.config)
25   - end
26   -
27 20 should 'point correctly to google maps' do
28 21 assert_equal 'http://maps.google.com/maps?file=api&amp;v=2&amp;key=DOMAIN_KEY', GoogleMaps.api_url(domain.name)
29 22 end
30 23  
31 24 should 'provide initial_zoom setting' do
32   - GoogleMaps.stubs(:config).returns({'initial_zoom' => 2})
33   - assert_equal 2, GoogleMaps.initial_zoom
  25 + with_constants :NOOSFERO_CONF => {'googlemaps_initial_zoom' => 2} do
  26 + assert_equal 2, GoogleMaps.initial_zoom
  27 + end
34 28 end
35 29  
36 30 should 'use 4 as default initial_zoom' do
... ...
test/unit/load_config_test.rb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class LoadConfigTest < Test::Unit::TestCase
  4 +
  5 + should 'ensure YAML file exists' do
  6 + assert File.exists?("#{RAILS_ROOT}/config/noosfero.yml")
  7 + end
  8 +
  9 + should 'ensure YAML file was loaded' do
  10 + assert NOOSFERO_CONF
  11 + assert_kind_of Hash, NOOSFERO_CONF
  12 + end
  13 +
  14 +end
... ...
test/unit/mail_conf_test.rb
... ... @@ -2,36 +2,23 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
2 2  
3 3 class MailConfTest < ActiveSupport::TestCase
4 4  
5   - CONFIG_FILE = '/not/existing.yml'
6   -
7   - should 'use config/mail.yml as config' do
8   - assert_equal RAILS_ROOT + '/config/mail.yml', MailConf.config_file
9   - end
10   -
11 5 should 'enable if told to' do
12   - MailConf.stubs(:config_file).returns(CONFIG_FILE)
13   - File.expects(:exists?).with(CONFIG_FILE).returns(true)
14   - YAML.expects(:load_file).with(CONFIG_FILE).returns({ 'enabled' => true})
  6 + NOOSFERO_CONF['mail_enabled'] = true
15 7 assert_equal true, MailConf.enabled?
16 8 end
17 9  
18 10 should 'disable if told to' do
19   - MailConf.stubs(:config_file).returns(CONFIG_FILE)
20   - File.expects(:exists?).with(CONFIG_FILE).returns(true)
21   - YAML.expects(:load_file).with(CONFIG_FILE).returns({ 'enabled' => false })
  11 + NOOSFERO_CONF['mail_enabled'] = false
22 12 assert_equal false, MailConf.enabled?
23 13 end
24 14  
25   - should 'disable if config file not present' do
26   - MailConf.stubs(:config_file).returns(CONFIG_FILE)
27   - File.expects(:exists?).with(CONFIG_FILE).returns(false)
  15 + should 'disable by default' do
  16 + NOOSFERO_CONF['mail_enabled'] = nil
28 17 assert_equal false, MailConf.enabled?
29 18 end
30 19  
31 20 should 'provide webmail url preference' do
32   - MailConf.stubs(:config_file).returns(CONFIG_FILE)
33   - File.expects(:exists?).with(CONFIG_FILE).returns(true)
34   - YAML.expects(:load_file).with(CONFIG_FILE).returns({ 'enabled' => false, 'webmail_url' => 'http://some.url/webmail/%s/%s' })
  21 + NOOSFERO_CONF['webmail_url'] = 'http://some.url/webmail/%s/%s'
35 22 assert_equal 'http://some.url/webmail/login/example.com', MailConf.webmail_url('login', 'example.com')
36 23 end
37 24  
... ...