Sha256: f6c07de989dea5bb623dc10ed63977529a13c3e4e6e0faac8a509c9fddcf6cac
Contents?: true
Size: 1.28 KB
Versions: 23
Compression:
Stored size: 1.28 KB
Contents
module Hobo::Dryml module Parser class Document < REXML::Document def initialize(source, path) super(nil) # Replace <%...%> scriptlets with xml-safe references into a hash of scriptlets @scriptlets = {} source = source.gsub(/<%(.*?)%>/m) do _, scriptlet = *Regexp.last_match id = @scriptlets.size + 1 @scriptlets[id] = scriptlet newlines = "\n" * scriptlet.count("\n") "[![DRYML-ERB#{id}#{newlines}]!]" end @reference_src = "<dryml_page>" + source + "</dryml_page>" rex_src = Hobo::Dryml::Parser::Source.new(@reference_src) @elements = Hobo::Dryml::Parser::Elements.new(self) build(rex_src) rescue REXML::ParseException => e raise Hobo::Dryml::DrymlSyntaxError, "File: #{path}\n#{e}" end def element_line_num(el) offset = el.source_offset @reference_src[0..offset].count("\n") + 1 end def default_attribute_value "&true" end def restore_erb_scriptlets(src) src.gsub(/\[!\[DRYML-ERB(\d+)\s*\]!\]/m) {|s| "<%#{@scriptlets[$1.to_i]}%>" } end private def build( source ) Hobo::Dryml::Parser::TreeParser.new( source, self ).parse end end end end
Version data entries
23 entries across 23 versions & 1 rubygems