Sha256: 5fd93ed2dffc8b817c71813fa23195a9d65e5444fff59979157b87f0469e0fba
Contents?: true
Size: 1.41 KB
Versions: 7
Compression:
Stored size: 1.41 KB
Contents
module IsoDoc module ClassUtils def date_range(date) from = date.at(ns("./from")) to = date.at(ns("./to")) on = date.at(ns("./on")) return date.text unless from || on || to return on.text if on ret = "#{from.text}–" ret += to.text if to ret end def ns(xpath) xpath.gsub(%r{/([a-zA-z])}, "/xmlns:\\1") .gsub(%r{::([a-zA-z])}, "::xmlns:\\1") .gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]* ?=)}, "[xmlns:\\1") .gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]*[/\]])}, "[xmlns:\\1") end def liquid(doc) # unescape HTML escapes in doc doc = doc.split(%r<(\{%|%\})>).each_slice(4).map do |a| a[2] = a[2].gsub("<", "<").gsub(">", ">") if a.size > 2 a.join end.join Liquid::Template.parse(doc) end def case_strict(text, casing, script) return text unless %w(Latn Cyrl Grek Armn).include?(script) letters = text.chars case casing when "capital" then letters.first.upcase! when "lowercase" then letters.first.downcase! end letters.join end def case_with_markup(linkend, casing, script) seen = false xml = Nokogiri::XML("<root>#{linkend}</root>") xml.traverse do |b| next unless b.text? && !seen b.replace(Common::case_strict(b.text, casing, script)) seen = true end xml.root.children.to_xml end end end
Version data entries
7 entries across 7 versions & 1 rubygems