annotate .svn/pristine/e4/e479c671ce697e72b11bd49cf15871d767b7e451.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 module Redmine
Chris@909 19 module WikiFormatting
Chris@909 20 module Macros
Chris@909 21 module Definitions
Chris@909 22 def exec_macro(name, obj, args)
Chris@909 23 method_name = "macro_#{name}"
Chris@909 24 send(method_name, obj, args) if respond_to?(method_name)
Chris@909 25 end
Chris@909 26
Chris@909 27 def extract_macro_options(args, *keys)
Chris@909 28 options = {}
Chris@909 29 while args.last.to_s.strip =~ %r{^(.+)\=(.+)$} && keys.include?($1.downcase.to_sym)
Chris@909 30 options[$1.downcase.to_sym] = $2
Chris@909 31 args.pop
Chris@909 32 end
Chris@909 33 return [args, options]
Chris@909 34 end
Chris@909 35 end
Chris@909 36
Chris@909 37 @@available_macros = {}
Chris@909 38
Chris@909 39 class << self
Chris@909 40 # Called with a block to define additional macros.
Chris@909 41 # Macro blocks accept 2 arguments:
Chris@909 42 # * obj: the object that is rendered
Chris@909 43 # * args: macro arguments
Chris@909 44 #
Chris@909 45 # Plugins can use this method to define new macros:
Chris@909 46 #
Chris@909 47 # Redmine::WikiFormatting::Macros.register do
Chris@909 48 # desc "This is my macro"
Chris@909 49 # macro :my_macro do |obj, args|
Chris@909 50 # "My macro output"
Chris@909 51 # end
Chris@909 52 # end
Chris@909 53 def register(&block)
Chris@909 54 class_eval(&block) if block_given?
Chris@909 55 end
Chris@909 56
Chris@909 57 private
Chris@909 58 # Defines a new macro with the given name and block.
Chris@909 59 def macro(name, &block)
Chris@909 60 name = name.to_sym if name.is_a?(String)
Chris@909 61 @@available_macros[name] = @@desc || ''
Chris@909 62 @@desc = nil
Chris@909 63 raise "Can not create a macro without a block!" unless block_given?
Chris@909 64 Definitions.send :define_method, "macro_#{name}".downcase, &block
Chris@909 65 end
Chris@909 66
Chris@909 67 # Sets description for the next macro to be defined
Chris@909 68 def desc(txt)
Chris@909 69 @@desc = txt
Chris@909 70 end
Chris@909 71 end
Chris@909 72
Chris@909 73 # Builtin macros
Chris@909 74 desc "Sample macro."
Chris@909 75 macro :hello_world do |obj, args|
Chris@909 76 "Hello world! Object: #{obj.class.name}, " + (args.empty? ? "Called with no argument." : "Arguments: #{args.join(', ')}")
Chris@909 77 end
Chris@909 78
Chris@909 79 desc "Displays a list of all available macros, including description if available."
Chris@909 80 macro :macro_list do |obj, args|
Chris@909 81 out = ''
Chris@909 82 @@available_macros.keys.collect(&:to_s).sort.each do |macro|
Chris@909 83 out << content_tag('dt', content_tag('code', macro))
Chris@909 84 out << content_tag('dd', textilizable(@@available_macros[macro.to_sym]))
Chris@909 85 end
Chris@909 86 content_tag('dl', out)
Chris@909 87 end
Chris@909 88
Chris@909 89 desc "Displays a list of child pages. With no argument, it displays the child pages of the current wiki page. Examples:\n\n" +
Chris@909 90 " !{{child_pages}} -- can be used from a wiki page only\n" +
Chris@909 91 " !{{child_pages(Foo)}} -- lists all children of page Foo\n" +
Chris@909 92 " !{{child_pages(Foo, parent=1)}} -- same as above with a link to page Foo"
Chris@909 93 macro :child_pages do |obj, args|
Chris@909 94 args, options = extract_macro_options(args, :parent)
Chris@909 95 page = nil
Chris@909 96 if args.size > 0
Chris@909 97 page = Wiki.find_page(args.first.to_s, :project => @project)
Chris@909 98 elsif obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)
Chris@909 99 page = obj.page
Chris@909 100 else
Chris@909 101 raise 'With no argument, this macro can be called from wiki pages only.'
Chris@909 102 end
Chris@909 103 raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project)
Chris@909 104 pages = ([page] + page.descendants).group_by(&:parent_id)
Chris@909 105 render_page_hierarchy(pages, options[:parent] ? page.parent_id : page.id)
Chris@909 106 end
Chris@909 107
Chris@909 108 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)}}"
Chris@909 109 macro :include do |obj, args|
Chris@909 110 page = Wiki.find_page(args.first.to_s, :project => @project)
Chris@909 111 raise 'Page not found' if page.nil? || !User.current.allowed_to?(:view_wiki_pages, page.wiki.project)
Chris@909 112 @included_wiki_pages ||= []
Chris@909 113 raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.title)
Chris@909 114 @included_wiki_pages << page.title
Chris@909 115 out = textilizable(page.content, :text, :attachments => page.attachments, :headings => false)
Chris@909 116 @included_wiki_pages.pop
Chris@909 117 out
Chris@909 118 end
Chris@909 119 end
Chris@909 120 end
Chris@909 121 end