wiki.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. require 'tilt/template'
  2. module Tilt
  3. # Creole implementation. See:
  4. # http://www.wikicreole.org/
  5. class CreoleTemplate < Template
  6. def self.engine_initialized?
  7. defined? ::Creole
  8. end
  9. def initialize_engine
  10. require_template_library 'creole'
  11. end
  12. def prepare
  13. opts = {}
  14. [:allowed_schemes, :extensions, :no_escape].each do |k|
  15. opts[k] = options[k] if options[k]
  16. end
  17. @engine = Creole::Parser.new(data, opts)
  18. @output = nil
  19. end
  20. def evaluate(scope, locals, &block)
  21. @output ||= @engine.to_html
  22. end
  23. end
  24. # WikiCloth implementation. See:
  25. # http://redcloth.org/
  26. class WikiClothTemplate < Template
  27. def self.engine_initialized?
  28. defined? ::WikiCloth::Parser
  29. end
  30. def initialize_engine
  31. require_template_library 'wikicloth'
  32. end
  33. def prepare
  34. @parser = options.delete(:parser) || WikiCloth::Parser
  35. @engine = @parser.new options.merge(:data => data)
  36. @output = nil
  37. end
  38. def evaluate(scope, locals, &block)
  39. @output ||= @engine.to_html
  40. end
  41. end
  42. end