Sha256: d27772011746987eb95bff5381a24d32c0b3c84f911ef99f353cede0c4330cf6

Contents?: true

Size: 1.07 KB

Versions: 36

Compression:

Stored size: 1.07 KB

Contents

#!/usr/bin/env ruby

require "rexml/document"

def expand_ref(str)
  REXML::Text.unnormalize(str)
end

def expand_ext_ref(str, table)
  str.gsub(/%([^\s;]+);/) do |x|
    if table.has_key?($1)
      expand_ref(table[$1])
    else
      p table
      raise $1
    end
  end
end

File.open(File.join(*%W(lib rabbit parser ext entity)) + ".rb", "w") do |out|
  out.print <<-HEADER
require 'rabbit/element'

module Rabbit
  module Parser
    module Ext
      module Entity
        TABLE = {
HEADER

      ext_param = {}
      ARGF.each do |line|
        case line
        when /^<!ENTITY\s+%\s+(\w+)\s+"(\S+)"\s*>/
          # p ["%", $1, $2]
          ext_param[$1] = expand_ref($2)
        when /^<!ENTITY\s+(\w+)\s+"(\S+)"\s*>\s*<!--\s*(.+)\s*-->/
          key = $1
          comment = $3.strip
          value = expand_ext_ref($2.gsub(/&#38;/, '&'), ext_param)
          out.print <<-ITEM
          # #{comment}
          #{key.dump} => #{value.dump},
ITEM
          # p [key, value, comment, name]
        end
      end

      out.print <<-FOOTER
        }
      end
    end
  end
end
FOOTER

end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
rabbit-2.1.8 entities/ent2rb.rb
rabbit-2.1.7 entities/ent2rb.rb
rabbit-2.1.6 entities/ent2rb.rb
rabbit-2.1.5 entities/ent2rb.rb
rabbit-2.1.4 entities/ent2rb.rb
rabbit-2.1.3 entities/ent2rb.rb
rabbit-2.1.2 entities/ent2rb.rb
rabbit-2.1.1 entities/ent2rb.rb
rabbit-2.1.0 entities/ent2rb.rb
rabbit-2.0.9 entities/ent2rb.rb
rabbit-2.0.8 entities/ent2rb.rb
rabbit-2.0.7 entities/ent2rb.rb
rabbit-2.0.6 entities/ent2rb.rb
rabbit-2.0.5 entities/ent2rb.rb
rabbit-2.0.4 entities/ent2rb.rb
rabbit-2.0.3 entities/ent2rb.rb
rabbit-2.0.2 entities/ent2rb.rb
rabbit-2.0.1 entities/ent2rb.rb
rabbit-2.0.0 entities/ent2rb.rb
rabbit-1.0.9 entities/ent2rb.rb