Class: Lm2doc::Resource::Source

Inherits:
Lm2doc::Resource show all
Defined in:
lib/lm2doc/resource/source.rb

Instance Attribute Summary collapse

Attributes inherited from Lm2doc::Resource

#file

Class Method Summary collapse

Instance Method Summary collapse

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

#basenameObject

Returns the value of attribute basename.



7
8
9
# File 'lib/lm2doc/resource/source.rb', line 7

def basename
  @basename
end

#contentObject

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, options = {})
  theme = options[: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