mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
New super-duper awesome changes!
git-svn-id: svn://hamptoncatlin.com/haml/trunk@2 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
35f7e17de5
commit
dcbc4a8333
1 changed files with 22 additions and 9 deletions
31
lib/haml.rb
31
lib/haml.rb
|
@ -12,6 +12,9 @@ module HAML
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(template = "", locals = {})
|
def render(template = "", locals = {})
|
||||||
|
puts @base.inspect
|
||||||
|
|
||||||
|
|
||||||
@pony_land = HappyMagicPonyLand.new(@base, locals)
|
@pony_land = HappyMagicPonyLand.new(@base, locals)
|
||||||
@result = ""
|
@result = ""
|
||||||
@to_close_queue = []
|
@to_close_queue = []
|
||||||
|
@ -20,28 +23,37 @@ module HAML
|
||||||
#and interpretation
|
#and interpretation
|
||||||
template.each_line do |line|
|
template.each_line do |line|
|
||||||
count, line = count_levels(line)
|
count, line = count_levels(line)
|
||||||
if count <= @to_close_queue.size
|
if count < @to_close_queue.size
|
||||||
close_tag
|
close_tag
|
||||||
end
|
end
|
||||||
case line.first
|
case line.first
|
||||||
when '.', '#'
|
when '.', '#'
|
||||||
render_div(line)
|
render_div(line)
|
||||||
when '<'
|
when '%'
|
||||||
render_tag_or_line(line)
|
render_tag(line)
|
||||||
when '/'
|
when '/'
|
||||||
render_comment(line)
|
render_comment(line)
|
||||||
when '='
|
when '='
|
||||||
add template_eval(line[1, line.length])
|
add template_eval(line[1, line.length])
|
||||||
else
|
else
|
||||||
add line
|
add_single line
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
puts "closing... " + @to_close_queue.inspect
|
|
||||||
@to_close_queue.each { close_tag }
|
@to_close_queue.each { close_tag }
|
||||||
@result
|
@result
|
||||||
end
|
end
|
||||||
|
|
||||||
def add(line)
|
def add(line)
|
||||||
|
return nil if line.nil?
|
||||||
|
if (list = line.to_a).size > 1
|
||||||
|
list.each { |me| add(me) }
|
||||||
|
else
|
||||||
|
#bleh, stupid line to make sure a \n isn't on the end... dumb.
|
||||||
|
add_single(line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_single(line)
|
||||||
@result << tabify(@to_close_queue.size) + line + "\n"
|
@result << tabify(@to_close_queue.size) + line + "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -70,9 +82,9 @@ module HAML
|
||||||
add "<!-- #{line} -->"
|
add "<!-- #{line} -->"
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_tag_or_line(line)
|
def render_tag(line)
|
||||||
line.scan(/[<]([a-zA-Z]+)([a-zA-Z.\#]*)([=]?)([^\n]*)/).each do |tag_name, attributes, action, value|
|
line.scan(/[%]([a-zA-Z]+)([a-zA-Z.\#]*)([=]?)([^\n]*)/).each do |tag_name, attributes, action, value|
|
||||||
puts tag_name
|
#puts "tag = " + tag_name + " " + attributes + " " + action + " " + value
|
||||||
open_tag(tag_name, parse_attributes(attributes))
|
open_tag(tag_name, parse_attributes(attributes))
|
||||||
unless value.empty?
|
unless value.empty?
|
||||||
if(action == '=')
|
if(action == '=')
|
||||||
|
@ -122,6 +134,7 @@ module HAML
|
||||||
@table[name.to_sym]
|
@table[name.to_sym]
|
||||||
elsif @_action_view.respond_to? name
|
elsif @_action_view.respond_to? name
|
||||||
@_action_view.send(name, *args, &block)
|
@_action_view.send(name, *args, &block)
|
||||||
|
elsif @_action_view.respond_to? name.to_s[1, name.length].to_sym
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue