class Wikitree::Template
Attributes
name[R]
params[R]
Public Class Methods
new( name, params )
click to toggle source
# File lib/wikitree/nodes.rb, line 106 def initialize( name, params ) @name = name @params = [] params.each_with_index do |param,i| @params << Param.new( i+1, param[0], param[1] ) end end
Public Instance Methods
inspect()
click to toggle source
# File lib/wikitree/nodes.rb, line 114 def inspect "#<template #{@name}: #{@params.inspect}>" end
pretty_print(pp)
click to toggle source
# File lib/wikitree/nodes.rb, line 118 def pretty_print(pp) pp.text "#<template " pp.text "#{name}: " pp.breakable pp.pp @params pp.text ">" end
to_text()
click to toggle source
# File lib/wikitree/nodes.rb, line 126 def to_text ## build a template method name (e.g. add _ prefix and change space to _ too) ## and dowcase e.g. Infobox country => infobox_country method_name = "_#{@name.downcase.gsub( ' ', '_' )}".to_sym if respond_to?( method_name ) send( method_name ) ## todo/fix: add args too!!! else ## rebuild template as string buf = String.new('') buf << "!!{{" buf << "#{@name}" @params.each do |param| buf << " | " if param.name buf << param.name buf << "=" end buf << param.to_text ## note. param.to_text ONLY returns value (NOT name incl.) end buf << "}}" buf end end
to_wiki()
click to toggle source
# File lib/wikitree/nodes.rb, line 150 def to_wiki ## rebuild template as string buf = String.new('') buf << "{{" buf << "#{@name}" @params.each do |param| buf << " | " if param.name buf << param.name buf << "=" end buf << param.to_wiki ## note. param.to_text ONLY returns value (NOT name incl.) end buf << "}}" buf end