Skip to content

Commit

Permalink
[#851] allow ERB comments in DrymlDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanlarsen authored and ddnexus committed Nov 13, 2010
1 parent 3722423 commit a810f07
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions dryml/lib/dryml/dryml_doc.rb
Expand Up @@ -32,15 +32,21 @@ class Taglib

def initialize(home, filename, name=nil)
@name = name || filename.sub(/.dryml$/, '')[home.length+1..-1]
@source = File.read(filename)
@doc = Dryml::Parser::Document.new(File.read(filename), filename)
parse_tag_defs
end

attr_reader :name, :doc, :tag_defs

attr_reader :name, :doc, :tag_defs, :source
def comment
first_node = doc[0][0]
doc.restore_erb_scriptlets(first_node.to_s.strip) if first_node.is_a?(REXML::Comment)
if first_node.is_a?(REXML::Comment)
doc.restore_erb_scriptlets(first_node.to_s.strip)
elsif first_node.to_s.strip.starts_with?("[![DRYML-ERB")
text = doc.restore_erb_scriptlets(first_node.to_s.strip)
text.match(/<%#(.*?)%>/m)[1] rescue nil
end
end

include CommentMethods
Expand Down Expand Up @@ -76,8 +82,8 @@ def name
def source
doc.restore_erb_scriptlets(node.to_s).strip
end

# The contents of the XML comment, if any, immediately above the tag definition
# The contents of the XML or ERB comment, if any, immediately above the tag definition
def comment
@comment ||= begin
space = node.previous_sibling and
Expand All @@ -86,6 +92,9 @@ def comment

if comment_node.is_a?(REXML::Comment)
doc.restore_erb_scriptlets(comment_node.to_s.strip)
elsif space.to_s.strip.starts_with?("[![DRYML-ERB")
text = doc.restore_erb_scriptlets(space.to_s.strip)
text.match(/.*<%#(.*?)%>$/m)[1] rescue nil
end
end
end
Expand Down

0 comments on commit a810f07

Please sign in to comment.