From 199589e294bd117afdfe07e53c6e890eb02f2278 Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Wed, 30 Jan 2008 22:18:07 +0000 Subject: [PATCH] ActionItem139: added helper to insert css specific to blocks in use --- app/helpers/application_helper.rb | 17 ++++++++++++++--- app/helpers/boxes_helper.rb | 9 +++++++++ app/views/layouts/application.rhtml | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6796bad..f7a6b8b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -343,14 +343,25 @@ module ApplicationHelper def stylesheet_import(*sources) - options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { } + options = sources.last.is_a?(Hash) ? sources.pop : { } + themed_source = options.delete(:themed_source) content_tag( 'style', "\n" + - sources.flatten.collect do |source| - source = ' @import url('+ stylesheet_path(source.to_s()) +");\n"; + sources.flatten.map do |source| + ' @import url(' + + ( themed_source ? theme_stylesheet_path(source.to_s) : stylesheet_path(source.to_s) ) + + ");\n"; end.join(), { "type" => "text/css" }.merge(options) ) + end + + def theme_stylesheet_path(file_name) + '/designs/templates/' + current_theme + '/stylesheets/' + file_name + '.css' + end + + def current_theme + 'default' end end diff --git a/app/helpers/boxes_helper.rb b/app/helpers/boxes_helper.rb index 4408a5d..300337c 100644 --- a/app/helpers/boxes_helper.rb +++ b/app/helpers/boxes_helper.rb @@ -109,4 +109,13 @@ module BoxesHelper content_tag('div', buttons.join("\n") + tag('br', :style => 'clear: left'), :class => 'button-bar') end + def current_blocks + @controller.boxes_holder.boxes.map(&:blocks).flatten + end + + def import_blocks_stylesheets + stylesheet_import( current_blocks.map(&:css_class_name).uniq ) + "\n" + + stylesheet_import( current_blocks.map(&:css_class_name).uniq, :themed_source => true ) + end + end diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml index 468bee5..74b78a7 100644 --- a/app/views/layouts/application.rhtml +++ b/app/views/layouts/application.rhtml @@ -14,6 +14,7 @@ must be loaded before the page show. %> <%= stylesheet_import %w( common help menu button search blocks forms login-box ) %> + <%= import_blocks_stylesheets %> <%= # Load the controller's css file if it exists: css = "controller_"+ @controller.controller_name() +".css" -- libgit2 0.21.2