Commit dd840bc5ecd5aa3a5a43a91dfad78ea9ef1e115d
1 parent
46b708cb
Exists in
staging
and in
42 other branches
ActionItem0: refactoring plugin
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@142 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
6 changed files
with
17 additions
and
81 deletions
Show diff stats
app/controllers/application.rb
@@ -9,34 +9,14 @@ class ApplicationController < ActionController::Base | @@ -9,34 +9,14 @@ class ApplicationController < ActionController::Base | ||
9 | before_filter :detect_stuff_by_domain | 9 | before_filter :detect_stuff_by_domain |
10 | attr_reader :virtual_community | 10 | attr_reader :virtual_community |
11 | 11 | ||
12 | - uses_flexible_template :owner => 'owner' | ||
13 | 12 | ||
14 | - def flexible_template_owner | ||
15 | - Profile.find(1) | ||
16 | - end | ||
17 | - | ||
18 | - before_filter :load_template | ||
19 | - # Load the template belongs to a Profile and set it at @chosen_template variable. | ||
20 | - # If no profile exist the @chosen_template variable is set to 'default' | ||
21 | - def load_template | 13 | + before_filter :load_owner |
14 | + # Load the owner | ||
15 | + def load_owner | ||
22 | # TODO: this should not be hardcoded | 16 | # TODO: this should not be hardcoded |
23 | if Profile.exists?(1) | 17 | if Profile.exists?(1) |
24 | @owner = Profile.find(1) | 18 | @owner = Profile.find(1) |
25 | end | 19 | end |
26 | - @chosen_template = @owner.template.nil? ? "default" : @owner.template | ||
27 | - self.chosen_template = @chosen_template | ||
28 | - end | ||
29 | - | ||
30 | - before_filter :load_boxes | ||
31 | - | ||
32 | - before_filter :load_theme | ||
33 | - # Load the theme belongs to a Profile and set it at @chosen_theme variable. | ||
34 | - # If no profile exist the @chosen_theme variable is set to 'default' | ||
35 | - def load_theme | ||
36 | - if Profile.exists?(1) | ||
37 | - @owner = Profile.find(1) | ||
38 | - end | ||
39 | - @chosen_theme = @owner.theme.nil? ? "default" : @owner.theme | ||
40 | end | 20 | end |
41 | 21 | ||
42 | before_filter :load_icons_theme | 22 | before_filter :load_icons_theme |
app/controllers/edit_template_controller.rb
1 | class EditTemplateController < ApplicationController | 1 | class EditTemplateController < ApplicationController |
2 | 2 | ||
3 | -# before_filter :leila | ||
4 | - uses_flexible_template :edit => true, :owner => 'owner' | 3 | + uses_flexible_template(:edit => true, :owner => 'owner') |
5 | 4 | ||
6 | -# def leila | ||
7 | -# @owner = Profile.find(1) | ||
8 | -# end | 5 | + def flexible_template_owner |
6 | + Profile.find(1) | ||
7 | + end | ||
9 | 8 | ||
10 | end | 9 | end |
app/controllers/home_controller.rb
1 | class HomeController < ApplicationController | 1 | class HomeController < ApplicationController |
2 | 2 | ||
3 | - def index | ||
4 | - end | 3 | + uses_flexible_template :owner => 'owner' |
5 | 4 | ||
6 | - uses_flexible_template :edit => false, :owner => 'owner' | 5 | + def flexible_template_owner |
6 | + Profile.find(1) | ||
7 | + end | ||
7 | 8 | ||
8 | end | 9 | end |
app/helpers/application_helper.rb
1 | # Methods added to this helper will be available to all templates in the application. | 1 | # Methods added to this helper will be available to all templates in the application. |
2 | module ApplicationHelper | 2 | module ApplicationHelper |
3 | 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 | ||
6 | - REJECTED_DIRS = %w[ | ||
7 | - . | ||
8 | - .. | ||
9 | - .svn | ||
10 | - ] | ||
11 | - | ||
12 | ICONS_DIR_PATH = "#{RAILS_ROOT}/public/icons" | 4 | ICONS_DIR_PATH = "#{RAILS_ROOT}/public/icons" |
13 | - THEME_DIR_PATH = "#{RAILS_ROOT}/public/themes" | ||
14 | - | ||
15 | - # Generate a select option to choose one of the available themes. | ||
16 | - # The available themes are those in 'public/themes' | ||
17 | - def select_theme(object, chosen_theme = nil) | ||
18 | - return '' if object.nil? | ||
19 | - available_themes = Dir.new("#{THEME_DIR_PATH}").to_a - REJECTED_DIRS | ||
20 | - theme_options = options_for_select(available_themes.map{|theme| [theme, theme] }, chosen_theme) | ||
21 | - select_tag('theme_name', theme_options ) + | ||
22 | - change_theme('theme_name', object) | ||
23 | - end | ||
24 | - | ||
25 | - # Generate a observer to reload a page when a theme is selected | ||
26 | - def change_theme(observed_field, object) | ||
27 | - observe_field( observed_field, | ||
28 | - :url => {:action => 'set_default_theme'}, | ||
29 | - :with =>"'theme_name=' + escape(value) + '&object_id=' + escape(#{object.id})", | ||
30 | - :complete => "document.location.reload();" | ||
31 | - ) | ||
32 | - end | ||
33 | 5 | ||
34 | 6 | ||
35 | # Generate a select option to choose one of the available icons themes. | 7 | # Generate a select option to choose one of the available icons themes. |
@@ -57,23 +29,6 @@ module ApplicationHelper | @@ -57,23 +29,6 @@ module ApplicationHelper | ||
57 | image_tag("/icons/#{icons_theme}/#{icon}.png", options) | 29 | image_tag("/icons/#{icons_theme}/#{icon}.png", options) |
58 | end | 30 | end |
59 | 31 | ||
60 | - # Load all the css files of a existing theme with the theme_name passed as argument. | ||
61 | - # | ||
62 | - # The files loaded are in the path: | ||
63 | - # | ||
64 | - # 'public/themes/#{theme_name}/*' | ||
65 | - # If a invalid theme it's passed the 'default' theme is applied | ||
66 | - def stylesheet_link_tag_theme(theme_name) | ||
67 | - if !File.exists? "#{THEME_DIR_PATH}/#{theme_name}" | ||
68 | - flash[:notice] = _("The theme %s it's not a valid theme") % theme_name | ||
69 | - theme_name = 'default' | ||
70 | - end | ||
71 | - | ||
72 | - d = Dir.new("#{THEME_DIR_PATH}/#{theme_name}/").to_a - REJECTED_DIRS | ||
73 | - d.map do |filename| | ||
74 | - stylesheet_link_tag("/themes/#{theme_name}/#{filename}") | ||
75 | - end | ||
76 | - end | ||
77 | 32 | ||
78 | # Displays context help. You can pass the content of the help message as the | 33 | # Displays context help. You can pass the content of the help message as the |
79 | # first parameter or using template code inside a block passed to this | 34 | # first parameter or using template code inside a block passed to this |
app/views/home/index.rhtml
1 | <%= flash[:notice] %> | 1 | <%= flash[:notice] %> |
2 | Start page of Virtual Community <%= @virtual_community.name %> | 2 | Start page of Virtual Community <%= @virtual_community.name %> |
3 | 3 | ||
4 | +<%= @boxes.length %> | ||
5 | + | ||
4 | Teste: | 6 | Teste: |
5 | -<%= @bla %> | ||
6 | -<%= @bli.inspect %> | 7 | +<%= @ft_config[:template].inspect %> |
7 | caralho | 8 | caralho |
8 | 9 |
app/views/layouts/application.rhtml
1 | <html> | 1 | <html> |
2 | <head> | 2 | <head> |
3 | <%= javascript_include_tag :defaults %> | 3 | <%= javascript_include_tag :defaults %> |
4 | - <%= javascript_include_tag_template @chosen_template %> | ||
5 | - <%= stylesheet_link_tag_template @chosen_template %> | ||
6 | - <%= stylesheet_link_tag_theme @chosen_theme %> | 4 | + <%= javascript_include_tag_template %> |
5 | + <%= stylesheet_link_tag_template %> | ||
6 | + <%= stylesheet_link_tag_theme %> | ||
7 | 7 | ||
8 | </head> | 8 | </head> |
9 | 9 |