Class: Lm2doc::Resource::Source
- Inherits:
-
Lm2doc::Resource
- Object
- Lm2doc::Resource
- Lm2doc::Resource::Source
- Defined in:
- lib/lm2doc/resource/source.rb
Instance Attribute Summary collapse
-
#basename ⇒ Object
Returns the value of attribute basename.
-
#content ⇒ Object
Returns the value of attribute content.
Attributes inherited from Lm2doc::Resource
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file, converter) ⇒ Source
constructor
A new instance of Source.
- #write(dir, options = {}) ⇒ Object
Constructor Details
#initialize(file, converter) ⇒ Source
Returns a new instance of Source.
9 10 11 12 13 14 15 16 17 |
# File 'lib/lm2doc/resource/source.rb', line 9 def initialize(file, converter) self.file = file extname = File.extname(file) self.basename = File.basename(file, extname) raw = File.read(self.file) converter.content = raw self.content = converter.as_html end |
Instance Attribute Details
#basename ⇒ Object
Returns the value of attribute basename.
7 8 9 |
# File 'lib/lm2doc/resource/source.rb', line 7 def basename @basename end |
#content ⇒ Object
Returns the value of attribute content.
7 8 9 |
# File 'lib/lm2doc/resource/source.rb', line 7 def content @content end |
Class Method Details
.build(file) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/lm2doc/resource/source.rb', line 29 def self.build(file) extname = File.extname(file) converter_class = Converter.subclasses.find {|clazz| clazz.perfer_exts.include?(extname) } converter = converter_class.new self.new(file, converter) end |
Instance Method Details
#write(dir, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/lm2doc/resource/source.rb', line 19 def write(dir, = {}) theme = [:theme] result = theme.render(:article => self.content) target = File.join(dir, "#{basename}.html") File.open(target, "w") { |f| f << result } theme.write_assets(dir) end |