new helpers and some specs

This commit is contained in:
tdreyno 2009-11-03 12:34:57 -08:00
parent b09a7ae619
commit ecce56d6ae
6 changed files with 49 additions and 15 deletions

View file

@ -7,17 +7,33 @@ module Middleman
end
module Helpers
def page_classes(*additional)
path = request.path_info
def haml_partial(name, options = {})
haml name.to_sym, options.merge(:layout => false)
end
def auto_stylesheet_link_tag
path = request.path_info.dup
path << self.class.index_file if path.match(%r{/$})
path = path.gsub(%r{^/}, '')
path = path.gsub(File.extname(path), '')
path = path.gsub('/', '-')
css_file = File.join(File.basename(self.class.public), self.class.css_dir, "#{path}.css")
sass_file = File.join(File.basename(self.class.views), self.class.css_dir, "#{path}.css.sass")
if File.exists?(css_file) || File.exists?(sass_file)
stylesheet_link_tag "#{path}.css"
end
end
def page_classes
path = request.path_info.dup
path << options.index_file if path.match(%r{/$})
path.gsub!(%r{^/}, '')
path = path.gsub(%r{^/}, '')
classes = []
parts = path.split('.')[0].split('/')
parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
classes << "index" if classes.empty?
classes += additional unless additional.empty?
classes.join(' ')
end

View file

@ -4,6 +4,6 @@
= stylesheet_link_tag "site.css"
= yield_content :head
%body
%body{ :class => page_classes }
#frame
= yield

View file

@ -49,10 +49,6 @@ describe "Builder" do
it "should not build partial files" do
File.exists?("#{@root_dir}/build/_partial.html").should be_false
end
it "should minify inline javascript" do
File.readlines("#{@root_dir}/build/inline-js.html").length.should == 9
end
it "should combine javascript" do
File.read("#{@root_dir}/build/javascripts/empty-with-include.js").should include("combo")

View file

@ -1 +1,4 @@
# enable :maruku
# enable :maruku
get "/inline-js.html" do
haml :"inline-js.html", :layout => false
end

View file

@ -0,0 +1,21 @@
require 'rack/test'
require File.join(File.dirname(__FILE__), "spec_helper")
base = ::Middleman::Base
base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample")
describe "Minify Javascript Feature" do
it "should not minify inline js if off" do
base.disable :minify_javascript
browser = Rack::Test::Session.new(Rack::MockSession.new(base.new))
browser.get("/inline-js.html")
browser.last_response.body.chomp.split($/).length.should == 10
end
it "should minify inline js if on" do
base.enable :minify_javascript
browser = Rack::Test::Session.new(Rack::MockSession.new(base.new))
browser.get("/inline-js.html")
browser.last_response.body.chomp.split($/).length.should == 1
end
end

View file

@ -11,9 +11,7 @@ describe "Relative Assets Feature" do
browser.get("/stylesheets/relative_assets.css")
browser.last_response.body.should_not include("../")
end
end
describe "Relative Assets Feature" do
it "should contain ../ if on" do
base.enable :relative_assets
browser = Rack::Test::Session.new(Rack::MockSession.new(base.new))