1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/lib/middleman/renderers/haml.rb
2011-06-02 11:37:58 +02:00

43 lines
No EOL
1.1 KiB
Ruby
Executable file

require "haml"
require "coffee-filter"
module Middleman
module Renderers
module Haml
class << self
def registered(app)
app.helpers Middleman::Renderers::Haml::Helpers
end
alias :included :registered
end
module Helpers
def haml_partial(name, options = {})
partial(name, options)
end
end
module Table
include ::Haml::Filters::Base
def render(text)
output = '<div class="table"><table cellspacing="0" cellpadding="0">'
line_num = 0
text.each_line do |line|
line_num += 1
next if line.strip.empty?
output << %Q{<tr class="#{(line_num % 2 == 0) ? "even" : "odd" }#{(line_num == 1) ? " first" : "" }">}
columns = line.split("|").map { |p| p.strip }
columns.each_with_index do |col, i|
output << %Q{<td class="col#{i+1}">#{col}</td>}
end
output << "</tr>"
end
output + "</table></div>"
end
end
end
end
end