Class: Infoboxer::MediaWiki::Traits

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

Returns:

  • (Boolean)


78
79
80
# File 'lib/infoboxer/media_wiki/traits.rb', line 78

def interwiki?(prefix)
  known_interwikis.key?(prefix)
end

#namespace?(prefix) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/infoboxer/media_wiki/traits.rb', line 74

def namespace?(prefix)
  known_namespaces.include?(prefix)
end