Class: PrettyDoc::Resource::Source
- Inherits:
-
PrettyDoc::Resource
- Object
- PrettyDoc::Resource
- PrettyDoc::Resource::Source
- Defined in:
- lib/pretty_doc/resources/source.rb
Overview
Source Resource
Instance Attribute Summary collapse
-
#basename ⇒ Object
Returns the value of attribute basename.
-
#content ⇒ Object
Returns the value of attribute content.
Attributes inherited from PrettyDoc::Resource
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file, converter, options) ⇒ Source
constructor
A new instance of Source.
- #write(target_dir, options = {}) ⇒ Object
Constructor Details
#initialize(file, converter, options) ⇒ Source
Returns a new instance of Source.
9 10 11 12 13 14 15 16 |
# File 'lib/pretty_doc/resources/source.rb', line 9 def initialize(file, converter, ) self.file = file extname = File.extname(file) self.basename = File.basename(file, extname) converter.content = File.read(self.file) converter. = self.content = converter.as_html end |
Instance Attribute Details
#basename ⇒ Object
Returns the value of attribute basename.
7 8 9 |
# File 'lib/pretty_doc/resources/source.rb', line 7 def basename @basename end |
#content ⇒ Object
Returns the value of attribute content.
7 8 9 |
# File 'lib/pretty_doc/resources/source.rb', line 7 def content @content end |
Class Method Details
.build(options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pretty_doc/resources/source.rb', line 27 def self.build() puts 'Converting files ...' output_dir = .output .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, ) result.write(output_dir, ) else puts "No corresponding converter found for file `#{file}`" end end end |
Instance Method Details
#write(target_dir, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/pretty_doc/resources/source.rb', line 18 def write(target_dir, = {}) template = [: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 |