45 |
45 |
if self.class.instance_method(method_name).arity == 3
|
46 |
46 |
send(method_name, obj, args, text)
|
47 |
47 |
elsif text
|
48 |
|
raise "This macro does not accept a block of text"
|
|
48 |
raise t(:error_macro_does_not_accept_block)
|
49 |
49 |
else
|
50 |
50 |
send(method_name, obj, args)
|
51 |
51 |
end
|
52 |
52 |
rescue => e
|
53 |
|
"<div class=\"flash error\">Error executing the <strong>#{h name}</strong> macro (#{h e.to_s})</div>".html_safe
|
|
53 |
%|<div class="flash error">#{t(:error_can_not_execute_macro_html, :name => name, :error => e.to_s)}</div>|.html_safe
|
54 |
54 |
end
|
55 |
55 |
end
|
56 |
56 |
|
... | ... | |
152 |
152 |
def macro(name, options={}, &block)
|
153 |
153 |
options.assert_valid_keys(:desc, :parse_args)
|
154 |
154 |
unless /\A\w+\z/.match?(name.to_s)
|
155 |
|
raise "Invalid macro name: #{name} (only 0-9, A-Z, a-z and _ characters are accepted)"
|
|
155 |
raise t(:error_invalid_macro_name, :name => name)
|
156 |
156 |
end
|
157 |
157 |
unless block_given?
|
158 |
|
raise "Can not create a macro without a block!"
|
|
158 |
raise t(:error_can_not_create_macro_without_block)
|
159 |
159 |
end
|
160 |
160 |
name = name.to_s.downcase.to_sym
|
161 |
161 |
available_macros[name] = {:desc => @@desc || ''}.merge(options)
|
... | ... | |
204 |
204 |
elsif obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)
|
205 |
205 |
page = obj.page
|
206 |
206 |
else
|
207 |
|
raise 'With no argument, this macro can be called from wiki pages only.'
|
|
207 |
raise t(:error_childpages_macro_no_argument)
|
208 |
208 |
end
|
209 |
|
raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project)
|
|
209 |
raise t(:error_page_not_found) if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project)
|
210 |
210 |
pages = page.self_and_descendants(options[:depth]).group_by(&:parent_id)
|
211 |
211 |
render_page_hierarchy(pages, options[:parent] ? page.parent_id : page.id)
|
212 |
212 |
end
|
... | ... | |
216 |
216 |
"{{include(projectname:Foo)}} -- to include a page of a specific project wiki"
|
217 |
217 |
macro :include do |obj, args|
|
218 |
218 |
page = Wiki.find_page(args.first.to_s, :project => @project)
|
219 |
|
raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project)
|
|
219 |
raise t(:error_page_not_found) if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project)
|
220 |
220 |
@included_wiki_pages ||= []
|
221 |
|
raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.id)
|
|
221 |
raise t(:error_circular_inclusion) if @included_wiki_pages.include?(page.id)
|
222 |
222 |
@included_wiki_pages << page.id
|
223 |
223 |
out = textilizable(page.content, :text, :attachments => page.attachments, :headings => false, :inline_attachments => @@inline_attachments)
|
224 |
224 |
@included_wiki_pages.pop
|
... | ... | |
247 |
247 |
macro :thumbnail do |obj, args|
|
248 |
248 |
args, options = extract_macro_options(args, :size, :title)
|
249 |
249 |
filename = args.first
|
250 |
|
raise 'Filename required' unless filename.present?
|
|
250 |
raise t(:error_filename_required) unless filename.present?
|
251 |
251 |
size = options[:size]
|
252 |
|
raise 'Invalid size parameter' unless size.nil? || /^\d+$/.match?(size)
|
|
252 |
raise t(:error_invalid_size_parameter) unless size.nil? || /^\d+$/.match?(size)
|
253 |
253 |
size = size.to_i
|
254 |
254 |
size = 200 unless size > 0
|
255 |
255 |
if obj && obj.respond_to?(:attachments) && attachment = Attachment.latest_attach(obj.attachments, filename)
|
... | ... | |
260 |
260 |
img = image_tag(thumbnail_url, :alt => attachment.filename)
|
261 |
261 |
link_to(img, image_url, :class => 'thumbnail', :title => title)
|
262 |
262 |
else
|
263 |
|
raise "Attachment #{filename} not found"
|
|
263 |
raise t(:error_attachment_not_found, :name => filename)
|
264 |
264 |
end
|
265 |
265 |
end
|
266 |
266 |
|