Commit 913d398aa3e8cbfbc7b55f778022ce23a75ffbe3
1 parent
25ee5ed5
Exists in
master
and in
29 other branches
ActionItem114: searching for controllers inside design_blocks
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@843 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
22 additions
and
11 deletions
Show diff stats
lib/noosfero.rb
| @@ -3,23 +3,28 @@ module Noosfero | @@ -3,23 +3,28 @@ module Noosfero | ||
| 3 | VERSION = '0.3.0' | 3 | VERSION = '0.3.0' |
| 4 | SVN_ROOT = 'https://svn.colivre.coop.br/svn/noosfero' | 4 | SVN_ROOT = 'https://svn.colivre.coop.br/svn/noosfero' |
| 5 | 5 | ||
| 6 | - def self.controllers_in_directory(dir) | ||
| 7 | - app_controller_path = Dir.glob(File.join(RAILS_ROOT, 'app', 'controllers', dir, '*_controller.rb')) | 6 | + def self.pattern_for_controllers_in_directory(dir) |
| 7 | + disjunction = controllers_in_directory(dir).join('|') | ||
| 8 | + pattern = disjunction.blank? ? '' : ('(' + disjunction + ')') | ||
| 9 | + Regexp.new(pattern) | ||
| 10 | + end | ||
| 8 | 11 | ||
| 9 | - # FIXME we can remove this line here if the controllers needed by application are not loaded | ||
| 10 | - # directly | ||
| 11 | - design_controller_path = Dir.glob(File.join(RAILS_ROOT, 'app', 'design_blocks', '*', 'controllers', '*_controller.rb')) | 12 | + def self.pattern_for_controllers_from_design_blocks |
| 13 | + items = Dir.glob(File.join(RAILS_ROOT, 'app', 'design_blocks', '*', 'controllers', '*_controller.rb')).map do |item| | ||
| 14 | + item.gsub(/^.*\/([^\/]+)_controller.rb$/, '\1') | ||
| 15 | + end.join('|') | ||
| 16 | + Regexp.new(items.blank? ? '' : ('(' + items + ')')) | ||
| 17 | + end | ||
| 12 | 18 | ||
| 13 | - (app_controller_path + design_controller_path).map do |item| | 19 | + private |
| 20 | + | ||
| 21 | + def self.controllers_in_directory(dir) | ||
| 22 | + app_controller_path = Dir.glob(File.join(RAILS_ROOT, 'app', 'controllers', dir, '*_controller.rb')) | ||
| 23 | + app_controller_path.map do |item| | ||
| 14 | item.gsub(/^.*\/([^\/]+)_controller.rb$/, '\1') | 24 | item.gsub(/^.*\/([^\/]+)_controller.rb$/, '\1') |
| 15 | end | 25 | end |
| 16 | end | 26 | end |
| 17 | 27 | ||
| 18 | - def self.pattern_for_controllers_in_directory(dir) | ||
| 19 | - disjunction = controllers_in_directory(dir).join('|') | ||
| 20 | - pattern = disjunction.blank? ? '' : (('(' + disjunction + ')')) | ||
| 21 | - Regexp.new(pattern) | ||
| 22 | - end | ||
| 23 | end | 28 | end |
| 24 | 29 | ||
| 25 | require 'noosfero/constants' | 30 | require 'noosfero/constants' |
test/unit/noosfero_test.rb
| @@ -17,4 +17,10 @@ class NoosferoTest < Test::Unit::TestCase | @@ -17,4 +17,10 @@ class NoosferoTest < Test::Unit::TestCase | ||
| 17 | Dir.stubs(:glob).returns([]) | 17 | Dir.stubs(:glob).returns([]) |
| 18 | assert_equal(//, Noosfero.pattern_for_controllers_in_directory('lala')) | 18 | assert_equal(//, Noosfero.pattern_for_controllers_in_directory('lala')) |
| 19 | end | 19 | end |
| 20 | + | ||
| 21 | + should 'support controllers from design_blocks directory' do | ||
| 22 | + Dir.expects(:glob).with("#{RAILS_ROOT}/app/design_blocks/*/controllers/*_controller.rb").returns(['app/design_blocks/block1/controllers/block1_controller.rb', 'app/design_blocks/block2/controllers/block2_controller.rb']) | ||
| 23 | + assert_equal(/(block1|block2)/, Noosfero.pattern_for_controllers_from_design_blocks) | ||
| 24 | + end | ||
| 25 | + | ||
| 20 | end | 26 | end |