03-compatibility_with_chili_project_and_addition_of_wiki_macro_or_liquid_tag_for_chili_project_3_0.patch
app/helpers/download_helper.rb (working copy) | ||
---|---|---|
6 | 6 |
return render(:partial => 'download/button', |
7 | 7 |
:locals => { :label => download_label(version, download), |
8 | 8 |
:package => download_package(version, download), |
9 |
:link => download_link(version, download) }) |
|
9 |
:link => download_link(version, download), |
|
10 |
:style => options[:style] }) |
|
10 | 11 |
end |
11 | 12 |
end |
12 | 13 |
app/views/download/_button.rhtml (working copy) | ||
---|---|---|
1 |
<a href="<%= h(link) %>" class="download"> |
|
1 |
<a href="<%= h(link) %>" class="download" style="<%= h(style) %>">
|
|
2 | 2 |
<span class="icon-download"> |
3 | 3 |
<%= h(label) %> |
4 | 4 |
<span class="version"><%= h(package) %></span> |
5 | 5 |
</span> |
6 |
<div class="clear"></div> |
|
6 | 7 |
</a> |
app/views/download/_tag.rhtml (revision 0) | ||
---|---|---|
1 |
<div class="download-button" style="<%= h(container_style) %>"> |
|
2 |
<%= download_button(project, download, :style => button_style) %> |
|
3 |
<div class="clear"></div> |
|
4 |
</div> |
app/views/download/_sidebar.rhtml (working copy) | ||
---|---|---|
5 | 5 |
controller.class.name == 'ActivitiesController' || |
6 | 6 |
controller.class.name == 'VersionsController' || |
7 | 7 |
controller.class.name == 'WikiController' %> |
8 |
<p><%= download_button(@project, @download) %></p> |
|
8 |
<div class="download-button"> |
|
9 |
<%= download_button(@project, @download) %> |
|
10 |
<div class="clear"></div> |
|
11 |
</div> |
|
9 | 12 |
<% end %> |
10 | 13 |
<% end %> |
11 | 14 |
<% end %> |
assets/stylesheets/download.css (working copy) | ||
---|---|---|
7 | 7 |
background-position: left bottom; |
8 | 8 |
background-repeat: repeat-x; |
9 | 9 |
border: 1px solid #288c44; |
10 |
color: #f8f8f8; |
|
11 | 10 |
padding: 2px 20px 2px 0; |
12 | 11 |
text-align: center; |
13 | 12 |
text-decoration: none; |
14 | 13 |
border-radius: 5px; |
15 | 14 |
-moz-border-radius: 5px; |
15 |
float: left; /* required in particular for ChiliProject 3.0 theme */ |
|
16 | 16 |
} |
17 |
a.download span.icon-download { |
|
17 |
a.download .icon-download { |
|
18 |
color: #f8f8f8; |
|
18 | 19 |
background-image: url(../images/arrow.gif); |
19 | 20 |
background-position: 7px center; |
20 | 21 |
background-repeat: no-repeat; |
... | ... | |
23 | 24 |
} |
24 | 25 |
a.download .version { |
25 | 26 |
display: block; |
26 |
font-size: 10px;
|
|
27 |
font-size: 70%;
|
|
27 | 28 |
font-weight: normal; |
28 | 29 |
margin-top: -3px; |
29 | 30 |
} |
31 |
/* force no text decoration for button */ |
|
32 |
a.download:hover { |
|
33 |
text-decoration: none; |
|
34 |
} |
|
35 |
a.download:link { |
|
36 |
text-decoration: none; |
|
37 |
} |
|
38 |
a.download:visited { |
|
39 |
text-decoration: none; |
|
40 |
} |
|
41 |
#sidebar a.download:hover { |
|
42 |
text-decoration: none; |
|
43 |
} |
|
44 |
#sidebar a.download:link { |
|
45 |
text-decoration: none; |
|
46 |
} |
|
47 |
#sidebar a.download:visited { |
|
48 |
text-decoration: none; |
|
49 |
} |
|
50 |
a.download .clear { |
|
51 |
clear: both; |
|
52 |
} |
|
53 |
.download-button .clear { |
|
54 |
clear: both; |
|
55 |
} |
|
56 |
/* ID used for project settings preview */ |
|
30 | 57 |
#download-button { |
31 | 58 |
margin: 0.5em 0.5em 0 0; |
32 | 59 |
float: right; |
init.rb (working copy) | ||
---|---|---|
32 | 32 |
version '0.0.2' |
33 | 33 | |
34 | 34 |
permission :manage_download_button, { :projects => :settings, :download => :edit }, :require => :member |
35 | ||
36 |
begin |
|
37 | ||
38 |
class DownloadButtonTag < ChiliProject::Liquid::Tags::Tag |
|
39 |
include DownloadMacroHelper |
|
40 | ||
41 |
def initialize(tag_name, markup, tokens) |
|
42 |
tag_args = markup.strip.gsub(/^[("']|["']|["')]$/, '') |
|
43 |
if tag_args.present? |
|
44 |
@args = tag_args.split(',') |
|
45 |
else |
|
46 |
@args = [] |
|
47 |
end |
|
48 |
super |
|
49 |
end |
|
50 | ||
51 |
def render(context) |
|
52 |
# render context |
|
53 |
@project = Project.find(context['project'].identifier ) if context['project'].present? |
|
54 |
@view = context.registers[:view] |
|
55 |
# parse arguments |
|
56 |
attributes, options = extract_download_options(@args) |
|
57 |
# find project |
|
58 |
if attributes[:project_id] |
|
59 |
@project = Project.find_by_id(attributes[:project_id]) |
|
60 |
raise "invalid project ID: #{h(attributes[:project_id])}" unless @project |
|
61 |
elsif @project.present? |
|
62 |
attributes[:project_id] = @project.id |
|
63 |
else |
|
64 |
raise "download button tag can only be used outside project context with project_id option" |
|
65 |
end |
|
66 |
# instantiate new (temporary) download button |
|
67 |
download = DownloadButton.new(attributes) |
|
68 |
raise "Failed to instantiate download button" unless download |
|
69 |
# render download button |
|
70 |
@view.render(:partial => "download/tag", :locals => { :project => @project, |
|
71 |
:download => download, |
|
72 |
:container_style => to_container_style(options), |
|
73 |
:button_style => to_button_style(options) }) |
|
74 |
end |
|
75 | ||
76 |
end |
|
77 | ||
78 |
ChiliProject::Liquid::Tags::register_tag('download', DownloadButtonTag, :html => true) |
|
79 | ||
80 |
rescue |
|
81 | ||
82 |
Redmine::WikiFormatting::Macros.register do |
|
83 |
desc "Inserts Download button in wiki pages with optional arguments" |
|
84 |
macro :download do |obj, args| |
|
85 |
# parse arguments |
|
86 |
attributes, options = DownloadMacroHelper.extract_download_options(args) |
|
87 |
# find project |
|
88 |
if attributes[:project_id] |
|
89 |
@project = Project.find_by_id(attributes[:project_id]) |
|
90 |
raise "invalid project ID: #{h(attributes[:project_id])}" unless @project |
|
91 |
elsif @project.present? |
|
92 |
attributes[:project_id] = @project.id |
|
93 |
else |
|
94 |
raise "download button macro can only be used outside project context with project_id option" |
|
95 |
end |
|
96 |
# instantiate new (temporary) download button |
|
97 |
download = DownloadButton.new(attributes) |
|
98 |
raise "Failed to instantiate download button" unless download |
|
99 |
# render download button |
|
100 |
render(:partial => "download/tag", :locals => { :project => @project, |
|
101 |
:download => download, |
|
102 |
:container_style => DownloadMacroHelper.to_container_style(options), |
|
103 |
:button_style => DownloadMacroHelper.to_button_style(options) }) |
|
104 |
end |
|
105 |
end |
|
106 | ||
107 |
end |
|
35 | 108 |
end |
lib/download_macro_helper.rb (revision 0) | ||
---|---|---|
1 | ||
2 |
module DownloadMacroHelper |
|
3 |
module_function |
|
4 | ||
5 |
def extract_macro_options(args, *keys) |
|
6 |
options = {} |
|
7 |
args.delete_if do |arg| |
|
8 |
if arg.to_s.strip =~ %r{^([^=]+)\=(.+)$} && keys.include?($1.downcase.to_sym) |
|
9 |
options[$1.downcase.to_sym] = $2 |
|
10 |
true |
|
11 |
else |
|
12 |
false |
|
13 |
end |
|
14 |
end |
|
15 |
return [args, options] |
|
16 |
end |
|
17 | ||
18 |
def extract_download_options(args) |
|
19 |
# parse arguments |
|
20 |
attribute_keys = [:project_id, :label, :package, :include_version, :file_id, :url] |
|
21 |
#style_keys = [:float, :width, :font_size, :margin, :margin_top, :margin_right, |
|
22 |
# :margin_bottom, :margin_left] |
|
23 | ||
24 |
rest, options = extract_macro_options(args, :project_id, :label, :package, |
|
25 |
:include_version, :file_id, :url, |
|
26 |
:float, :width, :font_size, :margin, |
|
27 |
:margin_top, :margin_right, |
|
28 |
:margin_bottom, :margin_left) |
|
29 | ||
30 |
# throw error if invalid arguments given |
|
31 |
raise "invalid argument(s): \"#{rest.join(', ')}\" (correctly parsed #{options.length} arguments)" if rest.length > 0 |
|
32 |
# compose style of download button container |
|
33 |
container_style = [] |
|
34 |
container_style.push("float: #{options[:float]}") if options[:float] |
|
35 |
container_style.push("margin: #{options[:margin]}") if options[:margin] |
|
36 |
container_style.push("margin-top: #{options[:margin_top]}") if options[:margin_top] |
|
37 |
container_style.push("margin-right: #{options[:margin_right]}") if options[:margin_right] |
|
38 |
container_style.push("margin-bottom: #{options[:margin_bottom]}") if options[:margin_bottom] |
|
39 |
container_style.push("margin-left: #{options[:margin_left]}") if options[:margin_left] |
|
40 |
container_style = container_style.join('; ') |
|
41 |
# compase style of download button itself |
|
42 |
button_style = [] |
|
43 |
button_style.push("width: #{options[:width]}") if options[:width] |
|
44 |
button_style.push("font-size: #{options[:font_size]}") if options[:font_size] |
|
45 |
button_style = button_style.join('; ') |
|
46 |
# extract download button attributes from options |
|
47 |
attributes = {} |
|
48 |
options.select do |k, v| |
|
49 |
attributes[k] = v if attribute_keys.include?(k) |
|
50 |
end |
|
51 |
attributes[:file_id] = -1 if attributes[:url] |
|
52 |
attributes[:disabled] = false |
|
53 | ||
54 |
return [attributes, options] |
|
55 |
end |
|
56 | ||
57 |
def to_container_style(options) |
|
58 |
container_style = [] |
|
59 |
container_style.push("float: #{options[:float]}") if options[:float] |
|
60 |
container_style.push("margin: #{options[:margin]}") if options[:margin] |
|
61 |
container_style.push("margin-top: #{options[:margin_top]}") if options[:margin_top] |
|
62 |
container_style.push("margin-right: #{options[:margin_right]}") if options[:margin_right] |
|
63 |
container_style.push("margin-bottom: #{options[:margin_bottom]}") if options[:margin_bottom] |
|
64 |
container_style.push("margin-left: #{options[:margin_left]}") if options[:margin_left] |
|
65 |
return container_style.join('; ') |
|
66 |
end |
|
67 | ||
68 |
def to_button_style(options) |
|
69 |
button_style = [] |
|
70 |
button_style.push("width: #{options[:width]}") if options[:width] |
|
71 |
button_style.push("font-size: #{options[:font_size]}") if options[:font_size] |
|
72 |
return button_style.join('; ') |
|
73 |
end |
|
74 | ||
75 |
end |