From 53797ac95a0ed9f4e613afdfb93b110dc3b132db Mon Sep 17 00:00:00 2001 From: nex3 Date: Sun, 18 Feb 2007 20:25:04 +0000 Subject: [PATCH] Moved several Regexes to be constants. git-svn-id: svn://hamptoncatlin.com/haml/trunk@369 7063305b-7217-0410-af8c-cdc13e5119b9 --- lib/haml/engine.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/haml/engine.rb b/lib/haml/engine.rb index 87107dec..e53a7fac 100644 --- a/lib/haml/engine.rb +++ b/lib/haml/engine.rb @@ -92,6 +92,15 @@ module Haml # is a member of this array. MID_BLOCK_KEYWORDS = ['else', 'elsif', 'rescue', 'ensure', 'when'] + # The Regex that matches an HTML comment command. + COMMENT_REGEX = /\/(\[[a-zA-Z0-9 \.]*\])?(.*)/ + + # The Regex that matches a Doctype command. + DOCTYPE_REGEX = /([0-9]\.[0-9])?[\s]*([a-zA-Z]*)/ + + # The Regex that matches an HTML tag command. + TAG_REGEX = /[%]([-:_a-zA-Z0-9]+)([-_a-zA-Z0-9\.\#]*)(\{.*\})?(\[.*\])?([=\/\~]?)?(.*)?/ + FLAT_WARNING = <@precompiled. def render_tag(line) matched = false - line.scan(/[%]([-:_a-zA-Z0-9]+)([-_a-zA-Z0-9\.\#]*)(\{.*\})?(\[.*\])?([=\/\~]?)?(.*)?/) do |tag_name, attributes, attributes_hash, object_ref, action, value| + line.scan(TAG_REGEX) do |tag_name, attributes, attributes_hash, object_ref, action, value| matched = true value = value.to_s @@ -625,7 +634,7 @@ END # Renders an XHTML comment. def render_comment(line) - conditional, content = line.scan(/\/(\[[a-zA-Z0-9 \.]*\])?(.*)/)[0] + conditional, content = line.scan(COMMENT_REGEX)[0] content.strip! if @block_opened && !content.empty? @@ -653,7 +662,7 @@ END wrapper = @options[:attr_wrapper] doctype = "" else - version, type = line.scan(/([0-9]\.[0-9])?[\s]*([a-zA-Z]*)/)[0] + version, type = line.scan(DOCTYPE_REGEX)[0] if version == "1.1" doctype = '' else