Sinatra 1.0 based prerelease

This commit is contained in:
tdreyno 2010-02-02 17:03:43 -08:00
parent ce6deb4c9f
commit af8f1c4f26
7 changed files with 59 additions and 1 deletions

View file

@ -1 +1 @@
0.12.2 0.13.0

View file

@ -0,0 +1,12 @@
Feature: Alternate between multiple asset hosts
In order to speed up page loading
Scenario: Rendering css with the feature enabled
Given I am using an asset host
When I go to "/stylesheets/asset_host.css"
Then I should see "http://assets"
Scenario: Rendering html with the feature enabled
Given I am using an asset host
When I go to "/asset_host.html"
Then I should see "http://assets"

View file

@ -0,0 +1,6 @@
Given /^I am using an asset host$/ do
Middleman::Base.set :asset_host do |asset|
"http://assets%d.example.com" % (asset.hash % 4)
end
@browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Base.new))
end

View file

@ -39,6 +39,13 @@ module Middleman
super super
end end
def self.set(option, value=self, &block)
if block_given?
value = Proc.new { block }
end
super(option, value)
end
@@afters = [] @@afters = []
def self.after_feature_init(&block) def self.after_feature_init(&block)
@@afters << block @@afters << block
@ -134,6 +141,7 @@ class Middleman::Base
helpers Middleman::Helpers helpers Middleman::Helpers
# Features disabled by default # Features disabled by default
enable :asset_host
disable :slickmap disable :slickmap
disable :cache_buster disable :cache_buster
disable :minify_css disable :minify_css

View file

@ -0,0 +1,28 @@
class Middleman::Base
after_feature_init do
::Compass.configuration do |config|
config.asset_host(&self.asset_host)
end
end if self.enabled?(:asset_host)
end
class << Middleman::Base
alias_method :pre_asset_host_asset_url, :asset_url
def asset_url(path, prefix="", request=nil)
original_output = pre_asset_host_asset_url(path, prefix, request)
valid_extensions = %w(.png .gif .jpg .jpeg .js .css)
if !self.enabled?(:asset_host) || path.include?("://") || !valid_extensions.include?(File.extname(path)) || !self.asset_host
return original_output
end
asset_prefix = if self.asset_host.is_a?(Proc) || self.asset_host.respond_to?(:call)
self.asset_host.call(original_output)
else
(self.asset_host =~ /%d/) ? self.asset_host % (original_output.hash % 4) : self.asset_host
end
return File.join(asset_prefix, original_output)
end
end

View file

@ -0,0 +1 @@
= image_tag "blank.gif"

View file

@ -0,0 +1,3 @@
@import compass.sass
h1
background= image_url("blank.gif")