Module: Docter::HTML

Included in:
Collection, Resource::Base, Template::ContextMethods
Defined in:
lib/docter/common.rb

Class Method Summary collapse

Class Method Details

.inner_text_from(html) ⇒ Object

:call-seq:

inner_text_from(html) => text

Returns the inner text from some HTML text, effectively stripping the tags, normalizing whitespaces and stripping leading/trailing spaces.



31
32
33
# File 'lib/docter/common.rb', line 31

def inner_text_from(html)
  html.gsub(/<(\w*).*?>(.*?)<\/\1\s*>/m, '\2').strip.gsub(/\s+/m, ' ')
end

.regexp_attribute(name) ⇒ Object



39
40
41
# File 'lib/docter/common.rb', line 39

def regexp_attribute(name)
  /(#{name})=([\"'])(.*?)\2/mi
end

.regexp_element(name) ⇒ Object



35
36
37
# File 'lib/docter/common.rb', line 35

def regexp_element(name)
  /<(#{name})(?:>|\s+(.*?)>)(.*?)<\/\1\s*>/mi
end