Sha256: eadad4fda948bf51c9a13dc7a54dcc18f4835ee7a417ec4fcebf8e7fbef5b20b

Contents?: true

Size: 838 Bytes

Versions: 59

Compression:

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

Version data entries

59 entries across 56 versions & 2 rubygems

Version Path
isodoc-1.5.5 lib/isodoc/class_utils.rb
isodoc-1.5.4 lib/isodoc/class_utils.rb
isodoc-1.5.3 lib/isodoc/class_utils.rb
isodoc-1.5.2 lib/isodoc/class_utils.rb
isodoc-1.5.1 lib/isodoc/class_utils.rb
isodoc-1.5.0 lib/isodoc/class_utils.rb
isodoc-1.4.2 lib/isodoc/class_utils.rb
isodoc-1.4.1 lib/isodoc/class_utils.rb
isodoc-1.4.0 lib/isodoc/class_utils.rb
isodoc-1.3.1 lib/isodoc/class_utils.rb
isodoc-1.3.0 lib/isodoc/class_utils.rb
isodoc-1.2.8 lib/isodoc/class_utils.rb
isodoc-1.2.7 lib/isodoc/class_utils.rb
isodoc-1.2.6 lib/isodoc/class_utils.rb
isodoc-1.2.5 lib/isodoc/class_utils.rb
isodoc-1.2.4 lib/isodoc/class_utils.rb
isodoc-1.2.3 lib/isodoc/class_utils.rb
isodoc-1.2.2 lib/isodoc/class_utils.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/isodoc-1.1.2/lib/isodoc/class_utils.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/isodoc-1.1.3/lib/isodoc/class_utils.rb