Class: Infoboxer::MediaWiki::Traits
- Inherits:
-
Object
- Object
- Infoboxer::MediaWiki::Traits
- Defined in:
- lib/infoboxer/media_wiki/traits.rb
Overview
DSL for defining "traits" for some site.
More docs (and possible refactoring) to follow.
You can look at current English Wikipedia traits definitions in Infoboxer's repo.
Class Method Summary collapse
-
.for(domain, &block) ⇒ Object
Define traits for some domain.
-
.templates(&definition) ⇒ Object
Define set of templates for current site's traits.
Instance Method Summary collapse
-
#initialize(site_info = {}) ⇒ Traits
constructor
A new instance of Traits.
- #interwiki?(prefix) ⇒ Boolean
- #namespace?(prefix) ⇒ Boolean
Constructor Details
#initialize(site_info = {}) ⇒ Traits
Returns a new instance of Traits.
70 71 72 |
# File 'lib/infoboxer/media_wiki/traits.rb', line 70 def initialize(site_info = {}) @site_info = site_info end |
Class Method Details
.for(domain, &block) ⇒ Object
Define traits for some domain. Use it like:
MediaWiki::Traits.for 'ru.wikipedia.org' do
templates do
template '...' do
# some template definition
end
end
end
Again, you can look at current English Wikipedia traits for example implementation.
61 62 63 64 |
# File 'lib/infoboxer/media_wiki/traits.rb', line 61 def for(domain, &block) Traits.domains[domain]&.instance_eval(&block) || Class.new(self, &block).domain(domain) end |
.templates(&definition) ⇒ Object
Define set of templates for current site's traits.
See Templates::Set for longer (yet insufficient) explanation.
Expected to be used inside Traits definition block.
19 20 21 22 23 24 25 |
# File 'lib/infoboxer/media_wiki/traits.rb', line 19 def templates(&definition) @templates ||= Templates::Set.new return @templates unless definition @templates.define(&definition) end |
Instance Method Details
#interwiki?(prefix) ⇒ Boolean
78 79 80 |
# File 'lib/infoboxer/media_wiki/traits.rb', line 78 def interwiki?(prefix) known_interwikis.key?(prefix) end |
#namespace?(prefix) ⇒ Boolean
74 75 76 |
# File 'lib/infoboxer/media_wiki/traits.rb', line 74 def namespace?(prefix) known_namespaces.include?(prefix) end |