Sha256: c912feb7860ff7f21c921d33f11755a363994697d71910771a8830df1e6caa1b

Contents?: true

Size: 833 Bytes

Versions: 10

Compression:

Stored size: 833 Bytes

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].gsub!("&lt;", "<").gsub!("&gt;", ">") if a.size > 2
        a.join("")
      end.join("")
      Liquid::Template.parse(doc)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
isodoc-1.0.3 lib/isodoc/class_utils.rb
isodoc-1.0.2 lib/isodoc/class_utils.rb
isodoc-1.0.1 lib/isodoc/class_utils.rb
isodoc-1.0.0 lib/isodoc/class_utils.rb
isodoc-0.10.4 lib/isodoc/class_utils.rb
isodoc-0.10.3 lib/isodoc/class_utils.rb
isodoc-0.10.2 lib/isodoc/class_utils.rb
isodoc-0.10.1 lib/isodoc/class_utils.rb
isodoc-0.10.0 lib/isodoc/class_utils.rb
isodoc-0.9.23 lib/isodoc/class_utils.rb