Merge branch 'master' of github.com:middleman/middleman
This commit is contained in:
commit
b6f85ccce9
|
@ -33,17 +33,16 @@ end
|
||||||
# Default command is server
|
# Default command is server
|
||||||
ARGV.unshift("server") if ARGV.length < 1 || ARGV.first.include?("-")
|
ARGV.unshift("server") if ARGV.length < 1 || ARGV.first.include?("-")
|
||||||
|
|
||||||
# Require Middleman
|
|
||||||
require 'middleman-core'
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# Rubygems
|
|
||||||
require "middleman-more"
|
|
||||||
rescue LoadError
|
|
||||||
begin
|
|
||||||
# Local
|
# Local
|
||||||
require File.expand_path(File.join(File.dirname(File.dirname(libdir)), "middleman-more", "lib", "middleman-more"))
|
require File.expand_path(File.join(File.dirname(File.dirname(libdir)), "middleman-more", "lib", "middleman-more"))
|
||||||
|
rescue LoadError
|
||||||
|
begin
|
||||||
|
# Rubygems
|
||||||
|
require "middleman-more"
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
# Require Middleman
|
||||||
|
require 'middleman-core'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -15,5 +15,5 @@ Feature: Wildcards in Page helper
|
||||||
Then I should see "Normal Layout"
|
Then I should see "Normal Layout"
|
||||||
When I go to "/admin/"
|
When I go to "/admin/"
|
||||||
Then I should see "Admin Layout"
|
Then I should see "Admin Layout"
|
||||||
When I go to "/admin/page.html"
|
When I go to "/admin/page/"
|
||||||
Then I should see "Admin Layout"
|
Then I should see "Admin Layout"
|
|
@ -371,11 +371,11 @@ class Middleman::Base
|
||||||
# Run before callbacks
|
# Run before callbacks
|
||||||
run_hook :before
|
run_hook :before
|
||||||
|
|
||||||
# Return 404 if not in sitemap
|
|
||||||
return not_found unless sitemap.exists?(@request_path)
|
|
||||||
|
|
||||||
# Get the page object for this path
|
# Get the page object for this path
|
||||||
sitemap_page = sitemap.page(@request_path)
|
sitemap_page = sitemap.page_by_destination(@request_path)
|
||||||
|
|
||||||
|
# Return 404 if not in sitemap
|
||||||
|
return not_found unless sitemap_page
|
||||||
|
|
||||||
# Return 404 if this path is specifically ignored
|
# Return 404 if this path is specifically ignored
|
||||||
return not_found if sitemap_page.ignored?
|
return not_found if sitemap_page.ignored?
|
||||||
|
|
|
@ -31,6 +31,10 @@ module Middleman::Cli
|
||||||
:aliases => "-g",
|
:aliases => "-g",
|
||||||
:default => nil,
|
:default => nil,
|
||||||
:desc => 'Build a subset of the project'
|
:desc => 'Build a subset of the project'
|
||||||
|
method_option :verbose,
|
||||||
|
:type => :boolean,
|
||||||
|
:default => false,
|
||||||
|
:desc => 'Print debug messages'
|
||||||
|
|
||||||
# Core build Thor command
|
# Core build Thor command
|
||||||
# @return [void]
|
# @return [void]
|
||||||
|
@ -40,6 +44,8 @@ module Middleman::Cli
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.class.shared_instance(options["verbose"] || false)
|
||||||
|
|
||||||
if options.has_key?("relative") && options["relative"]
|
if options.has_key?("relative") && options["relative"]
|
||||||
self.class.shared_instance.activate :relative_assets
|
self.class.shared_instance.activate :relative_assets
|
||||||
end
|
end
|
||||||
|
@ -61,9 +67,10 @@ module Middleman::Cli
|
||||||
# Middleman::Base singleton
|
# Middleman::Base singleton
|
||||||
#
|
#
|
||||||
# @return [Middleman::Base]
|
# @return [Middleman::Base]
|
||||||
def shared_instance
|
def shared_instance(verbose=false)
|
||||||
@_shared_instance ||= ::Middleman.server.inst do
|
@_shared_instance ||= ::Middleman.server.inst do
|
||||||
set :environment, :build
|
set :environment, :build
|
||||||
|
set :logging, verbose
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -95,27 +102,20 @@ module Middleman::Cli
|
||||||
# Ignore following method
|
# Ignore following method
|
||||||
desc "", "", :hide => true
|
desc "", "", :hide => true
|
||||||
|
|
||||||
# Render a template to a file.
|
# Render a page to a file.
|
||||||
#
|
#
|
||||||
# @param [String] source
|
# @param [Middleman::Sitemap::Page] page
|
||||||
# @param [String] destination
|
# @return [void]
|
||||||
# @param [Hash] config
|
def tilt_template(page)
|
||||||
# @return [String] the actual destination file path that was created
|
|
||||||
def tilt_template(source, destination, config={})
|
|
||||||
build_dir = self.class.shared_instance.build_dir
|
build_dir = self.class.shared_instance.build_dir
|
||||||
request_path = destination.sub(/^#{build_dir}/, "")
|
output_file = File.join(self.class.shared_instance.build_dir, page.destination_path)
|
||||||
config[:force] = true
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
destination, request_path = self.class.shared_instance.reroute_builder(destination, request_path)
|
response = self.class.shared_rack.get(page.request_path.gsub(/\s/, "%20"))
|
||||||
|
create_file(output_file, response.body, { :force => true })
|
||||||
response = self.class.shared_rack.get(request_path.gsub(/\s/, "%20"))
|
|
||||||
|
|
||||||
create_file(destination, response.body, config)
|
|
||||||
|
|
||||||
destination
|
|
||||||
rescue
|
rescue
|
||||||
say_status :error, destination, :red
|
say_status :error, output_file, :red
|
||||||
|
puts $!
|
||||||
abort
|
abort
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -209,6 +209,8 @@ module Middleman::Cli
|
||||||
# Sort paths to be built by the above order. This is primarily so Compass can
|
# Sort paths to be built by the above order. This is primarily so Compass can
|
||||||
# find files in the build folder when it needs to generate sprites for the
|
# find files in the build folder when it needs to generate sprites for the
|
||||||
# css files
|
# css files
|
||||||
|
|
||||||
|
# TODO: deal with pages, not paths
|
||||||
paths = @app.sitemap.all_paths.sort do |a, b|
|
paths = @app.sitemap.all_paths.sort do |a, b|
|
||||||
a_ext = File.extname(a)
|
a_ext = File.extname(a)
|
||||||
b_ext = File.extname(b)
|
b_ext = File.extname(b)
|
||||||
|
@ -221,21 +223,15 @@ module Middleman::Cli
|
||||||
|
|
||||||
# Loop over all the paths and build them.
|
# Loop over all the paths and build them.
|
||||||
paths.each do |path|
|
paths.each do |path|
|
||||||
file_source = path
|
page = @app.sitemap.page(path)
|
||||||
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
|
|
||||||
file_destination.gsub!('/./', '/')
|
|
||||||
|
|
||||||
if @app.sitemap.proxied?(file_source)
|
next if page.ignored?
|
||||||
file_source = @app.sitemap.page(file_source).proxied_to
|
next if @config[:glob] && !File.fnmatch(@config[:glob], path)
|
||||||
elsif @app.sitemap.page(file_source).ignored?
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
next if @config[:glob] && !File.fnmatch(@config[:glob], file_source)
|
base.tilt_template(page)
|
||||||
|
|
||||||
file_destination = base.tilt_template(file_source, file_destination)
|
output_path = File.join(@destination, page.destination_path)
|
||||||
|
@cleaning_queue.delete(Pathname.new(output_path).realpath) if cleaning?
|
||||||
@cleaning_queue.delete(Pathname.new(file_destination).realpath) if cleaning?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,8 @@ module Middleman::CoreExtensions::Builder
|
||||||
# Build Class Methods
|
# Build Class Methods
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
# Get a list of callbacks which can modify a files build path
|
# Get a list of callbacks which can modify a files build path
|
||||||
#
|
# Each callback takes a destination path and a request path and
|
||||||
|
# returns a new destination path, or false if it doesn't want to reroute.
|
||||||
# @return [Array<Proc>]
|
# @return [Array<Proc>]
|
||||||
def build_reroute(&block)
|
def build_reroute(&block)
|
||||||
@build_rerouters ||= []
|
@build_rerouters ||= []
|
||||||
|
@ -29,14 +30,14 @@ module Middleman::CoreExtensions::Builder
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
# Run through callbacks and get the new values
|
# Run through callbacks and get the new values
|
||||||
#
|
#
|
||||||
# @param [String] destination The current destination of the built file
|
# @param [String] destination The current destination path of the built file
|
||||||
# @param [String] request_path The current request path of the file
|
# @param [String] request_path The request path of the file
|
||||||
# @return [Array<String>] The new values
|
# @return [String] The new destination path
|
||||||
def reroute_builder(destination, request_path)
|
def reroute_builder(destination, request_path)
|
||||||
result = [destination, request_path]
|
result = [destination, request_path]
|
||||||
|
|
||||||
build_reroute.each do |block|
|
build_reroute.each do |block|
|
||||||
output = instance_exec(destination, request_path, &block)
|
output = block.call(destination, request_path)
|
||||||
if output
|
if output
|
||||||
result = output
|
result = output
|
||||||
break
|
break
|
||||||
|
|
|
@ -97,17 +97,17 @@ module Middleman::CoreExtensions::Extensions
|
||||||
# @param [Symbol, Module] ext Which extension to activate
|
# @param [Symbol, Module] ext Which extension to activate
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def activate(ext, options={}, &block)
|
def activate(ext, options={}, &block)
|
||||||
if !ext.is_a?(Module)
|
ext_module = if ext.is_a?(Module)
|
||||||
ext = ::Middleman::Extensions.load(ext.to_sym)
|
ext
|
||||||
|
else
|
||||||
|
::Middleman::Extensions.load(ext.to_sym)
|
||||||
end
|
end
|
||||||
|
|
||||||
if ext.nil?
|
if ext_module.nil?
|
||||||
puts "== Unknown Extension: #{ext}"
|
puts "== Unknown Extension: #{ext}"
|
||||||
elsif ext.is_a?(String)
|
|
||||||
puts ext
|
|
||||||
else
|
else
|
||||||
puts "== Activating: #{ext}" if logging?
|
puts "== Activating: #{ext}" if logging?
|
||||||
self.class.register(ext, options, &block)
|
self.class.register(ext_module, options, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ module Middleman::CoreExtensions::Routing
|
||||||
|
|
||||||
# Setup proxy
|
# Setup proxy
|
||||||
if opts.has_key?(:proxy)
|
if opts.has_key?(:proxy)
|
||||||
reroute(url, opts[:proxy])
|
proxy(url, opts[:proxy])
|
||||||
|
|
||||||
if opts.has_key?(:ignore) && opts[:ignore]
|
if opts.has_key?(:ignore) && opts[:ignore]
|
||||||
ignore(opts[:proxy])
|
ignore(opts[:proxy])
|
||||||
|
|
|
@ -74,7 +74,7 @@ module Middleman::CoreExtensions::Sitemap
|
||||||
# @param [String] url
|
# @param [String] url
|
||||||
# @param [String] target
|
# @param [String] target
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def reroute(*args)
|
def proxy(*args)
|
||||||
sitemap.proxy(*args)
|
sitemap.proxy(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,72 +12,33 @@ module Middleman::Extensions
|
||||||
# Include methods
|
# Include methods
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
|
|
||||||
# Before requests
|
app.after_configuration do
|
||||||
app.before do
|
# Register a reroute transform that turns regular paths into indexed paths
|
||||||
prefix = @original_path.sub(/\/$/, "")
|
sitemap.reroute do |destination, page|
|
||||||
indexed_path = prefix + "/" + index_file
|
|
||||||
extensioned_path = prefix + File.extname(index_file)
|
|
||||||
|
|
||||||
is_ignored = false
|
|
||||||
fm_ignored = false
|
|
||||||
|
|
||||||
# If the sitemap knows about the path
|
|
||||||
if sitemap.exists?(@original_path)
|
|
||||||
# Inspect frontmatter
|
|
||||||
d = sitemap.page(@original_path).data
|
|
||||||
|
|
||||||
# Allow the frontmatter to ignore a directory index
|
|
||||||
if !d.nil? && d.has_key?("directory_index") && d["directory_index"] == false
|
|
||||||
fm_ignored = true
|
|
||||||
else
|
|
||||||
next
|
|
||||||
end
|
|
||||||
else
|
|
||||||
# Otherwise check this extension for list of ignored indexes
|
|
||||||
is_ignored = ignored_directory_indexes.include?(extensioned_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
# If we're going to remap to a directory index
|
|
||||||
if !sitemap.exists?(indexed_path) && !is_ignored && !fm_ignored
|
|
||||||
parts = @original_path.split("/")
|
|
||||||
last_part = parts.last
|
|
||||||
last_part_ext = File.extname(last_part)
|
|
||||||
|
|
||||||
# Change the request
|
|
||||||
if last_part_ext.blank?
|
|
||||||
# This is a folder, redirect to index
|
|
||||||
@request_path = extensioned_path
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Basically does the same as above, but in build mode
|
|
||||||
app.build_reroute do |destination, request_path|
|
|
||||||
index_ext = File.extname(index_file)
|
|
||||||
new_index_path = "/#{index_file}"
|
new_index_path = "/#{index_file}"
|
||||||
frontmatter_ignore = false
|
frontmatter_ignore = false
|
||||||
|
|
||||||
# Check for file and frontmatter
|
# Check for file and frontmatter
|
||||||
if sitemap.exists?(request_path)
|
d = page.data
|
||||||
p = sitemap.page(request_path)
|
if !page.data.nil?
|
||||||
d = p.data
|
|
||||||
if !d.nil?
|
|
||||||
frontmatter_ignore = d.has_key?("directory_index") && d["directory_index"] == false
|
frontmatter_ignore = d.has_key?("directory_index") && d["directory_index"] == false
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
index_ext = File.extname(index_file)
|
||||||
|
|
||||||
# Only reroute if not ignored
|
# Only reroute if not ignored
|
||||||
if ignored_directory_indexes.include?(request_path)
|
path = page.path
|
||||||
false
|
if ignored_directory_indexes.include? page
|
||||||
elsif request_path =~ /#{new_index_path}$/
|
destination
|
||||||
false
|
elsif path == index_file || path.end_with?(new_index_path)
|
||||||
|
destination
|
||||||
elsif frontmatter_ignore
|
elsif frontmatter_ignore
|
||||||
false
|
destination
|
||||||
|
elsif index_ext != File.extname(path)
|
||||||
|
destination
|
||||||
else
|
else
|
||||||
[
|
destination.chomp(File.extname(index_file)) + new_index_path
|
||||||
destination.sub(/#{index_ext.gsub(".", "\\.")}$/, new_index_path),
|
end
|
||||||
request_path
|
|
||||||
]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -85,10 +46,9 @@ module Middleman::Extensions
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
# Directory indexes instance methods
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
# A list of pages which will not use directory indexes
|
# A list of pages which will not use directory indexes
|
||||||
# @return [Array<String>]
|
# @return [Array<Middleman::Sitemap::Page>]
|
||||||
def ignored_directory_indexes
|
def ignored_directory_indexes
|
||||||
@_ignored_directory_indexes ||= []
|
@_ignored_directory_indexes ||= []
|
||||||
end
|
end
|
||||||
|
@ -100,7 +60,7 @@ module Middleman::Extensions
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def page(url, options={}, &block)
|
def page(url, options={}, &block)
|
||||||
if options.has_key?(:directory_index) && !options["directory_index"]
|
if options.has_key?(:directory_index) && !options["directory_index"]
|
||||||
ignored_directory_indexes << url
|
ignored_directory_indexes << sitemap.page(url)
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,8 @@ module Middleman::Sitemap
|
||||||
# @return [Middleman::Sitemap::Store]
|
# @return [Middleman::Sitemap::Store]
|
||||||
attr_accessor :store
|
attr_accessor :store
|
||||||
|
|
||||||
|
# The source path of this page (relative to the source directory,
|
||||||
|
# without template extensions)
|
||||||
# @return [String]
|
# @return [String]
|
||||||
attr_accessor :path
|
attr_accessor :path
|
||||||
|
|
||||||
|
@ -41,9 +43,9 @@ module Middleman::Sitemap
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def request_path
|
def request_path
|
||||||
if proxy?
|
if proxy?
|
||||||
store.page(proxied_to).path
|
store.page(proxied_to).destination_path
|
||||||
else
|
else
|
||||||
path
|
destination_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -186,6 +188,16 @@ module Middleman::Sitemap
|
||||||
self.source_file ? self.source_file.sub(app.source_dir, '') : nil
|
self.source_file ? self.source_file.sub(app.source_dir, '') : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Get the destination path, relative to the build directory.
|
||||||
|
# This path can be affected by proxy callbacks.
|
||||||
|
# @return [String]
|
||||||
|
def destination_path
|
||||||
|
# TODO: memoize this value
|
||||||
|
store.reroute_callbacks.inject(self.path) do |destination, callback|
|
||||||
|
callback.call(destination, self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# This page's frontmatter
|
# This page's frontmatter
|
||||||
# @return [Hash, nil]
|
# @return [Hash, nil]
|
||||||
def data
|
def data
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
module Middleman::Sitemap
|
module Middleman::Sitemap
|
||||||
|
|
||||||
# The Store class
|
# The Store class
|
||||||
|
#
|
||||||
|
# The Store manages a collection of Page objects, which represent
|
||||||
|
# individual items in the sitemap. Pages are indexed by "source path",
|
||||||
|
# which is the path relative to the source directory, minus any template
|
||||||
|
# extensions. All "path" parameters used in this class are source paths.
|
||||||
class Store
|
class Store
|
||||||
|
|
||||||
# @return [Middleman::Base]
|
# @return [Middleman::Base]
|
||||||
|
@ -16,24 +21,25 @@ module Middleman::Sitemap
|
||||||
@ignored_globs = []
|
@ignored_globs = []
|
||||||
@ignored_regexes = []
|
@ignored_regexes = []
|
||||||
@ignored_callbacks = []
|
@ignored_callbacks = []
|
||||||
|
@reroute_callbacks = []
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check to see if we know about a specific path
|
# Check to see if we know about a specific path
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def exists?(path)
|
def exists?(path)
|
||||||
@pages.has_key?(path.sub(/^\//, ""))
|
@pages.has_key?(normalize_path(path))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Ignore a path or add an ignore callback
|
# Ignore a path or add an ignore callback
|
||||||
# @param [String, Regexp] path
|
# @param [String, Regexp] path, path glob expression, or path regex
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def ignore(path=nil, &block)
|
def ignore(path=nil, &block)
|
||||||
if !path.nil? && path.include?("*")
|
if !path.nil? && path.include?("*")
|
||||||
path_clean = path.sub(/^\//, "")
|
path_clean = normalize_path(path)
|
||||||
@ignored_globs << path_clean unless @ignored_globs.include?(path_clean)
|
@ignored_globs << path_clean unless @ignored_globs.include?(path_clean)
|
||||||
elsif path.is_a? String
|
elsif path.is_a? String
|
||||||
path_clean = path.sub(/^\//, "")
|
path_clean = normalize_path(path)
|
||||||
@ignored_paths << path_clean unless @ignored_paths.include?(path_clean)
|
@ignored_paths << path_clean unless @ignored_paths.include?(path_clean)
|
||||||
elsif path.is_a? Regexp
|
elsif path.is_a? Regexp
|
||||||
@ignored_regexes << path unless @ignored_regexes.include?(path)
|
@ignored_regexes << path unless @ignored_regexes.include?(path)
|
||||||
|
@ -42,28 +48,47 @@ module Middleman::Sitemap
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Add a callback that will be run with each page's destination path
|
||||||
|
# and can produce a new destination path or pass through the old one.
|
||||||
|
# @return [void]
|
||||||
|
def reroute(&block)
|
||||||
|
@reroute_callbacks << block if block_given?
|
||||||
|
end
|
||||||
|
|
||||||
|
# The list of reroute callbacks
|
||||||
|
# @return [Array<Proc>]
|
||||||
|
def reroute_callbacks
|
||||||
|
@reroute_callbacks
|
||||||
|
end
|
||||||
|
|
||||||
# Setup a proxy from a path to a target
|
# Setup a proxy from a path to a target
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @param [String] target
|
# @param [String] target
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def proxy(path, target)
|
def proxy(path, target)
|
||||||
page(path) { proxy_to(target.sub(%r{^/}, "")) }
|
page(path).proxy_to(normalize_path(target))
|
||||||
app.cache.remove(:proxied_paths)
|
app.cache.remove(:proxied_paths)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get a page instance for a given path
|
# Get a page instance for a given path
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [Middleman::Sitemap::Page]
|
# @return [Middleman::Sitemap::Page]
|
||||||
def page(path, &block)
|
def page(path)
|
||||||
path = path.sub(/^\//, "").gsub("%20", " ")
|
path = normalize_path(path)
|
||||||
@pages[path] = ::Middleman::Sitemap::Page.new(self, path) unless @pages.has_key?(path)
|
@pages.fetch(path) { @pages[path] = ::Middleman::Sitemap::Page.new(self, path) }
|
||||||
@pages[path].instance_exec(&block) if block_given?
|
end
|
||||||
@pages[path]
|
|
||||||
|
# Find a page given its destination path
|
||||||
|
def page_by_destination(destination_path)
|
||||||
|
# TODO: memoize this
|
||||||
|
destination_path = normalize_path(destination_path)
|
||||||
|
@pages.values.find {|p| p.destination_path == destination_path }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Loop over known pages
|
# Loop over known pages
|
||||||
|
# @yield [path, page]
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def each(&block)
|
def each
|
||||||
@pages.each do |k, v|
|
@pages.each do |k, v|
|
||||||
yield k, v
|
yield k, v
|
||||||
end
|
end
|
||||||
|
@ -79,15 +104,15 @@ module Middleman::Sitemap
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def ignored?(path)
|
def ignored?(path)
|
||||||
path_clean = path.sub(/^\//, "")
|
path_clean = normalize_path(path)
|
||||||
|
|
||||||
# $stderr.puts path_clean, @ignored_globs, @ignored_paths
|
|
||||||
|
|
||||||
return true if @ignored_paths.include?(path_clean)
|
return true if @ignored_paths.include?(path_clean)
|
||||||
return true if @ignored_globs.any? { |g| File.fnmatch(g, path_clean) }
|
return true if @ignored_globs.any? { |g| File.fnmatch(g, path_clean) }
|
||||||
return true if @ignored_regexes.any? { |r| r.match(path_clean) }
|
return true if @ignored_regexes.any? { |r| r.match(path_clean) }
|
||||||
return true if @ignored_callbacks.any? { |b| b.call(path_clean) }
|
return true if @ignored_callbacks.any? { |b| b.call(path_clean) }
|
||||||
|
|
||||||
|
# TODO: We should also check ignored_sitemap_matchers here
|
||||||
|
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -101,7 +126,7 @@ module Middleman::Sitemap
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def generic?(path)
|
def generic?(path)
|
||||||
generic_paths.include?(path.sub(/^\//, ""))
|
generic_paths.include?(normalize_path(path))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get a list of generic paths
|
# Get a list of generic paths
|
||||||
|
@ -116,7 +141,7 @@ module Middleman::Sitemap
|
||||||
# @param [String] path
|
# @param [String] path
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def proxied?(path)
|
def proxied?(path)
|
||||||
proxied_paths.include?(path.sub(/^\//, ""))
|
proxied_paths.include?(normalize_path(path))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get a list of proxied paths
|
# Get a list of proxied paths
|
||||||
|
@ -134,7 +159,7 @@ module Middleman::Sitemap
|
||||||
path = file_to_path(file)
|
path = file_to_path(file)
|
||||||
return false unless path
|
return false unless path
|
||||||
|
|
||||||
path = path.sub(/^\//, "")
|
path = normalize_path(path)
|
||||||
if @pages.has_key?(path)
|
if @pages.has_key?(path)
|
||||||
page(path).delete()
|
page(path).delete()
|
||||||
@pages.delete(path)
|
@pages.delete(path)
|
||||||
|
@ -189,7 +214,7 @@ module Middleman::Sitemap
|
||||||
|
|
||||||
# Get a path without templating extensions
|
# Get a path without templating extensions
|
||||||
# @param [String] file
|
# @param [String] file
|
||||||
# @param [String]
|
# @return [String]
|
||||||
def extensionless_path(file)
|
def extensionless_path(file)
|
||||||
app.cache.fetch(:extensionless_path, file) do
|
app.cache.fetch(:extensionless_path, file) do
|
||||||
path = file.dup
|
path = file.dup
|
||||||
|
@ -206,5 +231,12 @@ module Middleman::Sitemap
|
||||||
path
|
path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Normalize a path to not include a leading slash
|
||||||
|
# @param [String] path
|
||||||
|
# @return [String]
|
||||||
|
def normalize_path(path)
|
||||||
|
path.sub(/^\//, "").gsub("%20", " ")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,6 +40,7 @@ module Middleman
|
||||||
$LOAD_PATH << File.expand_path('../../middleman-core/vendor/linux/lib', __FILE__)
|
$LOAD_PATH << File.expand_path('../../middleman-core/vendor/linux/lib', __FILE__)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
register_signal_handlers
|
||||||
start
|
start
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,7 +64,9 @@ module Middleman
|
||||||
bootup
|
bootup
|
||||||
else
|
else
|
||||||
@server_job = fork {
|
@server_job = fork {
|
||||||
Signal.trap(::Middleman::WINDOWS ? :KILL : :TERM) { exit! }
|
trap("INT") { exit(0) }
|
||||||
|
trap("TERM") { exit(0) }
|
||||||
|
trap("QUIT") { exit(0) }
|
||||||
bootup
|
bootup
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -95,8 +98,8 @@ module Middleman
|
||||||
puts "== The Middleman is shutting down"
|
puts "== The Middleman is shutting down"
|
||||||
if !@options[:"disable-watcher"]
|
if !@options[:"disable-watcher"]
|
||||||
Process.kill(::Middleman::WINDOWS ? :KILL : :TERM, @server_job)
|
Process.kill(::Middleman::WINDOWS ? :KILL : :TERM, @server_job)
|
||||||
Process.wait @server_job
|
# Process.wait @server_job
|
||||||
@server_job = nil
|
# @server_job = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -134,6 +137,13 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
# Trap the interupt signal and shut down FSSM (and thus the server) smoothly
|
||||||
|
def register_signal_handlers
|
||||||
|
trap("INT") { stop; exit(0) }
|
||||||
|
trap("TERM") { stop; exit(0) }
|
||||||
|
trap("QUIT") { stop; exit(0) }
|
||||||
|
end
|
||||||
|
|
||||||
# Whether the passed files are config.rb, lib/*.rb or helpers
|
# Whether the passed files are config.rb, lib/*.rb or helpers
|
||||||
# @param [Array<String>] paths Array of paths to check
|
# @param [Array<String>] paths Array of paths to check
|
||||||
# @return [Boolean] Whether the server needs to reload
|
# @return [Boolean] Whether the server needs to reload
|
||||||
|
@ -152,9 +162,3 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Trap the interupt signal and shut down FSSM (and thus the server) smoothly
|
|
||||||
trap(::Middleman::Watcher.kill_command) do
|
|
||||||
::Middleman::Watcher.singleton.stop
|
|
||||||
exit(0)
|
|
||||||
end
|
|
|
@ -1,12 +1,21 @@
|
||||||
Feature: Relative Assets
|
Feature: Relative Assets
|
||||||
In order easily switch between relative and absolute paths
|
In order easily switch between relative and absolute paths
|
||||||
|
|
||||||
Scenario: Rendering css with the feature disabled
|
Scenario: Previewing css with the feature disabled
|
||||||
Given "relative_assets" feature is "disabled"
|
Given "relative_assets" feature is "disabled"
|
||||||
And the Server is running at "relative-assets-app"
|
And the Server is running at "relative-assets-app"
|
||||||
When I go to "/stylesheets/relative_assets.css"
|
When I go to "/stylesheets/relative_assets.css"
|
||||||
Then I should not see "url('../"
|
Then I should not see "url('../"
|
||||||
And I should see "/images/blank.gif"
|
And I should see "/images/blank.gif')"
|
||||||
|
|
||||||
|
Scenario: Building css with the feature disabled
|
||||||
|
Given a fixture app "relative-assets-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
Given a successfully built app at "relative-assets-app"
|
||||||
|
When I cd to "build"
|
||||||
|
Then the file "stylesheets/relative_assets.css" should contain "url('/images/blank.gif')"
|
||||||
|
|
||||||
Scenario: Rendering html with the feature disabled
|
Scenario: Rendering html with the feature disabled
|
||||||
Given "relative_assets" feature is "disabled"
|
Given "relative_assets" feature is "disabled"
|
||||||
|
@ -20,6 +29,16 @@ Feature: Relative Assets
|
||||||
When I go to "/stylesheets/relative_assets.css"
|
When I go to "/stylesheets/relative_assets.css"
|
||||||
Then I should see "url('../images/blank.gif"
|
Then I should see "url('../images/blank.gif"
|
||||||
|
|
||||||
|
Scenario: Building css with the feature enabled
|
||||||
|
Given a fixture app "relative-assets-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
activate :relative_assets
|
||||||
|
"""
|
||||||
|
Given a successfully built app at "relative-assets-app"
|
||||||
|
When I cd to "build"
|
||||||
|
Then the file "stylesheets/relative_assets.css" should contain "url('../images/blank.gif')"
|
||||||
|
|
||||||
Scenario: Rendering html with the feature enabled
|
Scenario: Rendering html with the feature enabled
|
||||||
Given "relative_assets" feature is "enabled"
|
Given "relative_assets" feature is "enabled"
|
||||||
And the Server is running at "relative-assets-app"
|
And the Server is running at "relative-assets-app"
|
||||||
|
@ -27,14 +46,25 @@ Feature: Relative Assets
|
||||||
Then I should not see "/images/blank.gif"
|
Then I should not see "/images/blank.gif"
|
||||||
And I should see "images/blank.gif"
|
And I should see "images/blank.gif"
|
||||||
|
|
||||||
Scenario: Rendering html with a custom images_dir
|
Scenario: Rendering css with a custom images_dir
|
||||||
Given "relative_assets" feature is "enabled"
|
Given "relative_assets" feature is "enabled"
|
||||||
And "images_dir" is set to "img"
|
And "images_dir" is set to "img"
|
||||||
And the Server is running at "relative-assets-app"
|
And the Server is running at "relative-assets-app"
|
||||||
When I go to "/stylesheets/relative_assets.css"
|
When I go to "/stylesheets/relative_assets.css"
|
||||||
Then I should see "url('../img/blank.gif"
|
Then I should see "url('../img/blank.gif')"
|
||||||
|
|
||||||
Scenario: Rendering css with a custom images_dir
|
Scenario: Building css with a custom images_dir
|
||||||
|
Given a fixture app "relative-assets-app"
|
||||||
|
And a file named "config.rb" with:
|
||||||
|
"""
|
||||||
|
set :images_dir, "img"
|
||||||
|
activate :relative_assets
|
||||||
|
"""
|
||||||
|
Given a successfully built app at "relative-assets-app"
|
||||||
|
When I cd to "build"
|
||||||
|
Then the file "stylesheets/relative_assets.css" should contain "url('../img/blank.gif')"
|
||||||
|
|
||||||
|
Scenario: Rendering html with a custom images_dir
|
||||||
Given "relative_assets" feature is "enabled"
|
Given "relative_assets" feature is "enabled"
|
||||||
And "images_dir" is set to "img"
|
And "images_dir" is set to "img"
|
||||||
And the Server is running at "relative-assets-app"
|
And the Server is running at "relative-assets-app"
|
||||||
|
@ -43,8 +73,9 @@ Feature: Relative Assets
|
||||||
Then I should not see "/img/blank.gif"
|
Then I should not see "/img/blank.gif"
|
||||||
And I should see "img/blank.gif"
|
And I should see "img/blank.gif"
|
||||||
|
|
||||||
|
|
||||||
Scenario: Rendering scss with the feature enabled
|
Scenario: Rendering scss with the feature enabled
|
||||||
Given "relative_assets" feature is "enabled"
|
Given "relative_assets" feature is "enabled"
|
||||||
And the Server is running at "fonts-app"
|
And the Server is running at "fonts-app"
|
||||||
When I go to "/stylesheets/fonts.css"
|
When I go to "/stylesheets/fonts.css"
|
||||||
Then I should see "url('../fonts/StMarie"
|
Then I should see "url('../fonts/StMarie-Thin.otf"
|
|
@ -0,0 +1 @@
|
||||||
|
# activate :relative_assets
|
|
@ -16,38 +16,15 @@ module Middleman::CoreExtensions::Compass
|
||||||
|
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
::Compass.configuration do |config|
|
::Compass.configuration do |config|
|
||||||
config.project_path = root
|
config.project_path = source_dir
|
||||||
config.environment = :development
|
config.environment = :development
|
||||||
config.cache_path = File.join(root, ".sass-cache")
|
config.cache_path = File.join(root, ".sass-cache")
|
||||||
config.sass_dir = File.join(source, css_dir)
|
config.sass_dir = css_dir
|
||||||
config.css_dir = File.join(source, css_dir)
|
config.css_dir = css_dir
|
||||||
config.javascripts_dir = File.join(source, js_dir)
|
config.javascripts_dir = js_dir
|
||||||
config.fonts_dir = File.join(source, fonts_dir)
|
config.fonts_dir = fonts_dir
|
||||||
config.images_dir = File.join(source, images_dir)
|
config.images_dir = images_dir
|
||||||
|
config.http_path = http_prefix
|
||||||
config.http_images_path = if respond_to? :http_images_path
|
|
||||||
http_images_path
|
|
||||||
else
|
|
||||||
File.join(http_prefix, images_dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
config.http_stylesheets_path = if respond_to? :http_css_path
|
|
||||||
http_css_path
|
|
||||||
else
|
|
||||||
File.join(http_prefix, css_dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
config.http_javascripts_path = if respond_to? :http_js_path
|
|
||||||
http_js_path
|
|
||||||
else
|
|
||||||
File.join(http_prefix, js_dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
config.http_fonts_path = if respond_to? :http_fonts_path
|
|
||||||
http_fonts_path
|
|
||||||
else
|
|
||||||
File.join(http_prefix, fonts_dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
config.asset_cache_buster :none
|
config.asset_cache_buster :none
|
||||||
config.output_style = :nested
|
config.output_style = :nested
|
||||||
|
@ -57,15 +34,11 @@ module Middleman::CoreExtensions::Compass
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Change paths when in build mode. Required for relative paths
|
# if build?
|
||||||
configure :build do
|
# ::Compass.configuration do |config|
|
||||||
::Compass.configuration do |config|
|
# config.environment = :production
|
||||||
config.environment = :production
|
# end
|
||||||
config.css_dir = File.join(build_dir, css_dir)
|
# end
|
||||||
config.images_dir = File.join(build_dir, images_dir)
|
|
||||||
config.fonts_dir = File.join(build_dir, fonts_dir)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
run_hook :compass_config, ::Compass.configuration
|
run_hook :compass_config, ::Compass.configuration
|
||||||
run_hook :after_compass_config
|
run_hook :after_compass_config
|
||||||
|
|
|
@ -70,5 +70,5 @@ module Middleman::Extensions
|
||||||
end
|
end
|
||||||
|
|
||||||
# Register the extension
|
# Register the extension
|
||||||
register :cache_buster, CacheBuster
|
# register :cache_buster, CacheBuster
|
||||||
end
|
end
|
|
@ -22,5 +22,5 @@ module Middleman::Extensions
|
||||||
end
|
end
|
||||||
|
|
||||||
# Register extension
|
# Register extension
|
||||||
register :minify_css, MinifyCss
|
# register :minify_css, MinifyCss
|
||||||
end
|
end
|
|
@ -73,5 +73,5 @@ module Middleman::Extensions
|
||||||
end
|
end
|
||||||
|
|
||||||
# Register extension
|
# Register extension
|
||||||
register :minify_javascript, MinifyJavascript
|
# register :minify_javascript, MinifyJavascript
|
||||||
end
|
end
|
|
@ -17,6 +17,7 @@ module Middleman::Extensions
|
||||||
# Include instance methods
|
# Include instance methods
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -58,5 +59,5 @@ module Middleman::Extensions
|
||||||
end
|
end
|
||||||
|
|
||||||
# Register extension
|
# Register extension
|
||||||
register :relative_assets, RelativeAssets
|
# register :relative_assets, RelativeAssets
|
||||||
end
|
end
|
|
@ -1,7 +1,10 @@
|
||||||
# Pull in gems
|
# Pull in gems
|
||||||
require "sass"
|
|
||||||
require "sprockets"
|
require "sprockets"
|
||||||
require "sprockets-sass"
|
require "sprockets-sass"
|
||||||
|
require "sass"
|
||||||
|
|
||||||
|
# Stick with Compass' asset functions
|
||||||
|
Sprockets::Sass.add_sass_functions = false
|
||||||
|
|
||||||
# Sass renderer
|
# Sass renderer
|
||||||
module Middleman::Renderers::Sass
|
module Middleman::Renderers::Sass
|
||||||
|
|
|
@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
||||||
s.add_dependency("uglifier", ["~> 1.2.0"])
|
s.add_dependency("uglifier", ["~> 1.2.0"])
|
||||||
s.add_dependency("haml", ["~> 3.1.0"])
|
s.add_dependency("haml", ["~> 3.1.0"])
|
||||||
s.add_dependency("sass", ["~> 3.1.7"])
|
s.add_dependency("sass", ["~> 3.1.7"])
|
||||||
s.add_dependency("compass", ["~> 0.11.3"])
|
s.add_dependency("compass", ["0.12.rc.1"])
|
||||||
s.add_dependency("coffee-script", ["~> 2.2.0"])
|
s.add_dependency("coffee-script", ["~> 2.2.0"])
|
||||||
s.add_dependency("execjs", ["~> 1.2.7"])
|
s.add_dependency("execjs", ["~> 1.2.7"])
|
||||||
s.add_dependency("sprockets", ["~> 2.1.0"])
|
s.add_dependency("sprockets", ["~> 2.1.0"])
|
||||||
|
|
Loading…
Reference in a new issue