final copping

This commit is contained in:
Thomas Reynolds 2014-07-02 11:05:57 -07:00
parent 5a936d315d
commit 6bb9673630
11 changed files with 57 additions and 51 deletions

View file

@ -32,9 +32,10 @@ module Middleman
def include_environment(name) def include_environment(name)
path = File.dirname(__FILE__) path = File.dirname(__FILE__)
other_config = File.join(path, name.to_s) other_config = File.join(path, name.to_s)
if File.exist? other_config
instance_eval File.read(other_config), other_config, 1 return unless File.exist? other_config
end
instance_eval File.read(other_config), other_config, 1
end end
def ready(&block) def ready(&block)

View file

@ -17,16 +17,16 @@ module Middleman
def after_configuration def after_configuration
helpers_path = File.join(app.root, app.config[:helpers_dir]) helpers_path = File.join(app.root, app.config[:helpers_dir])
if File.exist?(helpers_path) return unless File.exist?(helpers_path)
Dir[File.join(helpers_path, app.config[:helpers_filename_glob])].each do |filename|
module_name = app.config[:helpers_filename_to_module_name_proc].call(filename)
next unless module_name
require filename Dir[File.join(helpers_path, app.config[:helpers_filename_glob])].each do |filename|
next unless Object.const_defined?(module_name.to_sym) module_name = app.config[:helpers_filename_to_module_name_proc].call(filename)
next unless module_name
app.template_context_class.send :include, Object.const_get(module_name.to_sym) require filename
end next unless Object.const_defined?(module_name.to_sym)
app.template_context_class.send :include, Object.const_get(module_name.to_sym)
end end
end end
end end

View file

@ -81,9 +81,9 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
# This is for backwards compatibility with the old provides_metadata-based code # This is for backwards compatibility with the old provides_metadata-based code
# that used to be in this extension, but I don't know how much sense it makes. # that used to be in this extension, but I don't know how much sense it makes.
unless resource.options[:lang] next if resource.options[:lang]
resource.add_metadata options: { lang: @mount_at_root }, locals: { lang: @mount_at_root }
end resource.add_metadata options: { lang: @mount_at_root }, locals: { lang: @mount_at_root }
end end
resources + new_resources resources + new_resources

View file

@ -61,9 +61,7 @@ module Middleman
end end
end end
if path.is_a?(String) path = '/' + Util.strip_leading_slash(path) if path.is_a?(String)
path = '/' + Util.strip_leading_slash(path)
end
@page_configs << [path, metadata] @page_configs << [path, metadata]
end end

View file

@ -233,10 +233,11 @@ module Middleman
@app = app @app = app
ext = self ext = self
if ext.respond_to?(:instance_available)
@klass.instance_available do return unless ext.respond_to?(:instance_available)
ext.instance_available
end @klass.instance_available do
ext.instance_available
end end
end end

View file

@ -67,10 +67,10 @@ module Middleman
raise 'You must provide a Middleman::Extension or a block that returns a Middleman::Extension' raise 'You must provide a Middleman::Extension or a block that returns a Middleman::Extension'
end end
if options[:auto_activate] return unless options[:auto_activate]
descriptor = AutoActivation.new(name, options[:modes] || :all)
@auto_activate[options[:auto_activate]] << descriptor descriptor = AutoActivation.new(name, options[:modes] || :all)
end @auto_activate[options[:auto_activate]] << descriptor
end end
# @api private # @api private
@ -114,9 +114,9 @@ module Middleman
# @param [Middleman::Application] app An instance of the app. # @param [Middleman::Application] app An instance of the app.
def auto_activate(group, app) def auto_activate(group, app)
@auto_activate[group].each do |descriptor| @auto_activate[group].each do |descriptor|
if descriptor[:modes] == :all || descriptor[:modes].include?(app.config[:mode]) next unless descriptor[:modes] == :all || descriptor[:modes].include?(app.config[:mode])
app.activate descriptor[:name]
end app.activate descriptor[:name]
end end
end end
end end

View file

@ -35,12 +35,11 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
asset_path asset_path
end end
if asset_page = app.sitemap.find_resource_by_path(full_asset_path) return unless asset_page = app.sitemap.find_resource_by_path(full_asset_path)
replacement_path = "/#{asset_page.destination_path}"
replacement_path = Pathname.new(replacement_path).relative_path_from(dirpath).to_s if relative_path
replacement_path replacement_path = "/#{asset_page.destination_path}"
end replacement_path = Pathname.new(replacement_path).relative_path_from(dirpath).to_s if relative_path
replacement_path
end end
# Update the main sitemap resource list # Update the main sitemap resource list

