middleman-core 4.0.0 → 4.1.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/features/asset_hash.feature +63 -0
  3. data/features/asset_host.feature +14 -0
  4. data/features/cache_buster.feature +15 -1
  5. data/features/clean_build.feature +16 -0
  6. data/features/cli/preview_server.feature +6 -4
  7. data/features/cli_extension.feature +1 -1
  8. data/features/directory_index.feature +3 -1
  9. data/features/encoding_option.feature +28 -0
  10. data/features/i18n_mixed_sources.feature +39 -0
  11. data/features/ignore.feature +33 -4
  12. data/features/relative_assets.feature +14 -0
  13. data/features/support/env.rb +1 -1
  14. data/fixtures/asset-hash-app/source/index.html.erb +3 -0
  15. data/fixtures/asset-hash-app/source/layout.erb +3 -3
  16. data/fixtures/asset-hash-app/source/other.html.erb +3 -0
  17. data/fixtures/asset-hash-app/source/stylesheets/fragment.css.scss +7 -0
  18. data/fixtures/asset-hash-host-app/source/index.html.erb +3 -0
  19. data/fixtures/asset-hash-host-app/source/layout.erb +3 -3
  20. data/fixtures/asset-hash-host-app/source/other.html.erb +3 -0
  21. data/fixtures/asset-hash-host-app/source/stylesheets/fragment.css.scss +3 -0
  22. data/fixtures/i-8859-1-app/config.rb +1 -0
  23. data/fixtures/i-8859-1-app/source/index.html.erb +1 -0
  24. data/fixtures/i18n-mixed-sources/config.rb +1 -0
  25. data/fixtures/i18n-mixed-sources/locales/en.yml +4 -0
  26. data/fixtures/i18n-mixed-sources/locales/es.yml +4 -0
  27. data/fixtures/i18n-mixed-sources/source/a/sub.html.erb +9 -0
  28. data/fixtures/i18n-mixed-sources/source/b/index.html.erb +9 -0
  29. data/fixtures/i18n-mixed-sources/source/index.html.erb +9 -0
  30. data/fixtures/i18n-mixed-sources/source/localizable/a/index.html.erb +9 -0
  31. data/fixtures/i18n-mixed-sources/source/localizable/b/sub.html.erb +9 -0
  32. data/fixtures/i18n-mixed-sources/source/localizable/index.html.erb +9 -0
  33. data/fixtures/import-app/config.rb +1 -1
  34. data/fixtures/indexable-app/config.rb +1 -0
  35. data/fixtures/indexable-app/source/regex_leave_me_alone2.html +1 -0
  36. data/lib/middleman-core/application.rb +6 -5
  37. data/lib/middleman-core/builder.rb +7 -3
  38. data/lib/middleman-core/core_extensions/collections.rb +3 -1
  39. data/lib/middleman-core/core_extensions/collections/step_context.rb +6 -7
  40. data/lib/middleman-core/core_extensions/default_helpers.rb +2 -2
  41. data/lib/middleman-core/core_extensions/front_matter.rb +1 -0
  42. data/lib/middleman-core/core_extensions/i18n.rb +16 -9
  43. data/lib/middleman-core/core_extensions/routing.rb +1 -1
  44. data/lib/middleman-core/extension.rb +34 -0
  45. data/lib/middleman-core/extensions/asset_hash.rb +2 -0
  46. data/lib/middleman-core/extensions/asset_host.rb +2 -0
  47. data/lib/middleman-core/extensions/cache_buster.rb +2 -0
  48. data/lib/middleman-core/extensions/external_pipeline.rb +0 -2
  49. data/lib/middleman-core/extensions/gzip.rb +1 -1
  50. data/lib/middleman-core/extensions/relative_assets.rb +2 -0
  51. data/lib/middleman-core/load_paths.rb +1 -1
  52. data/lib/middleman-core/meta_pages/sitemap_resource.rb +1 -1
  53. data/lib/middleman-core/middleware/inline_url_rewriter.rb +10 -2
  54. data/lib/middleman-core/sitemap/extensions/ignores.rb +37 -39
  55. data/lib/middleman-core/sitemap/extensions/import.rb +24 -66
  56. data/lib/middleman-core/sitemap/extensions/move_file.rb +9 -38
  57. data/lib/middleman-core/sitemap/extensions/proxies.rb +20 -52
  58. data/lib/middleman-core/sitemap/extensions/traversal.rb +13 -1
  59. data/lib/middleman-core/sitemap/resource.rb +4 -9
  60. data/lib/middleman-core/sitemap/store.rb +10 -9
  61. data/lib/middleman-core/step_definitions/server_steps.rb +4 -0
  62. data/lib/middleman-core/util.rb +22 -24
  63. data/lib/middleman-core/version.rb +1 -1
  64. data/spec/middleman-core/util_spec.rb +10 -1
  65. metadata +34 -4
