From b3c56d2c0b0d73245a73e8af875d3649590262b8 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 16 Jan 2015 15:00:47 -0800 Subject: [PATCH] Added support for text blocks with wiki formatting. Added dispatch hook to allow dynamic reloading. --- init.rb | 18 ++++++++++--- lib/wiki_notes_macros.rb | 58 +++++++++++++++++++++++----------------- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/init.rb b/init.rb index a37ae16..3421484 100644 --- a/init.rb +++ b/init.rb @@ -21,9 +21,21 @@ begin rescue LoadError end -Dir::foreach(File.join(File.dirname(__FILE__), 'lib')) do |file| - next unless /\.rb$/ =~ file - require file +def init_redmine_wiki_notes + Dir::foreach(File.join(File.dirname(__FILE__), 'lib')) do |file| + next unless /\.rb$/ =~ file + require_dependency file + end +end + +if Rails::VERSION::MAJOR >= 3 + ActionDispatch::Callbacks.to_prepare do + init_redmine_wiki_notes + end +else + Dispatcher.to_prepare :redmine_wiki_notes do + init_redmine_wiki_notes + end end require 'redcloth3' diff --git a/lib/wiki_notes_macros.rb b/lib/wiki_notes_macros.rb index 8145186..43865f4 100644 --- a/lib/wiki_notes_macros.rb +++ b/lib/wiki_notes_macros.rb @@ -1,37 +1,45 @@ module WikiNotesMacro Redmine::WikiFormatting::Macros.register do desc "Adds a note to the wiki page:\n\n" + - " @!{{note(text)}}@\n" + - " @!{{tip(text)}}@\n" + - " @!{{important(text)}}@\n" - " @!{{warning(text)}}@\n" - - macro :note, :parse_args => false do |obj, args| - o = '
' - o << textilizable(args) - o << '
' - o.html_safe + "
\n" +
+      "{{note(text with *wiki formatting*)}}\n" +
+      "{{note\nAlternately, you can put blocks of *wiki-formatted* text here.\n}}\n" +
+      "{{note(Or if you really want)\nYou can do both...\n}}\n" +
+      "
" + macro :note, :parse_args => false do |obj, args, text| + o = textilizable(args) + if text.present? + o << textilizable(text, :object => obj, :headings => false) + end + content_tag('div', o.html_safe, :class => "noteclassic") end - macro :tip, :parse_args => false do |obj, args| - o = '
' - o << textilizable(args) - o << '
' - o.html_safe + desc "Variant of @note@." + macro :tip, :parse_args => false do |obj, args, text| + o = textilizable(args) + if text.present? + o << textilizable(text, :object => obj, :headings => false) + end + content_tag('div', o.html_safe, :class => "notetip") end - macro :important, :parse_args => false do |obj, args| - o = '
' - o << textilizable(args) - o << '
' - o.html_safe + desc "Variant of @note@." + macro :important, :parse_args => false do |obj, args, text| + o = textilizable(args) + if text.present? + o << textilizable(text, :object => obj, :headings => false) + end + content_tag('div', o.html_safe, :class => "noteimportant") end - macro :warning, :parse_args => false do |obj, args| - o = '
' - o << textilizable(args) - o << '
' - o.html_safe + desc "Variant of @note@." + macro :warning, :parse_args => false do |obj, args, text| + o = textilizable(args) + if text.present? + o << textilizable(text, :object => obj, :headings => false) + end + content_tag('div', o.html_safe, :class => "notewarning") end end + end