a little testing

This commit is contained in:
tdreyno 2009-10-01 11:26:46 -07:00
parent a55725a9be
commit b35f026aba
9 changed files with 115 additions and 26 deletions

View file

@ -1,5 +1,4 @@
require 'rubygems' unless ENV['NO_RUBYGEMS']
require 'haml'
require 'sinatra/base'
require 'middleman/helpers'
@ -15,14 +14,16 @@ module Middleman
set :environment, ENV['MM_ENV'] || :development
set :supported_formats, []
set :index_file, 'index.html'
set :js_dir, "javascripts"
set :css_dir, "stylesheets"
set :images_dir, "images"
set :build_dir, "build"
set :http_prefix, "/"
enable :compass
enable :content_for
enable :sprockets
#enable :slickmap
disable :slickmap
disable :cache_buster
disable :minify_css
disable :minify_javascript
@ -38,7 +39,6 @@ module Middleman
enable :minify_css
enable :minify_javascript
enable :cache_buster
# disable :slickmap
end
def template_exists?(path, renderer=nil)

View file

@ -1,9 +1,18 @@
# def cache_buster
# if File.readable?(real_path)
# File.mtime(real_path).strftime("%s")
# else
# $stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
# end
# end
class Middleman::Base
helpers do
alias_method :pre_cache_buster_asset_url, :asset_url
def asset_url(path, prefix="")
path = pre_cache_buster_asset_url(path, prefix)
if path.include?("://")
path
else
real_path = File.join(options.public, path)
if File.readable?(real_path)
path << "?" + File.mtime(real_path).strftime("%s")
else
$stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
end
end
end
end
end

View file

@ -17,9 +17,9 @@ class Middleman::Base
false
end
end
config.http_images_path = "/#{self.images_dir}"
config.http_stylesheets_path = "/#{self.css_dir}"
config.http_images_path = File.join(self.http_prefix, self.images_dir)
config.http_stylesheets_path = File.join(self.http_prefix, self.css_dir)
config.add_import_path(config.sass_dir)
end

View file

@ -1,3 +1,5 @@
require 'haml'
module Middleman
module Haml
def self.included(base)

View file

@ -8,12 +8,14 @@ class Middleman::Base
end
helpers do
def asset_url(path)
alias_method :pre_relative_asset_url, :asset_url
def asset_url(path, prefix="")
path = pre_relative_asset_url(path, prefix)
if path.include?("://")
path
else
request_path = request.path_info.dup
request_path << "index.html" if path.match(%r{/$})
request_path << self.index_file if path.match(%r{/$})
request_path.gsub!(%r{^/}, '')
parts = request_path.split('/')

View file

@ -1,5 +1,24 @@
require 'slickmap'
get '/sitemap.html' do
haml :sitemap, :layout => false
end
class Middleman::Base
def build_sitemap(&block)
# views - stylesheets
# public
# .select
# block.call(this)
end
get '/sitemap.html' do
@tree = build_sitemap do |file_name|
true
end
haml :sitemap, :layout => false
end
use_in_file_templates!
end
__END__
@@ sitemap
%div.title Hello world!!!!!

View file

@ -2,7 +2,7 @@ module Middleman
module Helpers
def page_classes(*additional)
path = request.path_info
path << "index.html" if path.match(%r{/$})
path << options.index_file if path.match(%r{/$})
path.gsub!(%r{^/}, '')
classes = []
@ -20,26 +20,27 @@ module Middleman
%Q{<a #{params}>#{title}</a>}
end
def asset_url(path)
path.include?("://") ? path : "/#{path}"
def asset_url(path, prefix="")
base_url = File.join(options.http_prefix, prefix)
path.include?("://") ? path : File.join(base_url, path)
end
def image_tag(path, options={})
options[:alt] ||= ""
params = options.merge(:src => asset_url(path))
params = options.merge(:src => asset_url(path, self.images_dir))
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
"<img #{params} />"
end
def javascript_include_tag(path, options={})
params = options.merge(:src => asset_url(path), :type => "text/javascript")
params = options.merge(:src => asset_url(path, self.js_dir), :type => "text/javascript")
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
"<script #{params}></script>"
end
def stylesheet_link_tag(path, options={})
options[:rel] ||= "stylesheet"
params = options.merge(:href => asset_url(path), :type => "text/css")
params = options.merge(:href => asset_url(path, self.css_dir), :type => "text/css")
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
"<link #{params} />"
end

28
spec/cache_buster_spec.rb Normal file
View file

@ -0,0 +1,28 @@
require File.join(File.dirname(__FILE__), "spec_helper")
base = ::Middleman::Base
base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample")
describe "Cache Buster Feature" do
before do
base.disable :cache_buster
base.init!
@app = base.new
end
it "should not append query string if off" do
@app.asset_url("stylesheets/static.css").should_not include("?")
end
end
describe "Cache Buster Feature" do
before do
base.enable :cache_buster
base.init!
@app = base.new
end
it "should append query string if on" do
@app.asset_url("stylesheets/static.css").should include("?")
end
end

View file

@ -0,0 +1,28 @@
# require File.join(File.dirname(__FILE__), "spec_helper")
#
# base = ::Middleman::Base
# base.set :root, File.join(File.dirname(__FILE__), "fixtures", "sample")
#
# describe "Relative Assets Feature" do
# before do
# base.disable :relative_assets
# base.init!
# @app = base.new
# end
#
# it "should not contain ../ if off" do
# @app.asset_url("stylesheets/static.css").should_not include("?")
# end
# end
#
# describe "Relative Assets Feature" do
# before do
# base.enable :relative_assets
# base.init!
# @app = base.new
# end
#
# it "should contain ../ if on" do
# @app.asset_url("stylesheets/static.css").should include("?")
# end
# end