Class: BookChef::Compiler::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/bookchef/compilers/html.rb

Overview

Converts XML into HTML using xslt

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fn, xslt_stylesheet = "#{BookChef::LIB_PATH}/stylesheets/xslt/bookchef_to_html.xsl") ⇒ HTML

Returns a new instance of HTML.



9
10
11
12
13
14
# File 'lib/bookchef/compilers/html.rb', line 9

def initialize(fn, xslt_stylesheet="#{BookChef::LIB_PATH}/stylesheets/xslt/bookchef_to_html.xsl")
  xslt_stylesheet = File.read(xslt_stylesheet).sub('#{gem_path}', "file://#{BookChef::LIB_PATH}")
  @document     = XML::XSLT.new
  @document.xml = fn
  @document.xsl = xslt_stylesheet
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



7
8
9
# File 'lib/bookchef/compilers/html.rb', line 7

def document
  @document
end

#resultObject (readonly)

Returns the value of attribute result.



7
8
9
# File 'lib/bookchef/compilers/html.rb', line 7

def result
  @result
end

Instance Method Details

#runObject



16
17
18
19
# File 'lib/bookchef/compilers/html.rb', line 16

def run
  @result = BookChef.decode_special_chars(@document.serve)
  @result = BookChef.replace_https_with_http(@result)
end

#save_to(fn) ⇒ Object



21
22
23
24
25
# File 'lib/bookchef/compilers/html.rb', line 21

def save_to(fn)
  f = File.open(fn, "w")
  f.write @result 
  f.close
end