middleman-core-with-external-sources-watch-fix 4.1.0 → 4.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/features/asset_hash.feature +47 -10
  3. data/features/builder.feature +8 -4
  4. data/features/collections.feature +27 -0
  5. data/features/custom_layouts.feature +17 -1
  6. data/features/dynamic_pages.feature +15 -12
  7. data/features/front-matter-neighbor.feature +6 -2
  8. data/features/helpers_link_to.feature +11 -1
  9. data/features/i18n_link_to.feature +34 -34
  10. data/features/markdown_redcarpet_in_slim.feature +41 -0
  11. data/features/page-id.feature +26 -0
  12. data/features/partials.feature +17 -5
  13. data/features/relative_assets.feature +1 -1
  14. data/features/relative_assets_helpers_only.feature +123 -0
  15. data/features/sass_in_slim.feature +40 -0
  16. data/features/template-key-collision.feature +26 -0
  17. data/fixtures/asset-hash-minified-app/source/images/100px.jpg +0 -0
  18. data/fixtures/asset-hash-minified-app/source/stylesheets/test.css +3 -0
  19. data/fixtures/asset-hash-prefix/config.rb +7 -0
  20. data/fixtures/asset-hash-prefix/lib/middleware.rb +16 -0
  21. data/fixtures/asset-hash-prefix/source/index.html.erb +6 -0
  22. data/fixtures/asset-hash-prefix/source/javascripts/application.js +2 -0
  23. data/fixtures/asset-hash-prefix/source/javascripts/application.js.map +1 -0
  24. data/fixtures/asset-hash-prefix/source/layout.erb +17 -0
  25. data/fixtures/asset-hash-source-map/config.rb +6 -0
  26. data/fixtures/asset-hash-source-map/lib/middleware.rb +16 -0
  27. data/fixtures/asset-hash-source-map/source/index.html.erb +6 -0
  28. data/fixtures/asset-hash-source-map/source/javascripts/application.js +2 -0
  29. data/fixtures/asset-hash-source-map/source/javascripts/application.js.map +1 -0
  30. data/fixtures/asset-hash-source-map/source/layout.erb +17 -0
  31. data/fixtures/asset-host-app/source/images/blank0.gif +0 -0
  32. data/fixtures/asset-host-app/source/images/blank1.gif +0 -0
  33. data/fixtures/asset-host-app/source/images/blank10.gif +0 -0
  34. data/fixtures/asset-host-app/source/images/blank100.gif +0 -0
  35. data/fixtures/asset-host-app/source/images/blank101.gif +0 -0
  36. data/fixtures/asset-host-app/source/images/blank1010.gif +0 -0
  37. data/fixtures/asset-host-app/source/images/blank102.gif +0 -0
  38. data/fixtures/asset-host-app/source/images/blank1020.gif +0 -0
  39. data/fixtures/asset-host-app/source/images/blank1021.gif +0 -0
  40. data/fixtures/asset-host-app/source/images/blank1022.gif +0 -0
  41. data/fixtures/asset-host-app/source/images/blank1023.gif +0 -0
  42. data/fixtures/asset-host-app/source/images/blank1024.gif +0 -0
  43. data/fixtures/asset-host-app/source/images/blank103.gif +0 -0
  44. data/fixtures/asset-host-app/source/images/blank1030.gif +0 -0
  45. data/fixtures/asset-host-app/source/images/blank1031.gif +0 -0
  46. data/fixtures/asset-host-app/source/images/blank1032.gif +0 -0
  47. data/fixtures/asset-host-app/source/images/blank1033.gif +0 -0
  48. data/fixtures/asset-host-app/source/images/blank1034.gif +0 -0
  49. data/fixtures/asset-host-app/source/images/blank104.gif +0 -0
  50. data/fixtures/asset-host-app/source/images/blank1043.gif +0 -0
  51. data/fixtures/asset-host-app/source/images/blank1054.gif +0 -0
  52. data/fixtures/asset-host-app/source/images/blank2.gif +0 -0
  53. data/fixtures/asset-host-app/source/images/blank20.gif +0 -0
  54. data/fixtures/asset-host-app/source/images/blank21.gif +0 -0
  55. data/fixtures/asset-host-app/source/images/blank22.gif +0 -0
  56. data/fixtures/asset-host-app/source/images/blank23.gif +0 -0
  57. data/fixtures/asset-host-app/source/images/blank24.gif +0 -0
  58. data/fixtures/asset-host-app/source/images/blank3.gif +0 -0
  59. data/fixtures/asset-host-app/source/images/blank30.gif +0 -0
  60. data/fixtures/asset-host-app/source/images/blank31.gif +0 -0
  61. data/fixtures/asset-host-app/source/images/blank32.gif +0 -0
  62. data/fixtures/asset-host-app/source/images/blank33.gif +0 -0
  63. data/fixtures/asset-host-app/source/images/blank34.gif +0 -0
  64. data/fixtures/asset-host-app/source/images/blank4.gif +0 -0
  65. data/fixtures/asset-host-app/source/images/blank43.gif +0 -0
  66. data/fixtures/asset-host-app/source/images/blank54.gif +0 -0
  67. data/fixtures/dynamic-pages-app/config.rb +4 -0
  68. data/fixtures/dynamic-pages-app/source/should_be_ignored9.html +1 -0
  69. data/fixtures/external-pipeline-error/config.rb +5 -0
  70. data/fixtures/external-pipeline-error/source/javascripts/file.js +0 -0
  71. data/fixtures/page-id-app/config.rb +5 -0
  72. data/fixtures/page-id-app/source/fm.html.erb +5 -0
  73. data/fixtures/page-id-app/source/index.html.erb +6 -0
  74. data/fixtures/page-id-app/source/overwrites/from-default.html.erb +1 -0
  75. data/fixtures/page-id-app/source/overwrites/from-frontmatter.html.erb +5 -0
  76. data/fixtures/partials-app/source/_block.erb +3 -0
  77. data/fixtures/partials-app/source/block.html.erb +3 -0
  78. data/fixtures/partials-app/source/index_missing.html.erb +3 -0
  79. data/fixtures/relative-assets-app/source/images/blank2.gif +0 -0
  80. data/fixtures/sass-in-slim-app/config.rb +0 -0
  81. data/lib/middleman-core/application.rb +30 -4
  82. data/lib/middleman-core/builder.rb +8 -2
  83. data/lib/middleman-core/config_context.rb +5 -1
  84. data/lib/middleman-core/configuration.rb +1 -1
  85. data/lib/middleman-core/core_extensions/collections.rb +28 -17
  86. data/lib/middleman-core/core_extensions/collections/step_context.rb +14 -7
  87. data/lib/middleman-core/core_extensions/data.rb +4 -2
  88. data/lib/middleman-core/core_extensions/default_helpers.rb +1 -0
  89. data/lib/middleman-core/core_extensions/front_matter.rb +8 -6
  90. data/lib/middleman-core/core_extensions/i18n.rb +3 -1
  91. data/lib/middleman-core/core_extensions/inline_url_rewriter.rb +20 -35
  92. data/lib/middleman-core/core_extensions/routing.rb +6 -3
  93. data/lib/middleman-core/extension.rb +41 -6
  94. data/lib/middleman-core/extensions.rb +2 -2
  95. data/lib/middleman-core/extensions/asset_hash.rb +10 -5
  96. data/lib/middleman-core/extensions/asset_host.rb +4 -3
  97. data/lib/middleman-core/extensions/cache_buster.rb +2 -2
  98. data/lib/middleman-core/extensions/directory_indexes.rb +8 -2
  99. data/lib/middleman-core/extensions/external_pipeline.rb +54 -8
  100. data/lib/middleman-core/extensions/minify_css.rb +9 -1
  101. data/lib/middleman-core/extensions/minify_javascript.rb +8 -0
  102. data/lib/middleman-core/extensions/relative_assets.rb +38 -13
  103. data/lib/middleman-core/file_renderer.rb +4 -4
  104. data/lib/middleman-core/load_paths.rb +3 -1
  105. data/lib/middleman-core/logger.rb +1 -1
  106. data/lib/middleman-core/meta_pages/templates/index.html.erb +3 -1
  107. data/lib/middleman-core/preview_server.rb +25 -18
  108. data/lib/middleman-core/rack.rb +2 -0
  109. data/lib/middleman-core/renderers/redcarpet.rb +2 -2
  110. data/lib/middleman-core/renderers/sass_functions.rb +4 -6
  111. data/lib/middleman-core/renderers/slim.rb +1 -5
  112. data/lib/middleman-core/sitemap/extensions/import.rb +2 -2
  113. data/lib/middleman-core/sitemap/extensions/proxies.rb +4 -1
  114. data/lib/middleman-core/sitemap/extensions/redirects.rb +1 -2
  115. data/lib/middleman-core/sitemap/resource.rb +15 -5
  116. data/lib/middleman-core/sitemap/store.rb +33 -2
  117. data/lib/middleman-core/sources.rb +2 -1
  118. data/lib/middleman-core/sources/source_watcher.rb +17 -6
  119. data/lib/middleman-core/template_context.rb +26 -21
  120. data/lib/middleman-core/template_renderer.rb +22 -9
  121. data/lib/middleman-core/util/binary.rb +4 -5
  122. data/lib/middleman-core/util/data.rb +33 -18
  123. data/lib/middleman-core/util/files.rb +27 -24
  124. data/lib/middleman-core/util/paths.rb +74 -14
  125. data/lib/middleman-core/util/rack.rb +16 -6
  126. data/lib/middleman-core/version.rb +1 -1
  127. data/middleman-core.gemspec +11 -8
  128. data/spec/middleman-core/core_extensions/data_spec.rb +107 -1
  129. data/spec/middleman-core/util_spec.rb +37 -0
  130. metadata +196 -18