@@ -2,10 +2,22 @@ module Middleman
2
2
  module Sitemap
3
3
  module Extensions
4
4
  module Traversal
5
+ def traversal_root
6
+ root = if !@app.extensions[:i18n]
7
+ '/'
8
+ else
9
+ @app.extensions[:i18n].path_root(::I18n.locale)
10
+ end
11
+
12
+ root.sub(/^\//, '')
13
+ end
14
+
5
15
  # This resource's parent resource
6
16
  # @return [Middleman::Sitemap::Resource, nil]
7
17
  def parent
8
- parts = path.split('/')
18
+ root = path.sub(/^#{::Regexp.escape(traversal_root)}/, '')
19
+ parts = root.split('/')
20
+
9
21
  tail = parts.pop
10
22
  is_index = (tail == @app.config[:index_file])
11
23
 
@@ -38,6 +38,8 @@ module Middleman
38
38
  Contract METADATA_HASH
39
39
  attr_reader :metadata
40
40
 
41
+ attr_accessor :ignored
42
+
41
43
  # Initialize resource with parent store and URL
42
44
  # @param [Middleman::Sitemap::Store] store
43
45
  # @param [String] path
@@ -47,6 +49,7 @@ module Middleman
47
49
  @store = store
48
50
  @app = @store.app
49
51
  @path = path
52
+ @ignored = false
50
53
 
51
54
  source = Pathname(source) if source && source.is_a?(String)
52
55
 
@@ -173,15 +176,7 @@ module Middleman
173
176
  # @return [Boolean]
174
177
  Contract Bool
175
178
  def ignored?
176
- return true if @ignored
177
- # Ignore based on the source path (without template extensions)
178
- return true if @app.sitemap.ignored?(path)
179
- # This allows files to be ignored by their source file name (with template extensions)
180
- if !self.is_a?(ProxyResource) && file_descriptor && @app.sitemap.ignored?(file_descriptor[:relative_path].to_s)
181
- true
182
- else
183
- false
184
- end
179
+ @ignored
185
180
  end
186
181
 
187
182
  # The preferred MIME content type for this resource based on extension or metadata
@@ -3,12 +3,6 @@ require 'active_support/core_ext/hash/deep_merge'
3
3
  require 'monitor'
4
4
  require 'hamster'
5
5
 
6
- # Ignores
7
- Middleman::Extensions.register :sitemap_ignore, auto_activate: :before_configuration do
8
- require 'middleman-core/sitemap/extensions/ignores'
9
- Middleman::Sitemap::Extensions::Ignores
10
- end
11
-
12
6
  # Files on Disk
13
7
  Middleman::Extensions.register :sitemap_ondisk, auto_activate: :before_configuration do
14
8
  require 'middleman-core/sitemap/extensions/on_disk'
@@ -45,6 +39,12 @@ Middleman::Extensions.register :sitemap_move_files, auto_activate: :before_confi
45
39
  Middleman::Sitemap::Extensions::MoveFile
46
40
  end
47
41
 
42
+ # Ignores
43
+ Middleman::Extensions.register :sitemap_ignore, auto_activate: :before_configuration do
44
+ require 'middleman-core/sitemap/extensions/ignores'
45
+ Middleman::Sitemap::Extensions::Ignores
46
+ end
47
+
48
48
  require 'middleman-core/contracts'
49
49
 
50
50
  module Middleman
@@ -108,14 +108,15 @@ module Middleman
108
108
  [m[:priority], n]
109
109
  end
110
110
 
111
- rebuild_resource_list!(:registered_new)
111
+ rebuild_resource_list!(:"registered_new_manipulator_#{name}")
112
112
  end
113
113
 
114
114
  # Rebuild the list of resources from scratch, using registed manipulators
115
115
  # @return [void]
116
116
  Contract Maybe[Symbol] => Any
117
- def rebuild_resource_list!(_name=nil)
117
+ def rebuild_resource_list!(name=nil)
118
118
  @lock.synchronize do
119
+ @app.logger.debug "== Requesting resource list rebuilding: #{name}"
119
120
  @needs_sitemap_rebuild = true
120
121
  end
121
122
  end
@@ -159,7 +160,7 @@ module Middleman
159
160
  end
160
161
  end
161
162
 
162
- # Invalidate our cached view of resource that are not ingnored. If your extension
163
+ # Invalidate our cached view of resource that are not ignored. If your extension
163
164
  # adds ways to ignore files, you should call this to make sure #resources works right.
164
165
  def invalidate_resources_not_ignored_cache!
165
166
  @resources_not_ignored = nil
@@ -75,6 +75,10 @@ Then /^the content type should be "([^\"]*)"$/ do |expected|
75
75
  expect(page.response_headers['Content-Type']).to start_with expected
76
76
  end
77
77
 
78
+ Then /^the "([^\"]*)" header should contain "([^\"]*)"$/ do |header, expected|
79
+ expect(page.response_headers[header]).to include expected
80
+ end
81
+
78
82
  Then /^I should see "([^\"]*)"$/ do |expected|
79
83
  expect(page.body).to include expected
80
84
  end
@@ -201,31 +201,32 @@ module Middleman
201
201
  Contract IsA['Middleman::Application'], String, String, Hash => String
202
202
  def asset_url(app, path, prefix='', options={})
203
203
  # Don't touch assets which already have a full path
204
- if path.include?('//') || path.start_with?('data:')
205
- path
206
- else # rewrite paths to use their destination path
207
- result = if resource = app.sitemap.find_resource_by_destination_path(url_for(app, path))
204
+ return path if path.include?('//') || path.start_with?('data:')
205
+
206
+ if options[:relative] && !options[:current_resource]
207
+ raise ArgumentError, '#asset_url must be run in a context with current_resource if relative: true'
208
+ end
209
+
210
+ uri = URI(path)
211
+ path = uri.path
212
+
213
+ result = if resource = app.sitemap.find_resource_by_destination_path(url_for(app, path, options))
214
+ resource.url
215
+ else
216
+ path = File.join(prefix, path)
217
+ if resource = app.sitemap.find_resource_by_path(path)
208
218
  resource.url
209
219
  else
210
- path = File.join(prefix, path)
211
- if resource = app.sitemap.find_resource_by_path(path)
212
- resource.url
213
- else
214
- File.join(app.config[:http_prefix], path)
215
- end
220
+ File.join(app.config[:http_prefix], path)
216
221
  end
222
+ end
217
223
 
218
- if options[:relative] != true
219
- result
220
- else
221
- unless options[:current_resource]
222
- raise ArgumentError, '#asset_url must be run in a context with current_resource if relative: true'
223
- end
224
+ final_result = URI.encode(relative_path_from_resource(options[:current_resource], result, options[:relative]))
224
225
 
225
- current_dir = Pathname('/' + options[:current_resource].destination_path)
226
- Pathname(result).relative_path_from(current_dir.dirname).to_s
227
- end
228
- end
226
+ result_uri = URI(final_result)
227
+ result_uri.query = uri.query
228
+ result_uri.fragment = uri.fragment
229
+ result_uri.to_s
229
230
  end
230
231
 
231
232
  # Given a source path (referenced either absolutely or relatively)
@@ -290,9 +291,6 @@ module Middleman
290
291
  else
291
292
  resource_url
292
293
  end
293
- else
294
- # If they explicitly asked for relative links but we can't find a resource...
295
- raise "No resource exists at #{url}" if relative
296
294
  end
297
295
 
298
296
  # Support a :query option that can be a string or hash
@@ -368,7 +366,7 @@ module Middleman
368
366
  case
369
367
  when mime.start_with?('text/')
370
368
  true
371
- when mime.include?('xml')
369
+ when mime.include?('xml') && !mime.include?('officedocument')
372
370
  true
373
371
  when mime.include?('json')
374
372
  true
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  # Current Version
3
3
  # @return [String]
4
- VERSION = '4.0.0' unless const_defined?(:VERSION)
4
+ VERSION = '4.1.0.rc.1' unless const_defined?(:VERSION)
5
5
  end
@@ -98,6 +98,15 @@ describe Middleman::Util do
98
98
  end
99
99
  end
100
100
 
101
+ it "returns path relative to the provided current_resource" do
102
+ Given.fixture 'clean-dir-app'
103
+ Given.file 'source/a-path/index.html', ''
104
+ Given.file 'source/a-path/images/blank.gif', ''
105
+ @mm = Middleman::Application.new
106
+ current_resource = @mm.sitemap.find_resource_by_path('a-path/index.html')
107
+ expect( Middleman::Util.asset_url( @mm, 'images/blank.gif', 'images', current_resource: current_resource ) ).to eq '/a-path/images/blank.gif'
108
+ end
109
+
101
110
  context "when relative is true" do
102
111
 
103
112
  before(:each) do
@@ -106,7 +115,7 @@ describe Middleman::Util do
106
115
  end
107
116
 
108
117
  it "returns path relative to the provided current_resource" do
109
- current_resource = instance_double("Middleman::Sitemap::Resource", destination_path: 'a-path/index.html')
118
+ current_resource = instance_double("Middleman::Sitemap::Resource", destination_path: 'a-path/index.html', path: 'a-path/index.html')
110
119
  expect( Middleman::Util.asset_url( @mm, 'blank.gif', 'images', current_resource: current_resource,
111
120
  relative: true ) ).to eq '../images/blank.gif'
112
121
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Reynolds
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-12-16 00:00:00.000000000 Z
13
+ date: 2016-01-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -314,6 +314,7 @@ files:
314
314
  - features/default-layout.feature
315
315
  - features/directory_index.feature
316
316
  - features/dynamic_pages.feature
317
+ - features/encoding_option.feature
317
318
  - features/extension_api_deprecations.feature
318
319
  - features/extension_hooks.feature
319
320
  - features/extensionless_text_files.feature
@@ -336,6 +337,7 @@ files:
336
337
  - features/i18n_builder.feature
337
338
  - features/i18n_force_locale.feature
338
339
  - features/i18n_link_to.feature
340
+ - features/i18n_mixed_sources.feature
339
341
  - features/i18n_partials.feature
340
342
  - features/i18n_preview.feature
341
343
  - features/ignore.feature
@@ -403,6 +405,7 @@ files:
403
405
  - fixtures/asset-hash-app/source/partials.html.erb
404
406
  - fixtures/asset-hash-app/source/slim.html.slim
405
407
  - fixtures/asset-hash-app/source/stylesheets/_partial.sass
408
+ - fixtures/asset-hash-app/source/stylesheets/fragment.css.scss
406
409
  - fixtures/asset-hash-app/source/stylesheets/site.css.scss
407
410
  - fixtures/asset-hash-app/source/stylesheets/uses_fonts.css
408
411
  - fixtures/asset-hash-app/source/stylesheets/uses_partials.css.sass
@@ -669,6 +672,8 @@ files:
669
672
  - fixtures/gzip-app/source/index.html
670
673
  - fixtures/gzip-app/source/javascripts/test.js
671
674
  - fixtures/gzip-app/source/stylesheets/test.css
675
+ - fixtures/i-8859-1-app/config.rb
676
+ - fixtures/i-8859-1-app/source/index.html.erb
672
677
  - fixtures/i18n-alt-root-app/locales/en.yml
673
678
  - fixtures/i18n-alt-root-app/locales/es.yml
674
679
  - fixtures/i18n-alt-root-app/source/lang_data/hello.html.erb
@@ -682,6 +687,15 @@ files:
682
687
  - fixtures/i18n-force-locale/locales/es.yml
683
688
  - fixtures/i18n-force-locale/locales/fr.yml
684
689
  - fixtures/i18n-force-locale/source/index.html.haml
690
+ - fixtures/i18n-mixed-sources/config.rb
691
+ - fixtures/i18n-mixed-sources/locales/en.yml
692
+ - fixtures/i18n-mixed-sources/locales/es.yml
693
+ - fixtures/i18n-mixed-sources/source/a/sub.html.erb
694
+ - fixtures/i18n-mixed-sources/source/b/index.html.erb
695
+ - fixtures/i18n-mixed-sources/source/index.html.erb
696
+ - fixtures/i18n-mixed-sources/source/localizable/a/index.html.erb
697
+ - fixtures/i18n-mixed-sources/source/localizable/b/sub.html.erb
698
+ - fixtures/i18n-mixed-sources/source/localizable/index.html.erb
685
699
  - fixtures/i18n-nested-app/locales/en.yml
686
700
  - fixtures/i18n-nested-app/locales/en/more.yml
687
701
  - fixtures/i18n-nested-app/locales/es.yml
@@ -826,6 +840,7 @@ files:
826
840
  - fixtures/indexable-app/source/evil spaces.html
827
841
  - fixtures/indexable-app/source/leave_me_alone.html
828
842
  - fixtures/indexable-app/source/needs_index.html
843
+ - fixtures/indexable-app/source/regex_leave_me_alone2.html
829
844
  - fixtures/indexable-app/source/regular/index.html
830
845
  - fixtures/indexable-app/source/wildcard_leave_me_alone.html
831
846
  - fixtures/javascript-app/config.rb
@@ -1411,9 +1426,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
1411
1426
  version: 2.0.0
1412
1427
  required_rubygems_version: !ruby/object:Gem::Requirement
1413
1428
  requirements:
1414
- - - ">="
1429
+ - - ">"
1415
1430
  - !ruby/object:Gem::Version
1416
- version: '0'
1431
+ version: 1.3.1
1417
1432
  requirements: []
1418
1433
  rubyforge_project:
1419
1434
  rubygems_version: 2.4.8
@@ -1448,6 +1463,7 @@ test_files:
1448
1463
  - features/default-layout.feature
1449
1464
  - features/directory_index.feature
1450
1465
  - features/dynamic_pages.feature
1466
+ - features/encoding_option.feature
1451
1467
  - features/extension_api_deprecations.feature
1452
1468
  - features/extension_hooks.feature
1453
1469
  - features/extensionless_text_files.feature
@@ -1470,6 +1486,7 @@ test_files:
1470
1486
  - features/i18n_builder.feature
1471
1487
  - features/i18n_force_locale.feature
1472
1488
  - features/i18n_link_to.feature
1489
+ - features/i18n_mixed_sources.feature
1473
1490
  - features/i18n_partials.feature
1474
1491
  - features/i18n_preview.feature
1475
1492
  - features/ignore.feature
@@ -1537,6 +1554,7 @@ test_files:
1537
1554
  - fixtures/asset-hash-app/source/partials.html.erb
1538
1555
  - fixtures/asset-hash-app/source/slim.html.slim
1539
1556
  - fixtures/asset-hash-app/source/stylesheets/_partial.sass
1557
+ - fixtures/asset-hash-app/source/stylesheets/fragment.css.scss
1540
1558
  - fixtures/asset-hash-app/source/stylesheets/site.css.scss
1541
1559
  - fixtures/asset-hash-app/source/stylesheets/uses_fonts.css
1542
1560
  - fixtures/asset-hash-app/source/stylesheets/uses_partials.css.sass
@@ -1803,6 +1821,8 @@ test_files:
1803
1821
  - fixtures/gzip-app/source/index.html
1804
1822
  - fixtures/gzip-app/source/javascripts/test.js
1805
1823
  - fixtures/gzip-app/source/stylesheets/test.css
1824
+ - fixtures/i-8859-1-app/config.rb
1825
+ - fixtures/i-8859-1-app/source/index.html.erb
1806
1826
  - fixtures/i18n-alt-root-app/locales/en.yml
1807
1827
  - fixtures/i18n-alt-root-app/locales/es.yml
1808
1828
  - fixtures/i18n-alt-root-app/source/lang_data/hello.html.erb
@@ -1816,6 +1836,15 @@ test_files:
1816
1836
  - fixtures/i18n-force-locale/locales/es.yml
1817
1837
  - fixtures/i18n-force-locale/locales/fr.yml
1818
1838
  - fixtures/i18n-force-locale/source/index.html.haml
1839
+ - fixtures/i18n-mixed-sources/config.rb
1840
+ - fixtures/i18n-mixed-sources/locales/en.yml
1841
+ - fixtures/i18n-mixed-sources/locales/es.yml
1842
+ - fixtures/i18n-mixed-sources/source/a/sub.html.erb
1843
+ - fixtures/i18n-mixed-sources/source/b/index.html.erb
1844
+ - fixtures/i18n-mixed-sources/source/index.html.erb
1845
+ - fixtures/i18n-mixed-sources/source/localizable/a/index.html.erb
1846
+ - fixtures/i18n-mixed-sources/source/localizable/b/sub.html.erb
1847
+ - fixtures/i18n-mixed-sources/source/localizable/index.html.erb
1819
1848
  - fixtures/i18n-nested-app/locales/en.yml
1820
1849
  - fixtures/i18n-nested-app/locales/en/more.yml
1821
1850
  - fixtures/i18n-nested-app/locales/es.yml
@@ -1960,6 +1989,7 @@ test_files:
1960
1989
  - fixtures/indexable-app/source/evil spaces.html
1961
1990
  - fixtures/indexable-app/source/leave_me_alone.html
1962
1991
  - fixtures/indexable-app/source/needs_index.html
1992
+ - fixtures/indexable-app/source/regex_leave_me_alone2.html
1963
1993
  - fixtures/indexable-app/source/regular/index.html
1964
1994
  - fixtures/indexable-app/source/wildcard_leave_me_alone.html
1965
1995
  - fixtures/javascript-app/config.rb