mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
new helpers and some specs
This commit is contained in:
parent
b09a7ae619
commit
ecce56d6ae
6 changed files with 49 additions and 15 deletions
|
@ -7,17 +7,33 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
module Helpers
|
module Helpers
|
||||||
def page_classes(*additional)
|
def haml_partial(name, options = {})
|
||||||
path = request.path_info
|
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 << options.index_file if path.match(%r{/$})
|
||||||
path.gsub!(%r{^/}, '')
|
path = path.gsub(%r{^/}, '')
|
||||||
|
|
||||||
classes = []
|
classes = []
|
||||||
parts = path.split('.')[0].split('/')
|
parts = path.split('.')[0].split('/')
|
||||||
parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
|
parts.each_with_index { |path, i| classes << parts.first(i+1).join('_') }
|
||||||
|
|
||||||
classes << "index" if classes.empty?
|
|
||||||
classes += additional unless additional.empty?
|
|
||||||
classes.join(' ')
|
classes.join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,6 @@
|
||||||
= stylesheet_link_tag "site.css"
|
= stylesheet_link_tag "site.css"
|
||||||
= yield_content :head
|
= yield_content :head
|
||||||
|
|
||||||
%body
|
%body{ :class => page_classes }
|
||||||
#frame
|
#frame
|
||||||
= yield
|
= yield
|
|
@ -50,10 +50,6 @@ describe "Builder" do
|
||||||
File.exists?("#{@root_dir}/build/_partial.html").should be_false
|
File.exists?("#{@root_dir}/build/_partial.html").should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should minify inline javascript" do
|
|
||||||
File.readlines("#{@root_dir}/build/inline-js.html").length.should == 9
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should combine javascript" do
|
it "should combine javascript" do
|
||||||
File.read("#{@root_dir}/build/javascripts/empty-with-include.js").should include("combo")
|
File.read("#{@root_dir}/build/javascripts/empty-with-include.js").should include("combo")
|
||||||
end
|
end
|
||||||
|
|
3
spec/fixtures/sample/init.rb
vendored
3
spec/fixtures/sample/init.rb
vendored
|
@ -1 +1,4 @@
|
||||||
# enable :maruku
|
# enable :maruku
|
||||||
|
get "/inline-js.html" do
|
||||||
|
haml :"inline-js.html", :layout => false
|
||||||
|
end
|
21
spec/minify_javascript_spec.rb
Normal file
21
spec/minify_javascript_spec.rb
Normal 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
|
|
@ -11,9 +11,7 @@ describe "Relative Assets Feature" do
|
||||||
browser.get("/stylesheets/relative_assets.css")
|
browser.get("/stylesheets/relative_assets.css")
|
||||||
browser.last_response.body.should_not include("../")
|
browser.last_response.body.should_not include("../")
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
describe "Relative Assets Feature" do
|
|
||||||
it "should contain ../ if on" do
|
it "should contain ../ if on" do
|
||||||
base.enable :relative_assets
|
base.enable :relative_assets
|
||||||
browser = Rack::Test::Session.new(Rack::MockSession.new(base.new))
|
browser = Rack::Test::Session.new(Rack::MockSession.new(base.new))
|
||||||
|
|
Loading…
Reference in a new issue