diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index aefb8ac..1856018 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -324,21 +324,30 @@ module ApplicationHelper def stylesheet_import(*sources) options = sources.last.is_a?(Hash) ? sources.pop : { } themed_source = options.delete(:themed_source) - content_tag( 'style', + content_tag( + 'style', "\n" + sources.flatten.map do |source| - ' @import url(' + - ( themed_source ? theme_stylesheet_path(source.to_s) : stylesheet_path(source.to_s) ) + - ");\n"; + filename = filename_for_stylesheet(source.to_s, themed_source) + if File.exists?(File.join(RAILS_ROOT, 'public', filename)) + "@import url(#{filename});\n" + else + '' + end end.join(), { "type" => "text/css" }.merge(options) ) end - def theme_stylesheet_path(file_name) - '/designs/templates/' + current_theme + '/stylesheets/' + file_name + '.css' + def filename_for_stylesheet(name, in_theme) + result = '' + if in_theme + result << '/designs/templates/' + current_theme + end + result << '/stylesheets/' << name << '.css' end + # FIXME do not hardcode 'default' like this def current_theme 'default' end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index d9370d1..006cfdc 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -16,7 +16,22 @@ class ApplicationHelperTest < Test::Unit::TestCase assert_equal 'runtime_error', partial_for_class(RuntimeError) end - should 'stop without reaching nil superclass' do + should 'generate link to stylesheet' do + File.expects(:exists?).with(File.join(RAILS_ROOT, 'public', 'stylesheets', 'something.css')).returns(true) + expects(:filename_for_stylesheet).with('something', nil).returns('/stylesheets/something.css') + assert_match '@import url(/stylesheets/something.css)', stylesheet_import('something') + end + + should 'not generate link to unexisting stylesheet' do + File.expects(:exists?).with(File.join(RAILS_ROOT, 'public', 'stylesheets', 'something.css')).returns(false) + expects(:filename_for_stylesheet).with('something', nil).returns('/stylesheets/something.css') + assert_equal '', stylesheet_import('something') + end + + protected + + def content_tag(tag, content, options) + content.strip end end -- libgit2 0.21.2