More cleaning up.

git-svn-id: svn://hamptoncatlin.com/haml/trunk@678 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
nex3 2007-11-26 00:36:03 +00:00
parent 4c41a4e8d4
commit 2871354789
1 changed files with 35 additions and 40 deletions

View File

@ -483,7 +483,7 @@ END
when '~': parse = flattened = true when '~': parse = flattened = true
when '=': when '=':
parse = true parse = true
value = value[1..-1].strip.dump.gsub('\\#', '#') if value[0] == ?= value = unescape_interpolation(value[1..-1].strip) if value[0] == ?=
end end
if parse && @options[:suppress_eval] if parse && @options[:suppress_eval]
@ -551,48 +551,46 @@ END
raise SyntaxError.new('Illegal Nesting: Nesting within a tag that already has content is illegal.') raise SyntaxError.new('Illegal Nesting: Nesting within a tag that already has content is illegal.')
end end
text_out = "<!--#{conditional.to_s} " open = "<!--#{conditional} "
if do_one_liner = !content.empty? && Buffer.one_liner?(content)
close_tag = conditional ? "<![endif]-->" : "-->" # Render it statically if possible
push_text("#{text_out}#{content} #{close_tag}") if !content.empty? && Buffer.one_liner?(content)
else return push_text("#{open}#{content} #{conditional ? "<![endif]-->" : "-->"}")
push_text(text_out, 1) end
push_text(open, 1)
@output_tabs += 1 @output_tabs += 1
push_and_tabulate([:comment, !conditional.nil?]) push_and_tabulate([:comment, !conditional.nil?])
if !content.empty? unless content.empty?
push_text(content) push_text(content)
close close
end end
end end
end
# Renders an XHTML doctype or XML shebang. # Renders an XHTML doctype or XML shebang.
def render_doctype(line) def render_doctype(line)
if @block_opened raise SyntaxError.new("Illegal Nesting: Nesting within a header command is illegal.") if @block_opened
raise SyntaxError.new("Illegal Nesting: Nesting within a header command is illegal.") push_text text_for_doctype(line)
end end
line = line[3..-1].lstrip.downcase
if line[0...3] == "xml" def text_for_doctype(text)
encoding = line.split[1] || "utf-8" text = text[3..-1].lstrip.downcase
if text[0...3] == "xml"
wrapper = @options[:attr_wrapper] wrapper = @options[:attr_wrapper]
doctype = "<?xml version=#{wrapper}1.0#{wrapper} encoding=#{wrapper}#{encoding}#{wrapper} ?>" return "<?xml version=#{wrapper}1.0#{wrapper} encoding=#{wrapper}#{text.split(' ')[1] || "utf-8"}#{wrapper} ?>"
else end
version, type = line.scan(DOCTYPE_REGEX)[0]
version, type = text.scan(DOCTYPE_REGEX)[0]
if version == "1.1" if version == "1.1"
doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
else end
case type case type
when "strict" when "strict": return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' when "frameset": return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'
when "frameset" else return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'
else
doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
end end
end end
end
push_text doctype
end
# Starts a filtered block. # Starts a filtered block.
def start_filtered(name) def start_filtered(name)
@ -613,11 +611,8 @@ END
def unescape_interpolation(str) def unescape_interpolation(str)
first = str.index(/(^|[^\\])\#\{/) first = str.index(/(^|[^\\])\#\{/)
if first.nil? return str.dump if first.nil?
return str.dump first += 1 unless first == 0
elsif first != 0
first += 1
end
last = str.rindex '}' last = str.rindex '}'