class KramdownRFC::ParameterSet
Attributes
av[R]
f[R]
Public Class Methods
new(y)
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 7 def initialize(y) raise "*** invalid parameter set #{y.inspect}" unless Hash === y @f = y @av = {} end
Public Instance Methods
[](pn)
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 13 def [](pn) @f.delete(pn.to_s) end
[]=(pn, val)
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 16 def []=(pn, val) @f[pn.to_s] = val end
arr(an, converthash=true, must_have_one=false, &block)
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 72 def arr(an, converthash=true, must_have_one=false, &block) arr = self[an] || [] arr = [arr] if Hash === arr && converthash arr << { } if must_have_one && arr.empty? Array(arr).each(&block) end
attr(pn)
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 38 def attr(pn) val, an = van(pn) @av[an.intern] = val %{#{an}="#{escattr(val)}"} if val end
attrs(*pns)
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 43 def attrs(*pns) pns.map{ |pn| attr(pn) if pn }.compact.join(" ") end
default(pn, &block)
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 19 def default(pn, &block) @f.fetch(pn.to_s, &block) end
default!(pn, value)
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 22 def default!(pn, value) default(pn) { @f[pn.to_s] = value } end
ele(pn, attr=nil, defcontent=nil, markdown=false)
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 46 def ele(pn, attr=nil, defcontent=nil, markdown=false) val, an = van(pn) val ||= defcontent val = [val] if Hash === val Array(val).map do |val1| a = Array(attr).dup if Hash === val1 val1.each do |k, v| if k == ":" val1 = v else k = Kramdown::Element.attrmangle(k) || k a.unshift(%{#{k}="#{escattr(v)}"}) end end end v = val1.to_s.strip contents = if markdown ::Kramdown::Converter::Rfc2629::process_markdown(v) else escape_html(v) end %{<#{[an, *a.map(&:to_s)].join(" ").strip}>#{contents}</#{an}>} end.join(" ") end
escattr(str)
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 30 def escattr(str) escape_html(str.to_s, :attribute) end
has(pn)
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 27 def has(pn) @f[pn.to_s] end
rest()
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 78 def rest @f end
van(pn)
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 33 def van(pn) # pn is a parameter name, possibly with an =alias an, pn = pn.to_s.split("=") pn ||= an [self[pn] || self[an], an] end
warn_if_leftovers()
click to toggle source
# File lib/kramdown-rfc/parameterset.rb, line 81 def warn_if_leftovers if !@f.empty? warn "*** attributes left #{@f.inspect}!" end end