Commit d272a36e656fb3c3310d08e0021dba2ffe55a6bb
1 parent
4f33beec
Exists in
master
and in
29 other branches
ActionItem0: upgrading documentation code
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@66 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
9 changed files
with
92 additions
and
10 deletions
Show diff stats
app/controllers/application.rb
... | ... | @@ -12,10 +12,18 @@ class ApplicationController < ActionController::Base |
12 | 12 | def load_boxes |
13 | 13 | if Profile.exists?(1) |
14 | 14 | owner = Profile.find(1) |
15 | - owner.nil? ? Array.new : @boxes = owner.boxes | |
15 | + @boxes = owner.boxes | |
16 | 16 | end |
17 | 17 | end |
18 | 18 | |
19 | + before_filter :load_template | |
20 | + def load_template | |
21 | + if Profile.exists?(1) | |
22 | + owner = Profile.find(1) | |
23 | + end | |
24 | + @chosen_template = owner.nil? ? "default" : owner.template | |
25 | + end | |
26 | + | |
19 | 27 | protected |
20 | 28 | |
21 | 29 | def detect_stuff_by_domain | ... | ... |
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 | + REJECTED_DIRS = %w[ | |
4 | + . | |
5 | + .. | |
6 | + .svn | |
7 | + ] | |
3 | 8 | |
4 | 9 | # This method expect an array of boxes and the content retuned of a controller action |
10 | + # It will generate the boxes div according the yaml definition | |
5 | 11 | def display_boxes(boxes, main_content = "") |
6 | 12 | # If no boxes is passed return the main content |
7 | 13 | return main_content if boxes.nil? |
... | ... | @@ -17,12 +23,48 @@ module ApplicationHelper |
17 | 23 | content |
18 | 24 | end |
19 | 25 | |
26 | + # Load all the css files of a existing template with the template_name passed as argument. | |
27 | + # | |
28 | + # The files loaded are in the path: | |
29 | + # | |
30 | + # 'public/templates/#{template_name}/stylesheets/*' | |
31 | + #TODO I think that implements this idea describe above it's good. Let's discuss about it. | |
32 | + # OBS: If no files are found in path the default template is used | |
33 | + def stylesheet_link_tag_template(template_name) | |
34 | + d = Dir.new("public/templates/#{template_name}/stylesheets/") | |
35 | + d.map do |filename| | |
36 | + stylesheet_link_tag("/templates/#{template_name}/stylesheets/#{filename}") unless REJECTED_DIRS.include?(filename.gsub(/.css/,"")) | |
37 | + end | |
38 | + end | |
39 | + | |
40 | + # Load all the javascript files of a existing template with the template_name passed as argument. | |
41 | + # | |
42 | + # The files loaded are in the path: | |
43 | + # | |
44 | + # 'public/templates/#{template_name}/javascripts/*' | |
45 | + # | |
46 | + #TODO I think that implements this idea describe above it's good. Let's discuss about it. | |
47 | + # OBS: If no files are found in path the default template is used | |
48 | + def javascript_include_tag_template(template_name) | |
49 | + d = Dir.new("public/templates/#{template_name}/javascripts/") | |
50 | + d.map do |filename| | |
51 | + javascript_include_tag("/templates/#{template_name}/javascripts/#{filename}") unless REJECTED_DIRS.include?(filename.gsub(/.js/,"")) | |
52 | + end | |
53 | + end | |
54 | + | |
20 | 55 | private |
21 | 56 | |
57 | + # Check if the current controller is the controller that allows layout editing | |
22 | 58 | def edit_mode? |
23 | - true if controller.controller_name == 'edit_template' | |
59 | + controller.controller_name == 'edit_template' ? true : false | |
24 | 60 | end |
25 | 61 | |
62 | + # Shows the block as the struture bellow | |
63 | + # <ul id="sort#{number of the box}"> | |
64 | + # <li class="block_item_box_#{number of the box}" id="block_#{id of block}"> | |
65 | + # </li> | |
66 | + # </ul> | |
67 | + # | |
26 | 68 | def show_blocks(box, main_content = "") |
27 | 69 | blocks = box.blocks_sort_by_position |
28 | 70 | content_tag(:ul, |
... | ... | @@ -32,6 +74,8 @@ module ApplicationHelper |
32 | 74 | ) |
33 | 75 | end |
34 | 76 | |
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 | |
35 | 79 | def edit_blocks(box, main_content = "") |
36 | 80 | blocks = box.blocks_sort_by_position |
37 | 81 | content_tag(:ul, |
... | ... | @@ -41,16 +85,19 @@ module ApplicationHelper |
41 | 85 | ) + drag_drop_items(box) + sortable_block(box.number) |
42 | 86 | end |
43 | 87 | |
88 | + # Allows the biven box to have sortable elements | |
44 | 89 | def sortable_block(box_number) |
45 | 90 | sortable_element "sort_#{box_number}", |
46 | 91 | :url => {:action => 'sort_box', :box_number => box_number }, |
47 | 92 | :complete => visual_effect(:highlight, "sort_#{box_number}") |
48 | 93 | end |
49 | 94 | |
95 | + # Allows an element item to be draggable | |
50 | 96 | def draggable(item) |
51 | 97 | draggable_element(item, :ghosting=>true, :revert=>true) |
52 | 98 | end |
53 | 99 | |
100 | + # Allows an draggable element change between diferrents boxes | |
54 | 101 | def drag_drop_items(box) |
55 | 102 | boxes = Box.find_not_box(box.id) |
56 | 103 | ... | ... |
app/models/block.rb
1 | +#It's the class that define the block's content will be displayed on box in a determined web | |
1 | 2 | class Block < ActiveRecord::Base |
2 | - include ActionView::Helpers::UrlHelper | |
3 | 3 | include ActionView::Helpers::TagHelper |
4 | 4 | belongs_to :box |
5 | 5 | |
... | ... | @@ -9,11 +9,16 @@ class Block < ActiveRecord::Base |
9 | 9 | # A block must be associated to a box |
10 | 10 | validates_presence_of :box_id |
11 | 11 | |
12 | + # Method that define the html code displayed on the box. | |
13 | + # This method cannot be used directly it will be redefined by the children classes | |
12 | 14 | def to_html |
13 | - #TODO Upgrade this test | |
14 | -# raise _("This is a main class, don't use it") | |
15 | + raise _("This is a main class, don't use it") | |
15 | 16 | end |
16 | 17 | |
18 | + # This method always return false excepted when redefined by the MainBlock class. It mean the current block it's not the result of a | |
19 | + # controller action. | |
20 | + # | |
21 | + # The child class MainBlock subscribes this method returning true. | |
17 | 22 | def main? |
18 | 23 | false |
19 | 24 | end | ... | ... |
app/models/box.rb
... | ... | @@ -8,10 +8,12 @@ class Box < ActiveRecord::Base |
8 | 8 | #<tt>number</tt> could not be nil and must be an integer |
9 | 9 | validates_numericality_of :number, :only_integer => true, :message => _('%{fn} must be composed only of integers.') |
10 | 10 | |
11 | + # Find all boxes except the box with the id given. | |
11 | 12 | def self.find_not_box(box_id) |
12 | 13 | return Box.find(:all, :conditions => ['id != ?', box_id]) |
13 | 14 | end |
14 | 15 | |
16 | + # Return all blocks of the current box object sorted by the position block | |
15 | 17 | def blocks_sort_by_position |
16 | 18 | self.blocks.sort{|x,y| x.position <=> y.position} |
17 | 19 | end | ... | ... |
app/models/link_block.rb
1 | 1 | class LinkBlock < Block |
2 | + | |
3 | + # Redefinition of to_html Block method that show a list of links showing the Profile name. | |
4 | + # | |
5 | + # Ex: | |
6 | + # | |
7 | + # <a href="http://www.colivre.coop.br"> Colivre </a> | |
8 | + # | |
9 | + # <a href="http://www.ba.softwarelivre.org"> PSL-BA </a> | |
2 | 10 | def to_html |
3 | 11 | profiles = Profile.find(:all).map do |p| |
4 | 12 | content_tag("a href='http://www.google.com.br'", p.name) | ... | ... |
app/models/main_block.rb
app/views/layouts/application.rhtml
db/migrate/002_create_profiles.rb
1 | 1 | class CreateProfiles < ActiveRecord::Migration |
2 | 2 | def self.up |
3 | 3 | create_table :profiles do |t| |
4 | - t.column :name, :string | |
5 | - t.column :identifier, :string | |
4 | + t.column :name, :string | |
5 | + t.column :identifier, :string | |
6 | 6 | t.column :virtual_community_id, :integer |
7 | + t.column :template, :string, :default => "default" | |
8 | + t.column :theme, :string, :default => "default" | |
9 | + t.column :icons_theme, :string, :default => "default" | |
7 | 10 | end |
8 | 11 | end |
9 | 12 | ... | ... |
test/fixtures/profiles.yml
1 | 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
2 | -first: | |
2 | +one: | |
3 | 3 | id: 1 |
4 | 4 | name: 'John Doe' |
5 | 5 | identifier: johndoe |
6 | 6 | virtual_community_id: 1 |
7 | -another: | |
7 | + template: 'default' | |
8 | + icons_theme: 'default' | |
9 | + theme: 'default' | |
10 | +two: | |
8 | 11 | id: 2 |
9 | 12 | name: 'Joe Random Hacker' |
10 | 13 | identifier: joerandomhacker |
11 | 14 | virtual_community_id: 1 |
15 | + template: 'simple' | |
16 | + icons_theme: 'simple' | |
17 | + theme: 'simple' | ... | ... |