Commit 5827dbd831603cc3672af80021ffb9fd240cab36

Authored by LeandroNunes
1 parent 2f094f54

ActionItem0: adding simple template and making struture to change templates

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@68 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/application.rb
... ... @@ -5,10 +5,10 @@ class ApplicationController < ActionController::Base
5 5 before_filter :detect_stuff_by_domain
6 6 attr_reader :virtual_community
7 7  
  8 + before_filter :load_boxes
8 9 #TODO To diplay the content we need a variable called '@boxes'.
9 10 #This variable is a set of boxes belongs to a owner
10 11 #We have to see a better way to do that
11   - before_filter :load_boxes
12 12 def load_boxes
13 13 if Profile.exists?(1)
14 14 owner = Profile.find(1)
... ... @@ -17,11 +17,25 @@ class ApplicationController < ActionController::Base
17 17 end
18 18  
19 19 before_filter :load_template
  20 + # Load the template belongs to a Profile and set it at @chosen_template variable.
  21 + # If no profile exist the @chosen_template variable is set to 'default'
20 22 def load_template
21 23 if Profile.exists?(1)
22   - owner = Profile.find(1)
  24 + @owner = Profile.find(1)
23 25 end
24   - @chosen_template = owner.nil? ? "default" : owner.template
  26 + @chosen_template = @owner.nil? ? "default" : @owner.template
  27 + end
  28 +
  29 + def set_default_template
  30 + p = Profile.find(params[:object_id])
  31 + set_template(p,params[:template_name])
  32 + end
  33 +
  34 + private
  35 +
  36 + def set_template(object, template_name)
  37 + object.template = template_name
  38 + object.save
25 39 end
26 40  
27 41 protected
... ...
app/helpers/application_helper.rb
1 1 # Methods added to this helper will be available to all templates in the application.
2 2 module ApplicationHelper
  3 +
  4 + # Directories to be rejected of the directories list when needed.
  5 + # TODO I think the better way is create a Dir class method that returns a list of files of a given path
3 6 REJECTED_DIRS = %w[
4 7 .
5 8 ..
6 9 .svn
7 10 ]
8 11  
  12 + # Generate a select option to choose one of the available templates.
  13 + # The available templates are those in 'public/templates'
  14 + def select_template(object, chosen_template = nil)
  15 + return '' if object.nil?
  16 + available_templates = Dir.new('public/templates').to_a - REJECTED_DIRS
  17 + template_options = options_for_select(available_templates.map{|template| [template, template] }, chosen_template)
  18 + select_tag('template_name', template_options ) +
  19 + change_tempate('template_name', object)
  20 + end
  21 +
  22 + def change_tempate(observed_field, object)
  23 + observe_field( observed_field,
  24 + :url => {:action => 'set_default_template'},
  25 + :with =>"'template_name=' + escape(value) + '&object_id=' + escape(#{object.id})",
  26 + :complete => "document.location.reload();"
  27 + )
  28 + end
  29 +
9 30 # This method expect an array of boxes and the content retuned of a controller action
10 31 # It will generate the boxes div according the yaml definition
11 32 def display_boxes(boxes, main_content = "")
... ... @@ -31,9 +52,9 @@ module ApplicationHelper
31 52 #TODO I think that implements this idea describe above it's good. Let's discuss about it.
32 53 # OBS: If no files are found in path the default template is used
33 54 def stylesheet_link_tag_template(template_name)
34   - d = Dir.new("public/templates/#{template_name}/stylesheets/")
  55 + d = Dir.new("public/templates/#{template_name}/stylesheets/").to_a - REJECTED_DIRS
35 56 d.map do |filename|
36   - stylesheet_link_tag("/templates/#{template_name}/stylesheets/#{filename}") unless REJECTED_DIRS.include?(filename.gsub(/.css/,""))
  57 + stylesheet_link_tag("/templates/#{template_name}/stylesheets/#{filename}")
37 58 end
38 59 end
39 60  
... ... @@ -46,9 +67,9 @@ module ApplicationHelper
46 67 #TODO I think that implements this idea describe above it's good. Let's discuss about it.
47 68 # OBS: If no files are found in path the default template is used
48 69 def javascript_include_tag_template(template_name)
49   - d = Dir.new("public/templates/#{template_name}/javascripts/")
  70 + d = Dir.new("public/templates/#{template_name}/javascripts/").to_a - REJECTED_DIRS
50 71 d.map do |filename|
51   - javascript_include_tag("/templates/#{template_name}/javascripts/#{filename}") unless REJECTED_DIRS.include?(filename.gsub(/.js/,""))
  72 + javascript_include_tag("/templates/#{template_name}/javascripts/#{filename}")
