1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00

move table filter into middleman

This commit is contained in:
tdreyno 2009-09-04 13:58:58 -07:00
parent 0ffea4cd25
commit c5d89b0a32
3 changed files with 36 additions and 1 deletions

View file

@ -4,4 +4,5 @@
require File.join(File.dirname(__FILE__), '..', 'lib', 'middleman')
# Start Middleman
Middleman.set :server, %w[thin webrick]
Middleman.run!(:root => Dir.pwd)

View file

@ -45,7 +45,6 @@ class Middleman < Sinatra::Base
config.output_style = :nested
config.css_dir = File.join(File.basename(self.public), "stylesheets")
config.images_dir = File.join(File.basename(self.public), "images")
config.http_path = "/"
config.http_images_path = "/images"
config.http_stylesheets_path = "/stylesheets"
config.add_import_path(config.sass_dir)

View file

@ -1,3 +1,38 @@
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
def find_and_include_related_sass_file
path = request.path_info.dup
path << "index.html" if path.match(%r{/$})
path.gsub!(%r{^/}, '')
path.gsub!(File.extname(path), '')
path.gsub!('/', '-')
sass_file = File.join(File.basename(self.class.views), "stylesheets", "#{path}.sass")
if File.exists? sass_file
stylesheet_link_tag "stylesheets/#{path}.css"
end
end
def link_to(title, url="#", params={})
params.merge!(:href => url)
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')