Class: AsciiPress::Renderer
- Inherits:
-
Object
- Object
- AsciiPress::Renderer
- Defined in:
- lib/ascii_press.rb
Defined Under Namespace
Classes: Rendering
Instance Method Summary collapse
- #capture_stderr ⇒ Object
-
#initialize(options = {}) ⇒ Renderer
constructor
A new instance of Renderer.
- #render(adoc_file_path) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Renderer
Returns a new instance of Renderer.
48 49 50 |
# File 'lib/ascii_press.rb', line 48 def initialize( = {}) @options = end |
Instance Method Details
#capture_stderr ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/ascii_press.rb', line 76 def capture_stderr real_stderr, $stderr = $stderr, StringIO.new yield $stderr.string ensure $stderr = real_stderr end |
#render(adoc_file_path) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ascii_press.rb', line 52 def render(adoc_file_path) doc = nil errors = capture_stderr { doc = Asciidoctor.load_file(adoc_file_path, @options) } puts errors.split(/[\n\r]+/).reject {|line| line.match(/out of sequence/) }.join("\n") html = doc.convert data = doc.attributes.each_with_object({}) do |(key, value), result| result[key.to_sym] = value.to_s end data.reject! {|_, value| value.nil? } Rendering.new(html, doc, data).tap do |rendering| rendering. = rendering.list_attribute_value('tags') rendering. << 'public' if rendering.attribute_exists?(:public) rendering. << 'private' if rendering.attribute_exists?(:private) if @options[:extra_tags_proc] rendering..concat @options[:extra_tags_proc].call(rendering) end end end |