lib/infoboxer/templates/base.rb in infoboxer-0.1.0 vs lib/infoboxer/templates/base.rb in infoboxer-0.1.1
- old
+ new
@@ -13,33 +13,10 @@
def clean_name
template_name ? "Template[#{template_name}]" : 'Template'
end
end
- def unnamed_variables
- variables.select{|v| v.name =~ /^\d+$/}
- end
-
- def fetch(*patterns)
- Nodes[*patterns.map{|p| variables.find(name: p)}.flatten]
- end
-
- def fetch_hash(*patterns)
- fetch(*patterns).map{|v| [v.name, v]}.to_h
- end
-
- def fetch_date(*patterns)
- components = fetch(*patterns)
- components.pop while components.last.nil? && !components.empty?
-
- if components.empty?
- nil
- else
- Date.new(*components.map{|v| v.to_s.to_i})
- end
- end
-
def ==(other)
other.kind_of?(Tree::Template) && _eq(other)
end
protected
@@ -52,30 +29,38 @@
end
end
end
# Renders all of its unnamed variables as space-separated text
- # Also allows in-template navigation
+ # Also allows in-template navigation.
+ #
+ # Used for {Set} definitions.
class Show < Base
alias_method :children, :unnamed_variables
protected
def children_separator
' '
end
end
+ # Replaces template with replacement, while rendering.
+ #
+ # Used for {Set} definitions.
class Replace < Base
def replace
fail(NotImplementedError, "Descendants should define :replace")
end
def text
replace
end
end
+ # Replaces template with its name, while rendering.
+ #
+ # Used for {Set} definitions.
class Literal < Base
alias_method :text, :name
end
end
end