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(options = {}) ⇒ Traits
constructor
A new instance of Traits.
Constructor Details
#initialize(options = {}) ⇒ Traits
Returns a new instance of Traits.
70 71 72 73 74 75 76 |
# File 'lib/infoboxer/media_wiki/traits.rb', line 70 def initialize( = {}) @options = @file_namespace = [DEFAULTS[:file_namespace], namespace_aliases(, 'File')]. flatten.compact.uniq @category_namespace = [DEFAULTS[:category_namespace], namespace_aliases(, 'Category')]. flatten.compact.uniq 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].tap{|c| c && c.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.
18 19 20 21 22 23 24 |
# File 'lib/infoboxer/media_wiki/traits.rb', line 18 def templates(&definition) @templates ||= Templates::Set.new return @templates unless definition @templates.define(&definition) end |