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.
49 50 51 |
# File 'lib/ascii_press.rb', line 49 def initialize( = {}) @options = end |
Instance Method Details
#capture_stderr ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/ascii_press.rb', line 88 def capture_stderr real_stderr, $stderr = $stderr, StringIO.new yield $stderr.string ensure $stderr = real_stderr end |
#render(adoc_file_path) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ascii_press.rb', line 53 def render(adoc_file_path) doc = nil errors = capture_stderr do document_text = File.read(adoc_file_path) base_dir = ::File.(File.dirname(adoc_file_path)) if before_convertion = @options[:before_convertion] document_text = before_convertion.call(document_text) end doc = Asciidoctor.load(document_text, @options.merge(base_dir: base_dir)) end puts errors.split(/[\n\r]+/).reject {|line| line.match(/out of sequence/) }.join("\n") html = doc.convert if after_conversion = @options[:after_conversion] html = after_conversion.call(html) end 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 |