prep alpha, backwards compat

This commit is contained in:
Thomas Reynolds 2014-12-23 14:54:21 -08:00
parent d8e8b06cb6
commit ee4c68b03c
16 changed files with 94 additions and 23 deletions

View file

@ -84,7 +84,6 @@ module Middleman::Cli
end
no_tasks do
# Handles incoming events from the builder.
# @param [Symbol] event_type The type of event.
# @param [String] contents The event contents.

View file

@ -319,6 +319,29 @@ module Middleman
config[:environment] == key
end
# Backwards compatible helper. What the current environment is.
# @return [Symbol]
def environment
config[:environment]
end
# Backwards compatible helper. Whether we're in dev mode.
# @return [Boolean]
def development?
environment?(:development)
end
# Backwards compatible helper. Whether we're in production mode.
# @return [Boolean]
def production?
environment?(:production)
end
# Backwards compatible helper. The full path to the default source dir.
def source_dir
Pathname(File.join(root, config[:source]))
end
MiddlewareDescriptor = Struct.new(:class, :options, :block)
# Use Rack middleware

View file

@ -33,7 +33,7 @@ module Middleman
# Setup data files before anything else so they are available when
# parsing config.rb
app.files.changed(:data, &@data_store.method(:update_files))
app.files.on_change(:data, &@data_store.method(:update_files))
end
def after_configuration

View file

@ -35,7 +35,6 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
# The helpers
helpers do
# Make all block content html_safe
def content_tag(name, content=nil, options=nil, &block)
# safe_content_tag(name, content, options, &block)

View file

@ -27,7 +27,7 @@ module Middleman::CoreExtensions
end
def before_configuration
app.files.changed(:source, &method(:clear_data))
app.files.on_change(:source, &method(:clear_data))
end
# @return Array<Middleman::Sitemap::Resource>

View file

@ -23,7 +23,7 @@ class Middleman::CoreExtensions::Internationalization < ::Middleman::Extension
# Setup data files before anything else so they are available when
# parsing config.rb
app.files.changed(:locales, &method(:on_file_changed))
app.files.on_change(:locales, &method(:on_file_changed))
@maps = {}
@mount_at_root = options[:mount_at_root].nil? ? langs.first : options[:mount_at_root]

View file

@ -64,8 +64,8 @@ module Middleman
block
elsif extension_class && extension_class.ancestors.include?(::Middleman::Extension)
extension_class
else
raise 'You must provide a Middleman::Extension or a block that returns a Middleman::Extension'
else
raise 'You must provide a Middleman::Extension or a block that returns a Middleman::Extension'
end
return unless options[:auto_activate]

View file

@ -120,7 +120,7 @@ module Middleman
end
end
app.files.changed :reload do
app.files.on_change :reload do
$mm_reload = true
@webrick.stop
end

View file