@@ -28,3 +28,7 @@ page "fake/*", locals: { glob_var: "I am one glob" }
28
28
  page "fake2/*", locals: { glob_var: "I am two glob" }
29
29
  page "fake3/*", locals: { glob_var: "I am three glob" }
30
30
  page "fake4/*", locals: { glob_var: "I am four glob" }
31
+
32
+ ["tom", "dick", "harry"].each do |name|
33
+ proxy "/about/#{name}.html", "/should_be_ignored9.html", locals: { person_name: name }, ignore: true
34
+ end
@@ -0,0 +1 @@
1
+ <h1>Ignore me! 9</h1>
@@ -0,0 +1,5 @@
1
+ activate :external_pipeline,
2
+ name: :failing,
3
+ command: "mv does-not-exist tmp/file.js",
4
+ source: "tmp",
5
+ latency: 2
@@ -0,0 +1,5 @@
1
+ %w(1 2 3).each do |n|
2
+ proxy "/#{n}.html", "/index.html", id: "page#{n}"
3
+ end
4
+
5
+ page "/overwrites/*", id: :"something-else"
@@ -0,0 +1,5 @@
1
+ ---
2
+ id: frontmatter
3
+ ---
4
+
5
+ I am: <%= current_resource.page_id %>
@@ -0,0 +1,6 @@
1
+ I am: <%= current_resource.page_id %>
2
+
3
+ URL1: <%= url_for "frontmatter" %>
4
+ URL2: <%= url_for "page2" %>
5
+ URL3: <%= link_to "Hi", "page3" %>
6
+ URL4: <%= link_to "Sym", :"something-else" %>
@@ -0,0 +1 @@
1
+ I am: <%= current_resource.page_id %>
@@ -0,0 +1,5 @@
1
+ ---
2
+ id: from_frontmatter
3
+ ---
4
+
5
+ I am: <%= current_resource.page_id %>
@@ -0,0 +1,3 @@
1
+ Start
2
+ <%= yield %>
3
+ End
@@ -0,0 +1,3 @@
1
+ <% partial "block" do %>
2
+ Contents
3
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <%= partial "shared/header" %>
2
+ <%= partial "i_do_not_exist" %>
3
+ <%= partial "shared/footer" %>
File without changes
@@ -96,6 +96,10 @@ module Middleman
96
96
  # @return [String]