View file

@ -29,9 +29,9 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
asset_path asset_path
end end
if !full_asset_path.include?('//') && !asset_path.start_with?('data:') return unless !full_asset_path.include?('//') && !asset_path.start_with?('data:')
current_dir = Pathname('/' + request_path).dirname
Pathname(full_asset_path).relative_path_from(current_dir).to_s current_dir = Pathname('/' + request_path).dirname
end Pathname(full_asset_path).relative_path_from(current_dir).to_s
end end
end end

View file

@ -2,6 +2,7 @@ require 'webrick'
require 'middleman-core/meta_pages' require 'middleman-core/meta_pages'
require 'middleman-core/logger' require 'middleman-core/logger'
# rubocop:disable GlobalVars
module Middleman module Middleman
module PreviewServer module PreviewServer
DEFAULT_PORT = 4567 DEFAULT_PORT = 4567
@ -110,12 +111,12 @@ module Middleman
end end
def start_file_watcher def start_file_watcher
return if @listener or @options[:disable_watcher] return if @listener || @options[:disable_watcher]
# Watcher Library # Watcher Library
require 'listen' require 'listen'
options = {force_polling: @options[:force_polling]} options = { force_polling: @options[:force_polling] }
options[:latency] = @options[:latency] if @options[:latency] options[:latency] = @options[:latency] if @options[:latency]
@listener = Listen.to(Dir.pwd, options) do |modified, added, removed| @listener = Listen.to(Dir.pwd, options) do |modified, added, removed|
@ -153,6 +154,7 @@ module Middleman
Signal.trap(sig) do Signal.trap(sig) do
# Do as little work as possible in the signal context # Do as little work as possible in the signal context
$mm_shutdown = true $mm_shutdown = true
@webrick.stop @webrick.stop
end end
end end

View file

@ -12,10 +12,10 @@ module Middleman
def manipulate_resource_list(resources) def manipulate_resource_list(resources)
resources.each do |resource| resources.each do |resource|
next unless resource.source_file =~ %r{\.liquid$}
# Convert data object into a hash for liquid # Convert data object into a hash for liquid
if resource.source_file =~ %r{\.liquid$} resource.add_metadata locals: { data: app.data.to_h }
resource.add_metadata locals: { data: app.data.to_h }
end
end end
end end
end end

View file

@ -100,15 +100,15 @@ module Middleman
# @param [String] path A path as a string # @param [String] path A path as a string
# @return [Boolean] Whether the path matches the matcher # @return [Boolean] Whether the path matches the matcher
def path_match(matcher, path) def path_match(matcher, path)
!!case case
when matcher.is_a?(String) when matcher.is_a?(String)
if matcher.include? '*' if matcher.include? '*'
File.fnmatch(matcher, path) File.fnmatch(matcher, path)
else else
path == matcher path == matcher
end end
when matcher.respond_to?(:match) when matcher.respond_to?(:match)
matcher.match(path) !matcher.match(path).nil?
when matcher.respond_to?(:call) when matcher.respond_to?(:call)
matcher.call(path) matcher.call(path)
else else
@ -149,11 +149,16 @@ module Middleman
return source if source.to_s.include?('//') || source.to_s.start_with?('data:') return source if source.to_s.include?('//') || source.to_s.start_with?('data:')
asset_folder = case kind asset_folder = case kind
when :css then app.config[:css_dir] when :css
when :js then app.config[:js_dir] app.config[:css_dir]
when :images then app.config[:images_dir] when :js
when :fonts then app.config[:fonts_dir] app.config[:js_dir]
else kind.to_s when :images
app.config[:images_dir]
when :fonts
app.config[:fonts_dir]
else
kind.to_s
end end
source = source.to_s.tr(' ', '') source = source.to_s.tr(' ', '')
@ -172,7 +177,7 @@ module Middleman
# @return [String] The fully qualified asset url # @return [String] The fully qualified asset url
def asset_url(app, path, prefix='', _options={}) def asset_url(app, path, prefix='', _options={})
# Don't touch assets which already have a full path # Don't touch assets which already have a full path
if path.include?('//') or path.start_with?('data:') if path.include?('//') || path.start_with?('data:')
path path
else # rewrite paths to use their destination path else # rewrite paths to use their destination path
if resource = app.sitemap.find_resource_by_destination_path(url_for(app, path)) if resource = app.sitemap.find_resource_by_destination_path(url_for(app, path))