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 end
no_tasks do no_tasks do
# Handles incoming events from the builder. # Handles incoming events from the builder.
# @param [Symbol] event_type The type of event. # @param [Symbol] event_type The type of event.
# @param [String] contents The event contents. # @param [String] contents The event contents.

View file

@ -319,6 +319,29 @@ module Middleman
config[:environment] == key config[:environment] == key
end 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) MiddlewareDescriptor = Struct.new(:class, :options, :block)
# Use Rack middleware # Use Rack middleware

View file

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

View file

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

View file

@ -27,7 +27,7 @@ module Middleman::CoreExtensions
end end
def before_configuration def before_configuration
app.files.changed(:source, &method(:clear_data)) app.files.on_change(:source, &method(:clear_data))
end end
# @return Array<Middleman::Sitemap::Resource> # @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 # Setup data files before anything else so they are available when
# parsing config.rb # parsing config.rb
app.files.changed(:locales, &method(:on_file_changed)) app.files.on_change(:locales, &method(:on_file_changed))
@maps = {} @maps = {}
@mount_at_root = options[:mount_at_root].nil? ? langs.first : options[:mount_at_root] @mount_at_root = options[:mount_at_root].nil? ? langs.first : options[:mount_at_root]

View file

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

View file

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

View file

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

View file

@ -42,12 +42,22 @@ module Middleman
# @param [Middleman::Sitemap::Store] store # @param [Middleman::Sitemap::Store] store
# @param [String] path # @param [String] path
# @param [String] source_file # @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) def initialize(store, path, source_file=nil)
@store = store @store = store
@app = @store.app @app = @store.app
@path = path.gsub(' ', '%20') # handle spaces in filenames @path = path.gsub(' ', '%20') # handle spaces in filenames
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 @source_file = source_file
end
@destination_path = @path @destination_path = @path
# Options are generally rendering/sitemap options # Options are generally rendering/sitemap options

View file

@ -19,7 +19,7 @@ module Middleman
attr_reader :app attr_reader :app
# Duck-typed definition of a valid source watcher # Duck-typed definition of a valid source watcher
HANDLER = RespondTo[:changed] HANDLER = RespondTo[:on_change]
# Config # Config
Contract None => Hash Contract None => Hash
@ -114,7 +114,7 @@ module Middleman
[priority, n] [priority, n]
end.reverse.freeze end.reverse.freeze
handler.changed(&method(:did_change)) handler.on_change(&method(:did_change))
if @running if @running
handler.poll_once! handler.poll_once!
@ -134,7 +134,7 @@ module Middleman
# #
# @param [SourceWatcher] watcher The watcher to remove. # @param [SourceWatcher] watcher The watcher to remove.
# @return [void] # @return [void]
Contract RespondTo[:changed] => Any Contract RespondTo[:on_change] => Any
def unwatch(watcher) def unwatch(watcher)
@watchers.delete(watcher) @watchers.delete(watcher)
@ -233,16 +233,53 @@ module Middleman
# A callback requires a type and the proc to execute. # A callback requires a type and the proc to execute.
CallbackDescriptor = Struct.new :type, :proc 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>] # @return [Set<CallbackDescriptor>]
Contract Symbol, Proc => ArrayOf[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 << CallbackDescriptor.new(type, block)
@on_change_callbacks @on_change_callbacks
end 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 protected
# Whether a validator matches a file. # 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 # @param [Proc] matcher A Regexp to match the change path against
# @return [Set<Proc>] # @return [Set<Proc>]
Contract Proc => SetOf[Proc] Contract Proc => SetOf[Proc]
def changed(&block) def on_change(&block)
@on_change_callbacks << block @on_change_callbacks << block
@on_change_callbacks @on_change_callbacks
end end

View file

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

View file

@ -2,3 +2,6 @@ require 'middleman-core'
# Make the VERSION string available # Make the VERSION string available
require 'middleman-core/version' 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-core', Middleman::VERSION)
s.add_dependency('middleman-cli', Middleman::VERSION) s.add_dependency('middleman-cli', Middleman::VERSION)
# s.add_dependency('middleman-sprockets', '>= 3.1.2') Disabled in alphas s.add_dependency('middleman-sprockets', '>= 3.4.0')
# s.add_dependency('middleman-compass', '4.0.0.alpha.2') s.add_dependency('middleman-compass', '4.0.0.alpha.3')
s.add_dependency('sass', ['>= 3.4.0', '< 4.0']) s.add_dependency('sass', ['>= 3.4.0', '< 4.0'])
s.add_dependency('compass-import-once', ['1.0.5']) s.add_dependency('compass-import-once', ['1.0.5'])
s.add_dependency('haml', ['>= 4.0.5']) s.add_dependency('haml', ['>= 4.0.5'])