Skip to content

Commit

Permalink
minor rdoc tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed Oct 6, 2009
1 parent 7e84564 commit 8874e97
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 60 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Rake::RDocTask.new do |rdoc|
rdoc.title = "middleman #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
rdoc.rdoc_files.exclude('lib/middleman/features/sprockets+ruby19.rb')
end

desc "Build and publish documentation using GitHub Pages."
Expand Down
12 changes: 6 additions & 6 deletions lib/middleman/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
# We're riding on Sinatra, so let's include it
require 'sinatra/base'

# Rack helper for adding mime-types during local preview
def mime(ext, type)
ext = ".#{ext}" unless ext.to_s[0] == ?.
Rack::Mime::MIME_TYPES[ext.to_s] = type
end

module Middleman
class Base < Sinatra::Base
set :app_file, __FILE__
Expand Down Expand Up @@ -45,6 +39,12 @@ class Base < Sinatra::Base
enable :cache_buster
end

# Rack helper for adding mime-types during local preview
def mime(ext, type)
ext = ".#{ext}" unless ext.to_s[0] == ?.
Rack::Mime::MIME_TYPES[ext.to_s] = type
end

# Convenience function to discover if a tempalte exists for the requested renderer (haml, sass, etc)
def template_exists?(path, renderer=nil)
template_path = path.dup
Expand Down
92 changes: 47 additions & 45 deletions lib/middleman/features/haml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,64 @@

module Middleman
module Haml
def self.included(base)
base.supported_formats << "haml"
base.helpers Middleman::HamlHelpers
end
module Renderer
def self.included(base)
base.supported_formats << "haml"
base.helpers Middleman::Haml::Helpers
end

def render_path(path)
if template_exists?(path, :haml)
result = nil
begin
result = haml(path.to_sym, :layout => File.extname(path) != ".xml")
rescue ::Haml::Error => e
result = "Haml Error: #{e}"
result << "<pre>Backtrace: #{e.backtrace.join("\n")}</pre>"
def render_path(path)
if template_exists?(path, :haml)
result = nil
begin
result = haml(path.to_sym, :layout => File.extname(path) != ".xml")
rescue ::Haml::Error => e
result = "Haml Error: #{e}"
result << "<pre>Backtrace: #{e.backtrace.join("\n")}</pre>"
end
result
else
super
end
result
else
super
end
end
end

module HamlHelpers
def haml_partial(name, options = {})
item_name = name.to_sym
counter_name = "#{name}_counter".to_sym
if collection = options.delete(:collection)
collection.enum_for(:each_with_index).collect do |item,index|
haml_partial name, options.merge(:locals => {item_name => item, counter_name => index+1})
end.join
elsif object = options.delete(:object)
haml_partial name, options.merge(:locals => {item_name => object, counter_name => nil})
else
haml "_#{name}".to_sym, options.merge(:layout => false)
module Helpers
def haml_partial(name, options = {})
item_name = name.to_sym
counter_name = "#{name}_counter".to_sym
if collection = options.delete(:collection)
collection.enum_for(:each_with_index).collect do |item,index|
haml_partial name, options.merge(:locals => {item_name => item, counter_name => index+1})
end.join
elsif object = options.delete(:object)
haml_partial name, options.merge(:locals => {item_name => object, counter_name => nil})
else
haml "_#{name}".to_sym, options.merge(:layout => false)
end
end
end
end

module Table
include ::Haml::Filters::Base
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" : "" }">}
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
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>"
output << "</tr>"
end
output + "</table></div>"
end
output + "</table></div>"
end
end

Expand Down Expand Up @@ -125,6 +127,6 @@ def sass_exception_string(e)
end

class Middleman::Base
include Middleman::Haml
include Middleman::Haml::Renderer
include Middleman::Sass
end
18 changes: 9 additions & 9 deletions lib/middleman/features/minify_javascript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ def render_with_options(text, options)
END
end
end
end

module Compressor
def render_path(path)
if template_exists?(path, :js)
compressor = YUI::JavaScriptCompressor.new(:munge => true)
compressor.compress(super)
else
super
module StaticJavascript
def render_path(path)
if template_exists?(path, :js)
compressor = YUI::JavaScriptCompressor.new(:munge => true)
compressor.compress(super)
else
super
end
end
end
end

class Base
include Middleman::Compressor
include Middleman::Minified::StaticJavascript
end
end

0 comments on commit 8874e97

Please sign in to comment.