Class: Flannel::BaseBlock
- Inherits:
-
Object
- Object
- Flannel::BaseBlock
- Defined in:
- lib/flannel/base_block.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#parent_id ⇒ Object
readonly
Returns the value of attribute parent_id.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #create_from_list(list) ⇒ Object
-
#initialize(block) ⇒ BaseBlock
constructor
A new instance of BaseBlock.
- #strip_and_encode_text ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(block) ⇒ BaseBlock
Returns a new instance of BaseBlock.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/flannel/base_block.rb', line 8 def initialize block form = block[0] if form == :block create_from_list block[1] else @text = block[1] @type = :paragraph end strip_and_encode_text end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/flannel/base_block.rb', line 6 def attributes @attributes end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/flannel/base_block.rb', line 6 def id @id end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id.
6 7 8 |
# File 'lib/flannel/base_block.rb', line 6 def parent_id @parent_id end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
6 7 8 |
# File 'lib/flannel/base_block.rb', line 6 def text @text end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/flannel/base_block.rb', line 6 def type @type end |
Instance Method Details
#create_from_list(list) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/flannel/base_block.rb', line 21 def create_from_list list header = list.shift @type = header.shift[1] @id = header.shift[1] @attributes = {} next_item = header.shift while next_item case next_item[0] when :parent_id then @parent_id = next_item[1] when :attribute_list then next_item.shift next_item.each do |attribute| @attributes[attribute[0]] = attribute[1] end end next_item = header.shift end @text = list.shift end |
#strip_and_encode_text ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/flannel/base_block.rb', line 49 def strip_and_encode_text return unless @text @text.force_encoding("UTF-8") return if @type == :preformatted return unless @text @text = @text.strip end |
#to_h ⇒ Object
44 45 46 47 |
# File 'lib/flannel/base_block.rb', line 44 def to_h html_formatter = Flannel::HtmlFormatter.new html_formatter.do(@text, @type, @id) end |