Commit b3e60f94024fd563d7bb3871cdec9f3ab15b2012

Authored by AntonioTerceiro
1 parent 37e9940b

r262@sede: terceiro | 2007-07-29 20:34:06 -0300

ActionItem0: moving available design components into Design module
 


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@266 3f533792-8f58-4932-b0fe-aaf55b0a4547
vendor/plugins/design/lib/design.rb
@@ -8,10 +8,13 @@ require 'design/editor' @@ -8,10 +8,13 @@ require 'design/editor'
8 8
9 module Design 9 module Design
10 10
  11 + def design_plugin_data
  12 + @design_plugin_data ||= Hash.new
  13 + end
  14 +
11 # gets the Design object for this controller 15 # gets the Design object for this controller
12 def design 16 def design
13 - @design_plugin_data ||= Hash.new  
14 - data = @design_plugin_data 17 + data = design_plugin_data
15 18
16 return data[:design] if data.has_key?(:design) 19 return data[:design] if data.has_key?(:design)
17 20
@@ -54,5 +57,17 @@ module Design @@ -54,5 +57,17 @@ module Design
54 Design.instance_variable_set('@public_filesystem_root', value) 57 Design.instance_variable_set('@public_filesystem_root', value)
55 end 58 end
56 59
  60 + def Design.available_templates
  61 + Dir.glob(File.join(Design.public_filesystem_root, Design.design_root, 'templates', '*')).select {|item| File.directory?(item) }.map {|item| File.basename(item) }
  62 + end
  63 +
  64 + def Design.available_themes
  65 + Dir.glob(File.join(Design.public_filesystem_root, Design.design_root, 'themes', '*')).select {|item| File.directory?(item) }.map {|item| File.basename(item) }
  66 + end
  67 +
  68 + def Design.available_icon_themes
  69 + Dir.glob(File.join(Design.public_filesystem_root, Design.design_root, 'icons', '*')).select {|item| File.directory?(item) }.map {|item| File.basename(item) }
  70 + end
  71 +
