1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Trying to find ways around the white-space sensitive tags that exist in HTML.

Currently I have added the action "~" and... oh fuck it... I'm going to do it a different way.




git-svn-id: svn://hamptoncatlin.com/haml/trunk@12 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
hcatlin 2006-07-31 14:28:44 +00:00
parent 782a199d5d
commit ff323de099
4 changed files with 17 additions and 10 deletions

View file

@ -1,3 +1,4 @@
require 'haml'
require 'haml_helpers'
ActionView::Base.register_template_handler("haml", HAML::TemplateEngine)

View file

@ -1,6 +1,8 @@
module HAML
class TemplateEngine
include HAMLHelpers
def initialize(base)
@base = base
@ -112,21 +114,21 @@ module HAML
end
def render_tag(line)
broken_up = line.scan(/[%]([-_a-z1-9]+)([-_a-z\.\#]*)(\{.*\})?([=\/]?)?([^\n]*)?/)
broken_up = line.scan(/[%]([-_a-z1-9]+)([-_a-z\.\#]*)(\{.*\})?([=\/\~]?)?(.*)?/)
broken_up.each do |tag_name, attributes, attributes_hash, action, value|
attributes = parse_attributes(attributes.to_s)
unless(attributes_hash.nil? || attributes_hash.empty?)
attributes_hash = template_eval(attributes_hash)
attributes = attributes.merge(attributes_hash)
end
attributes.merge!(template_eval(attributes_hash)) unless (attributes_hash.nil? || attributes_hash.empty?)
#TODO: this is seriously dirty stuff.
#check to see if we're a one liner
if(action == "\/")
atomic_tag(tag_name, attributes)
elsif(action == "=")
value = template_eval(value)
print_tag(tag_name, value.to_s, attributes) if value != false
elsif(action == "~") #worse than ugly... un-DRY!
value = template_eval(value)
one_line_tag(tag_name, value.to_s, attributes) if value != false
else
print_tag(tag_name, value, attributes)
end

7
lib/haml_helpers.rb Normal file
View file

@ -0,0 +1,7 @@
module HAMLHelpers
def flatten(input)
input.gsub(/\n/, '&#x000A').gsub(/\r/, '')
end
end

View file

@ -1,3 +0,0 @@
module HAML
end