Class: XRT::Statement::Tag

Inherits:
Block show all
Defined in:
lib/xrt/statement.rb

Instance Method Summary collapse

Methods inherited from Block

#<<, #children, #closed?, #content, #inspect

Methods inherited from XRT::Statement

#==, #auto_indent, #children, #contains_directive?, #content, #depth, #find_block_texts, #find_blocks, #find_blocks_with_directive, #include?, #inspect, #replace_child, #statements

Constructor Details

#initialize(content) ⇒ Tag

Returns a new instance of Tag.



194
195
196
197
198
# File 'lib/xrt/statement.rb', line 194

def initialize content
  @children = []
  tag_start = XRT::Statement::TagStart.new content
  self << tag_start
end

Instance Method Details

#tag_closing?Boolean

Returns:

  • (Boolean)


217
218
219
# File 'lib/xrt/statement.rb', line 217

def tag_closing?
  @children[1].content[0] == '/'
end

#tag_independent?Boolean

Returns:

  • (Boolean)


221
222
223
# File 'lib/xrt/statement.rb', line 221

def tag_independent?
  @children[-2].content[-1] == '/'
end

#tag_nameObject



206
207
208
209
210
211
# File 'lib/xrt/statement.rb', line 206

def tag_name
  return nil if @children.empty?
  matched = @children[1].content.match(%r{\A/?(\w+)})
  return nil unless matched
  return matched[1].downcase
end

#tag_opening?Boolean

Returns:

  • (Boolean)


213
214
215
# File 'lib/xrt/statement.rb', line 213

def tag_opening?
  !tag_independent? && !tag_closing? && !tag_void_element?
end

#tag_void_element?Boolean

Returns:

  • (Boolean)


200
201
202
203
204
# File 'lib/xrt/statement.rb', line 200

def tag_void_element?
  # https://www.w3.org/TR/html5/syntax.html#void-elements
  void_element_names = %w( area base br col embed hr img input keygen link meta param source track wbr )
  void_element_names.include?(self.tag_name)
end