57 72
58 end 73 end
vendor/plugins/design/lib/design/editor.rb
@@ -6,11 +6,7 @@ module Design @@ -6,11 +6,7 @@ module Design
6 # from flexible_template 6 # from flexible_template
7 module Editor 7 module Editor
8 8
9 - #FIXME: move extraction of these values elsewhere  
10 - def start  
11 - @ft_config[:available_templates] = parse_path(Dir.glob("#{RAILS_ROOT}/public/templates/*"), 'templates/')  
12 - @ft_config[:available_themes] = parse_path(Dir.glob("#{RAILS_ROOT}/public/themes/*"), 'themes/')  
13 - @ft_config[:available_icon_themes] = parse_path(Dir.glob("#{RAILS_ROOT}/public/icons/*"), 'icons/') 9 + def designer
14 end 10 end
15 11
16 def flexible_template_edit_template? 12 def flexible_template_edit_template?
@@ -19,21 +15,21 @@ module Design @@ -19,21 +15,21 @@ module Design
19 15
20 # Set the default template to the profile 16 # Set the default template to the profile
21 def set_default_template 17 def set_default_template
22 - set_template(@ft_config[:owner],params[:template_name]) if exist_template? params[:template_name] 18 + set_template(design,params[:template_name]) if exist_template? params[:template_name]
23 end 19 end
24 20
25 # Set the default theme to the profile 21 # Set the default theme to the profile
26 def set_default_theme 22 def set_default_theme
27 - set_theme(@ft_config[:owner],params[:theme_name]) if exist_theme? params[:theme_name] 23 + set_theme(design,params[:theme_name]) if exist_theme? params[:theme_name]
28 end 24 end
29 25
30 # Set the default icons theme to the profile 26 # Set the default icons theme to the profile
31 def set_default_icon_theme 27 def set_default_icon_theme
32 - set_icon_theme(@ft_config[:owner],params[:icon_theme_name]) if exist_icon_theme? params[:icon_theme_name] 28 + set_icon_theme(design,params[:icon_theme_name]) if exist_icon_theme? params[:icon_theme_name]
33 end 29 end
34 30
35 def flexible_template_set_sort_mode 31 def flexible_template_set_sort_mode
36 - box = @ft_config[:owner].boxes.find(params[:box_id]) 32 + box = design.boxes.find(params[:box_id])
37 render :update do |page| 33 render :update do |page|
38 page.replace_html "box_#{box.number}", edit_blocks(box) 34 page.replace_html "box_#{box.number}", edit_blocks(box)
39 page.sortable "sort_#{box.number}", :url => {:action => 'flexible_template_sort_box', :box_number => box.number} 35 page.sortable "sort_#{box.number}", :url => {:action => 'flexible_template_sort_box', :box_number => box.number}
@@ -56,19 +52,19 @@ module Design @@ -56,19 +52,19 @@ module Design
56 # updates all boxes at the ends 52 # updates all boxes at the ends
57 def flexible_template_change_box 53 def flexible_template_change_box
58 #TODO fix it i tried the source code comment but i have no success 54 #TODO fix it i tried the source code comment but i have no success
59 - #b = @ft_config[:owner].blocks.detect{|b| b.id.to_s == params[:block].to_s } 55 + #b = design.blocks.detect{|b| b.id.to_s == params[:block].to_s }
60 b = Block.find(params[:block]) 56 b = Block.find(params[:block])
61 - b.box = @ft_config[:owner].boxes.find(params[:box_id]) 57 + b.box = design.boxes.find(params[:box_id])
62 b.save 58 b.save
63 render :update do |page| 59 render :update do |page|
64 - @ft_config[:owner].boxes.each do |box| 60 + design.boxes.each do |box|
65 page.replace_html "box_#{box.number}", edit_blocks(box) 61 page.replace_html "box_#{box.number}", edit_blocks(box)
66 end 62 end
67 end 63 end
68 end 64 end
69 65
70 def flexible_template_new_block 66 def flexible_template_new_block
71 - box = @ft_config[:owner].boxes.find(params[:box_id]) 67 + box = design.boxes.find(params[:box_id])
72 render :update do |page| 68 render :update do |page|
73 page.replace_html "box_#{box.number}", new_block_form(box) 69 page.replace_html "box_#{box.number}", new_block_form(box)
74 end 70 end
@@ -127,14 +123,14 @@ module Design @@ -127,14 +123,14 @@ module Design
127 #If no chosen_template was selected the default template is set 123 #If no chosen_template was selected the default template is set
128 def ft_load_boxes 124 def ft_load_boxes
129 n = boxes_by_template(@ft_config[:template]) 125 n = boxes_by_template(@ft_config[:template])
130 - boxes = @ft_config[:owner].boxes 126 + boxes = design.boxes
131 127
132 if boxes.length >= n 128 if boxes.length >= n
133 boxes = boxes.first(n) 129 boxes = boxes.first(n)
134 else 130 else
135 while boxes.length < n do 131 while boxes.length < n do
136 b = Box.new 132 b = Box.new
137 - b.owner = @ft_config[:owner] 133 + b.owner = design
138 raise _('The box cannot be saved becaus of erros %s') % b.errors if !b.save 134 raise _('The box cannot be saved becaus of erros %s') % b.errors if !b.save
139 boxes.push(b) 135 boxes.push(b)
140 end 136 end
vendor/plugins/design/test/design_test.rb
@@ -2,6 +2,13 @@ require File.join(File.dirname(__FILE__), &#39;test_helper&#39;) @@ -2,6 +2,13 @@ require File.join(File.dirname(__FILE__), &#39;test_helper&#39;)
2 2
3 class DesignTest < Test::Unit::TestCase 3 class DesignTest < Test::Unit::TestCase
4 4
  5 + def setup
  6 + Design.public_filesystem_root = File.join(File.dirname(__FILE__))
  7 + end
  8 + def teardown
  9 + Design.public_filesystem_root = nil
  10 + end
  11 +
5 def test_design_should_include_design_module 12 def test_design_should_include_design_module
6 assert FixedDesignTestController.included_modules.include?(Design) 13 assert FixedDesignTestController.included_modules.include?(Design)
7 end 14 end
@@ -59,4 +66,34 @@ class DesignTest &lt; Test::Unit::TestCase @@ -59,4 +66,34 @@ class DesignTest &lt; Test::Unit::TestCase
59 assert_equal 'sample_object', InheritanceDesignTestController.send(:design_plugin_config)[:holder] 66 assert_equal 'sample_object', InheritanceDesignTestController.send(:design_plugin_config)[:holder]
60 end 67 end
61 68
  69 + def test_should_list_available_templates
  70 + ['empty', 'default'].each do |item|
  71 + assert Design.available_templates.include?(item)
  72 + end
  73 + end
  74 +
  75 + def test_should_ignore_non_directory_when_listing_available_templates
  76 + assert ! Design.available_templates.include?('non_directory_should_be_ignored')
  77 + end
  78 +
  79 + def test_should_list_available_themes
  80 + ['empty', 'default'].each do |item|
  81 + assert Design.available_themes.include?(item)
  82 + end
  83 + end
  84 +
  85 + def test_should_ignore_non_directory_when_listing_available_themes
  86 + assert ! Design.available_themes.include?('non_directory_should_be_ignored')
  87 + end
  88 +
  89 + def test_should_list_available_icon_themes
  90 + ['empty', 'default'].each do |item|
  91 + assert Design.available_icon_themes.include?(item)
  92 + end
  93 + end
  94 +
  95 + def test_should_ignore_non_directory_when_listing_available_icon_themes
  96 + assert ! Design.available_icon_themes.include?('non_directory_should_be_ignored')
  97 + end
  98 +
62 end 99 end