Module: Docter::HTML
- Included in:
- Collection, Resource::Base, Template::ContextMethods
- Defined in:
- lib/docter/common.rb
Class Method Summary collapse
-
.inner_text_from(html) ⇒ Object
:call-seq: inner_text_from(html) => text.
- .regexp_attribute(name) ⇒ Object
- .regexp_element(name) ⇒ Object
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.
12 13 14 |
# File 'lib/docter/common.rb', line 12 def inner_text_from(html) html.gsub(/<(\w*).*?>(.*?)<\/\1\s*>/m, "\\2").strip.gsub(/\s+/m, ' ') end |
.regexp_attribute(name) ⇒ Object
20 21 22 |
# File 'lib/docter/common.rb', line 20 def regexp_attribute(name) Regexp.new("(#{name})=([\"'])(.*?)\\2", Regexp::MULTILINE + Regexp::IGNORECASE) end |
.regexp_element(name) ⇒ Object
16 17 18 |
# File 'lib/docter/common.rb', line 16 def regexp_element(name) Regexp.new("<(#{name})(?:>|\s+(.*?)>)(.*?)<\\/\\1\\s*>", Regexp::MULTILINE + Regexp::IGNORECASE) end |