mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
minor rdoc tweaks
This commit is contained in:
parent
7e845647ea
commit
8874e97608
4 changed files with 63 additions and 60 deletions
1
Rakefile
1
Rakefile
|
@ -62,6 +62,7 @@ Rake::RDocTask.new do |rdoc|
|
||||||
rdoc.title = "middleman #{version}"
|
rdoc.title = "middleman #{version}"
|
||||||
rdoc.rdoc_files.include('README*')
|
rdoc.rdoc_files.include('README*')
|
||||||
rdoc.rdoc_files.include('lib/**/*.rb')
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
||||||
|
rdoc.rdoc_files.exclude('lib/middleman/features/sprockets+ruby19.rb')
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Build and publish documentation using GitHub Pages."
|
desc "Build and publish documentation using GitHub Pages."
|
||||||
|
|
|
@ -4,12 +4,6 @@ require 'rubygems' unless ENV['NO_RUBYGEMS']
|
||||||
# We're riding on Sinatra, so let's include it
|
# We're riding on Sinatra, so let's include it
|
||||||
require 'sinatra/base'
|
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
|
module Middleman
|
||||||
class Base < Sinatra::Base
|
class Base < Sinatra::Base
|
||||||
set :app_file, __FILE__
|
set :app_file, __FILE__
|
||||||
|
@ -45,6 +39,12 @@ module Middleman
|
||||||
enable :cache_buster
|
enable :cache_buster
|
||||||
end
|
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)
|
# Convenience function to discover if a tempalte exists for the requested renderer (haml, sass, etc)
|
||||||
def template_exists?(path, renderer=nil)
|
def template_exists?(path, renderer=nil)
|
||||||
template_path = path.dup
|
template_path = path.dup
|
||||||
|
|
|
@ -2,62 +2,64 @@ require 'haml'
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module Haml
|
module Haml
|
||||||
def self.included(base)
|
module Renderer
|
||||||
base.supported_formats << "haml"
|
def self.included(base)
|
||||||
base.helpers Middleman::HamlHelpers
|
base.supported_formats << "haml"
|
||||||
end
|
base.helpers Middleman::Haml::Helpers
|
||||||
|
end
|
||||||
|
|
||||||
def render_path(path)
|
def render_path(path)
|
||||||
if template_exists?(path, :haml)
|
if template_exists?(path, :haml)
|
||||||
result = nil
|
result = nil
|
||||||
begin
|
begin
|
||||||
result = haml(path.to_sym, :layout => File.extname(path) != ".xml")
|
result = haml(path.to_sym, :layout => File.extname(path) != ".xml")
|
||||||
rescue ::Haml::Error => e
|
rescue ::Haml::Error => e
|
||||||
result = "Haml Error: #{e}"
|
result = "Haml Error: #{e}"
|
||||||
result << "<pre>Backtrace: #{e.backtrace.join("\n")}</pre>"
|
result << "<pre>Backtrace: #{e.backtrace.join("\n")}</pre>"
|
||||||
|
end
|
||||||
|
result
|
||||||
|
else
|
||||||
|
super
|
||||||
end
|
end
|
||||||
result
|
|
||||||
else
|
|
||||||
super
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
module HamlHelpers
|
module Helpers
|
||||||
def haml_partial(name, options = {})
|
def haml_partial(name, options = {})
|
||||||
item_name = name.to_sym
|
item_name = name.to_sym
|
||||||
counter_name = "#{name}_counter".to_sym
|
counter_name = "#{name}_counter".to_sym
|
||||||
if collection = options.delete(:collection)
|
if collection = options.delete(:collection)
|
||||||
collection.enum_for(:each_with_index).collect do |item,index|
|
collection.enum_for(:each_with_index).collect do |item,index|
|
||||||
haml_partial name, options.merge(:locals => {item_name => item, counter_name => index+1})
|
haml_partial name, options.merge(:locals => {item_name => item, counter_name => index+1})
|
||||||
end.join
|
end.join
|
||||||
elsif object = options.delete(:object)
|
elsif object = options.delete(:object)
|
||||||
haml_partial name, options.merge(:locals => {item_name => object, counter_name => nil})
|
haml_partial name, options.merge(:locals => {item_name => object, counter_name => nil})
|
||||||
else
|
else
|
||||||
haml "_#{name}".to_sym, options.merge(:layout => false)
|
haml "_#{name}".to_sym, options.merge(:layout => false)
|
||||||
end
|
|
||||||
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
|
end
|
||||||
|
|
||||||
output << "</tr>"
|
|
||||||
end
|
end
|
||||||
output + "</table></div>"
|
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
|
||||||
|
|
||||||
|
@ -125,6 +127,6 @@ END
|
||||||
end
|
end
|
||||||
|
|
||||||
class Middleman::Base
|
class Middleman::Base
|
||||||
include Middleman::Haml
|
include Middleman::Haml::Renderer
|
||||||
include Middleman::Sass
|
include Middleman::Sass
|
||||||
end
|
end
|
|
@ -12,20 +12,20 @@ module Middleman
|
||||||
END
|
END
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
module Compressor
|
module StaticJavascript
|
||||||
def render_path(path)
|
def render_path(path)
|
||||||
if template_exists?(path, :js)
|
if template_exists?(path, :js)
|
||||||
compressor = YUI::JavaScriptCompressor.new(:munge => true)
|
compressor = YUI::JavaScriptCompressor.new(:munge => true)
|
||||||
compressor.compress(super)
|
compressor.compress(super)
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Base
|
class Base
|
||||||
include Middleman::Compressor
|
include Middleman::Minified::StaticJavascript
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue