Skip to content

Commit

Permalink
a little testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tdreyno committed Oct 1, 2009
1 parent a55725a commit b35f026
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 26 deletions.
6 changes: 3 additions & 3 deletions lib/middleman/base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'rubygems' unless ENV['NO_RUBYGEMS']
require 'haml'
require 'sinatra/base'
require 'middleman/helpers'

Expand All @@ -15,14 +14,16 @@ class Base < Sinatra::Base
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
Expand All @@ -38,7 +39,6 @@ class Base < Sinatra::Base
enable :minify_css
enable :minify_javascript
enable :cache_buster
# disable :slickmap
end

def template_exists?(path, renderer=nil)
Expand Down
27 changes: 18 additions & 9 deletions lib/middleman/features/cache_buster.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions lib/middleman/features/compass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lib/middleman/features/haml.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'haml'

module Middleman
module Haml
def self.included(base)
Expand Down
6 changes: 4 additions & 2 deletions lib/middleman/features/relative_assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')

Expand Down
25 changes: 22 additions & 3 deletions lib/middleman/features/slickmap.rb
Original file line number Diff line number Diff line change
@@ -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!!!!!
13 changes: 7 additions & 6 deletions lib/middleman/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -20,26 +20,27 @@ def link_to(title, url="#", params={})
%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
Expand Down
28 changes: 28 additions & 0 deletions spec/cache_buster_spec.rb
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions spec/relative_assets_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b35f026

Please sign in to comment.