From d272a36e656fb3c3310d08e0021dba2ffe55a6bb Mon Sep 17 00:00:00 2001 From: LeandroNunes Date: Tue, 10 Jul 2007 13:45:09 +0000 Subject: [PATCH] ActionItem0: upgrading documentation code --- app/controllers/application.rb | 10 +++++++++- app/helpers/application_helper.rb | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- app/models/block.rb | 11 ++++++++--- app/models/box.rb | 2 ++ app/models/link_block.rb | 8 ++++++++ app/models/main_block.rb | 2 ++ app/views/layouts/application.rhtml | 3 ++- db/migrate/002_create_profiles.rb | 7 +++++-- test/fixtures/profiles.yml | 10 ++++++++-- 9 files changed, 92 insertions(+), 10 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 2b3dbb8..66ae6f9 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -12,10 +12,18 @@ class ApplicationController < ActionController::Base def load_boxes if Profile.exists?(1) owner = Profile.find(1) - owner.nil? ? Array.new : @boxes = owner.boxes + @boxes = owner.boxes end end + before_filter :load_template + def load_template + if Profile.exists?(1) + owner = Profile.find(1) + end + @chosen_template = owner.nil? ? "default" : owner.template + end + protected def detect_stuff_by_domain diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6b2a949..348bb0a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,7 +1,13 @@ # Methods added to this helper will be available to all templates in the application. module ApplicationHelper + REJECTED_DIRS = %w[ + . + .. + .svn + ] # This method expect an array of boxes and the content retuned of a controller action + # It will generate the boxes div according the yaml definition def display_boxes(boxes, main_content = "") # If no boxes is passed return the main content return main_content if boxes.nil? @@ -17,12 +23,48 @@ module ApplicationHelper content end + # Load all the css files of a existing template with the template_name passed as argument. + # + # The files loaded are in the path: + # + # 'public/templates/#{template_name}/stylesheets/*' + #TODO I think that implements this idea describe above it's good. Let's discuss about it. + # OBS: If no files are found in path the default template is used + def stylesheet_link_tag_template(template_name) + d = Dir.new("public/templates/#{template_name}/stylesheets/") + d.map do |filename| + stylesheet_link_tag("/templates/#{template_name}/stylesheets/#{filename}") unless REJECTED_DIRS.include?(filename.gsub(/.css/,"")) + end + end + + # Load all the javascript files of a existing template with the template_name passed as argument. + # + # The files loaded are in the path: + # + # 'public/templates/#{template_name}/javascripts/*' + # + #TODO I think that implements this idea describe above it's good. Let's discuss about it. + # OBS: If no files are found in path the default template is used + def javascript_include_tag_template(template_name) + d = Dir.new("public/templates/#{template_name}/javascripts/") + d.map do |filename| + javascript_include_tag("/templates/#{template_name}/javascripts/#{filename}") unless REJECTED_DIRS.include?(filename.gsub(/.js/,"")) + end + end + private + # Check if the current controller is the controller that allows layout editing def edit_mode? - true if controller.controller_name == 'edit_template' + controller.controller_name == 'edit_template' ? true : false end + # Shows the block as the struture bellow + # + # def show_blocks(box, main_content = "") blocks = box.blocks_sort_by_position content_tag(:ul, @@ -32,6 +74,8 @@ module ApplicationHelper ) end + # Shows the blocks as defined in show_blocks adding the sortable and draggable elements. + # In this case the layout can be manipulated def edit_blocks(box, main_content = "") blocks = box.blocks_sort_by_position content_tag(:ul, @@ -41,16 +85,19 @@ module ApplicationHelper ) + drag_drop_items(box) + sortable_block(box.number) end + # Allows the biven box to have sortable elements def sortable_block(box_number) sortable_element "sort_#{box_number}", :url => {:action => 'sort_box', :box_number => box_number }, :complete => visual_effect(:highlight, "sort_#{box_number}") end + # Allows an element item to be draggable def draggable(item) draggable_element(item, :ghosting=>true, :revert=>true) end + # Allows an draggable element change between diferrents boxes def drag_drop_items(box) boxes = Box.find_not_box(box.id) diff --git a/app/models/block.rb b/app/models/block.rb index ce46264..2f74650 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -1,5 +1,5 @@ +#It's the class that define the block's content will be displayed on box in a determined web class Block < ActiveRecord::Base - include ActionView::Helpers::UrlHelper include ActionView::Helpers::TagHelper belongs_to :box @@ -9,11 +9,16 @@ class Block < ActiveRecord::Base # A block must be associated to a box validates_presence_of :box_id + # Method that define the html code displayed on the box. + # This method cannot be used directly it will be redefined by the children classes def to_html - #TODO Upgrade this test -# raise _("This is a main class, don't use it") + raise _("This is a main class, don't use it") end + # This method always return false excepted when redefined by the MainBlock class. It mean the current block it's not the result of a + # controller action. + # + # The child class MainBlock subscribes this method returning true. def main? false end diff --git a/app/models/box.rb b/app/models/box.rb index 601e8ef..e61bd9b 100644 --- a/app/models/box.rb +++ b/app/models/box.rb @@ -8,10 +8,12 @@ class Box < ActiveRecord::Base #number could not be nil and must be an integer validates_numericality_of :number, :only_integer => true, :message => _('%{fn} must be composed only of integers.') + # Find all boxes except the box with the id given. def self.find_not_box(box_id) return Box.find(:all, :conditions => ['id != ?', box_id]) end + # Return all blocks of the current box object sorted by the position block def blocks_sort_by_position self.blocks.sort{|x,y| x.position <=> y.position} end diff --git a/app/models/link_block.rb b/app/models/link_block.rb index d679d78..c6b2fb1 100644 --- a/app/models/link_block.rb +++ b/app/models/link_block.rb @@ -1,4 +1,12 @@ class LinkBlock < Block + + # Redefinition of to_html Block method that show a list of links showing the Profile name. + # + # Ex: + # + # Colivre + # + # PSL-BA def to_html profiles = Profile.find(:all).map do |p| content_tag("a href='http://www.google.com.br'", p.name) diff --git a/app/models/main_block.rb b/app/models/main_block.rb index aebc0a4..5b3ac82 100644 --- a/app/models/main_block.rb +++ b/app/models/main_block.rb @@ -1,5 +1,7 @@ class MainBlock < Block + #This method always return true. It means the current block have to display the result of controller action. + #It has the same result of put the yield variable on the application layout def main? true end diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml index b3c721d..0df88c2 100644 --- a/app/views/layouts/application.rhtml +++ b/app/views/layouts/application.rhtml @@ -1,7 +1,8 @@ <%= javascript_include_tag :defaults %> - <%= stylesheet_link_tag 'default' %> + <%= javascript_include_tag_template @chosen_template %> + <%= stylesheet_link_tag_template @chosen_template %> diff --git a/db/migrate/002_create_profiles.rb b/db/migrate/002_create_profiles.rb index 865fbd8..4a59e7a 100644 --- a/db/migrate/002_create_profiles.rb +++ b/db/migrate/002_create_profiles.rb @@ -1,9 +1,12 @@ class CreateProfiles < ActiveRecord::Migration def self.up create_table :profiles do |t| - t.column :name, :string - t.column :identifier, :string + t.column :name, :string + t.column :identifier, :string t.column :virtual_community_id, :integer + t.column :template, :string, :default => "default" + t.column :theme, :string, :default => "default" + t.column :icons_theme, :string, :default => "default" end end diff --git a/test/fixtures/profiles.yml b/test/fixtures/profiles.yml index 1819f14..10ded38 100644 --- a/test/fixtures/profiles.yml +++ b/test/fixtures/profiles.yml @@ -1,11 +1,17 @@ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html -first: +one: id: 1 name: 'John Doe' identifier: johndoe virtual_community_id: 1 -another: + template: 'default' + icons_theme: 'default' + theme: 'default' +two: id: 2 name: 'Joe Random Hacker' identifier: joerandomhacker virtual_community_id: 1 + template: 'simple' + icons_theme: 'simple' + theme: 'simple' -- libgit2 0.21.2