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:
parent
782a199d5d
commit
ff323de099
4 changed files with 17 additions and 10 deletions
1
init.rb
1
init.rb
|
@ -1,3 +1,4 @@
|
|||
require 'haml'
|
||||
require 'haml_helpers'
|
||||
|
||||
ActionView::Base.register_template_handler("haml", HAML::TemplateEngine)
|
16
lib/haml.rb
16
lib/haml.rb
|
@ -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
7
lib/haml_helpers.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
|
||||
module HAMLHelpers
|
||||
def flatten(input)
|
||||
input.gsub(/\n/, '
').gsub(/\r/, '')
|
||||
end
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
module HAML
|
||||
|
||||
end
|
Loading…
Reference in a new issue