class PrettyDoc::Resource::Source
Attributes
basename[RW]
content[RW]
Public Class Methods
build(options)
click to toggle source
# File lib/pretty_doc/resources/source.rb, line 27 def self.build(options) puts 'Converting files ...' output_dir = options.output options.files.each do |file| extname = File.extname(file) converter_class = PrettyDoc::Converter.descendants.find do |klass| klass.perfer_exts.include?(extname) end if converter_class converter = converter_class.new result = new(file, converter, options) result.write(output_dir, options) else puts "No corresponding converter found for file `#{file}`" end end end
new(file, converter, options)
click to toggle source
# File lib/pretty_doc/resources/source.rb, line 9 def initialize(file, converter, options) self.file = file extname = File.extname(file) self.basename = File.basename(file, extname) converter.content = File.read(self.file, encoding: 'utf-8') converter.options = options self.content = converter.as_html end
Public Instance Methods
write(target_dir, options = {})
click to toggle source
# File lib/pretty_doc/resources/source.rb, line 18 def write(target_dir, options = {}) template = options[:template] result = template.render(content: content) target = File.join(target_dir, "#{basename}.html") File.open(target, 'w') { |f| f << result } template.write_assets(target_dir) puts "Create File: #{target}" end