Module: Muddle::Filter
- Included in:
- BoilerplateCSS, BoilerplateStyleElement
- Defined in:
- lib/muddle/filter.rb
Defined Under Namespace
Modules: BoilerplateAttributes, BoilerplateCSS, BoilerplateStyleElement, Premailer, SchemaValidation
Instance Method Summary collapse
-
#append_or_insert(doc, content) ⇒ Object
Append the content if child nodes exist, otherwise insert it.
-
#find_or_append(doc, selector, opts) {|doc.search(selector)| ... } ⇒ Object
Find ‘selector` within `doc`.
-
#find_or_prepend(doc, selector, opts) {|doc.search(selector)| ... } ⇒ Object
Find ‘selector` within `doc` if not found, create using `with` as the first child of `doc`.
-
#prepend_or_insert(doc, content) ⇒ Object
Prepend the content if child nodes exist, otherwise insert it.
Instance Method Details
#append_or_insert(doc, content) ⇒ Object
Append the content if child nodes exist, otherwise insert it
14 15 16 17 18 19 20 |
# File 'lib/muddle/filter.rb', line 14 def append_or_insert(doc, content) unless doc.empty? doc.children.last.after(content) else doc.inner_html(content) end end |
#find_or_append(doc, selector, opts) {|doc.search(selector)| ... } ⇒ Object
Find ‘selector` within `doc`. If not found, create using `with` as the last child of `doc`
26 27 28 29 |
# File 'lib/muddle/filter.rb', line 26 def find_or_append(doc, selector, opts, &block) append_or_insert(doc, opts[:with]) if doc.search(selector).empty? yield doc.search(selector) end |
#find_or_prepend(doc, selector, opts) {|doc.search(selector)| ... } ⇒ Object
Find ‘selector` within `doc` if not found, create using `with` as the first child of `doc`
yields to ‘block` and passes the found/created element
36 37 38 39 |
# File 'lib/muddle/filter.rb', line 36 def find_or_prepend(doc, selector, opts, &block) prepend_or_insert(doc, opts[:with]) if doc.search(selector).empty? yield doc.search(selector) end |
#prepend_or_insert(doc, content) ⇒ Object
Prepend the content if child nodes exist, otherwise insert it
4 5 6 7 8 9 10 |
# File 'lib/muddle/filter.rb', line 4 def prepend_or_insert(doc, content) unless doc.empty? doc.children.first.before(content) else doc.inner_html(content) end end |