97
97
  define_setting :source, 'source', 'Name of the source directory'
98
98
 
99
+ # If we should not run the sitemap.
100
+ # @return [Boolean]
101
+ define_setting :disable_sitemap, false, 'If we should not run the sitemap.'
102
+
99
103
  # If we should exit before ready event.
100
104
  # @return [Boolean]
101
105
  define_setting :exit_before_ready, false, 'If we should exit before ready event.'
@@ -106,7 +110,7 @@ module Middleman
106
110
 
107
111
  # Middleman environment. Defaults to :development
108
112
  # @return [String]
109
- define_setting :environment, ((ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development), 'Middleman environment. Defaults to :development'
113
+ define_setting :environment, ((ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development), 'Middleman environment. Defaults to :development', import: proc { |s| s.to_sym }
110
114
 
111
115
  # Which file should be used for directory indexes
112
116
  # @return [String]
@@ -156,6 +160,10 @@ module Middleman
156
160
  # @return [Array.<String>]
157
161
  define_setting :extensions_with_layout, %w(.htm .html .xhtml .php), 'Which file extensions have a layout by default.'
158
162
 
163
+ # Which file extensions are "assets."
164
+ # @return [Array.<String>]
165
+ define_setting :asset_extensions, %w(.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2 .eot .ico .map), 'Which file extensions are treated as assets.'
166
+
159
167
  # Default string encoding for templates and output.
160
168
  # @return [String]
161
169
  define_setting :encoding, 'utf-8', 'Default string encoding for templates and output'
@@ -183,13 +191,15 @@ module Middleman
183
191
  ignored
184
192
  end,
185
193
 
186
- layout: proc do |file, _sitemap_app|
187
- file[:relative_path].to_s.start_with?('layout.', 'layouts/')
194
+ layout: proc do |file, app|
195
+ file[:relative_path].to_s.start_with?('layout.', app.config[:layouts_dir] + '/')
188
196
  end
189
197
  }, 'Callbacks that can exclude paths from the sitemap'
190
198
 
191
199
  define_setting :skip_build_clean, proc { |p| [/\.git/].any? { |r| p =~ r } }, 'Whether some paths should not be removed during a clean build.'
192
200
 
201
+ define_setting :cli_options, {}, 'Options from the Command Line.'
202
+
193
203
  define_setting :watcher_disable, false, 'If the Listen watcher should not run'
194
204
  define_setting :watcher_force_polling, false, 'If the Listen watcher should run in polling mode'
195
205
  define_setting :watcher_latency, nil, 'The Listen watcher latency'
@@ -225,7 +235,8 @@ module Middleman
225
235
  :before, # Before Rack requests
226
236
  :before_render,
227
237
  :after_render,
228
- :before_server
238
+ :before_server,
239
+ :reload
229
240
  ])
