Commit 4f106fcd579b0b302ef75b355990964a1c6232bf
1 parent
1d119389
Exists in
staging
and in
42 other branches
ActionItem186: not linking to unexisting stylesheets
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1475 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
31 additions
and
7 deletions
Show diff stats
app/helpers/application_helper.rb
| ... | ... | @@ -324,21 +324,30 @@ module ApplicationHelper |
| 324 | 324 | def stylesheet_import(*sources) |
| 325 | 325 | options = sources.last.is_a?(Hash) ? sources.pop : { } |
| 326 | 326 | themed_source = options.delete(:themed_source) |
| 327 | - content_tag( 'style', | |
| 327 | + content_tag( | |
| 328 | + 'style', | |
| 328 | 329 | "\n" + |
| 329 | 330 | sources.flatten.map do |source| |
| 330 | - ' @import url(' + | |
| 331 | - ( themed_source ? theme_stylesheet_path(source.to_s) : stylesheet_path(source.to_s) ) + | |
| 332 | - ");\n"; | |
| 331 | + filename = filename_for_stylesheet(source.to_s, themed_source) | |
| 332 | + if File.exists?(File.join(RAILS_ROOT, 'public', filename)) | |
| 333 | + "@import url(#{filename});\n" | |
| 334 | + else | |
| 335 | + '' | |
| 336 | + end | |
| 333 | 337 | end.join(), |
| 334 | 338 | { "type" => "text/css" }.merge(options) |
| 335 | 339 | ) |
| 336 | 340 | end |
| 337 | 341 | |
| 338 | - def theme_stylesheet_path(file_name) | |
| 339 | - '/designs/templates/' + current_theme + '/stylesheets/' + file_name + '.css' | |
| 342 | + def filename_for_stylesheet(name, in_theme) | |
| 343 | + result = '' | |
| 344 | + if in_theme | |
| 345 | + result << '/designs/templates/' + current_theme | |
| 346 | + end | |
| 347 | + result << '/stylesheets/' << name << '.css' | |
| 340 | 348 | end |
| 341 | 349 | |
| 350 | + # FIXME do not hardcode 'default' like this | |
| 342 | 351 | def current_theme |
| 343 | 352 | 'default' |
| 344 | 353 | end | ... | ... |
test/unit/application_helper_test.rb
| ... | ... | @@ -16,7 +16,22 @@ class ApplicationHelperTest < Test::Unit::TestCase |
| 16 | 16 | assert_equal 'runtime_error', partial_for_class(RuntimeError) |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | - should 'stop without reaching nil superclass' do | |
| 19 | + should 'generate link to stylesheet' do | |
| 20 | + File.expects(:exists?).with(File.join(RAILS_ROOT, 'public', 'stylesheets', 'something.css')).returns(true) | |
| 21 | + expects(:filename_for_stylesheet).with('something', nil).returns('/stylesheets/something.css') | |
| 22 | + assert_match '@import url(/stylesheets/something.css)', stylesheet_import('something') | |
| 23 | + end | |
| 24 | + | |
| 25 | + should 'not generate link to unexisting stylesheet' do | |
| 26 | + File.expects(:exists?).with(File.join(RAILS_ROOT, 'public', 'stylesheets', 'something.css')).returns(false) | |
| 27 | + expects(:filename_for_stylesheet).with('something', nil).returns('/stylesheets/something.css') | |
| 28 | + assert_equal '', stylesheet_import('something') | |
| 29 | + end | |
| 30 | + | |
| 31 | + protected | |
| 32 | + | |
| 33 | + def content_tag(tag, content, options) | |
| 34 | + content.strip | |
| 20 | 35 | end |
| 21 | 36 | |
| 22 | 37 | end | ... | ... |