allow build to use glob
This commit is contained in:
parent
bc7ee29486
commit
61d7e8abed
|
@ -17,6 +17,12 @@ Feature: Builder
|
||||||
Then "images/Child folder/regular_file(example).txt" should exist at "test-app"
|
Then "images/Child folder/regular_file(example).txt" should exist at "test-app"
|
||||||
And cleanup built app at "test-app"
|
And cleanup built app at "test-app"
|
||||||
|
|
||||||
|
Scenario: Build glob
|
||||||
|
Given a built app at "glob-app" with flags "--glob '**/*.sass'"
|
||||||
|
Then "stylesheets/site.css" should exist at "glob-app" and include "html"
|
||||||
|
Then "index.html" should not exist at "glob-app"
|
||||||
|
And cleanup built app at "glob-app"
|
||||||
|
|
||||||
# Scenario: Force relative assets
|
# Scenario: Force relative assets
|
||||||
# Given a built app at "relative-app" with flags "--relative"
|
# Given a built app at "relative-app" with flags "--relative"
|
||||||
# Then "stylesheets/relative_assets.css" should exist at "relative-app" and include "../"
|
# Then "stylesheets/relative_assets.css" should exist at "relative-app" and include "../"
|
||||||
|
|
1
fixtures/glob-app/config.rb
Normal file
1
fixtures/glob-app/config.rb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
page "/index.html", :layout => false
|
6
fixtures/glob-app/source/index.html.haml
Executable file
6
fixtures/glob-app/source/index.html.haml
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
%h1 Welcome
|
||||||
|
|
||||||
|
:markdown
|
||||||
|
## H2
|
||||||
|
|
||||||
|
Paragraph
|
1
fixtures/glob-app/source/stylesheets/site.css.sass
Executable file
1
fixtures/glob-app/source/stylesheets/site.css.sass
Executable file
|
@ -0,0 +1 @@
|
||||||
|
@import "compass/reset"
|
|
@ -38,12 +38,13 @@ module Middleman
|
||||||
@shared_rack ||= begin
|
@shared_rack ||= begin
|
||||||
mock = ::Rack::MockSession.new(SHARED_SERVER)
|
mock = ::Rack::MockSession.new(SHARED_SERVER)
|
||||||
sess = ::Rack::Test::Session.new(mock)
|
sess = ::Rack::Test::Session.new(mock)
|
||||||
sess.get("/")
|
# sess.get("/")
|
||||||
sess
|
sess
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class_option :relative, :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
|
class_option :relative, :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
|
||||||
|
class_option :glob, :type => :string, :aliases => "-g", :default => nil, :desc => 'Build a subset of the project'
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
super
|
super
|
||||||
|
@ -62,10 +63,14 @@ module Middleman
|
||||||
def build_all_files
|
def build_all_files
|
||||||
self.class.shared_rack
|
self.class.shared_rack
|
||||||
|
|
||||||
action Directory.new(self, SHARED_SERVER.views, SHARED_SERVER.build_dir, { :force => true })
|
if options.has_key?("glob")
|
||||||
|
action GlobAction.new(self, SHARED_SERVER.views, SHARED_SERVER.build_dir, { :force => true, :glob => options["glob"] })
|
||||||
|
else
|
||||||
|
action DirectoryAction.new(self, SHARED_SERVER.views, SHARED_SERVER.build_dir, { :force => true })
|
||||||
|
|
||||||
SHARED_SERVER.proxied_paths.each do |url, proxy|
|
SHARED_SERVER.proxied_paths.each do |url, proxy|
|
||||||
tilt_template(url.gsub(/^\//, "#{SHARED_SERVER.build_dir}/"), { :force => true })
|
tilt_template(url.gsub(/^\//, "#{SHARED_SERVER.build_dir}/"), { :force => true })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -75,6 +80,8 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_hooks
|
def run_hooks
|
||||||
|
return if options.has_key?("glob")
|
||||||
|
|
||||||
@@hooks.each do |name, proc|
|
@@hooks.each do |name, proc|
|
||||||
instance_eval(&proc)
|
instance_eval(&proc)
|
||||||
end
|
end
|
||||||
|
@ -85,7 +92,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Directory < ::Thor::Actions::EmptyDirectory
|
class BaseAction < ::Thor::Actions::EmptyDirectory
|
||||||
attr_reader :source
|
attr_reader :source
|
||||||
|
|
||||||
def initialize(base, source, destination=nil, config={}, &block)
|
def initialize(base, source, destination=nil, config={}, &block)
|
||||||
|
@ -95,14 +102,58 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
def invoke!
|
def invoke!
|
||||||
base.empty_directory given_destination, config
|
|
||||||
execute!
|
execute!
|
||||||
end
|
end
|
||||||
|
|
||||||
def revoke!
|
def revoke!
|
||||||
execute!
|
execute!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
def handle_path(file_source)
|
||||||
|
# Skip partials prefixed with an underscore
|
||||||
|
return unless file_source.gsub(SHARED_SERVER.root, '').split('/').select { |p| p[0,1] == '_' }.empty?
|
||||||
|
|
||||||
|
file_extension = File.extname(file_source)
|
||||||
|
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
|
||||||
|
file_destination.gsub!('/./', '/')
|
||||||
|
|
||||||
|
handled_by_tilt = ::Tilt.mappings.has_key?(file_extension.gsub(/^\./, ""))
|
||||||
|
if handled_by_tilt
|
||||||
|
file_destination.gsub!(file_extension, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
destination = base.tilt_template(file_source, file_destination, config, &@block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class GlobAction < BaseAction
|
||||||
|
|
||||||
|
protected
|
||||||
|
def execute!
|
||||||
|
Dir[File.join(source, @config[:glob])].each do |path|
|
||||||
|
file_name = path.gsub(SHARED_SERVER.views + "/", "")
|
||||||
|
if file_name == "layouts"
|
||||||
|
false
|
||||||
|
elsif file_name.include?("layout.") && file_name.split(".").length == 2
|
||||||
|
false
|
||||||
|
else
|
||||||
|
next if File.directory?(path)
|
||||||
|
|
||||||
|
handle_path(path)
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class DirectoryAction < BaseAction
|
||||||
|
def invoke!
|
||||||
|
base.empty_directory given_destination, config
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def handle_directory(lookup, &block)
|
def handle_directory(lookup, &block)
|
||||||
lookup = File.join(lookup, '*')
|
lookup = File.join(lookup, '*')
|
||||||
|
@ -131,19 +182,7 @@ module Middleman
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
# Skip partials prefixed with an underscore
|
handle_path(file_source)
|
||||||
next unless file_source.gsub(SHARED_SERVER.root, '').split('/').select { |p| p[0,1] == '_' }.empty?
|
|
||||||
|
|
||||||
file_extension = File.extname(file_source)
|
|
||||||
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
|
|
||||||
file_destination.gsub!('/./', '/')
|
|
||||||
|
|
||||||
handled_by_tilt = ::Tilt.mappings.has_key?(file_extension.gsub(/^\./, ""))
|
|
||||||
if handled_by_tilt
|
|
||||||
file_destination.gsub!(file_extension, "")
|
|
||||||
end
|
|
||||||
|
|
||||||
destination = base.tilt_template(file_source, file_destination, config, &@block)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,8 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "build", "Builds the static site for deployment"
|
desc "build", "Builds the static site for deployment"
|
||||||
method_option "relative", :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
|
method_option :relative, :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
|
||||||
|
method_option :glob, :type => :string, :aliases => "-g", :default => nil, :desc => 'Build a subset of the project'
|
||||||
def build
|
def build
|
||||||
v1_check
|
v1_check
|
||||||
thor_group = Middleman::Builder.new([], options).invoke_all
|
thor_group = Middleman::Builder.new([], options).invoke_all
|
||||||
|
|
Loading…
Reference in a new issue