230
241
 
231
242
  @middleware = Set.new
@@ -255,6 +266,8 @@ module Middleman
255
266
  # Evaluate a passed block if given
256
267
  config_context.instance_exec(&block) if block_given?
257
268
 
269
+ apply_cli_options
270
+
258
271
  execute_callbacks(:before_sitemap)
259
272
 
260
273
  # Initialize the Sitemap
@@ -277,6 +290,8 @@ module Middleman
277
290
  # Run any `configure` blocks for the current mode.
278
291
  execute_callbacks([:configure, config[:mode]])
279
292
 
293
+ apply_cli_options
294
+
280
295
  # Post parsing, pre-extension callback
281
296
  execute_callbacks(:after_configuration_eval)
282
297
 
@@ -293,6 +308,17 @@ module Middleman
293
308
  execute_callbacks(:ready) unless config[:exit_before_ready]
294
309
  end
295
310
 
311
+ def apply_cli_options
312
+ config[:cli_options].each do |k, v|
313
+ setting = config.setting(k.to_sym)
314
+ next unless setting
315
+
316
+ v = setting.options[:import].call(v) if setting.options[:import]
317
+
318
+ config[k.to_sym] = v
319
+ end
320
+ end
321
+
296
322
  # Eval config
297
323
  def evaluate_configuration!
298
324
  # Check for and evaluate local configuration in `config.rb`
@@ -97,7 +97,7 @@ module Middleman
97
97
 
98
98
  ::Middleman::Util.instrument 'builder.prerender.check-files' do
99
99
  # Double-check for compass sprites
100
- if @app.files.find_new_files!.length > 0
100
+ unless @app.files.find_new_files!.empty?
101
101
  logger.debug '== Checking for Compass sprites'
