lib/flannel/base_block.rb in flannel-0.2.11 vs lib/flannel/base_block.rb in flannel-0.2.12
- old
+ new
@@ -1,30 +1,42 @@
module Flannel
class BaseBlock
attr_reader :type, :id, :text, :parent_id, :attributes
- def initialize args
- header = args.shift
+ def initialize block
+ form = block[0]
+
+ if form == :block
+ create_from_list block[1]
+ else
+ @text = block[1]
+ @type = :paragraph
+ end
+
+ strip_text
+ end
+
+ def create_from_list list
+ header = list.shift
@type = header.shift[1]
@id = header.shift[1]
@attributes = {}
- next_arg = header.shift
- while next_arg
- case next_arg[0]
+ next_item = header.shift
+ while next_item
+ case next_item[0]
when :parent_id then
- @parent_id = next_arg[1]
+ @parent_id = next_item[1]
when :attribute_list then
- next_arg.shift
- next_arg.each do |attribute|
+ next_item.shift
+ next_item.each do |attribute|
@attributes[attribute[0]] = attribute[1]
end
end
- next_arg = header.shift
+ next_item = header.shift
end
- @text = args.shift
- strip_text
+ @text = list.shift
end
def to_h
html_formatter = Flannel::HtmlFormatter.new
html_formatter.do(@text, @type, @id)
\ No newline at end of file