a little testing
This commit is contained in:
parent
a55725a9be
commit
b35f026aba
9 changed files with 115 additions and 26 deletions
|
@ -1,5 +1,4 @@
|
||||||
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
||||||
require 'haml'
|
|
||||||
require 'sinatra/base'
|
require 'sinatra/base'
|
||||||
require 'middleman/helpers'
|
require 'middleman/helpers'
|
||||||
|
|
||||||
|
@ -15,14 +14,16 @@ module Middleman
|
||||||
set :environment, ENV['MM_ENV'] || :development
|
set :environment, ENV['MM_ENV'] || :development
|
||||||
set :supported_formats, []
|
set :supported_formats, []
|
||||||
set :index_file, 'index.html'
|
set :index_file, 'index.html'
|
||||||
|
set :js_dir, "javascripts"
|
||||||
set :css_dir, "stylesheets"
|
set :css_dir, "stylesheets"
|
||||||
set :images_dir, "images"
|
set :images_dir, "images"
|
||||||
set :build_dir, "build"
|
set :build_dir, "build"
|
||||||
|
set :http_prefix, "/"
|
||||||
|
|
||||||
enable :compass
|
enable :compass
|
||||||
enable :content_for
|
enable :content_for
|
||||||
enable :sprockets
|
enable :sprockets
|
||||||
#enable :slickmap
|
disable :slickmap
|
||||||
disable :cache_buster
|
disable :cache_buster
|
||||||
disable :minify_css
|
disable :minify_css
|
||||||
disable :minify_javascript
|
disable :minify_javascript
|
||||||
|
@ -38,7 +39,6 @@ module Middleman
|
||||||
enable :minify_css
|
enable :minify_css
|
||||||
enable :minify_javascript
|
enable :minify_javascript
|
||||||
enable :cache_buster
|
enable :cache_buster
|
||||||
# disable :slickmap
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def template_exists?(path, renderer=nil)
|
def template_exists?(path, renderer=nil)
|
||||||
|
|
|
@ -1,9 +1,18 @@
|
||||||
|
class Middleman::Base
|
||||||
|
helpers do
|
||||||
# def cache_buster
|
alias_method :pre_cache_buster_asset_url, :asset_url
|
||||||
# if File.readable?(real_path)
|
def asset_url(path, prefix="")
|
||||||
# File.mtime(real_path).strftime("%s")
|
path = pre_cache_buster_asset_url(path, prefix)
|
||||||
# else
|
if path.include?("://")
|
||||||
# $stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}"
|
path
|
||||||
# end
|
else
|
||||||
# end
|
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
|
|
@ -18,8 +18,8 @@ class Middleman::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
config.http_images_path = "/#{self.images_dir}"
|
config.http_images_path = File.join(self.http_prefix, self.images_dir)
|
||||||
config.http_stylesheets_path = "/#{self.css_dir}"
|
config.http_stylesheets_path = File.join(self.http_prefix, self.css_dir)
|
||||||
config.add_import_path(config.sass_dir)
|
config.add_import_path(config.sass_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'haml'
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
module Haml
|
module Haml
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
|
|
|
@ -8,12 +8,14 @@ class Middleman::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers do
|
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?("://")
|
if path.include?("://")
|
||||||
path
|
path
|
||||||
else
|
else
|
||||||
request_path = request.path_info.dup
|
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{^/}, '')
|
request_path.gsub!(%r{^/}, '')
|
||||||
parts = request_path.split('/')
|
parts = request_path.split('/')
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,24 @@
|
||||||
require 'slickmap'
|
require 'slickmap'
|
||||||
|
|
||||||
get '/sitemap.html' do
|
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
|
haml :sitemap, :layout => false
|
||||||
|
end
|
||||||
|
|
||||||
|
use_in_file_templates!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
@@ sitemap
|
||||||
|
%div.title Hello world!!!!!
|
|
@ -2,7 +2,7 @@ module Middleman
|
||||||
module Helpers
|
module Helpers
|
||||||
def page_classes(*additional)
|
def page_classes(*additional)
|
||||||
path = request.path_info
|
path = request.path_info
|
||||||
path << "index.html" if path.match(%r{/$})
|
path << options.index_file if path.match(%r{/$})
|
||||||
path.gsub!(%r{^/}, '')
|
path.gsub!(%r{^/}, '')
|
||||||
|
|
||||||
classes = []
|
classes = []
|
||||||
|
@ -20,26 +20,27 @@ module Middleman
|
||||||
%Q{<a #{params}>#{title}</a>}
|
%Q{<a #{params}>#{title}</a>}
|
||||||
end
|
end
|
||||||
|
|
||||||
def asset_url(path)
|
def asset_url(path, prefix="")
|
||||||
path.include?("://") ? path : "/#{path}"
|
base_url = File.join(options.http_prefix, prefix)
|
||||||
|
path.include?("://") ? path : File.join(base_url, path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_tag(path, options={})
|
def image_tag(path, options={})
|
||||||
options[:alt] ||= ""
|
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(' ')
|
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
|
||||||
"<img #{params} />"
|
"<img #{params} />"
|
||||||
end
|
end
|
||||||
|
|
||||||
def javascript_include_tag(path, options={})
|
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(' ')
|
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
|
||||||
"<script #{params}></script>"
|
"<script #{params}></script>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def stylesheet_link_tag(path, options={})
|
def stylesheet_link_tag(path, options={})
|
||||||
options[:rel] ||= "stylesheet"
|
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(' ')
|
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
|
||||||
"<link #{params} />"
|
"<link #{params} />"
|
||||||
end
|
end
|
||||||
|
|
28
spec/cache_buster_spec.rb
Normal file
28
spec/cache_buster_spec.rb
Normal 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
|
28
spec/relative_assets_spec.rb
Normal file
28
spec/relative_assets_spec.rb
Normal 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
|
Loading…
Add table
Reference in a new issue