102
102
  @app.sitemap.ensure_resource_list_updated!
103
103
  end
@@ -117,7 +117,13 @@ module Middleman
117
117
  .sort_by { |resource| SORT_ORDER.index(resource.ext) || 100 }
118
118
 
119
119
  if @glob
120
- resources = resources.select { |resource| File.fnmatch(@glob, resource.destination_path) }
120
+ resources = resources.select do |resource|
121
+ if defined?(::File::FNM_EXTGLOB)
122
+ File.fnmatch(@glob, resource.destination_path, ::File::FNM_EXTGLOB)
123
+ else
124
+ File.fnmatch(@glob, resource.destination_path)
125
+ end
126
+ end
121
127
  end
122
128
 
123
129
  output_resources(resources)
@@ -8,7 +8,7 @@ module Middleman
8
8
  attr_reader :app
9
9
 
10
10
  # Whitelist methods that can reach out.
11
- def_delegators :@app, :config, :logger, :use, :map, :mime_type, :files, :root, :build?, :server?, :environment?
11
+ def_delegators :@app, :config, :logger, :use, :map, :mime_type, :files, :root, :build?, :server?, :environment?, :extensions
12
12
  def_delegator :"@app.extensions", :activate
13
13
 
14
14
  def initialize(app, template_context_class)
@@ -22,6 +22,10 @@ module Middleman
22
22
  app.subscribe_to_callbacks(&method(:execute_callbacks))
23
23
  end
24
24
 
25
+ def include(mod)
26
+ extend(mod)
27
+ end
28
+
25
29
  def helpers(*helper_modules, &block)
26
30
  helper_modules ||= []
27
31
 
@@ -40,7 +40,7 @@ module Middleman
40
40
 
41
41
  # Allow configuration settings to be read and written via methods
42
42
  def method_missing(method, *args)
43
- if defines_setting?(method) && args.size == 0
43
+ if defines_setting?(method) && args.empty?
44
44
  self[method]
45
45
  elsif method.to_s =~ /^(\w+)=$/ && args.size == 1
46
46
  self[$1.to_sym] = args[0]
@@ -1,3 +1,4 @@
1
+ require 'monitor'
1
2
  require 'middleman-core/core_extensions/collections/pagination'
2
3
  require 'middleman-core/core_extensions/collections/step_context'
3
4
  require 'middleman-core/core_extensions/collections/lazy_root'
@@ -41,6 +42,8 @@ module Middleman
41
42
  @values_by_name = {}
42
43
 
43
44
  @collector_roots = []
45
+
46
+ @lock = Monitor.new
44
47
  end
45
48
 
46
49
  def before_configuration
@@ -81,27 +84,35 @@ module Middleman
81
84
 
82
85
  Contract ResourceList => ResourceList
83
86
  def manipulate_resource_list(resources)
84
- @collector_roots.each do |pair|
85
- dataset = pair[:block].call(app, resources)
86
- pair[:root].realize!(dataset)
87
- end
87
+ @lock.synchronize do
88
+ @collector_roots.each do |pair|
89
+ dataset = pair[:block].call(app, resources)
90
+ pair[:root].realize!(dataset)
91
+ end
88
92
 
89
- ctx = StepContext.new
90
- leaves = @leaves.dup
93
+ ctx = StepContext.new(app)
94
+ StepContext.current = ctx
91
95
 
92
- @collectors_by_name.each do |k, v|
93
- @values_by_name[k] = v.value(ctx)
94
- leaves.delete v
95
- end
96
+ leaves = @leaves.dup
96
97
 
97
- # Execute code paths
98
- leaves.each do |v|
99
- v.value(ctx)
100
- end
98
+ @collectors_by_name.each do |k, v|
99
+ @values_by_name[k] = v.value(ctx)
100
+ leaves.delete v
101
+ end
102
+
103
+ # Execute code paths
104
+ leaves.each do |v|
105
+ v.value(ctx)
106
+ end
107
+
108
+ # Inject descriptors
109
+ results = ctx.descriptors.reduce(resources) do |sum, d|
110
+ d.execute_descriptor(app, sum)
111
+ end
112
+
113
+ StepContext.current = nil
101
114
 
