Feature #21483 ยป theme_patch.diff
| app/helpers/application_helper.rb | ||
|---|---|---|
| 1179 | 1179 |
plugin = options.delete(:plugin) |
| 1180 | 1180 |
sources = sources.map do |source| |
| 1181 | 1181 |
if plugin |
| 1182 |
"/plugin_assets/#{plugin}/stylesheets/#{source}"
|
|
| 1182 |
if current_theme && current_theme.overrides?(plugin, source) |
|
| 1183 |
current_theme.override(plugin, source) |
|
| 1184 |
else |
|
| 1185 |
"/plugin_assets/#{plugin}/stylesheets/#{source}"
|
|
| 1186 |
end |
|
| 1183 | 1187 |
elsif current_theme && current_theme.stylesheets.include?(source) |
| 1184 | 1188 |
current_theme.stylesheet_path(source) |
| 1185 | 1189 |
else |
| ... | ... | |
| 1195 | 1199 |
# image_tag('image.png', :plugin => 'foo) # => picks image.png from plugin's assets
|
| 1196 | 1200 |
# |
| 1197 | 1201 |
def image_tag(source, options={})
|
| 1198 |
if plugin = options.delete(:plugin) |
|
| 1199 |
source = "/plugin_assets/#{plugin}/images/#{source}"
|
|
| 1202 |
plugin = options.delete(:plugin) |
|
| 1203 |
ns = source |
|
| 1204 |
if plugin |
|
| 1205 |
if current_theme && current_theme.overrides?(plugin, source) |
|
| 1206 |
ns = current_theme.override(plugin, source) |
|
| 1207 |
else |
|
| 1208 |
ns = "/plugin_assets/#{plugin}/images/#{source}"
|
|
| 1209 |
end |
|
| 1200 | 1210 |
elsif current_theme && current_theme.images.include?(source) |
| 1201 |
source = current_theme.image_path(source)
|
|
| 1211 |
ns = current_theme.image_path(source)
|
|
| 1202 | 1212 |
end |
| 1203 |
super source, options
|
|
| 1213 |
super ns, options
|
|
| 1204 | 1214 |
end |
| 1205 | 1215 | |
| 1206 | 1216 |
# Overrides Rails' javascript_include_tag with plugins support |
| ... | ... | |
| 1210 | 1220 |
# |
| 1211 | 1221 |
def javascript_include_tag(*sources) |
| 1212 | 1222 |
options = sources.last.is_a?(Hash) ? sources.pop : {}
|
| 1213 |
if plugin = options.delete(:plugin) |
|
| 1223 |
plugin = options.delete(:plugin) |
|
| 1224 |
if plugin |
|
| 1214 | 1225 |
sources = sources.map do |source| |
| 1215 | 1226 |
if plugin |
| 1216 |
"/plugin_assets/#{plugin}/javascripts/#{source}"
|
|
| 1227 |
if current_theme && current_theme.overrides?(plugin, source) |
|
| 1228 |
current_theme.override(plugin, source) |
|
| 1229 |
else |
|
| 1230 |
"/plugin_assets/#{plugin}/javascripts/#{source}"
|
|
| 1231 |
end |
|
| 1217 | 1232 |
else |
| 1218 | 1233 |
source |
| 1219 | 1234 |
end |
| lib/redmine/themes.rb | ||
|---|---|---|
| 63 | 63 |
name <=> theme.name |
| 64 | 64 |
end |
| 65 | 65 | |
| 66 |
def overrides?(plugin, source) |
|
| 67 |
@plugin_overrides ||= get_overrides |
|
| 68 |
@plugin_overrides[plugin] && @plugin_overrides[plugin].include?(source) |
|
| 69 |
end |
|
| 70 | ||
| 71 |
def override(plugin, source) |
|
| 72 |
"/themes/#{dir}/plugins/#{plugin}/#{source}"
|
|
| 73 |
end |
|
| 74 | ||
| 66 | 75 |
def stylesheets |
| 67 | 76 |
@stylesheets ||= assets("stylesheets", "css")
|
| 68 | 77 |
end |
| ... | ... | |
| 105 | 114 | |
| 106 | 115 |
private |
| 107 | 116 | |
| 117 |
def get_overrides |
|
| 118 |
overrides = Hash.new |
|
| 119 |
folders = Dir.glob("#{path}/plugins/*")
|
|
| 120 |
folders.each do |plugin| |
|
| 121 |
plugin_name = plugin.split("/")[-1]
|
|
| 122 |
folder = "#{path}/plugins/#{plugin_name}/*"
|
|
| 123 |
new_items = Dir[folder] |
|
| 124 |
items = [] |
|
| 125 |
while items.count < new_items.count |
|
| 126 |
items = new_items |
|
| 127 |
folder += "/*" |
|
| 128 |
new_items += Dir[folder] |
|
| 129 |
new_items.uniq! |
|
| 130 |
end |
|
| 131 |
ignore_path = "#{path}/plugins/#{plugin_name}/"
|
|
| 132 |
overrides[plugin_name] = items.map { |i| i.gsub(ignore_path, "") }
|
|
| 133 |
end |
|
| 134 |
overrides |
|
| 135 |
end |
|
| 136 | ||
| 108 | 137 |
def assets(dir, ext=nil) |
| 109 | 138 |
if ext |
| 110 | 139 |
Dir.glob("#{path}/#{dir}/*.#{ext}").collect {|f| File.basename(f).gsub(/\.#{ext}$/, '')}
|