52 73 end
53 74 end
54 75  
... ... @@ -74,43 +95,5 @@ module ApplicationHelper
74 95 )
75 96 end
76 97  
77   - # Shows the blocks as defined in <tt>show_blocks</tt> adding the sortable and draggable elements.
78   - # In this case the layout can be manipulated
79   - def edit_blocks(box, main_content = "")
80   - blocks = box.blocks_sort_by_position
81   - content_tag(:ul,
82   - blocks.map {|b|
83   - content_tag(:li, b.main? ? main_content : b.to_html , :class =>"block_item_box_#{box.number}" , :id => "block_#{b.id}" ) + draggable("block_#{b.id}")
84   - }, :id => "sort_#{box.number}"
85   - ) + drag_drop_items(box) + sortable_block(box.number)
86   - end
87   -
88   - # Allows the biven box to have sortable elements
89   - def sortable_block(box_number)
90   - sortable_element "sort_#{box_number}",
91   - :url => {:action => 'sort_box', :box_number => box_number },
92   - :complete => visual_effect(:highlight, "sort_#{box_number}")
93   - end
94   -
95   - # Allows an element item to be draggable
96   - def draggable(item)
97   - draggable_element(item, :ghosting=>true, :revert=>true)
98   - end
99   -
100   - # Allows an draggable element change between diferrents boxes
101   - def drag_drop_items(box)
102   - boxes = Box.find_not_box(box.id)
103   -
104   - boxes.map{ |b|
105   - drop_receiving_element("box_#{box.number}",
106   - :accept => "block_item_box_#{b.number}",
107   - :complete => "$('spinner').hide();",
108   - :before => "$('spinner').show();",
109   - :hoverclass => 'hover',
110   - :with => "'block=' + encodeURIComponent(element.id.split('_').last())",
111   - :url => {:action=>:change_box, :box_id => box.id})
112   - }.to_s
113   - end
114   -
115 98  
116 99 end
... ...
app/helpers/edit_template_helper.rb 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +# Methods added to this helper will be available to all templates in the application.
  2 +module EditTemplateHelper
  3 +
  4 + private
  5 +
  6 + # Shows the blocks as defined in <tt>show_blocks</tt> adding the sortable and draggable elements.
  7 + # In this case the layout can be manipulated
  8 + def edit_blocks(box, main_content = "")
  9 + blocks = box.blocks_sort_by_position
  10 + content_tag(:ul, box.name +
  11 + blocks.map {|b|
  12 + content_tag(:li, b.name, :class =>"block_item_box_#{box.number}" , :id => "block_#{b.id}" ) + draggable("block_#{b.id}")
  13 + }.to_s, :id => "sort_#{box.number}"
  14 + ) + drag_drop_items(box) + sortable_block(box.number)
  15 + end
  16 +
  17 + # Allows the biven box to have sortable elements
  18 + def sortable_block(box_number)
  19 + sortable_element "sort_#{box_number}",
  20 + :url => {:action => 'sort_box', :box_number => box_number },
  21 + :complete => visual_effect(:highlight, "sort_#{box_number}")
  22 + end
  23 +
  24 + # Allows an element item to be draggable
  25 + def draggable(item)
  26 + draggable_element(item, :ghosting=>true, :revert=>true)
  27 + end
  28 +
  29 + # Allows an draggable element change between diferrents boxes
  30 + def drag_drop_items(box)
  31 + boxes = Box.find_not_box(box.id)
  32 +
  33 + boxes.map{ |b|
  34 + drop_receiving_element("box_#{box.number}",
  35 + :accept => "block_item_box_#{b.number}",
  36 + :complete => "$('spinner').hide();",
  37 + :before => "$('spinner').show();",
  38 + :hoverclass => 'hover',
  39 + :with => "'block=' + encodeURIComponent(element.id.split('_').last())",
  40 + :url => {:action=>:change_box, :box_id => box.id})
  41 + }.to_s
  42 + end
  43 +
  44 +
  45 +end
... ...
app/views/layouts/application.rhtml
... ... @@ -11,8 +11,14 @@
11 11 <%= link_to _('Show Layout'), :controller => 'home' %>
12 12 <%= link_to _('Edit Layout'), :controller => 'edit_template' %>
13 13  
  14 + <%= select_template(@owner, @chosen_template) %>
  15 +
14 16 <%= display_boxes(@boxes, yield) %>
15 17  
  18 + <div id="footer">
  19 + footer content
  20 + </div>
  21 +
16 22 </body>
17 23  
18 24 </html>
... ...
public/templates/simple/images/loading.gif 0 → 100644

1.75 KB

public/templates/simple/images/ufba_logo.png 0 → 100644

2.08 KB

public/templates/simple/simple.yml 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +default:
  2 + number_of_boxes: 3
... ...
public/templates/simple/stylesheets/default.css 0 → 100644
... ... @@ -0,0 +1,48 @@
  1 +.edit_mode .hover {
  2 + background-color: blue;
  3 + border: 2px dotted red;
  4 +}
  5 +
  6 +.edit_mode .hover ul li {
  7 + border: 2px dotted yellow;
  8 +}
  9 +
  10 +.edit_mode #box_1 ul, .edit_mode #box_2 ul, .edit_mode #box_3 ul {
  11 + list-style: none;
  12 + cursor: -moz-grab;
  13 + margin: 10px;
  14 + padding:0px;
  15 +
  16 +}
  17 +
  18 +.edit_mode #box_1 ul li, .edit_mode #box_2 ul li, .edit_mode #box_3 ul li {
  19 + list-style: none;
  20 + cursor: -moz-grab;
  21 + border: 5px solid black;
  22 + margin: 15px;
  23 +}
  24 +
  25 +.edit_mode #box_1, .edit_mode #box_2, .edit_mode #box_3 {
  26 + border: 3px solid brown;
  27 +}
  28 +
  29 +#box_1 {
  30 + width: 200px;
  31 + float: left;
  32 +}
  33 +#box_2 {
  34 + width: 600px;
  35 + float: left;
  36 + margin: 0px 10px 0px 10px;
  37 +}
  38 +#box_3 {
  39 + width: 400px;
  40 +
  41 + clear: both;
  42 +}
  43 +
  44 +#footer{
  45 + font-size: 30px;
  46 + background: #FFFFFF url('../images/ufba_logo.png') repeat-x;
  47 +}
  48 +
... ...