Class: Wikilink::Converter::Site
- Inherits:
-
Object
- Object
- Wikilink::Converter::Site
- Includes:
- ArgumentExtractor
- Defined in:
- lib/wikilink/converter/site.rb
Overview
Site converter
Direct Known Subclasses
Wikilink::Converter::Sites::RubyChina, Wikilink::Converter::Sites::Wikipedia
Constant Summary collapse
- CURRENT_SITE_NAME =
''
- DEFAULT_NAMESPACE =
::Wikilink::Converter::Namespace::DEFAULT_NAME
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #default_namespace(*args, &block) ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Site
constructor
A new instance of Site.
- #namespace(*args, &block) ⇒ Object
- #run(namespace, run_options) ⇒ Object
Methods included from ArgumentExtractor
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Site
Returns a new instance of Site.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/wikilink/converter/site.rb', line 14 def initialize( = {}) @options = is_current_site = @options[:name].to_s == CURRENT_SITE_NAME @options[:external] = !is_current_site unless @options.key?(:external) @options[:prefix] ||= '/' if is_current_site @namespace_converters = {} namespace(DEFAULT_NAMESPACE) yield self if block_given? end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/wikilink/converter/site.rb', line 12 def @options end |
Instance Method Details
#default_namespace(*args, &block) ⇒ Object
54 55 56 |
# File 'lib/wikilink/converter/site.rb', line 54 def default_namespace(*args, &block) namespace(DEFAULT_NAMESPACE, *args, &block) end |
#namespace(*args, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wikilink/converter/site.rb', line 26 def namespace(*args, &block) namespace, converter, = extract_arguments(*args) namespace = DEFAULT_NAMESPACE if namespace.to_s.empty? converter ||= namespace_converter(namespace) if converter.nil? # do not add new handler if there's a instance method can handle it, # except that user passes a block to override it if block || instance_method_converter(namespace).nil? converter = ::Wikilink::Converter::Namespace converter = ::Wikilink::Converter::Namespace::Default if !block && namespace == DEFAULT_NAMESPACE end end if converter.is_a?(Class) = .merge() [:name] ||= namespace converter = converter.new() end if converter.respond_to?(:config) && block converter.config(&block) end set_namespace_converter namespace, converter if converter self end |
#run(namespace, run_options) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/wikilink/converter/site.rb', line 58 def run(namespace, ) if converter = namespace_converter(namespace) converter.run() elsif converter = instance_method_converter(namespace) converter.call() end end |