Restores support for :plugin support to stylesheet_link_tag and javascript_include_tag helpers.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9558 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
f12942ff40
commit
03335d014c
|
@ -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
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue