Class: KramdownRFC::ParameterSet
- Includes:
- Kramdown::Utils::Html
- Defined in:
- lib/kramdown-rfc/parameterset.rb
Instance Attribute Summary collapse
-
#f ⇒ Object
readonly
Returns the value of attribute f.
Instance Method Summary collapse
- #[](pn) ⇒ Object
- #arr(an, converthash = true, must_have_one = false, &block) ⇒ Object
- #attr(pn) ⇒ Object
- #attrs(*pns) ⇒ Object
- #ele(pn, attr = nil, defcontent = nil, markdown = false) ⇒ Object
- #escattr(str) ⇒ Object
- #has(pn) ⇒ Object
-
#initialize(y) ⇒ ParameterSet
constructor
A new instance of ParameterSet.
- #rest ⇒ Object
-
#van(pn) ⇒ Object
pn is a parameter name, possibly with an =alias.
- #warn_if_leftovers ⇒ Object
Constructor Details
#initialize(y) ⇒ ParameterSet
Returns a new instance of ParameterSet.
7 8 9 10 |
# File 'lib/kramdown-rfc/parameterset.rb', line 7 def initialize(y) raise "*** invalid parameter set #{y.inspect}" unless Hash === y @f = y end |
Instance Attribute Details
#f ⇒ Object (readonly)
Returns the value of attribute f.
6 7 8 |
# File 'lib/kramdown-rfc/parameterset.rb', line 6 def f @f end |
Instance Method Details
#[](pn) ⇒ Object
11 12 13 |
# File 'lib/kramdown-rfc/parameterset.rb', line 11 def [](pn) @f.delete(pn.to_s) end |
#arr(an, converthash = true, must_have_one = false, &block) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/kramdown-rfc/parameterset.rb', line 47 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) ⇒ Object
25 26 27 28 |
# File 'lib/kramdown-rfc/parameterset.rb', line 25 def attr(pn) val, an = van(pn) %{#{an}="#{escattr(val)}"} if val end |
#attrs(*pns) ⇒ Object
29 30 31 |
# File 'lib/kramdown-rfc/parameterset.rb', line 29 def attrs(*pns) pns.map{ |pn| attr(pn) }.compact.join(" ") end |
#ele(pn, attr = nil, defcontent = nil, markdown = false) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/kramdown-rfc/parameterset.rb', line 32 def ele(pn, attr=nil, defcontent=nil, markdown=false) val, an = van(pn) val ||= defcontent Array(val).map do |val1| v = val1.to_s.strip if markdown # Uuh. Heavy coupling. doc = Kramdown::Document.new(v, $global_markdown_options) $stderr.puts doc.warnings.to_yaml unless doc.warnings.empty? contents = doc.to_rfc2629[3..-6] # skip <t>...</t>\n else contents = escape_html(v) end %{<#{[an, *Array(attr).map(&:to_s)].join(" ").strip}>#{contents}</#{an}>} end.join(" ") end |
#escattr(str) ⇒ Object
17 18 19 |
# File 'lib/kramdown-rfc/parameterset.rb', line 17 def escattr(str) escape_html(str.to_s, :attribute) end |
#has(pn) ⇒ Object
14 15 16 |
# File 'lib/kramdown-rfc/parameterset.rb', line 14 def has(pn) @f[pn.to_s] end |
#rest ⇒ Object
53 54 55 |
# File 'lib/kramdown-rfc/parameterset.rb', line 53 def rest @f end |
#van(pn) ⇒ Object
pn is a parameter name, possibly with an =alias
20 21 22 23 24 |
# File 'lib/kramdown-rfc/parameterset.rb', line 20 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 ⇒ Object
56 57 58 59 60 |
# File 'lib/kramdown-rfc/parameterset.rb', line 56 def warn_if_leftovers if !@f.empty? warn "*** attributes left #{@f.inspect}!" end end |