add ignorable paths
This commit is contained in:
parent
5cde37177f
commit
c35a6fc369
|
@ -6,6 +6,10 @@ Feature: Dynamic Pages
|
|||
Then "fake.html" should exist and include "I am real"
|
||||
Then "fake/one.html" should exist and include "I am real: one"
|
||||
Then "fake/two.html" should exist and include "I am real: two"
|
||||
Then "target_ignore.html" should exist and include "Ignore me"
|
||||
Then "should_be_ignored.html" should not exist
|
||||
Then "should_be_ignored2.html" should not exist
|
||||
Then "should_be_ignored3.html" should not exist
|
||||
And cleanup built test app
|
||||
|
||||
Scenario: Preview basic proxy
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
Given /^page "([^\"]*)" has layout "([^\"]*)"$/ do |url, layout|
|
||||
@server ||= Middleman.server
|
||||
@server.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
|
||||
@server.page(url, :layout => layout.to_sym)
|
||||
end
|
||||
|
||||
Given /^"([^\"]*)" with_layout block has layout "([^\"]*)"$/ do |url, layout|
|
||||
@server ||= Middleman.server
|
||||
@server.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
|
||||
@server.with_layout(layout.to_sym) do
|
||||
page(url)
|
||||
end
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
page "/fake.html", :proxy => "/real.html", :layout => false
|
||||
|
||||
ignore "/should_be_ignored.html"
|
||||
page "/should_be_ignored2.html", :ignore => true
|
||||
page "/target_ignore.html", :proxy => "/should_be_ignored3.html", :ignore => true
|
||||
|
||||
%w(one two).each do |num|
|
||||
page "/fake/#{num}.html", :proxy => "/real/index.html" do
|
||||
@num = num
|
||||
|
|
1
fixtures/test-app/source/should_be_ignored.html
Normal file
1
fixtures/test-app/source/should_be_ignored.html
Normal file
|
@ -0,0 +1 @@
|
|||
<h1>Ignore me!</h1>
|
1
fixtures/test-app/source/should_be_ignored2.html
Normal file
1
fixtures/test-app/source/should_be_ignored2.html
Normal file
|
@ -0,0 +1 @@
|
|||
<h1>Ignore me! 2</h1>
|
1
fixtures/test-app/source/should_be_ignored3.html
Normal file
1
fixtures/test-app/source/should_be_ignored3.html
Normal file
|
@ -0,0 +1 @@
|
|||
<h1>Ignore me! 3</h1>
|
|
@ -5,7 +5,7 @@ require 'rack/test'
|
|||
SHARED_SERVER = Middleman.server
|
||||
SHARED_SERVER.set :environment, :build
|
||||
|
||||
module Middleman
|
||||
module Middleman
|
||||
module ThorActions
|
||||
def tilt_template(source, *args, &block)
|
||||
config = args.last.is_a?(Hash) ? args.pop : {}
|
||||
|
@ -13,14 +13,13 @@ module Middleman
|
|||
|
||||
# source = File.expand_path(find_in_source_paths(source.to_s))
|
||||
context = instance_eval('binding')
|
||||
|
||||
@@rack_test ||= ::Rack::Test::Session.new(::Rack::MockSession.new(SHARED_SERVER))
|
||||
|
||||
request_path = destination.sub(/^#{SHARED_SERVER.build_dir}/, "")
|
||||
return if SHARED_SERVER.excluded_paths.include?(request_path)
|
||||
|
||||
create_file destination, nil, config do
|
||||
# The default render just requests the page over Rack and writes the response
|
||||
request_path = destination.sub(/^#{SHARED_SERVER.build_dir}/, "")
|
||||
@@rack_test.get(request_path.gsub(/\s/, "%20"))
|
||||
@@rack_test.last_response.body
|
||||
Middleman::Builder.shared_rack.get(request_path.gsub(/\s/, "%20"))
|
||||
Middleman::Builder.shared_rack.last_response.body
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -29,6 +28,15 @@ module Middleman
|
|||
include Thor::Actions
|
||||
include Middleman::ThorActions
|
||||
|
||||
def self.shared_rack
|
||||
@shared_rack ||= begin
|
||||
mock = ::Rack::MockSession.new(SHARED_SERVER)
|
||||
sess = ::Rack::Test::Session.new(mock)
|
||||
sess.get("/")
|
||||
sess
|
||||
end
|
||||
end
|
||||
|
||||
class_option :relative, :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
|
||||
|
||||
def initialize(*args)
|
||||
|
@ -46,6 +54,8 @@ module Middleman
|
|||
end
|
||||
|
||||
def build_all_files
|
||||
self.class.shared_rack
|
||||
|
||||
action Directory.new(self, SHARED_SERVER.views, SHARED_SERVER.build_dir, { :force => true })
|
||||
|
||||
SHARED_SERVER.proxied_paths.each do |url, proxy|
|
||||
|
|
|
@ -4,6 +4,7 @@ module Middleman::CoreExtensions::Routing
|
|||
app.extend ClassMethods
|
||||
|
||||
app.set :proxied_paths, {}
|
||||
app.set :excluded_paths, []
|
||||
|
||||
# Normalize the path and add index if we're looking at a directory
|
||||
app.before_processing do
|
||||
|
@ -47,6 +48,13 @@ module Middleman::CoreExtensions::Routing
|
|||
paths
|
||||
end
|
||||
|
||||
# Keep a path from building
|
||||
def ignore(path)
|
||||
settings.excluded_paths << paths_for_url(path)
|
||||
settings.excluded_paths.flatten!
|
||||
settings.excluded_paths.uniq!
|
||||
end
|
||||
|
||||
# The page method allows the layout to be set on a specific path
|
||||
# page "/about.html", :layout => false
|
||||
# page "/", :layout => :homepage_layout
|
||||
|
@ -56,8 +64,15 @@ module Middleman::CoreExtensions::Routing
|
|||
|
||||
if options.has_key?(:proxy)
|
||||
settings.proxied_paths[url] = options[:proxy]
|
||||
if options.has_key?(:ignore) && options[:ignore]
|
||||
settings.ignore(options[:proxy])
|
||||
end
|
||||
else
|
||||
if options.has_key?(:ignore) && options[:ignore]
|
||||
settings.ignore(url)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
paths_for_url(url).each do |p|
|
||||
get(p) do
|
||||
if settings.proxied_paths.has_key?(url)
|
||||
|
|
Loading…
Reference in a new issue