Sha256: f2185ed80558f34989a34528dbe9fcb09da57f41eac3857abd2482ff527e17ed

Contents?: true

Size: 911 Bytes

Versions: 3

Compression:

Stored size: 911 Bytes

Contents

module Flannel
  class BaseBlock
    attr_reader :type, :id, :text, :parent_id, :attributes
    
    def initialize args
      header = args.shift
      @type = header.shift[1]
      @id = header.shift[1]
      @attributes = {}
      
      next_arg = header.shift
      while next_arg
        case next_arg[0]
        when :parent_id then
          @parent_id = next_arg[1]
        when :attribute_list then
          next_arg.shift
          next_arg.each do |attribute|
            @attributes[attribute[0]] = attribute[1]
          end
        end  
        next_arg = header.shift
      end
      
      @text = args.shift
      strip_text
    end
    
    def to_h
      html_formatter = Flannel::HtmlFormatter.new
      html_formatter.do(@text, @type, @id)
    end
    
    def strip_text
      return if @type == :preformatted
      return unless @text
      
      @text = @text.strip
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flannel-0.2.11 lib/flannel/base_block.rb
flannel-0.2.10 lib/flannel/base_block.rb
flannel-0.2.9 lib/flannel/base_block.rb