Module: Infoboxer::Navigation::Shortcuts::Node
- Included in:
- Tree::Node
- Defined in:
- lib/infoboxer/navigation/shortcuts.rb
Overview
Shortcuts::Node
module provides some convenience methods for
most used lookups. It's not a rocket science (as you can see
from methods code), yet should make your code cleaner and
more readable.
NB: as usual, Tree::Nodes class have synonyms for all of those methods, so you can call them fearlessly on any results of node lookup.
Instance Method Summary collapse
-
#bold? ⇒ Boolean
Returns true, if current node is inside bold.
-
#categories ⇒ Tree::Nodes
Returns all wikilinks in "categories namespace".
-
#external_links(*selectors, &block) ⇒ Tree::Nodes
Returns all external links inside current node.
-
#heading?(level = nil) ⇒ Boolean
Returns true, if current node is inside heading.
-
#headings(level = nil) ⇒ Tree::Nodes
Returns all headings inside current node.
-
#images(*selectors, &block) ⇒ Tree::Nodes
Returns all images (media) inside current node.
-
#infobox ⇒ Object
As users accustomed to have only one infobox on a page.
-
#infoboxes(*selectors, &block) ⇒ Tree::Nodes
Returns all infoboxes inside current node.
-
#italic? ⇒ Boolean
Returns true, if current node is inside italic.
-
#lists(*selectors, &block) ⇒ Tree::Nodes
Returns all lists (ordered/unordered/definition) inside current node.
-
#paragraphs(*selectors, &block) ⇒ Tree::Nodes
Returns all paragraph-level nodes (list items, plain paragraphs, headings and so on) inside current node.
-
#tables(*selectors, &block) ⇒ Tree::Nodes
Returns all tables inside current node.
-
#templates(*selectors, &block) ⇒ Tree::Nodes
Returns all templates inside current node.
-
#wikilinks(namespace = '') ⇒ Tree::Nodes
Returns all wikilinks inside current node.
Instance Method Details
#bold? ⇒ Boolean
Returns true, if current node is inside bold.
84 85 86 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 84 def bold? parent?(Tree::Bold) end |
#categories ⇒ Tree::Nodes
Returns all wikilinks in "categories namespace".
NB: depending on your MediaWiki settings, name of categories namespace may vary. When you are using MediaWiki#get, Infoboxer tries to handle this transparently (by examining used wiki for category names), yet bad things may happen here.
119 120 121 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 119 def categories lookup(Tree::Wikilink, namespace: /^#{ensure_traits.category_namespace.join('|')}$/) end |
#external_links(*selectors, &block) ⇒ Tree::Nodes
Returns all external links inside current node.
47 48 49 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 47 def external_links(*selectors, &block) lookup(Tree::ExternalLink, *selectors, &block) end |
#heading?(level = nil) ⇒ Boolean
Returns true, if current node is inside heading.
96 97 98 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 96 def heading?(level = nil) parent?(Tree::Heading, level: level) end |
#headings(level = nil) ⇒ Tree::Nodes
Returns all headings inside current node.
30 31 32 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 30 def headings(level = nil) lookup(Tree::Heading, level: level) end |
#images(*selectors, &block) ⇒ Tree::Nodes
Returns all images (media) inside current node.
55 56 57 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 55 def images(*selectors, &block) lookup(Tree::Image, *selectors, &block) end |
#infobox ⇒ Object
As users accustomed to have only one infobox on a page
124 125 126 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 124 def infobox infoboxes.first end |
#infoboxes(*selectors, &block) ⇒ Tree::Nodes
Returns all infoboxes inside current node.
Definition of what considered to be infobox depends on templates set used when parsing the page.
107 108 109 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 107 def infoboxes(*selectors, &block) lookup(Tree::Template, :infobox?, *selectors, &block) end |
#italic? ⇒ Boolean
Returns true, if current node is inside italic.
89 90 91 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 89 def italic? parent?(Tree::Italic) end |
#lists(*selectors, &block) ⇒ Tree::Nodes
Returns all lists (ordered/unordered/definition) inside current node.
79 80 81 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 79 def lists(*selectors, &block) lookup(Tree::List, *selectors, &block) end |
#paragraphs(*selectors, &block) ⇒ Tree::Nodes
Returns all paragraph-level nodes (list items, plain paragraphs, headings and so on) inside current node.
39 40 41 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 39 def paragraphs(*selectors, &block) lookup(Tree::BaseParagraph, *selectors, &block) end |
#tables(*selectors, &block) ⇒ Tree::Nodes
Returns all tables inside current node.
71 72 73 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 71 def tables(*selectors, &block) lookup(Tree::Table, *selectors, &block) end |
#templates(*selectors, &block) ⇒ Tree::Nodes
Returns all templates inside current node.
63 64 65 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 63 def templates(*selectors, &block) lookup(Tree::Template, *selectors, &block) end |
#wikilinks(namespace = '') ⇒ Tree::Nodes
Returns all wikilinks inside current node.
22 23 24 |
# File 'lib/infoboxer/navigation/shortcuts.rb', line 22 def wikilinks(namespace = '') lookup(Tree::Wikilink, namespace: namespace) end |