102
- # Inject descriptors
103
- ctx.descriptors.reduce(resources) do |sum, d|
104
- d.execute_descriptor(app, sum)
115
+ results
105
116
  end
106
117
  end
107
118
  end
@@ -2,23 +2,30 @@ module Middleman
2
2
  module CoreExtensions
3
3
  module Collections
4
4
  class StepContext
5
- def self.add_to_context(name, &func)
6
- send(:define_method, :"_internal_#{name}", &func)
5
+ class << self
6
+ attr_accessor :current
7
+
8
+ def add_to_context(name, &func)
9
+ send(:define_method, :"_internal_#{name}", &func)
10
+ end
7
11
  end
8
12
 
9
13
  attr_reader :descriptors
10
14
 
11
- def initialize
15
+ def initialize(app)
16
+ @app = app
12
17
  @descriptors = []
13
18
  end
14
19
 
15
20
  def method_missing(name, *args, &block)
16
21
  internal = :"_internal_#{name}"
17
22
 
18
- return super unless respond_to?(internal)
19
-
20
- send(internal, *args, &block).tap do |r|
21
- @descriptors << r if r.respond_to?(:execute_descriptor)
23
+ if respond_to?(internal)
24
+ send(internal, *args, &block).tap do |r|
25
+ @descriptors << r if r.respond_to?(:execute_descriptor)
26
+ end
27
+ else
28
+ @app.config_context.send(name, *args, &block)
22
29
  end
23
30
  end
24
31
  end
@@ -67,7 +67,7 @@ module Middleman
67
67
  # @param [Symbol] name Name of the data, used for namespacing
68
68
  # @param [Hash] content The content for this data
69
69
  # @return [Hash]
70
- Contract Symbol, Hash => Hash
70
+ Contract Symbol, Or[Hash, Array] => Hash
71
71
  def store(name=nil, content=nil)
72
72
  @local_sources[name.to_s] = content unless name.nil? || content.nil?
73
73
  @local_sources
@@ -88,6 +88,8 @@ module Middleman
88
88
  def update_files(updated_files, removed_files)
89
89
  updated_files.each(&method(:touch_file))
90
90
  removed_files.each(&method(:remove_file))
91
+
92
+ @app.sitemap.rebuild_resource_list!(:touched_data_file)
91
93
  end
92
94
 
93
95
  # Update the internal cache for a given file path
@@ -148,7 +150,7 @@ module Middleman
148
150
  #
149
151
  # @param [String, Symbol] path The name of the data namespace
150
152
  # @return [Hash, nil]
151
- Contract Or[String, Symbol] => Maybe[Hash]
153
+ Contract Or[String, Symbol] => Maybe[Or[Array, IsA['Middleman::Util::EnhancedHash']]]
152
154
  def data_for_path(path)
153
155
  response = if store.key?(path.to_s)
154
156
  store[path.to_s]
@@ -1,4 +1,5 @@
1
1
  require 'padrino-helpers'
2
+ require 'middleman-core/contracts'
2
3
 
3
4
  # Don't fail on invalid locale, that's not what our current
4
5
  # users expect.
@@ -73,18 +73,20 @@ module Middleman::CoreExtensions
73
73
 
74
74
  return [{}, nil] unless file
75
75
 
76
- return @cache[file[:full_path]] if @cache.key?(file[:full_path])
76
+ file_path = file[:full_path].to_s
77
77
 
78
- @cache[file[:full_path]] = ::Middleman::Util::Data.parse(
79
- file,
80
- app.config[:frontmatter_delims]
81
- )
78
+ @cache[file_path] ||= begin
79
+ ::Middleman::Util::Data.parse(
80
+ file,
81
+ app.config[:frontmatter_delims]
82
+ )
83
+ end
82
84
  end
83
85
 
84
86
  Contract ArrayOf[IsA['Middleman::SourceFile']], ArrayOf[IsA['Middleman::SourceFile']] => Any
85
87
  def clear_data(updated_files, removed_files)
86
88
  (updated_files + removed_files).each do |file|
87
- @cache.delete(file[:full_path])
89
+ @cache.delete(file[:full_path].to_s)
88
90
  end
89
91
  end
90
92
  end