middleman 3.0.0.alpha.3 → 3.0.0.alpha.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -2
- data/.yardopts +2 -0
- data/CHANGELOG.md +97 -0
- data/README.md +84 -13
- data/Rakefile +6 -2
- data/bin/middleman +5 -4
- data/features/builder.feature +7 -0
- data/features/clean_build.feature +11 -0
- data/features/current_page_request_path_backwards.feature +6 -0
- data/features/front-matter.feature +28 -1
- data/features/generator.feature +4 -4
- data/features/helpers_external.feature +6 -0
- data/features/helpers_lorem.feature +5 -0
- data/features/instance_vars.feature +20 -0
- data/features/markdown.feature +23 -3
- data/features/minify_css.feature +6 -1
- data/features/minify_javascript.feature +33 -1
- data/features/mount_rack.feature +8 -0
- data/features/partials.feature +7 -1
- data/features/preview_changes.feature +18 -0
- data/features/wildcard_page_helper.feature +19 -0
- data/fixtures/build-with-errors-app/config.rb +1 -0
- data/fixtures/build-with-errors-app/source/index.html.erb +1 -0
- data/fixtures/clean-app/source/index.html.haml +1 -6
- data/fixtures/clean-dir-app/config.rb +2 -0
- data/fixtures/clean-dir-app/source/about.html +1 -0
- data/fixtures/different-engine-partial/config.rb +0 -0
- data/fixtures/different-engine-partial/source/index.html.erb +1 -0
- data/fixtures/different-engine-partial/source/layouts/layout.erb +7 -0
- data/fixtures/different-engine-partial/source/shared/_footer.slim +1 -0
- data/fixtures/different-engine-partial/source/shared/_header.erb +1 -0
- data/fixtures/external-helpers/config.rb +4 -0
- data/fixtures/external-helpers/lib/hello_helper.rb +5 -0
- data/fixtures/external-helpers/source/index.html.erb +1 -0
- data/fixtures/instance-vars-app/config.rb +0 -0
- data/fixtures/instance-vars-app/source/_vartial.erb +5 -0
- data/fixtures/instance-vars-app/source/instance-var-set.html.erb +2 -0
- data/fixtures/instance-vars-app/source/layout.erb +3 -0
- data/fixtures/instance-vars-app/source/no-instance-var.html.erb +1 -0
- data/fixtures/markdown-app/config.rb +9 -0
- data/fixtures/markdown-app/source/autolink.html.markdown +5 -0
- data/fixtures/markdown-app/source/fenced_code_blocks.html.markdown +7 -0
- data/fixtures/markdown-app/source/index.html.markdown +4 -0
- data/fixtures/markdown-app/source/no_intra_emphasis.html.markdown +5 -0
- data/fixtures/markdown-app/source/smarty_pants.html.markdown +5 -0
- data/fixtures/markdown-app/source/space_after_headers.html.markdown +5 -0
- data/fixtures/markdown-app/source/strikethrough.html.markdown +5 -0
- data/fixtures/markdown-app/source/superscript.html.markdown +5 -0
- data/fixtures/markdown-app/source/tables.html.markdown +8 -0
- data/fixtures/passthrough-app/config.rb +17 -0
- data/fixtures/passthrough-app/source/.htaccess +1 -0
- data/fixtures/passthrough-app/source/inline-coffeescript.html.haml +3 -0
- data/fixtures/passthrough-app/source/inline-css.html.haml +4 -0
- data/fixtures/passthrough-app/source/inline-js.html.haml +7 -0
- data/fixtures/passthrough-app/source/javascripts/coffee_test.js.coffee +3 -0
- data/fixtures/passthrough-app/source/javascripts/js_test.js +8 -0
- data/fixtures/passthrough-app/source/stylesheets/site.css.sass +1 -0
- data/fixtures/preview-app/config.rb +0 -0
- data/fixtures/preview-app/source/content.html.erb +1 -0
- data/fixtures/preview-app/source/layout.erb +1 -0
- data/fixtures/sinatra-app/config.rb +11 -0
- data/fixtures/sinatra-app/source/index.html.erb +5 -0
- data/fixtures/test-app/config.rb +2 -2
- data/fixtures/test-app/source/front-matter-2.php.erb +7 -0
- data/fixtures/test-app/source/front-matter-change.html.erb +5 -0
- data/fixtures/test-app/source/index.html.slim +9 -0
- data/fixtures/test-app/source/javascripts/js_test.js +8 -0
- data/fixtures/test-app/source/lorem.html.erb +12 -0
- data/fixtures/test-app/source/request-path.html.erb +1 -0
- data/fixtures/wildcard-app/config.rb +1 -0
- data/fixtures/wildcard-app/source/admin/index.html.erb +1 -0
- data/fixtures/wildcard-app/source/admin/page.html.erb +1 -0
- data/fixtures/wildcard-app/source/index.html.erb +1 -0
- data/fixtures/wildcard-app/source/layouts/admin.erb +2 -0
- data/fixtures/wildcard-app/source/layouts/layout.erb +2 -0
- data/fixtures/wildcard-directory-index-app/config.rb +2 -0
- data/fixtures/wildcard-directory-index-app/source/admin/index.html.erb +1 -0
- data/fixtures/wildcard-directory-index-app/source/admin/page.html.erb +1 -0
- data/fixtures/wildcard-directory-index-app/source/index.html.erb +1 -0
- data/fixtures/wildcard-directory-index-app/source/layouts/admin.erb +2 -0
- data/fixtures/wildcard-directory-index-app/source/layouts/layout.erb +2 -0
- data/lib/middleman.rb +63 -8
- data/lib/middleman/base.rb +56 -12
- data/lib/middleman/builder.rb +18 -12
- data/lib/middleman/cli.rb +5 -5
- data/lib/middleman/core_extensions/assets.rb +12 -0
- data/lib/middleman/core_extensions/builder.rb +4 -4
- data/lib/middleman/core_extensions/extensions.rb +5 -51
- data/lib/middleman/core_extensions/front_matter.rb +30 -11
- data/lib/middleman/core_extensions/rendering.rb +18 -12
- data/lib/middleman/core_extensions/routing.rb +12 -0
- data/lib/middleman/core_extensions/show_exceptions.rb +16 -0
- data/lib/middleman/core_extensions/sitemap.rb +10 -4
- data/lib/middleman/extensions/minify_css.rb +4 -2
- data/lib/middleman/extensions/minify_javascript.rb +8 -6
- data/lib/middleman/guard.rb +80 -76
- data/lib/middleman/renderers/markdown.rb +8 -13
- data/lib/middleman/sitemap/page.rb +3 -2
- data/lib/middleman/sitemap/store.rb +3 -1
- data/lib/middleman/sitemap/template.rb +19 -5
- data/lib/middleman/step_definitions.rb +1 -0
- data/lib/middleman/step_definitions/builder_steps.rb +6 -1
- data/lib/middleman/step_definitions/generator_steps.rb +9 -13
- data/lib/middleman/step_definitions/middleman_steps.rb +13 -0
- data/lib/middleman/step_definitions/server_steps.rb +7 -0
- data/lib/middleman/templates.rb +42 -21
- data/lib/middleman/templates/default.rb +5 -0
- data/lib/middleman/templates/html5.rb +6 -0
- data/lib/middleman/templates/local.rb +5 -6
- data/lib/middleman/templates/mobile.rb +6 -0
- data/lib/middleman/version.rb +1 -1
- data/middleman-x86-mingw32.gemspec +1 -1
- data/middleman.gemspec +3 -2
- metadata +531 -242
- data/CHANGELOG +0 -98
- data/fixtures/test-app/source/index.html.haml +0 -9
- data/fixtures/test-app/source/markdown.html.markdown +0 -1
data/lib/middleman/base.rb
CHANGED
@@ -11,7 +11,7 @@ require "middleman/vendor/hooks-0.2.0/lib/hooks"
|
|
11
11
|
require "active_support"
|
12
12
|
require "active_support/json"
|
13
13
|
require "active_support/core_ext/string/inflections"
|
14
|
-
|
14
|
+
|
15
15
|
# Core Middleman Class
|
16
16
|
class Middleman::Base
|
17
17
|
# Uses callbacks
|
@@ -59,7 +59,17 @@ class Middleman::Base
|
|
59
59
|
# @return [Rack::Builder]
|
60
60
|
def to_rack_app(&block)
|
61
61
|
inner_app = inst(&block)
|
62
|
+
|
63
|
+
(@middleware || []).each do |m|
|
64
|
+
app.use(m[0], *m[1], &m[2])
|
65
|
+
end
|
66
|
+
|
62
67
|
app.map("/") { run inner_app }
|
68
|
+
|
69
|
+
(@mappings || []).each do |m|
|
70
|
+
app.map(m[0], &m[1])
|
71
|
+
end
|
72
|
+
|
63
73
|
app
|
64
74
|
end
|
65
75
|
|
@@ -82,14 +92,16 @@ class Middleman::Base
|
|
82
92
|
#
|
83
93
|
# @param [Class] Middleware
|
84
94
|
def use(middleware, *args, &block)
|
85
|
-
|
95
|
+
@middleware ||= []
|
96
|
+
@middleware << [middleware, args, block]
|
86
97
|
end
|
87
98
|
|
88
99
|
# Add Rack App mapped to specific path
|
89
100
|
#
|
90
101
|
# @param [String] Path to map
|
91
102
|
def map(map, &block)
|
92
|
-
|
103
|
+
@mappings ||= []
|
104
|
+
@mappings << [map, block]
|
93
105
|
end
|
94
106
|
|
95
107
|
# Mix-in helper methods. Accepts either a list of Modules
|
@@ -117,7 +129,7 @@ class Middleman::Base
|
|
117
129
|
end
|
118
130
|
end
|
119
131
|
|
120
|
-
# Set attributes
|
132
|
+
# Set attributes (global variables)
|
121
133
|
#
|
122
134
|
# @param [Symbol] Name of the attribue
|
123
135
|
# @param Attribute value
|
@@ -129,47 +141,65 @@ class Middleman::Base
|
|
129
141
|
end
|
130
142
|
|
131
143
|
# Root project directory (overwritten in middleman build/server)
|
144
|
+
# @return [String]
|
132
145
|
set :root, Dir.pwd
|
133
146
|
|
134
147
|
# Name of the source directory
|
148
|
+
# @return [String]
|
135
149
|
set :source, "source"
|
136
150
|
|
137
|
-
#
|
138
|
-
#
|
151
|
+
# Middleman environment. Defaults to :development, set to :build by the build process
|
152
|
+
# @return [String]
|
139
153
|
set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development
|
140
154
|
|
141
|
-
#
|
155
|
+
# Whether logging is active, disabled by default
|
156
|
+
# @return [String]
|
142
157
|
set :logging, false
|
143
158
|
|
144
159
|
# Which file should be used for directory indexes
|
160
|
+
# @return [String]
|
145
161
|
set :index_file, "index.html"
|
146
162
|
|
147
163
|
# Location of javascripts within source. Used by Sprockets.
|
164
|
+
# @return [String]
|
148
165
|
set :js_dir, "javascripts"
|
149
166
|
|
150
167
|
# Location of stylesheets within source. Used by Compass.
|
168
|
+
# @return [String]
|
151
169
|
set :css_dir, "stylesheets"
|
152
170
|
|
153
171
|
# Location of images within source. Used by HTML helpers and Compass.
|
172
|
+
# @return [String]
|
154
173
|
set :images_dir, "images"
|
155
174
|
|
156
175
|
# Where to build output files
|
176
|
+
# @return [String]
|
157
177
|
set :build_dir, "build"
|
158
178
|
|
159
179
|
# Default prefix for building paths. Used by HTML helpers and Compass.
|
180
|
+
# @return [String]
|
160
181
|
set :http_prefix, "/"
|
161
182
|
|
183
|
+
# Whether to catch and display exceptions
|
184
|
+
# @return [Boolean]
|
185
|
+
set :show_exceptions, true
|
186
|
+
|
162
187
|
# Automatically loaded extensions
|
188
|
+
# @return [Array<Symbol>]
|
163
189
|
set :default_extensions, [
|
164
190
|
:lorem,
|
165
191
|
# :sitemap_tree
|
166
192
|
]
|
167
193
|
|
168
194
|
# Default layout name
|
195
|
+
# @return [String, Symbold]
|
169
196
|
set :layout, :_auto_layout
|
170
197
|
|
171
198
|
# Activate custom features and extensions
|
172
199
|
include Middleman::CoreExtensions::Extensions
|
200
|
+
|
201
|
+
# Handle exceptions
|
202
|
+
register Middleman::CoreExtensions::ShowExceptions
|
173
203
|
|
174
204
|
# Add Builder Callbacks
|
175
205
|
register Middleman::CoreExtensions::Builder
|
@@ -224,18 +254,30 @@ class Middleman::Base
|
|
224
254
|
Middleman::Extensions.register(:sitemap_tree) {
|
225
255
|
Middleman::Extensions::SitemapTree }
|
226
256
|
|
257
|
+
# Backwards-compatibility with old request.path signature
|
258
|
+
attr :request
|
259
|
+
|
227
260
|
# Accessor for current path
|
228
|
-
|
229
|
-
|
261
|
+
# @return [String]
|
262
|
+
def current_path
|
263
|
+
@_current_path
|
264
|
+
end
|
265
|
+
|
266
|
+
def current_path=(path)
|
267
|
+
@_current_path = path
|
268
|
+
@request = Thor::CoreExt::HashWithIndifferentAccess.new({ :path => path })
|
269
|
+
end
|
270
|
+
|
230
271
|
# Initialize the Middleman project
|
231
272
|
def initialize(&block)
|
232
273
|
# Current path defaults to nil, used in views.
|
233
|
-
|
274
|
+
self.current_path = nil
|
234
275
|
|
276
|
+
# Clear the static class cache
|
235
277
|
cache.clear
|
236
278
|
|
237
279
|
# Setup the default values from calls to set before initialization
|
238
|
-
self.class.superclass.defaults.each { |k,v| set
|
280
|
+
self.class.superclass.defaults.each { |k,v| set(k,v) }
|
239
281
|
|
240
282
|
# Evaluate a passed block if given
|
241
283
|
instance_exec(&block) if block_given?
|
@@ -266,9 +308,11 @@ class Middleman::Base
|
|
266
308
|
attr :env
|
267
309
|
|
268
310
|
# Rack request
|
311
|
+
# @return [Rack::Request]
|
269
312
|
attr :req
|
270
313
|
|
271
314
|
# Rack response
|
315
|
+
# @return [Rack::Response]
|
272
316
|
attr :res
|
273
317
|
|
274
318
|
# Rack Interface
|
@@ -342,7 +386,7 @@ class Middleman::Base
|
|
342
386
|
return send_file(sitemap_page.source_file) unless sitemap_page.template?
|
343
387
|
|
344
388
|
# Set the current path for use in helpers
|
345
|
-
|
389
|
+
self.current_path = @request_path.dup
|
346
390
|
|
347
391
|
# Set a HTTP content type based on the request's extensions
|
348
392
|
content_type sitemap_page.mime_type
|
data/lib/middleman/builder.rb
CHANGED
@@ -30,20 +30,26 @@ module Middleman
|
|
30
30
|
|
31
31
|
# @private
|
32
32
|
module ThorActions
|
33
|
+
# Render a template to a file.
|
34
|
+
# @return [String] the actual destination file path that was created
|
33
35
|
def tilt_template(source, *args, &block)
|
34
36
|
config = args.last.is_a?(Hash) ? args.pop : {}
|
35
37
|
destination = args.first || source
|
36
38
|
|
37
39
|
request_path = destination.sub(/^#{::Middleman::Builder.shared_instance.build_dir}/, "")
|
38
40
|
|
39
|
-
|
41
|
+
begin
|
40
42
|
destination, request_path = ::Middleman::Builder.shared_instance.reroute_builder(destination, request_path)
|
41
43
|
|
42
44
|
response = ::Middleman::Builder.shared_rack.get(request_path.gsub(/\s/, "%20"))
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
|
46
|
+
create_file(destination, response.body, config)
|
47
|
+
|
48
|
+
destination
|
49
|
+
rescue
|
50
|
+
say_status :error, destination, :red
|
51
|
+
abort
|
52
|
+
end
|
47
53
|
end
|
48
54
|
end
|
49
55
|
include ThorActions
|
@@ -130,11 +136,11 @@ module Middleman
|
|
130
136
|
def queue_current_paths
|
131
137
|
@cleaning_queue = []
|
132
138
|
Find.find(@destination) do |path|
|
133
|
-
next if path.match(/\/\./)
|
139
|
+
next if path.match(/\/\./) && !path.match(/\.htaccess/)
|
134
140
|
unless path == destination
|
135
141
|
@cleaning_queue << path.sub(@destination, destination[/([^\/]+?)$/])
|
136
142
|
end
|
137
|
-
end
|
143
|
+
end if File.exist?(@destination)
|
138
144
|
end
|
139
145
|
|
140
146
|
def execute!
|
@@ -154,7 +160,7 @@ module Middleman
|
|
154
160
|
file_source = path
|
155
161
|
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
|
156
162
|
file_destination.gsub!('/./', '/')
|
157
|
-
|
163
|
+
|
158
164
|
if @app.sitemap.generic?(file_source)
|
159
165
|
# no-op
|
160
166
|
elsif @app.sitemap.proxied?(file_source)
|
@@ -163,14 +169,14 @@ module Middleman
|
|
163
169
|
next
|
164
170
|
end
|
165
171
|
|
166
|
-
@cleaning_queue.delete(file_destination) if cleaning?
|
167
|
-
|
168
172
|
if @config[:glob]
|
169
173
|
next unless File.fnmatch(@config[:glob], file_source)
|
170
174
|
end
|
171
175
|
|
172
|
-
base.tilt_template(file_source, file_destination, { :force => true })
|
176
|
+
file_destination = base.tilt_template(file_source, file_destination, { :force => true })
|
177
|
+
|
178
|
+
@cleaning_queue.delete(file_destination) if cleaning?
|
173
179
|
end
|
174
180
|
end
|
175
181
|
end
|
176
|
-
end
|
182
|
+
end
|
data/lib/middleman/cli.rb
CHANGED
@@ -16,7 +16,7 @@ module Middleman
|
|
16
16
|
end
|
17
17
|
|
18
18
|
desc "init NAME [options]", "Create new project NAME"
|
19
|
-
available_templates = Middleman::Templates.
|
19
|
+
available_templates = Middleman::Templates.registered.keys.join(", ")
|
20
20
|
method_option "template",
|
21
21
|
:aliases => "-T",
|
22
22
|
:default => "default",
|
@@ -40,11 +40,11 @@ module Middleman
|
|
40
40
|
:desc => 'Create a Gemfile and use Bundler to manage gems'
|
41
41
|
def init(name)
|
42
42
|
key = options[:template].to_sym
|
43
|
-
unless Middleman::Templates.
|
44
|
-
|
43
|
+
unless Middleman::Templates.registered.has_key?(key)
|
44
|
+
raise Thor::Error.new "Unknown project template '#{key}'"
|
45
45
|
end
|
46
46
|
|
47
|
-
thor_group = Middleman::Templates.
|
47
|
+
thor_group = Middleman::Templates.registered[key]
|
48
48
|
thor_group.new([name], options).invoke_all
|
49
49
|
end
|
50
50
|
|
@@ -120,4 +120,4 @@ module Middleman
|
|
120
120
|
exit 0
|
121
121
|
end
|
122
122
|
end
|
123
|
-
end
|
123
|
+
end
|
@@ -1,16 +1,28 @@
|
|
1
|
+
# Base helper to manipulate asset paths
|
1
2
|
module Middleman::CoreExtensions::Assets
|
3
|
+
|
4
|
+
# Extension registered
|
2
5
|
class << self
|
6
|
+
# @private
|
3
7
|
def registered(app)
|
4
8
|
# Disable Padrino cache buster
|
5
9
|
app.set :asset_stamp, false
|
6
10
|
|
11
|
+
# Include helpers
|
7
12
|
app.send :include, InstanceMethod
|
8
13
|
end
|
9
14
|
alias :included :registered
|
10
15
|
end
|
11
16
|
|
17
|
+
# Methods to be mixed-in to Middleman::Base
|
12
18
|
module InstanceMethod
|
19
|
+
|
20
|
+
# Get the URL of an asset given a type/prefix
|
21
|
+
#
|
22
|
+
# @param [String] path The path (such as "photo.jpg")
|
23
|
+
# @param [String] prefix The type prefix (such as "images")
|
13
24
|
def asset_url(path, prefix="")
|
25
|
+
# Don't touch assets which already have a full path
|
14
26
|
path.include?("://") ? path : File.join(http_prefix, prefix, path)
|
15
27
|
end
|
16
28
|
end
|
@@ -20,11 +20,11 @@ module Middleman::CoreExtensions::Builder
|
|
20
20
|
self.class.build_reroute(&block)
|
21
21
|
end
|
22
22
|
|
23
|
-
def reroute_builder(
|
24
|
-
result = [
|
23
|
+
def reroute_builder(destination, request_path)
|
24
|
+
result = [destination, request_path]
|
25
25
|
|
26
26
|
build_reroute.each do |block|
|
27
|
-
output = instance_exec(
|
27
|
+
output = instance_exec(destination, request_path, &block)
|
28
28
|
if output
|
29
29
|
result = output
|
30
30
|
break
|
@@ -34,4 +34,4 @@ module Middleman::CoreExtensions::Builder
|
|
34
34
|
result
|
35
35
|
end
|
36
36
|
end
|
37
|
-
end
|
37
|
+
end
|
@@ -43,55 +43,6 @@ module Middleman::CoreExtensions::Extensions
|
|
43
43
|
|
44
44
|
app.extend ClassMethods
|
45
45
|
app.send :include, InstanceMethods
|
46
|
-
|
47
|
-
# Setup extension API
|
48
|
-
::Middleman::Extensions.extend API
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
module API
|
53
|
-
def registered
|
54
|
-
@_registered ||= {}
|
55
|
-
end
|
56
|
-
|
57
|
-
def register(name, namespace=nil, version=nil, &block)
|
58
|
-
# If we've already got a matching extension that passed the
|
59
|
-
# version check, bail out.
|
60
|
-
return if registered.has_key?(name.to_sym) &&
|
61
|
-
!registered[name.to_sym].is_a?(String)
|
62
|
-
|
63
|
-
if block_given?
|
64
|
-
version = namespace
|
65
|
-
end
|
66
|
-
|
67
|
-
passed_version_check = true
|
68
|
-
if !version.nil?
|
69
|
-
requirement = ::Gem::Requirement.create(version)
|
70
|
-
if !requirement.satisfied_by?(Middleman::GEM_VERSION)
|
71
|
-
passed_version_check = false
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
registered[name.to_sym] = if !passed_version_check
|
76
|
-
"== #{name} failed version check. Requested #{version}, got #{Middleman::VERSION}"
|
77
|
-
elsif block_given?
|
78
|
-
block
|
79
|
-
elsif namespace
|
80
|
-
namespace
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def load(name)
|
85
|
-
name = name.to_sym
|
86
|
-
return nil unless registered.has_key?(name)
|
87
|
-
|
88
|
-
extension = registered[name]
|
89
|
-
if extension.is_a?(Proc)
|
90
|
-
extension = extension.call() || nil
|
91
|
-
registered[name] = extension
|
92
|
-
end
|
93
|
-
|
94
|
-
extension
|
95
46
|
end
|
96
47
|
end
|
97
48
|
|
@@ -140,9 +91,12 @@ module Middleman::CoreExtensions::Extensions
|
|
140
91
|
# Load features before starting server
|
141
92
|
def initialize
|
142
93
|
super
|
143
|
-
|
94
|
+
|
144
95
|
run_hook :before_configuration
|
145
96
|
|
97
|
+
# Search the root of the project for required files
|
98
|
+
$LOAD_PATH.unshift(root)
|
99
|
+
|
146
100
|
# Check for and evaluate local configuration
|
147
101
|
local_config = File.join(root, "config.rb")
|
148
102
|
if File.exists? local_config
|
@@ -157,7 +111,7 @@ module Middleman::CoreExtensions::Extensions
|
|
157
111
|
|
158
112
|
# Add in defaults
|
159
113
|
default_extensions.each do |ext|
|
160
|
-
|
114
|
+
activate ext
|
161
115
|
end
|
162
116
|
|
163
117
|
if logging?
|
@@ -4,28 +4,41 @@ require "tilt"
|
|
4
4
|
module Middleman::CoreExtensions::FrontMatter
|
5
5
|
class << self
|
6
6
|
def registered(app)
|
7
|
+
app.set :frontmatter_extensions, %w(.htm .html .php)
|
8
|
+
app.extend ClassMethods
|
7
9
|
app.send :include, InstanceMethods
|
8
10
|
end
|
9
11
|
alias :included :registered
|
10
12
|
end
|
11
13
|
|
14
|
+
module ClassMethods
|
15
|
+
def frontmatter_changed(matcher=nil, &block)
|
16
|
+
@_frontmatter_changed ||= []
|
17
|
+
@_frontmatter_changed << [block, matcher] if block_given?
|
18
|
+
@_frontmatter_changed
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
12
22
|
module InstanceMethods
|
13
23
|
def initialize
|
14
24
|
super
|
15
25
|
|
16
|
-
|
26
|
+
exts = frontmatter_extensions.join("|").gsub(".", "\.")
|
27
|
+
matcher = %r{source/.*(#{exts})}
|
28
|
+
|
29
|
+
file_changed matcher do |file|
|
17
30
|
frontmatter.touch_file(file)
|
18
31
|
end
|
19
32
|
|
20
|
-
file_deleted do |file|
|
33
|
+
file_deleted matcher do |file|
|
21
34
|
frontmatter.remove_file(file)
|
22
35
|
end
|
23
36
|
|
24
|
-
provides_metadata
|
37
|
+
provides_metadata matcher do |path|
|
25
38
|
relative_path = path.sub(source_dir, "")
|
26
39
|
|
27
40
|
data = if frontmatter.has_data?(relative_path)
|
28
|
-
frontmatter.data(relative_path)
|
41
|
+
frontmatter.data(relative_path)[0]
|
29
42
|
else
|
30
43
|
{}
|
31
44
|
end
|
@@ -41,7 +54,18 @@ module Middleman::CoreExtensions::FrontMatter
|
|
41
54
|
|
42
55
|
{ :options => data }
|
43
56
|
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def frontmatter_changed(*args, &block)
|
60
|
+
self.class.frontmatter_changed(*args, &block)
|
61
|
+
end
|
44
62
|
|
63
|
+
def frontmatter_did_change(path)
|
64
|
+
frontmatter_changed.each do |callback, matcher|
|
65
|
+
next if path.match(%r{^#{build_dir}/})
|
66
|
+
next if !matcher.nil? && !path.match(matcher)
|
67
|
+
instance_exec(path, &callback)
|
68
|
+
end
|
45
69
|
end
|
46
70
|
|
47
71
|
def frontmatter
|
@@ -50,12 +74,6 @@ module Middleman::CoreExtensions::FrontMatter
|
|
50
74
|
end
|
51
75
|
|
52
76
|
class FrontMatter
|
53
|
-
class << self
|
54
|
-
def matcher
|
55
|
-
%r{source/.*\.html}
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
77
|
def initialize(app)
|
60
78
|
@app = app
|
61
79
|
@source = File.expand_path(@app.source, @app.root)
|
@@ -81,6 +99,7 @@ module Middleman::CoreExtensions::FrontMatter
|
|
81
99
|
@local_data[file] = result
|
82
100
|
path = File.join(@app.source_dir, file)
|
83
101
|
@app.cache.set([:raw_template, path], result[1])
|
102
|
+
@app.frontmatter_did_change(path)
|
84
103
|
end
|
85
104
|
end
|
86
105
|
|
@@ -121,4 +140,4 @@ module Middleman::CoreExtensions::FrontMatter
|
|
121
140
|
[data, content]
|
122
141
|
end
|
123
142
|
end
|
124
|
-
end
|
143
|
+
end
|