Class: WikiCloth::WikiNamespaces
- Inherits:
-
Object
- Object
- WikiCloth::WikiNamespaces
- Defined in:
- lib/wikicloth/namespaces.rb
Direct Known Subclasses
Constant Summary collapse
- NAMESPACE_TYPES =
[:file,:category,:template,:special,:language,:help,:talk,:media]
Class Method Summary collapse
- .get_namespace_names_for(name) ⇒ Object
- .language_name(ns, locale = nil) ⇒ Object
- .language_namespace_names ⇒ Object
- .localise_ns(name, locale = nil) ⇒ Object
- .method_missing(method, *args) ⇒ Object
- .namespace_type(name) ⇒ Object
Class Method Details
.get_namespace_names_for(name) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/wikicloth/namespaces.rb', line 49 def get_namespace_names_for(name) ret = [] I18n.available_locales.each do |locale| I18n.with_locale(locale) do I18n.t("namespaces.#{name}").split(",").each { |ns| ret << ns.downcase unless ret.include?(ns.downcase) } end end ret end |
.language_name(ns, locale = nil) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/wikicloth/namespaces.rb', line 12 def language_name(ns, locale=nil) return nil unless language_namespace_names.include?(ns) locale ||= I18n.locale I18n.with_locale(locale) do I18n.t("languages.#{ns}") end end |
.language_namespace_names ⇒ Object
8 9 10 |
# File 'lib/wikicloth/namespaces.rb', line 8 def language_namespace_names I18n.available_locales.collect { |l| l.to_s.gsub(/[_]+/,'-') } end |
.localise_ns(name, locale = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/wikicloth/namespaces.rb', line 20 def localise_ns(name, locale=nil) locale ||= I18n.locale ns_type = namespace_type(name) unless ns_type.nil? || ns_type == :language I18n.with_locale(locale) do I18n.t("namespaces.#{ns_type.to_s}").split(",").first end else name end end |
.method_missing(method, *args) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/wikicloth/namespaces.rb', line 38 def method_missing(method, *args) if method.to_s =~ /^([a-z]+)_namespace_names$/ @@ns_cache ||= {} @@ns_cache[$1] ||= get_namespace_names_for($1) elsif method.to_s =~ /^([a-z]+)_namespace\?$/ namespace_type(args.first) == $1.to_sym ? true : false else super(method, *args) end end |
.namespace_type(name) ⇒ Object
32 33 34 35 36 |
# File 'lib/wikicloth/namespaces.rb', line 32 def namespace_type(name) return :language if language_namespace_names.include?(name) NAMESPACE_TYPES.each { |ns| return ns if send("#{ns}_namespace_names").include?(name.downcase) } nil end |