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, #to_s

Constructor Details

#initialize(content) ⇒ Tag

Returns a new instance of Tag.



173
174
175
176
177
# File 'lib/xrt/statement.rb', line 173

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

Instance Method Details

#tag_closing?Boolean

Returns:

  • (Boolean)


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

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

#tag_comment?Boolean

Returns:

  • (Boolean)


210
211
212
# File 'lib/xrt/statement.rb', line 210

def tag_comment?
  @children[1].content[0] == '!'
end

#tag_independent?Boolean

Returns:

  • (Boolean)


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

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

#tag_nameObject



191
192
193
194
195
196
# File 'lib/xrt/statement.rb', line 191

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)


198
199
200
# File 'lib/xrt/statement.rb', line 198

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

#tag_raw_text_element?Boolean

Returns:

  • (Boolean)


185
186
187
188
189
# File 'lib/xrt/statement.rb', line 185

def tag_raw_text_element?
  # https://www.w3.org/TR/html5/syntax.html#raw-text-elements
  raw_element_names = %w( script style )
  raw_element_names.include?(self.tag_name)
end

#tag_void_element?Boolean

Returns:

  • (Boolean)


179
180
181
182
183
# File 'lib/xrt/statement.rb', line 179

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