Sha256: 8af5b996b4b32b964b0481d7fc1729c58f0749ee1f8a73f913dae36f46b31fc7

Contents?: true

Size: 931 Bytes

Versions: 3

Compression:

Stored size: 931 Bytes

Contents

module Flannel
  class BlockCutter
    def cut markup
      #pieces = split_preformatted_blocks(markup)
      #pieces = pieces.map { |part| split_into_blocks(part) }
      #pieces.flatten!
      #convert_to_text_blocks pieces
      
      parser = BlockParser.new
      blocks = parser.parse(markup).content.map { |block| Flannel::BaseBlock.new(block) }
    end
    
    def split_into_blocks markup
      if is_preformatted markup
        markup
      else
        markup.split(/\n\s*?\n/).map { |s| s.strip }
      end
    end
    
    def split_preformatted_blocks markup
      markup.split(/^(_(?=\n\n)|(?=_))/).map { |s| s.strip }.reject { |s| is_invalid_block s}
    end
    
    def convert_to_text_blocks pieces
      pieces.map{ |piece| Flannel::TextBlock.new piece }
    end
    
    def is_invalid_block s
      s == "" || s == "_" 
    end
    
    def is_preformatted markup
      markup[0] == '_'[0]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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