Class: Jdoc::Generator
- Inherits:
-
Object
- Object
- Jdoc::Generator
- Defined in:
- lib/jdoc/generator.rb
Constant Summary collapse
- HTML_TEMPLATE_PATH =
File.("../../../template.html.erb", __FILE__)
- MARKDOWN_TEMPLATE_PATH =
File.("../../../template.md.erb", __FILE__)
Class Method Summary collapse
-
.call(*args) ⇒ String
Utility wrapper for Jdoc::Generator#call.
- .html_renderer ⇒ Erubis::Eruby
-
.html_template ⇒ String
ERB template.
- .markdown_renderer ⇒ Erubis::Eruby
-
.markdown_template ⇒ String
ERB template.
- .redcarpet ⇒ Object
Instance Method Summary collapse
-
#call ⇒ String
Generates Markdown or HTML documentation from JSON schema.
-
#initialize(schema, html: false) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(schema, html: false) ⇒ Generator
Returns a new instance of Generator.
44 45 46 47 |
# File 'lib/jdoc/generator.rb', line 44 def initialize(schema, html: false) @raw_schema = schema @html = html end |
Class Method Details
.call(*args) ⇒ String
Utility wrapper for Jdoc::Generator#call
38 39 40 |
# File 'lib/jdoc/generator.rb', line 38 def self.call(*args) new(*args).call end |
.html_renderer ⇒ Erubis::Eruby
13 14 15 |
# File 'lib/jdoc/generator.rb', line 13 def html_renderer @html_renderer ||= Erubis::Eruby.new(html_template) end |
.html_template ⇒ String
Returns ERB template.
31 32 33 |
# File 'lib/jdoc/generator.rb', line 31 def html_template File.read(HTML_TEMPLATE_PATH) end |
.markdown_renderer ⇒ Erubis::Eruby
8 9 10 |
# File 'lib/jdoc/generator.rb', line 8 def markdown_renderer @markdown_renderer ||= Erubis::Eruby.new(markdown_template) end |
.markdown_template ⇒ String
Returns ERB template.
26 27 28 |
# File 'lib/jdoc/generator.rb', line 26 def markdown_template File.read(MARKDOWN_TEMPLATE_PATH) end |
.redcarpet ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/jdoc/generator.rb', line 17 def redcarpet @redcarpet ||= Redcarpet::Markdown.new( Redcarpet::Render::HTML.new(hard_wrap: true, filter_html: true), autolink: true, fenced_code_blocks: true, ) end |
Instance Method Details
#call ⇒ String
Generates Markdown or HTML documentation from JSON schema
51 52 53 54 55 |
# File 'lib/jdoc/generator.rb', line 51 def call result = self.class.markdown_renderer.result(schema: schema) result = self.class.html_renderer.result(body: self.class.redcarpet.render(result)) if @html result end |