Module: KramdownRFC
- Extended by:
- Kramdown::Utils::Html
- Defined in:
- lib/kramdown-rfc/refxml.rb,
lib/kramdown-rfc/parameterset.rb
Defined Under Namespace
Classes: ParameterSet
Constant Summary collapse
- PERSON_ERB =
" <<%= element_name%> <%=aups.attrs(\"initials\", \"surname\", \"fullname=name\", \"role\")%>>\n <%= aups.ele(\"organization=org\", aups.attrs(\"abbrev=orgabbrev\",\n *[$options.v3 && \"ascii=orgascii\"]), \"\") %>\n <address>\n<% postal = %w{street city region code country}.select{|gi| aups.has(gi)}\n if postal != [] -%>\n <postal>\n<% postal.each do |gi| -%>\n <%= aups.ele(gi) %>\n<% end -%>\n </postal>\n<% end -%>\n<% %w{phone facsimile email uri}.select{|gi| aups.has(gi)}.each do |gi| -%>\n <%= aups.ele(gi) %>\n<% end -%>\n </address>\n </<%= element_name%>>\n"
Class Method Summary collapse
- .authorps_from_hash(au) ⇒ Object
- .dateattrs(date) ⇒ Object
- .escattr(str) ⇒ Object
- .person_element_from_aups(element_name, aups) ⇒ Object
- .ref_to_xml(k, v) ⇒ Object
Class Method Details
.authorps_from_hash(au) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kramdown-rfc/refxml.rb', line 40 def self.(au) aups = KramdownRFC::ParameterSet.new(au) if ins = aups[:ins] parts = ins.split('.').map(&:strip) aups.rest["initials"] = parts[0..-2].join('.') << '.' aups.rest["surname"] = parts[-1] end # hack ("heuristic for") initials and surname from name # -- only works for people with exactly one last name and uncomplicated first names if n = aups.rest["name"] n = n.split aups.rest["initials"] ||= n[0..-2].map(&:chr).join('.') << '.' aups.rest["surname"] ||= n[-1] end aups end |
.dateattrs(date) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/kramdown-rfc/refxml.rb', line 82 def self.dateattrs(date) begin case date when /\A\d\d\d\d\z/ %{year="#{date}"} when Integer %{year="#{"%04d" % date}"} when String Date.parse("#{date}-01").strftime(%{year="%Y" month="%B"}) when Date date.strftime(%{year="%Y" month="%B" day="%d"}) when Array # this allows to explicitly give a string %{year="#{date.join(" ")}"} when nil %{year="n.d."} end rescue ArgumentError warn "*** Invalid date: #{date} -- use 2012, 2012-07, or 2012-07-28" end end |
.escattr(str) ⇒ Object
5 6 7 |
# File 'lib/kramdown-rfc/refxml.rb', line 5 def self.escattr(str) escape_html(str.to_s, :attribute) end |
.person_element_from_aups(element_name, aups) ⇒ Object
77 78 79 80 |
# File 'lib/kramdown-rfc/refxml.rb', line 77 def self.person_element_from_aups(element_name, aups) erb = ERB.new(PERSON_ERB, nil, '-') erb.result(binding) end |
.ref_to_xml(k, v) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kramdown-rfc/refxml.rb', line 9 def self.ref_to_xml(k, v) vps = KramdownRFC::ParameterSet.new(v) erb = ERB.new "<reference anchor=\"<%= escattr(k) %>\" <%= vps.attr(\"target\") %>>\n<front>\n <%= vps.ele(\"title\") -%>\n\n<% vps.arr(\"author\", true, true) do |au|\n aups = authorps_from_hash(au)\n -%>\n <author <%=aups.attrs(\"initials\", \"surname\", \"fullname=name\", \"role\")%>>\n <%= aups.ele(\"organization=org\", aups.attr(\"abbrev=orgabbrev\"), \"\") %>\n </author>\n<% aups.warn_if_leftovers -%>\n<% end -%>\n <date <%= dateattrs(vps[:date]) %>/>\n</front>\n<% vps.arr(\"seriesinfo\", false) do |k, v| -%>\n<seriesInfo name=\"<%=escattr(k)%>\" value=\"<%=escattr(v)%>\"/>\n<% end -%>\n<% vps.arr(\"format\", false) do |k, v| -%>\n<format type=\"<%=escattr(k)%>\" target=\"<%=escattr(v)%>\"/>\n<% end -%>\n<%= vps.ele(\"annotation=ann\", nil, nil, true) -%>\n</reference>\n REFERB\n ret = erb.result(binding)\n vps.warn_if_leftovers\n ret\nend\n", nil, '-' |