2009-10-22 20:25:15 -04:00
|
|
|
require "haml"
|
2011-05-22 11:27:39 -04:00
|
|
|
require "coffee-filter"
|
2009-10-22 20:25:15 -04:00
|
|
|
|
|
|
|
module Middleman
|
2010-09-06 21:48:25 -04:00
|
|
|
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)
|
2009-10-22 20:25:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-06 21:48:25 -04:00
|
|
|
module Table
|
|
|
|
include ::Haml::Filters::Base
|
2009-10-22 20:25:15 -04:00
|
|
|
|
2010-09-06 21:48:25 -04:00
|
|
|
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" : "" }">}
|
2009-10-22 20:25:15 -04:00
|
|
|
|
2010-09-06 21:48:25 -04:00
|
|
|
columns = line.split("|").map { |p| p.strip }
|
|
|
|
columns.each_with_index do |col, i|
|
|
|
|
output << %Q{<td class="col#{i+1}">#{col}</td>}
|
|
|
|
end
|
2009-10-22 20:25:15 -04:00
|
|
|
|
2010-09-06 21:48:25 -04:00
|
|
|
output << "</tr>"
|
|
|
|
end
|
|
|
|
output + "</table></div>"
|
2009-10-22 20:25:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|