From 8874e976084430c546c5bef742c5550e2aaf042a Mon Sep 17 00:00:00 2001 From: tdreyno Date: Tue, 6 Oct 2009 16:51:34 -0700 Subject: [PATCH] minor rdoc tweaks --- Rakefile | 1 + lib/middleman/base.rb | 12 +-- lib/middleman/features/haml.rb | 92 +++++++++++---------- lib/middleman/features/minify_javascript.rb | 18 ++-- 4 files changed, 63 insertions(+), 60 deletions(-) diff --git a/Rakefile b/Rakefile index e24c3d1c..1ea64bdf 100644 --- a/Rakefile +++ b/Rakefile @@ -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." diff --git a/lib/middleman/base.rb b/lib/middleman/base.rb index 5d94bc57..5f6c0f9f 100644 --- a/lib/middleman/base.rb +++ b/lib/middleman/base.rb @@ -4,12 +4,6 @@ require 'rubygems' unless ENV['NO_RUBYGEMS'] # 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__ @@ -45,6 +39,12 @@ module Middleman 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 diff --git a/lib/middleman/features/haml.rb b/lib/middleman/features/haml.rb index 26f5317a..a28d7a7a 100644 --- a/lib/middleman/features/haml.rb +++ b/lib/middleman/features/haml.rb @@ -2,62 +2,64 @@ require 'haml' 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 << "
Backtrace: #{e.backtrace.join("\n")}
" + 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 << "
Backtrace: #{e.backtrace.join("\n")}
" + 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 = '
' - line_num = 0 - text.each_line do |line| - line_num += 1 - next if line.strip.empty? - output << %Q{} + def render(text) + output = '
' + line_num = 0 + text.each_line do |line| + line_num += 1 + next if line.strip.empty? + output << %Q{} - columns = line.split("|").map { |p| p.strip } - columns.each_with_index do |col, i| - output << %Q{} + columns = line.split("|").map { |p| p.strip } + columns.each_with_index do |col, i| + output << %Q{} + end + + output << "" end - - output << "" + output + "
#{col}#{col}
" end - output + "" end end @@ -125,6 +127,6 @@ END end class Middleman::Base - include Middleman::Haml + include Middleman::Haml::Renderer include Middleman::Sass end \ No newline at end of file diff --git a/lib/middleman/features/minify_javascript.rb b/lib/middleman/features/minify_javascript.rb index d57f9fb8..3c8844cc 100644 --- a/lib/middleman/features/minify_javascript.rb +++ b/lib/middleman/features/minify_javascript.rb @@ -12,20 +12,20 @@ module Middleman 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 \ No newline at end of file