Add some options to watcher to opt out of features later
This commit is contained in:
parent
6d1c3562a7
commit
5586784947
9 changed files with 125 additions and 22 deletions
|
@ -1,23 +1,112 @@
|
|||
require 'contracts'
|
||||
require 'hamster'
|
||||
if ENV['CONTRACTS'] != 'false'
|
||||
require 'contracts'
|
||||
require 'hamster'
|
||||
|
||||
module Contracts
|
||||
class IsA
|
||||
def self.[](val)
|
||||
@lookup ||= {}
|
||||
@lookup[val] ||= new(val)
|
||||
module Contracts
|
||||
class IsA
|
||||
def self.[](val)
|
||||
@lookup ||= {}
|
||||
@lookup[val] ||= new(val)
|
||||
end
|
||||
|
||||
def initialize(val)
|
||||
@val = val
|
||||
end
|
||||
|
||||
def valid?(val)
|
||||
val.is_a? @val.constantize
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(val)
|
||||
@val = val
|
||||
VectorOf = Contracts::CollectionOf::Factory.new(::Hamster::Vector)
|
||||
ResourceList = Contracts::ArrayOf[IsA['Middleman::Sitemap::Resource']]
|
||||
end
|
||||
else
|
||||
module Contracts
|
||||
def self.included(base)
|
||||
base.extend self
|
||||
end
|
||||
|
||||
def valid?(val)
|
||||
val.is_a? @val.constantize
|
||||
# rubocop:disable MethodName
|
||||
def Contract(*)
|
||||
end
|
||||
|
||||
class Callable
|
||||
def self.[](*)
|
||||
end
|
||||
end
|
||||
|
||||
class Bool
|
||||
end
|
||||
|
||||
class Num
|
||||
end
|
||||
|
||||
class Pos
|
||||
end
|
||||
|
||||
class Neg
|
||||
end
|
||||
|
||||
class Any
|
||||
end
|
||||
|
||||
class None
|
||||
end
|
||||
|
||||
class Or < Callable
|
||||
end
|
||||
|
||||
class Xor < Callable
|
||||
end
|
||||
|
||||
class And < Callable
|
||||
end
|
||||
|
||||
class Not < Callable
|
||||
end
|
||||
|
||||
class RespondTo < Callable
|
||||
end
|
||||
|
||||
class Send < Callable
|
||||
end
|
||||
|
||||
class Exactly < Callable
|
||||
end
|
||||
|
||||
class ArrayOf < Callable
|
||||
end
|
||||
|
||||
class ResourceList < Callable
|
||||
end
|
||||
|
||||
class Args < Callable
|
||||
end
|
||||
|
||||
class HashOf < Callable
|
||||
end
|
||||
|
||||
class Bool
|
||||
end
|
||||
|
||||
class Maybe < Callable
|
||||
end
|
||||
|
||||
class IsA < Callable
|
||||
end
|
||||
|
||||
class SetOf < Callable
|
||||
end
|
||||
|
||||
class Frozen < Callable
|
||||
end
|
||||
|
||||
class VectorOf < Callable
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
VectorOf = ::Contracts::CollectionOf::Factory.new(::Hamster::Vector)
|
||||
ResourceList = ::Contracts::ArrayOf[IsA['Middleman::Sitemap::Resource']]
|
||||
module Contracts
|
||||
PATH_MATCHER = Or[String, RespondTo[:match], RespondTo[:call], RespondTo[:to_s]]
|
||||
end
|
||||
|
|
|
@ -36,6 +36,7 @@ module Middleman::CoreExtensions
|
|||
resources.each do |resource|
|
||||
next if resource.binary?
|
||||
next if resource.file_descriptor.nil?
|
||||
next if resource.file_descriptor[:types].include?(:no_frontmatter)
|
||||
|
||||
fmdata = data(resource.file_descriptor[:full_path].to_s).first.dup
|
||||
|
||||
|
@ -74,6 +75,11 @@ module Middleman::CoreExtensions
|
|||
|
||||
return @cache[file[:full_path]] if @cache.key?(file[:full_path])
|
||||
|
||||
if file[:types].include?(:no_frontmatter)
|
||||
$stderr.puts file[:relative_path].to_s
|
||||
require 'pry'
|
||||
end
|
||||
|
||||
@cache[file[:full_path]] = ::Middleman::Util::Data.parse(
|
||||
file,
|
||||
app.config[:frontmatter_delims]
|
||||
|
|
|
@ -14,7 +14,8 @@ class Middleman::Extensions::ExternalPipeline < ::Middleman::Extension
|
|||
|
||||
@watcher = app.files.watch :source,
|
||||
path: File.expand_path(options[:source], app.root),
|
||||
latency: options[:latency]
|
||||
latency: options[:latency],
|
||||
frontmatter: false
|
||||
|
||||
logger.info "== Executing: `#{options[:command]}`"
|
||||
|
||||
|
|
|
@ -96,12 +96,13 @@ module Middleman
|
|||
# @return [String]
|
||||
Contract String
|
||||
def template_data_for_file
|
||||
if @app.extensions[:front_matter]
|
||||
file = @app.files.find(:source, @path)
|
||||
|
||||
if @app.extensions[:front_matter] || (file && !file[:types].include?(:no_frontmatter))
|
||||
result = @app.extensions[:front_matter].template_data_for_file(@path)
|
||||
return result unless result.nil?
|
||||
end
|
||||
|
||||
file = @app.files.find(:source, @path)
|
||||
file ? file.read : File.read(@path)
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ module Middleman
|
|||
# Ignore a path or add an ignore callback
|
||||
# @param [String, Regexp] path Path glob expression, or path regex
|
||||
# @return [IgnoreDescriptor]
|
||||
Contract Maybe[Or[String, Regexp]], Maybe[Proc] => RespondTo[:execute_descriptor]
|
||||
Contract Or[String, Regexp, Proc] => RespondTo[:execute_descriptor]
|
||||
def ignore(path=nil, &block)
|
||||
@app.sitemap.invalidate_resources_not_ignored_cache!
|
||||
IgnoreDescriptor.new(path, block)
|
||||
|
@ -49,7 +49,7 @@ module Middleman
|
|||
else
|
||||
match_path == path_clean
|
||||
end
|
||||
elsif block_given?
|
||||
elsif block
|
||||
block.call(match_path)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,8 +12,10 @@ module Middleman
|
|||
|
||||
ImportFileDescriptor = Struct.new(:from, :to) do
|
||||
def execute_descriptor(app, resources)
|
||||
source = ::Middleman::SourceFile.new(Pathname(from).relative_path_from(app.source_dir), Pathname(from), app.source_dir, Set.new([:source, :binary]), 0)
|
||||
|
||||
resources + [
|
||||
::Middleman::Sitemap::Resource.new(app.sitemap, to, from)
|
||||
::Middleman::Sitemap::Resource.new(app.sitemap, to, source)
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -161,7 +161,7 @@ module Middleman
|
|||
# @return [Boolean]
|
||||
Contract Bool
|
||||
def binary?
|
||||
!file_descriptor.nil? && ::Middleman::Util.binary?(file_descriptor[:full_path].to_s)
|
||||
!file_descriptor.nil? && (file_descriptor[:types].include?(:binary) || ::Middleman::Util.binary?(file_descriptor[:full_path].to_s))
|
||||
end
|
||||
|
||||
# Ignore a resource directly, without going through the whole
|
||||
|
|
|
@ -66,6 +66,8 @@ module Middleman
|
|||
@files = {}
|
||||
@extensionless_files = {}
|
||||
|
||||
@frontmatter = options.fetch(:frontmatter, true)
|
||||
@binary = options.fetch(:binary, false)
|
||||
@validator = options.fetch(:validator, proc { true })
|
||||
@ignored = options.fetch(:ignored, proc { false })
|
||||
@only = Array(options.fetch(:only, []))
|
||||
|
@ -181,7 +183,7 @@ module Middleman
|
|||
Contract ArrayOf[Pathname]
|
||||
def find_new_files!
|
||||
new_files = ::Middleman::Util.all_files_under(@directory.to_s)
|
||||
.reject { |p| @files.key?(p) }
|
||||
.reject { |p| @files.key?(p) }
|
||||
|
||||
update(new_files, [])
|
||||
|
||||
|
@ -278,6 +280,8 @@ module Middleman
|
|||
Contract Pathname, Pathname, Symbol, Maybe[String] => ::Middleman::SourceFile
|
||||
def path_to_source_file(path, directory, type, destination_dir)
|
||||
types = Set.new([type])
|
||||
types << :no_frontmatter unless @frontmatter
|
||||
types << :@binary if @binary
|
||||
|
||||
relative_path = path.relative_path_from(directory)
|
||||
relative_path = File.join(destination_dir, relative_path) if destination_dir
|
||||
|
|
|
@ -18,7 +18,7 @@ module Middleman
|
|||
Contract IsA['Middleman::SourceFile'], Maybe[Symbol] => [Hash, Maybe[String]]
|
||||
def parse(file, frontmatter_delims, known_type=nil)
|
||||
full_path = file[:full_path]
|
||||
return [{}, nil] if ::Middleman::Util.binary?(full_path)
|
||||
return [{}, nil] if ::Middleman::Util.binary?(full_path) || file[:types].include?(:binary)
|
||||
|
||||
# Avoid weird race condition when a file is renamed
|
||||
begin
|
||||
|
|
Loading…
Reference in a new issue