]> source.dussan.org Git - redmine.git/commitdiff
Restores support for :plugin support to stylesheet_link_tag and javascript_include_ta...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 28 Apr 2012 09:10:46 +0000 (09:10 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 28 Apr 2012 09:10:46 +0000 (09:10 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9558 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
extra/sample_plugin/app/views/example/say_goodbye.html.erb
extra/sample_plugin/app/views/example/say_hello.html.erb
lib/redmine/themes.rb
test/unit/helpers/application_helper_test.rb

index 8310a49726499ef709cd81849d9b4f8bfe5186ed..743bc34e3aca333eddbcafa5732cb9fb202871f7 100644 (file)
@@ -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
index 978fbd9b29f860278a11b04391d44a1abc757662..3307e877010db74119edf17af953a22b97fe80e3 100644 (file)
@@ -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 %>
index 9bfa8cc4fa8e757fc6bfb28c21fcf10b78df83a8..505bd2f70572a2be9c139a6e078c9777943adaf4 100644 (file)
@@ -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 %>
index 51b974fd7c685c64e955576c73d82f8d72272ec8..5e5261927fc9f8d522854edad0cde9b1397b99d5 100644 (file)
@@ -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')
index a7a05f3e052173c033e1d5cb2bfffdf3fc7485cc..f09d6664631381df77d84fd0faf75f47f3a03884 100644 (file)
@@ -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