Index: lib/redmine/wiki_formatting/macros.rb =================================================================== --- lib/redmine/wiki_formatting/macros.rb (revision 2034) +++ lib/redmine/wiki_formatting/macros.rb (working copy) @@ -5,12 +5,12 @@ # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -24,17 +24,17 @@ send(method_name, obj, args) if respond_to?(method_name) end end - + @@available_macros = {} - + class << self # Called with a block to define additional macros. # Macro blocks accept 2 arguments: # * obj: the object that is rendered # * args: macro arguments - # + # # Plugins can use this method to define new macros: - # + # # Redmine::WikiFormatting::Macros.register do # desc "This is my macro" # macro :my_macro do |obj, args| @@ -44,7 +44,7 @@ def register(&block) class_eval(&block) if block_given? end - + private # Defines a new macro with the given name and block. def macro(name, &block) @@ -54,19 +54,19 @@ raise "Can not create a macro without a block!" unless block_given? Definitions.send :define_method, "macro_#{name}".downcase, &block end - + # Sets description for the next macro to be defined def desc(txt) @@desc = txt end end - + # Builtin macros desc "Sample macro." macro :hello_world do |obj, args| "Hello world! Object: #{obj.class.name}, " + (args.empty? ? "Called with no argument." : "Arguments: #{args.join(', ')}") end - + desc "Displays a list of all available macros, including description if available." macro :macro_list do out = '' @@ -76,13 +76,13 @@ end content_tag('dl', out) end - + desc "Displays a list of child pages." macro :child_pages do |obj, args| raise 'This macro applies to wiki pages only.' unless obj.is_a?(WikiContent) render_page_hierarchy(obj.page.descendants.group_by(&:parent_id), obj.page.id) end - + desc "Include a wiki page. Example:\n\n !{{include(Foo)}}\n\nor to include a page of a specific project wiki:\n\n !{{include(projectname:Foo)}}" macro :include do |obj, args| project = @project @@ -102,6 +102,19 @@ @included_wiki_pages.pop out end + + desc "Attachment links." + macro :file do |obj, args| + out = '' + id = args.first.to_s + title = id + if title =~ %r{^([^\:]+)\:(.*)$} + id, title = $1, $2 + end + out << "#{title}" + out + end + end end end