Class: Apical::HtmlWriter
- Inherits:
-
Object
- Object
- Apical::HtmlWriter
- Defined in:
- lib/apical/writers/html_writer.rb
Instance Method Summary collapse
-
#initialize(runner) ⇒ HtmlWriter
constructor
A new instance of HtmlWriter.
- #markdown_to_html(str) ⇒ Object
- #resource_html(resource) ⇒ Object
- #write(stream) ⇒ Object
Constructor Details
#initialize(runner) ⇒ HtmlWriter
Returns a new instance of HtmlWriter.
3 4 5 |
# File 'lib/apical/writers/html_writer.rb', line 3 def initialize(runner) @runner = runner end |
Instance Method Details
#markdown_to_html(str) ⇒ Object
7 8 9 |
# File 'lib/apical/writers/html_writer.rb', line 7 def markdown_to_html(str) Kramdown::Document.new(str).to_html end |
#resource_html(resource) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/apical/writers/html_writer.rb', line 25 def resource_html(resource) Mustache.to_html(File.read(File.dirname(__FILE__) + '/../../../templates/resource.mustache'), { method: resource.method, path: resource.path, desc: markdown_to_html(resource.desc), accept: resource.accept, params: resource.formatted_params, content_type: resource.content_type, response: resource.formatted_response }) end |
#write(stream) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/apical/writers/html_writer.rb', line 11 def write(stream) @runner.run stream.write( Mustache.to_html(File.read(File.dirname(__FILE__) + '/../../../templates/layout.mustache'), { name: @runner.name, desc: markdown_to_html(@runner.desc), content: @runner.resources.map {|r| resource_html(r) }.join }) ) stream.rewind stream end |