From ee4c68b03c75c2bc4a2551683b48199cc2e6915a Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Tue, 23 Dec 2014 14:54:21 -0800 Subject: [PATCH] prep alpha, backwards compat --- middleman-cli/lib/middleman-cli/build.rb | 1 - .../lib/middleman-core/application.rb | 23 +++++++++ .../middleman-core/core_extensions/data.rb | 2 +- .../core_extensions/default_helpers.rb | 1 - .../core_extensions/front_matter.rb | 2 +- .../middleman-core/core_extensions/i18n.rb | 2 +- .../lib/middleman-core/extensions.rb | 4 +- .../lib/middleman-core/preview_server.rb | 2 +- .../lib/middleman-core/renderers/slim.rb | 4 +- .../sitemap/extensions/on_disk.rb | 2 +- .../lib/middleman-core/sitemap/resource.rb | 14 +++++- middleman-core/lib/middleman-core/sources.rb | 49 ++++++++++++++++--- .../middleman-core/sources/source_watcher.rb | 2 +- middleman-core/lib/middleman-core/version.rb | 2 +- middleman/lib/middleman.rb | 3 ++ middleman/middleman.gemspec | 4 +- 16 files changed, 94 insertions(+), 23 deletions(-) diff --git a/middleman-cli/lib/middleman-cli/build.rb b/middleman-cli/lib/middleman-cli/build.rb index 737d70f8..b8744673 100644 --- a/middleman-cli/lib/middleman-cli/build.rb +++ b/middleman-cli/lib/middleman-cli/build.rb @@ -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. diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 42e50f77..c222123c 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/core_extensions/data.rb b/middleman-core/lib/middleman-core/core_extensions/data.rb index 87fd77af..2f866ac0 100644 --- a/middleman-core/lib/middleman-core/core_extensions/data.rb +++ b/middleman-core/lib/middleman-core/core_extensions/data.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb index 0a79c3bb..dc179d41 100644 --- a/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-core/core_extensions/default_helpers.rb @@ -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) diff --git a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb index c173dccf..f0f6008b 100644 --- a/middleman-core/lib/middleman-core/core_extensions/front_matter.rb +++ b/middleman-core/lib/middleman-core/core_extensions/front_matter.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/core_extensions/i18n.rb b/middleman-core/lib/middleman-core/core_extensions/i18n.rb index 8c2b7052..d5dec8e2 100644 --- a/middleman-core/lib/middleman-core/core_extensions/i18n.rb +++ b/middleman-core/lib/middleman-core/core_extensions/i18n.rb @@ -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] diff --git a/middleman-core/lib/middleman-core/extensions.rb b/middleman-core/lib/middleman-core/extensions.rb index 1480091b..fa51796d 100644 --- a/middleman-core/lib/middleman-core/extensions.rb +++ b/middleman-core/lib/middleman-core/extensions.rb @@ -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] diff --git a/middleman-core/lib/middleman-core/preview_server.rb b/middleman-core/lib/middleman-core/preview_server.rb index 646236dc..5b77bbed 100644 --- a/middleman-core/lib/middleman-core/preview_server.rb +++ b/middleman-core/lib/middleman-core/preview_server.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/renderers/slim.rb b/middleman-core/lib/middleman-core/renderers/slim.rb index c89a99a0..40b44c34 100644 --- a/middleman-core/lib/middleman-core/renderers/slim.rb +++ b/middleman-core/lib/middleman-core/renderers/slim.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/sitemap/extensions/on_disk.rb b/middleman-core/lib/middleman-core/sitemap/extensions/on_disk.rb index 8d319313..3f58e169 100644 --- a/middleman-core/lib/middleman-core/sitemap/extensions/on_disk.rb +++ b/middleman-core/lib/middleman-core/sitemap/extensions/on_disk.rb @@ -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) diff --git a/middleman-core/lib/middleman-core/sitemap/resource.rb b/middleman-core/lib/middleman-core/sitemap/resource.rb index f7ae229c..b3653605 100644 --- a/middleman-core/lib/middleman-core/sitemap/resource.rb +++ b/middleman-core/lib/middleman-core/sitemap/resource.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/sources.rb b/middleman-core/lib/middleman-core/sources.rb index 8819e387..493c6bc0 100644 --- a/middleman-core/lib/middleman-core/sources.rb +++ b/middleman-core/lib/middleman-core/sources.rb @@ -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] 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. diff --git a/middleman-core/lib/middleman-core/sources/source_watcher.rb b/middleman-core/lib/middleman-core/sources/source_watcher.rb index 834fa0a9..faea6874 100644 --- a/middleman-core/lib/middleman-core/sources/source_watcher.rb +++ b/middleman-core/lib/middleman-core/sources/source_watcher.rb @@ -172,7 +172,7 @@ module Middleman # @param [Proc] matcher A Regexp to match the change path against # @return [Set] Contract Proc => SetOf[Proc] - def changed(&block) + def on_change(&block) @on_change_callbacks << block @on_change_callbacks end diff --git a/middleman-core/lib/middleman-core/version.rb b/middleman-core/lib/middleman-core/version.rb index 102d7a65..7f92da1d 100644 --- a/middleman-core/lib/middleman-core/version.rb +++ b/middleman-core/lib/middleman-core/version.rb @@ -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 diff --git a/middleman/lib/middleman.rb b/middleman/lib/middleman.rb index 878b9c59..01b9aa97 100644 --- a/middleman/lib/middleman.rb +++ b/middleman/lib/middleman.rb @@ -2,3 +2,6 @@ require 'middleman-core' # Make the VERSION string available require 'middleman-core/version' + +require 'middleman-sprockets' +require 'middleman-compass' diff --git a/middleman/middleman.gemspec b/middleman/middleman.gemspec index 19d05ffd..ed0acc6f 100644 --- a/middleman/middleman.gemspec +++ b/middleman/middleman.gemspec @@ -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'])