Added support for text blocks with wiki formatting.

Added dispatch hook to allow dynamic reloading.
This commit is contained in:
Adam 2015-01-16 15:00:47 -08:00
parent 2d01e88d98
commit b3c56d2c0b
2 changed files with 48 additions and 28 deletions

18
init.rb
View file

@ -21,9 +21,21 @@ begin
rescue LoadError rescue LoadError
end end
Dir::foreach(File.join(File.dirname(__FILE__), 'lib')) do |file| def init_redmine_wiki_notes
next unless /\.rb$/ =~ file Dir::foreach(File.join(File.dirname(__FILE__), 'lib')) do |file|
require 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 end
require 'redcloth3' require 'redcloth3'

View file

@ -1,37 +1,45 @@
module WikiNotesMacro module WikiNotesMacro
Redmine::WikiFormatting::Macros.register do Redmine::WikiFormatting::Macros.register do
desc "Adds a note to the wiki page:\n\n" + desc "Adds a note to the wiki page:\n\n" +
" @!{{note(text)}}@\n" + "<pre>\n" +
" @!{{tip(text)}}@\n" + "{{note(text with *wiki formatting*)}}\n" +
" @!{{important(text)}}@\n" "{{note\nAlternately, you can put blocks of *wiki-formatted* text here.\n}}\n" +
" @!{{warning(text)}}@\n" "{{note(Or if you really want)\nYou can do both...\n}}\n" +
"</pre>"
macro :note, :parse_args => false do |obj, args| macro :note, :parse_args => false do |obj, args, text|
o = '<div class="noteclassic">' o = textilizable(args)
o << textilizable(args) if text.present?
o << '</div>' o << textilizable(text, :object => obj, :headings => false)
o.html_safe end
content_tag('div', o.html_safe, :class => "noteclassic")
end end
macro :tip, :parse_args => false do |obj, args| desc "Variant of @note@."
o = '<div class="notetip">' macro :tip, :parse_args => false do |obj, args, text|
o << textilizable(args) o = textilizable(args)
o << '</div>' if text.present?
o.html_safe o << textilizable(text, :object => obj, :headings => false)
end
content_tag('div', o.html_safe, :class => "notetip")
end end
macro :important, :parse_args => false do |obj, args| desc "Variant of @note@."
o = '<div class="noteimportant">' macro :important, :parse_args => false do |obj, args, text|
o << textilizable(args) o = textilizable(args)
o << '</div>' if text.present?
o.html_safe o << textilizable(text, :object => obj, :headings => false)
end
content_tag('div', o.html_safe, :class => "noteimportant")
end end
macro :warning, :parse_args => false do |obj, args| desc "Variant of @note@."
o = '<div class="notewarning">' macro :warning, :parse_args => false do |obj, args, text|
o << textilizable(args) o = textilizable(args)
o << '</div>' if text.present?
o.html_safe o << textilizable(text, :object => obj, :headings => false)
end
content_tag('div', o.html_safe, :class => "notewarning")
end end
end end
end end