diff options
-rw-r--r-- | app/helpers/application_helper.rb | 39 | ||||
-rw-r--r-- | extra/sample_plugin/app/views/example/say_goodbye.html.erb | 2 | ||||
-rw-r--r-- | extra/sample_plugin/app/views/example/say_hello.html.erb | 2 | ||||
-rw-r--r-- | lib/redmine/themes.rb | 20 | ||||
-rw-r--r-- | test/unit/helpers/application_helper_test.rb | 16 |
5 files changed, 57 insertions, 22 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8310a4972..743bc34e3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1045,6 +1045,45 @@ module ApplicationHelper end end + # Overrides Rails' stylesheet_link_tag with themes and plugins support. + # Examples: + # stylesheet_link_tag('styles') # => picks styles.css from the current theme or defaults + # stylesheet_link_tag('styles', :plugin => 'foo) # => picks styles.css from plugin's assets + # + def stylesheet_link_tag(*sources) + options = sources.last.is_a?(Hash) ? sources.pop : {} + plugin = options.delete(:plugin) + sources = sources.map do |source| + if plugin + "/plugin_assets/#{plugin}/stylesheets/#{source}" + elsif current_theme && current_theme.stylesheets.include?(source) + current_theme.stylesheet_path(source) + else + source + end + end + super sources, options + end + + # Overrides Rails' javascript_include_tag with plugins support + # Examples: + # javascript_include_tag('scripts') # => picks scripts.js from defaults + # javascript_include_tag('scripts', :plugin => 'foo) # => picks scripts.js from plugin's assets + # + def javascript_include_tag(*sources) + options = sources.last.is_a?(Hash) ? sources.pop : {} + if plugin = options.delete(:plugin) + sources = sources.map do |source| + if plugin + "/plugin_assets/#{plugin}/javascripts/#{source}" + else + source + end + end + end + super sources, options + end + def content_for(name, content = nil, &block) @has_content ||= {} @has_content[name] = true diff --git a/extra/sample_plugin/app/views/example/say_goodbye.html.erb b/extra/sample_plugin/app/views/example/say_goodbye.html.erb index 978fbd9b2..3307e8770 100644 --- a/extra/sample_plugin/app/views/example/say_goodbye.html.erb +++ b/extra/sample_plugin/app/views/example/say_goodbye.html.erb @@ -3,5 +3,5 @@ <p class="icon icon-example-works"><%= l(:text_say_goodbye) %></p> <% content_for :header_tags do %> - <%= stylesheet_link_tag "/plugin_assets/sample_plugin/stylesheets/example.css", :media => "screen" %> + <%= stylesheet_link_tag 'example', :plugin => 'sample_plugin', :media => "screen" %> <% end %> diff --git a/extra/sample_plugin/app/views/example/say_hello.html.erb b/extra/sample_plugin/app/views/example/say_hello.html.erb index 9bfa8cc4f..505bd2f70 100644 --- a/extra/sample_plugin/app/views/example/say_hello.html.erb +++ b/extra/sample_plugin/app/views/example/say_hello.html.erb @@ -11,5 +11,5 @@ <% end %> <% content_for :header_tags do %> - <%= stylesheet_link_tag "/plugin_assets/sample_plugin/stylesheets/example.css", :media => "screen" %> + <%= stylesheet_link_tag 'example', :plugin => 'sample_plugin', :media => "screen" %> <% end %> diff --git a/lib/redmine/themes.rb b/lib/redmine/themes.rb index 51b974fd7..5e5261927 100644 --- a/lib/redmine/themes.rb +++ b/lib/redmine/themes.rb @@ -106,26 +106,6 @@ module ApplicationHelper @current_theme end - def stylesheet_path(source) - if current_theme && current_theme.stylesheets.include?(source) - super current_theme.stylesheet_path(source) - else - super - end - end - - def path_to_stylesheet(source) - stylesheet_path source - end - - def stylesheet_link_tag(source, *args) - if current_theme && current_theme.stylesheets.include?(source) - super current_theme.stylesheet_path(source), *args - else - super - end - end - # Returns the header tags for the current theme def heads_for_theme if current_theme && current_theme.javascripts.include?('theme') diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index a7a05f3e0..f09d66646 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -1045,4 +1045,20 @@ RAW User.current = User.find(4) assert_include '<option value="4"><< me >></option>', principals_options_for_select(users) end + + def test_stylesheet_link_tag_should_pick_the_default_stylesheet + assert_match 'href="/stylesheets/styles.css"', stylesheet_link_tag("styles") + end + + def test_stylesheet_link_tag_for_plugin_should_pick_the_plugin_stylesheet + assert_match 'href="/plugin_assets/foo/stylesheets/styles.css"', stylesheet_link_tag("styles", :plugin => :foo) + end + + def test_javascript_include_tag_should_pick_the_default_javascript + assert_match 'src="/javascripts/scripts.js"', javascript_include_tag("scripts") + end + + def test_javascript_include_tag_for_plugin_should_pick_the_plugin_javascript + assert_match 'src="/plugin_assets/foo/javascripts/scripts.js"', javascript_include_tag("scripts", :plugin => :foo) + end end |