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

Instance Method Details

#bold?Boolean

Returns true, if current node is inside bold.

Returns:

  • (Boolean)


85
86
87
# File 'lib/infoboxer/navigation/shortcuts.rb', line 85

def bold?
  has_parent?(Tree::Bold)
end

#categoriesTree::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.

Returns:



120
121
122
# File 'lib/infoboxer/navigation/shortcuts.rb', line 120

def categories
  lookup(Tree::Wikilink, namespace: /^#{ensure_traits.category_namespace.join('|')}$/)
end

Returns all external links inside current node.

Parameters:

  • selectors

    node selectors, as described at Lookup::Node

Returns:



48
49
50
# File 'lib/infoboxer/navigation/shortcuts.rb', line 48

def external_links(*selectors, &block)
  lookup(Tree::ExternalLink, *selectors, &block)
end

#heading?(level = nil) ⇒ Boolean

Returns true, if current node is inside heading.

Parameters:

  • level (defaults to: nil)

    optional concrete level to check

Returns:

  • (Boolean)


97
98
99
# File 'lib/infoboxer/navigation/shortcuts.rb', line 97

def heading?(level = nil)
  has_parent?(Tree::Heading, level: level)
end

#headings(level = nil) ⇒ Tree::Nodes

Returns all headings inside current node.

Parameters:

  • level (defaults to: nil)

    headings level to return.

Returns:



31
32
33
# File 'lib/infoboxer/navigation/shortcuts.rb', line 31

def headings(level = nil)
  lookup(Tree::Heading, level: level)
end

#images(*selectors, &block) ⇒ Tree::Nodes

Returns all images (media) inside current node.

Parameters:

  • selectors

    node selectors, as described at Lookup::Node

Returns:



56
57
58
# File 'lib/infoboxer/navigation/shortcuts.rb', line 56

def images(*selectors, &block)
  lookup(Tree::Image, *selectors, &block)
end

#infoboxObject

As users accustomed to have only one infobox on a page



125
126
127
# File 'lib/infoboxer/navigation/shortcuts.rb', line 125

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.

Parameters:

  • selectors

    node selectors, as described at Lookup::Node

Returns:



108
109
110
# File 'lib/infoboxer/navigation/shortcuts.rb', line 108

def infoboxes(*selectors, &block)
  lookup(Tree::Template, :infobox?, *selectors, &block)
end

#italic?Boolean

Returns true, if current node is inside italic.

Returns:

  • (Boolean)


90
91
92
# File 'lib/infoboxer/navigation/shortcuts.rb', line 90

def italic?
  has_parent?(Tree::Italic)
end

#lists(*selectors, &block) ⇒ Tree::Nodes

Returns all lists (ordered/unordered/definition) inside current node.

Parameters:

  • selectors

    node selectors, as described at Lookup::Node

Returns:



80
81
82
# File 'lib/infoboxer/navigation/shortcuts.rb', line 80

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.

Parameters:

  • selectors

    node selectors, as described at Lookup::Node

Returns:



40
41
42
# File 'lib/infoboxer/navigation/shortcuts.rb', line 40

def paragraphs(*selectors, &block)
  lookup(Tree::BaseParagraph, *selectors, &block)
end

#tables(*selectors, &block) ⇒ Tree::Nodes

Returns all tables inside current node.

Parameters:

  • selectors

    node selectors, as described at Lookup::Node

Returns:



72
73
74
# File 'lib/infoboxer/navigation/shortcuts.rb', line 72

def tables(*selectors, &block)
  lookup(Tree::Table, *selectors, &block)
end

#templates(*selectors, &block) ⇒ Tree::Nodes

Returns all templates inside current node.

Parameters:

  • selectors

    node selectors, as described at Lookup::Node

Returns:



64
65
66
# File 'lib/infoboxer/navigation/shortcuts.rb', line 64

def templates(*selectors, &block)
  lookup(Tree::Template, *selectors, &block)
end

Returns all wikilinks inside current node.

Parameters:

  • namespace (defaults to: '')

    from which namespace links do you want. It's '' (main namespace only) by default, if you really want all wikilinks on the page, including categories, interwikies and stuff, use wikilinks(nil)

Returns:



23
24
25
# File 'lib/infoboxer/navigation/shortcuts.rb', line 23

def wikilinks(namespace = '')
  lookup(Tree::Wikilink, namespace: namespace)
end