Allow extensions to take params and blocks
This commit is contained in:
parent
b5c88adb28
commit
7e86ed058f
|
@ -19,6 +19,7 @@
|
||||||
* Nested layouts using `wrap_layout` helper
|
* Nested layouts using `wrap_layout` helper
|
||||||
* Support for placekitten.com
|
* Support for placekitten.com
|
||||||
* Added MM_ROOT environmental variable
|
* Added MM_ROOT environmental variable
|
||||||
|
* activating extensions can now take an options hash
|
||||||
|
|
||||||
2.0.14
|
2.0.14
|
||||||
====
|
====
|
||||||
|
|
|
@ -2,13 +2,11 @@ Feature: Alternate between multiple asset hosts
|
||||||
In order to speed up page loading
|
In order to speed up page loading
|
||||||
|
|
||||||
Scenario: Rendering css with the feature enabled
|
Scenario: Rendering css with the feature enabled
|
||||||
Given I am using an asset host
|
Given the Server is running at "asset-host-app"
|
||||||
And the Server is running at "test-app"
|
|
||||||
When I go to "/stylesheets/asset_host.css"
|
When I go to "/stylesheets/asset_host.css"
|
||||||
Then I should see "http://assets"
|
Then I should see "http://assets"
|
||||||
|
|
||||||
Scenario: Rendering html with the feature enabled
|
Scenario: Rendering html with the feature enabled
|
||||||
Given I am using an asset host
|
Given the Server is running at "asset-host-app"
|
||||||
And the Server is running at "test-app"
|
|
||||||
When I go to "/asset_host.html"
|
When I go to "/asset_host.html"
|
||||||
Then I should see "http://assets"
|
Then I should see "http://assets"
|
6
features/feature_params.feature
Normal file
6
features/feature_params.feature
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
Feature: Be able to pass params to extensions
|
||||||
|
Scenario: Read some simple variables
|
||||||
|
Given the Server is running at "feature-params-app"
|
||||||
|
When I go to "/index.html"
|
||||||
|
Then I should see "hello: world"
|
||||||
|
And I should see "hola: mundo"
|
|
@ -1,9 +0,0 @@
|
||||||
Given /^I am using an asset host$/ do
|
|
||||||
@initialize_commands ||= []
|
|
||||||
@initialize_commands << lambda {
|
|
||||||
activate :asset_host
|
|
||||||
set :asset_host do |asset|
|
|
||||||
"http://assets%d.example.com" % (asset.hash % 4)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
|
6
fixtures/asset-host-app/config.rb
Normal file
6
fixtures/asset-host-app/config.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
set :layout, false
|
||||||
|
|
||||||
|
activate :asset_host
|
||||||
|
set :asset_host do |asset|
|
||||||
|
"http://assets%d.example.com" % (asset.hash % 4)
|
||||||
|
end
|
1
fixtures/asset-host-app/source/.htaccess
Normal file
1
fixtures/asset-host-app/source/.htaccess
Normal file
|
@ -0,0 +1 @@
|
||||||
|
# I'm an htaccess file!
|
1
fixtures/asset-host-app/source/asset_host.html.haml
Executable file
1
fixtures/asset-host-app/source/asset_host.html.haml
Executable file
|
@ -0,0 +1 @@
|
||||||
|
= image_tag "blank.gif"
|
BIN
fixtures/asset-host-app/source/images/blank.gif
Executable file
BIN
fixtures/asset-host-app/source/images/blank.gif
Executable file
Binary file not shown.
After Width: | Height: | Size: 43 B |
3
fixtures/asset-host-app/source/stylesheets/asset_host.css.sass
Executable file
3
fixtures/asset-host-app/source/stylesheets/asset_host.css.sass
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
@import "compass"
|
||||||
|
h1
|
||||||
|
background: image-url("blank.gif")
|
12
fixtures/feature-params-app/config.rb
Normal file
12
fixtures/feature-params-app/config.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
set :layout, false
|
||||||
|
|
||||||
|
module ExtensionA
|
||||||
|
class << self
|
||||||
|
def registered(app, options={})
|
||||||
|
app.set :a_options, options
|
||||||
|
end
|
||||||
|
alias :included :registered
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
activate ExtensionA, :hello => "world", :hola => "mundo"
|
3
fixtures/feature-params-app/source/index.html.erb
Normal file
3
fixtures/feature-params-app/source/index.html.erb
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<% a_options.each do |k, v| %>
|
||||||
|
<%= k %>: <%= v%>
|
||||||
|
<% end %>
|
|
@ -54,6 +54,15 @@ class Middleman::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Set the shared instance
|
||||||
|
#
|
||||||
|
# @private
|
||||||
|
# @param [Middleman::Base] inst
|
||||||
|
# @return [void]
|
||||||
|
def inst=(inst)
|
||||||
|
@inst = inst
|
||||||
|
end
|
||||||
|
|
||||||
# Return built Rack app
|
# Return built Rack app
|
||||||
#
|
#
|
||||||
# @private
|
# @private
|
||||||
|
@ -128,9 +137,11 @@ class Middleman::Base
|
||||||
# @param [Symbol] Unique key name
|
# @param [Symbol] Unique key name
|
||||||
# @param Default value
|
# @param Default value
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def set(key, value)
|
def set(key, value=nil, &block)
|
||||||
@defaults ||= {}
|
@defaults ||= {}
|
||||||
@defaults[key] = value
|
@defaults[key] = value
|
||||||
|
|
||||||
|
@inst.set(key, value, &block) if @inst
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -71,12 +71,17 @@ module Middleman::CoreExtensions::Extensions
|
||||||
#
|
#
|
||||||
# @param [Array<Module>] new_extensions Extension modules to register
|
# @param [Array<Module>] new_extensions Extension modules to register
|
||||||
# @return [Array<Module]
|
# @return [Array<Module]
|
||||||
def register(*new_extensions)
|
def register(extension, options={}, &block)
|
||||||
@extensions ||= []
|
@extensions ||= []
|
||||||
@extensions += new_extensions
|
@extensions += [extension]
|
||||||
new_extensions.each do |extension|
|
|
||||||
extend extension
|
extend extension
|
||||||
extension.registered(self) if extension.respond_to?(:registered)
|
if extension.respond_to?(:registered)
|
||||||
|
if extension.method(:registered).arity === 1
|
||||||
|
extension.registered(self, &block)
|
||||||
|
else
|
||||||
|
extension.registered(self, options, &block)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -89,10 +94,12 @@ module Middleman::CoreExtensions::Extensions
|
||||||
#
|
#
|
||||||
# activate :lorem
|
# activate :lorem
|
||||||
#
|
#
|
||||||
# @param [Symbol, Module] feature Which extension to activate
|
# @param [Symbol, Module] ext Which extension to activate
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def activate(feature)
|
def activate(ext, options={}, &block)
|
||||||
ext = ::Middleman::Extensions.load(feature.to_sym)
|
if !ext.is_a?(Module)
|
||||||
|
ext = ::Middleman::Extensions.load(ext.to_sym)
|
||||||
|
end
|
||||||
|
|
||||||
if ext.nil?
|
if ext.nil?
|
||||||
puts "== Unknown Extension: #{feature}"
|
puts "== Unknown Extension: #{feature}"
|
||||||
|
@ -100,7 +107,7 @@ module Middleman::CoreExtensions::Extensions
|
||||||
puts ext
|
puts ext
|
||||||
else
|
else
|
||||||
puts "== Activating: #{feature}" if logging?
|
puts "== Activating: #{feature}" if logging?
|
||||||
self.class.register(ext)
|
self.class.register(ext, options, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -108,6 +115,7 @@ module Middleman::CoreExtensions::Extensions
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
|
|
||||||
|
self.class.inst = self
|
||||||
run_hook :before_configuration
|
run_hook :before_configuration
|
||||||
|
|
||||||
# Search the root of the project for required files
|
# Search the root of the project for required files
|
||||||
|
|
|
@ -18,8 +18,9 @@ module Middleman::Extensions
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
def asset_url(path, prefix="")
|
def asset_url(path, prefix="")
|
||||||
original_output = super
|
original_output = super
|
||||||
|
return original_output unless asset_host
|
||||||
|
|
||||||
valid_extensions = %w(.png .gif .jpg .jpeg .svg .svgz .js .css)
|
# valid_extensions = %w(.png .gif .jpg .jpeg .svg .svgz .js .css)
|
||||||
|
|
||||||
asset_prefix = if asset_host.is_a?(Proc)
|
asset_prefix = if asset_host.is_a?(Proc)
|
||||||
asset_host.call(original_output)
|
asset_host.call(original_output)
|
||||||
|
|
Loading…
Reference in a new issue