class Darkmouun::Darkmouun
Attributes
post_process[RW]
pre_process[RW]
Public Class Methods
new(source, options ={}, converter = :html)
click to toggle source
# File lib/darkmouun/main.rb, line 18 def initialize(source, options ={}, converter = :html) @source, @options = source, options @templates = {} @converter = ('to_' + (converter.to_s)).intern end
Public Instance Methods
add_templates(dir, *tmpls)
click to toggle source
# File lib/darkmouun/main.rb, line 24 def add_templates(dir, *tmpls) # for Mustache tmpls.each do |tmpl| abs_path = dir + tmpl tmpl_module = Module.new tmpl_module.module_eval(File.read(abs_path), abs_path) tmpl_module.constants.each do |i| c = tmpl_module.const_get(i) if c.is_a?(Class) && c.superclass == Mustache @templates[i] = c end end end end
convert()
click to toggle source
# File lib/darkmouun/main.rb, line 39 def convert do_pre_process apply_mustache apply_kramdown do_post_process beautify end
Private Instance Methods
apply_kramdown()
click to toggle source
# File lib/darkmouun/main.rb, line 71 def apply_kramdown begin @result = Kramdown::Document.new(@source, @options).send(@converter) rescue => e raise e.class.new("\n#{e.message}\n\n>>> ERROR in \"kramdown-process\" <<<\n") end end
apply_mustache()
click to toggle source
# File lib/darkmouun/main.rb, line 57 def apply_mustache @source = @source.gsub(/<<(.+?)>>\n((?:[# \-]*[\w_][\w\d_]*: *\n?(?: +.+\n)+)+)/) do |s| begin obj_spot_template, data = (@templates[$1.to_sym]).new, $2 YAML.load_stream(data).compact.reduce(&:merge).each do |k, v| obj_spot_template.define_singleton_method(k){ v } end obj_spot_template.render + "\n" rescue => e raise e.class.new("\n#{e.message} in \"Mustache-process\" at *** #{s} ***\n") end end end
beautify()
click to toggle source
# File lib/darkmouun/main.rb, line 87 def beautify HtmlBeautifier.beautify(@result) end
do_post_process()
click to toggle source
# File lib/darkmouun/main.rb, line 79 def do_post_process begin @post_process.call(@result) unless @post_process.nil? rescue => e raise e.class.new("\n#{e.message}\n\n>>> ERROR in \"Post-process\" <<<\n") end end
do_pre_process()
click to toggle source
# File lib/darkmouun/main.rb, line 49 def do_pre_process begin @pre_process.call(@source) unless @pre_process.nil? rescue => e raise e.class.new("\n#{e.message}\n\n>>> ERROR in \"Pre-process\" <<<\n") end end