Sha256: 6fd85cb768d7ba9e660160fcae63dc2408bf78bbc45e3428b7ea7de3ef350db8

Contents?: true

Size: 620 Bytes

Versions: 1

Compression:

Stored size: 620 Bytes

Contents

require "nokogiri"

module Pricecut
  class MarkdownVisitor
    attr_reader :output

    def initialize
      @output = ""
    end

    def visit(node)
      if Pricecut::Elements.const_defined?(node.name.capitalize)
        element = Pricecut::Elements.const_get(node.name.capitalize)
        element.new(self, node).output!
      else
        # Unsupported element, continue visiting children.
        visit_children(node)
      end

      self
    end

    def append_output(string)
      @output << string
    end

    def visit_children(node)
      node.children.each {|child| child.accept(self) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pricecut-0.0.3 lib/pricecut/markdown_visitor.rb