@ -24,7 +24,7 @@ module Middleman
super
# Setup Slim options to work with partials
::Slim::Engine.set_default_options(
::Slim::Engine.set_options(
buffer: '@_out_buf',
use_html_safe: true,
generator: ::Temple::Generators::RailsOutputBuffer,
@ -39,7 +39,7 @@ module Middleman
::Slim::Embedded::SassEngine.disable_option_validator!
%w(sass scss markdown).each do |engine|
::Slim::Embedded.default_options[engine.to_sym] = context_hack
::Slim::Embedded.options[engine.to_sym] = context_hack
end
end
end

View file

@ -24,7 +24,7 @@ module Middleman
Contract None => Any
def before_configuration
app.files.changed(:source, &method(:update_files))
app.files.on_change(:source, &method(:update_files))
end
def ignored?(file)

View file

@ -42,12 +42,22 @@ module Middleman
# @param [Middleman::Sitemap::Store] store
# @param [String] path
# @param [String] source_file
Contract IsA['Middleman::Sitemap::Store'], String, Maybe[IsA['Middleman::SourceFile']] => Any
Contract IsA['Middleman::Sitemap::Store'], String, Maybe[Or[IsA['Middleman::SourceFile'], String]] => Any
def initialize(store, path, source_file=nil)
@store = store
@app = @store.app
@path = path.gsub(' ', '%20') # handle spaces in filenames
@source_file = source_file
if source_file && source_file.is_a?(String)
source_file = Pathname(source_file)
end
if source_file && source_file.is_a?(Pathname)
@source_file = ::Middleman::SourceFile.new(source_file.relative_path_from(@app.source_dir), source_file, @app.source_dir, Set.new([:source]))
else
@source_file = source_file
end
@destination_path = @path
# Options are generally rendering/sitemap options

View file

@ -19,7 +19,7 @@ module Middleman
attr_reader :app
# Duck-typed definition of a valid source watcher
HANDLER = RespondTo[:changed]
HANDLER = RespondTo[:on_change]
# Config
Contract None => Hash
@ -114,7 +114,7 @@ module Middleman
[priority, n]
end.reverse.freeze
handler.changed(&method(:did_change))
handler.on_change(&method(:did_change))
if @running
handler.poll_once!
@ -134,7 +134,7 @@ module Middleman
#
# @param [SourceWatcher] watcher The watcher to remove.
# @return [void]
Contract RespondTo[:changed] => Any
Contract RespondTo[:on_change] => Any
def unwatch(watcher)
@watchers.delete(watcher)
@ -233,16 +233,53 @@ module Middleman
# A callback requires a type and the proc to execute.
CallbackDescriptor = Struct.new :type, :proc
# Add callback to be run on file change
# Add callback to be run on file change or deletion
#
# @param [nil,Regexp] matcher A Regexp to match the change path against
# @param [Symbol] type The change type.
# @return [Set<CallbackDescriptor>]
Contract Symbol, Proc => ArrayOf[CallbackDescriptor]
def changed(type, &block)
def on_change(type, &block)
@on_change_callbacks << CallbackDescriptor.new(type, block)
@on_change_callbacks
end
# Backwards compatible change handler.
#
# @param [nil,Regexp] matcher A Regexp to match the change path against
# Contract Maybe[Regexp] => Any
def changed(matcher=nil, &block)
on_change :source do |updated, _removed|
updated.select { |f|
matcher.nil? ? true : matches?(matcher, f)
}.each do |f|
block.call(f[:relative_path])
end
end
end
# Backwards compatible delete handler.
#
# @param [nil,Regexp] matcher A Regexp to match the change path against
# Contract Maybe[Regexp] => Any
def deleted(matcher=nil, &block)
on_change :source do |_updated, removed|
removed.select { |f|
matcher.nil? ? true : matches?(matcher, f)
}.each do |f|
block.call(f[:relative_path])
end
end
end
# Backwards compatible ignored check.
#
# @param [Pathname,String] path The path to check.
Contract Or[Pathname, String] => Bool
def ignored?(path)
descriptor = find(:source, path)
!descriptor || globally_ignored?(descriptor)
end
protected
# Whether a validator matches a file.

View file

@ -172,7 +172,7 @@ module Middleman
# @param [Proc] matcher A Regexp to match the change path against
# @return [Set<Proc>]
Contract Proc => SetOf[Proc]
def changed(&block)
def on_change(&block)
@on_change_callbacks << block
@on_change_callbacks
end

View file

@ -1,5 +1,5 @@
module Middleman
# Current Version
# @return [String]
VERSION = '4.0.0.alpha.2' unless const_defined?(:VERSION)
VERSION = '4.0.0.alpha.3' unless const_defined?(:VERSION)
end

View file

@ -2,3 +2,6 @@ require 'middleman-core'
# Make the VERSION string available
require 'middleman-core/version'
require 'middleman-sprockets'
require 'middleman-compass'

View file

@ -20,8 +20,8 @@ Gem::Specification.new do |s|
s.add_dependency('middleman-core', Middleman::VERSION)
s.add_dependency('middleman-cli', Middleman::VERSION)
# s.add_dependency('middleman-sprockets', '>= 3.1.2') Disabled in alphas
# s.add_dependency('middleman-compass', '4.0.0.alpha.2')
s.add_dependency('middleman-sprockets', '>= 3.4.0')
s.add_dependency('middleman-compass', '4.0.0.alpha.3')
s.add_dependency('sass', ['>= 3.4.0', '< 4.0'])
s.add_dependency('compass-import-once', ['1.0.5'])
s.add_dependency('haml', ['>= 4.0.5'])