class Marksman::Converter
Attributes
presentation[RW]
theme[RW]
Public Class Methods
new(presentation)
click to toggle source
# File lib/marksman/converter.rb, line 9 def initialize(presentation) @presentation = presentation end
Public Instance Methods
write(directory)
click to toggle source
# File lib/marksman/converter.rb, line 13 def write(directory) puts 'Generating HTML...' FileUtils.mkdir_p(directory) Dir.glob(@presentation.theme.path.join('**/*')).each do |file| if File.file? file copy_file(Pathname.new(file), directory) end end end
Private Instance Methods
convert_haml(file, output)
click to toggle source
# File lib/marksman/converter.rb, line 40 def convert_haml(file, output) template = File.read(file) haml_engine = Haml::Engine.new(template) html = haml_engine.render(Object.new, { presentation: @presentation }) File.write(output, html) end
copy_file(source, target_dir)
click to toggle source
# File lib/marksman/converter.rb, line 25 def copy_file(source, target_dir) target = target_name(source, target_dir) FileUtils.mkdir(target.dirname) unless File.exist? target.dirname if (source.extname == '.haml') convert_haml(source, target.to_s.gsub(/\.haml$/, '.html')) else FileUtils.copy(source, target) end end
target_name(file, target_dir)
click to toggle source
# File lib/marksman/converter.rb, line 35 def target_name(file, target_dir) base_file = file.to_s[(@presentation.theme.path.to_s.length + 1)..-1] target_file = Pathname.new(target_dir).join(base_file) end