middleman-core 4.3.0.rc.1 → 4.3.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +0 -1
  3. data/cucumber.yml +2 -2
  4. data/features/asset_hash.feature +2 -2
  5. data/features/collections.feature +2 -2
  6. data/features/i18n_mixed_sources.feature +8 -0
  7. data/features/markdown.feature +0 -1
  8. data/features/multiple-sources-reload.feature +40 -0
  9. data/features/partials.feature +1 -1
  10. data/features/support/env.rb +4 -1
  11. data/features/tilde_directories.feature +0 -2
  12. data/features/unicode_filenames.feature +1 -1
  13. data/fixtures/asset-hash-app/config.rb +0 -1
  14. data/fixtures/asset-hash-app/lib/middleware.rb +2 -2
  15. data/fixtures/asset-hash-app/source/stylesheets/_partial.sass +1 -1
  16. data/fixtures/asset-hash-prefix/config.rb +1 -2
  17. data/fixtures/asset-hash-prefix/lib/middleware.rb +2 -2
  18. data/fixtures/asset-hash-source-map/config.rb +0 -1
  19. data/fixtures/asset-hash-source-map/lib/middleware.rb +2 -2
  20. data/fixtures/asset-host-app/config.rb +1 -1
  21. data/fixtures/auto-css-app/config.rb +2 -2
  22. data/fixtures/auto-js-app/config.rb +2 -2
  23. data/fixtures/auto-js-directory-index-app/config.rb +1 -1
  24. data/fixtures/automatic-directory-matcher-app/config.rb +1 -1
  25. data/fixtures/basic-data-app/config.rb +2 -2
  26. data/fixtures/capture-html-app/config.rb +4 -4
  27. data/fixtures/clean-app/config-complications.rb +6 -6
  28. data/fixtures/clean-app/config-hidden-dir-after.rb +4 -4
  29. data/fixtures/clean-app/config-hidden-dir-before.rb +1 -1
  30. data/fixtures/clean-app/config.rb +6 -6
  31. data/fixtures/clean-dir-app/config.rb +0 -1
  32. data/fixtures/clean-nested-app/config.rb +1 -1
  33. data/fixtures/collections-app/source/blog1/2011-01-01-new-article.html.markdown +1 -1
  34. data/fixtures/collections-app/source/blog1/2011-01-02-another-article.html.markdown +1 -1
  35. data/fixtures/collections-app/source/blog2/2011-01-01-new-article.html.markdown +1 -1
  36. data/fixtures/collections-app/source/blog2/2011-01-02-another-article.html.markdown +1 -1
  37. data/fixtures/content-for-app/config.rb +4 -4
  38. data/fixtures/destination-dir-different-from-source-dir-name/external/page.html.erb +1 -0
  39. data/fixtures/destination-dir-different-from-source-dir-name/my-app/config.rb +2 -0
  40. data/fixtures/destination-dir-different-from-source-dir-name/my-app/source/index.html.erb +1 -0
  41. data/fixtures/dynamic-pages-app/config.rb +25 -26
  42. data/fixtures/ember-cli-app/config.rb +4 -4
  43. data/fixtures/env-app/environments/development.rb +1 -1
  44. data/fixtures/env-app/environments/production.rb +1 -1
  45. data/fixtures/extension-hooks-app/config.rb +8 -8
  46. data/fixtures/external-helpers/config.rb +2 -2
  47. data/fixtures/external-helpers/helpers/derp.rb +3 -1
  48. data/fixtures/external-helpers/helpers/four_helpers.rb +3 -1
  49. data/fixtures/external-helpers/helpers/one_helper.rb +3 -1
  50. data/fixtures/external-helpers/helpers/yet_another_thingy.rb +3 -1
  51. data/fixtures/external-helpers/lib/hello_helper.rb +1 -1
  52. data/fixtures/external-pipeline-error/config.rb +4 -4
  53. data/fixtures/feature-params-app/config.rb +1 -1
  54. data/fixtures/frontmatter-app/config.rb +1 -1
  55. data/fixtures/glob-app/config.rb +1 -1
  56. data/fixtures/i-8859-1-app/config.rb +1 -1
  57. data/fixtures/i18n-force-locale/config.rb +4 -4
  58. data/fixtures/i18n-mixed-sources/config.rb +1 -1
  59. data/fixtures/i18n-mixed-sources/source/c/d/index.html.erb +9 -0
  60. data/fixtures/i18n-mixed-sources/source/localizable/c/d/index.html.erb +9 -0
  61. data/fixtures/import-app/config.rb +3 -3
  62. data/fixtures/indexable-app/config.rb +3 -3
  63. data/fixtures/large-build-app/config.rb +1 -1
  64. data/fixtures/manual-layout-override/config.rb +1 -1
  65. data/fixtures/missing-tilt-library-app/config.rb +2 -2
  66. data/fixtures/more-traversal-app/config.rb +4 -4
  67. data/fixtures/multiple-data-sources-app/config.rb +1 -1
  68. data/fixtures/multiple-sources-app/config.rb +1 -1
  69. data/fixtures/multiple-sources-with-destination-dir/config.rb +2 -0
  70. data/fixtures/multiple-sources-with-destination-dir/external/page.html.erb +1 -0
  71. data/fixtures/multiple-sources-with-destination-dir/source/index.html.erb +1 -0
  72. data/fixtures/multiple-sources-with-duplicate-file-names-app/config.rb +1 -1
  73. data/fixtures/multiple-sources-without-destination-dir/config.rb +1 -0
  74. data/fixtures/multiple-sources-without-destination-dir/external/page.html.erb +1 -0
  75. data/fixtures/multiple-sources-without-destination-dir/source/index.html.erb +1 -0
  76. data/fixtures/nested-layout-app/source/another.html.markdown +1 -1
  77. data/fixtures/nested-layout-app/source/haml-test.html.markdown +1 -1
  78. data/fixtures/nested-layout-app/source/slim-test.html.markdown +1 -1
  79. data/fixtures/padrino-helpers-app/config.rb +1 -1
  80. data/fixtures/page-classes-app/config.rb +2 -2
  81. data/fixtures/page-helper-layout-block-app/config.rb +1 -1
  82. data/fixtures/page-id-app/config-proc.rb +4 -4
  83. data/fixtures/page-id-app/config.rb +3 -3
  84. data/fixtures/paginate-app/source/blog/2011-01-01-test-article.html.markdown +1 -1
  85. data/fixtures/paginate-app/source/blog/2011-01-02-test-article.html.markdown +1 -1
  86. data/fixtures/paginate-app/source/blog/2011-01-03-test-article.html.markdown +1 -1
  87. data/fixtures/paginate-app/source/blog/2011-01-04-test-article.html.markdown +1 -1
  88. data/fixtures/paginate-app/source/blog/2011-01-05-test-article.html.markdown +1 -1
  89. data/fixtures/paginate-app/source/blog/2011-02-01-test-article.html.markdown +1 -1
  90. data/fixtures/paginate-app/source/blog/2011-02-02-test-article.html.markdown +1 -1
  91. data/fixtures/partials-app/source/_locals.erb +1 -1
  92. data/fixtures/partials-app/source/locals.html.erb +1 -1
  93. data/fixtures/proxy-pages-app/config.rb +13 -14
  94. data/fixtures/sass-assets-path-app/config.rb +2 -2
  95. data/fixtures/sinatra-app/config.rb +6 -6
  96. data/fixtures/traversal-app/config.rb +4 -4
  97. data/fixtures/v4-extension-callbacks/config.rb +2 -2
  98. data/fixtures/wildcard-app/config.rb +1 -1
  99. data/fixtures/wildcard-directory-index-app/config.rb +1 -1
  100. data/lib/middleman-core.rb +3 -3
  101. data/lib/middleman-core/application.rb +5 -5
  102. data/lib/middleman-core/builder.rb +20 -20
  103. data/lib/middleman-core/callback_manager.rb +1 -1
  104. data/lib/middleman-core/config_context.rb +2 -2
  105. data/lib/middleman-core/configuration.rb +5 -5
  106. data/lib/middleman-core/contracts.rb +2 -2
  107. data/lib/middleman-core/core_extensions/collections.rb +1 -1
  108. data/lib/middleman-core/core_extensions/collections/lazy_root.rb +1 -1
  109. data/lib/middleman-core/core_extensions/collections/lazy_step.rb +9 -9
  110. data/lib/middleman-core/core_extensions/collections/pagination.rb +6 -6
  111. data/lib/middleman-core/core_extensions/data.rb +10 -10
  112. data/lib/middleman-core/core_extensions/default_helpers.rb +26 -22
  113. data/lib/middleman-core/core_extensions/file_watcher.rb +1 -1
  114. data/lib/middleman-core/core_extensions/front_matter.rb +3 -3
  115. data/lib/middleman-core/core_extensions/i18n.rb +24 -24
  116. data/lib/middleman-core/core_extensions/inline_url_rewriter.rb +10 -7
  117. data/lib/middleman-core/core_extensions/routing.rb +1 -1
  118. data/lib/middleman-core/dns_resolver.rb +1 -1
  119. data/lib/middleman-core/dns_resolver/basic_network_resolver.rb +3 -3
  120. data/lib/middleman-core/dns_resolver/hosts_resolver.rb +1 -1
  121. data/lib/middleman-core/dns_resolver/local_link_resolver.rb +1 -1
  122. data/lib/middleman-core/dns_resolver/network_resolver.rb +1 -1
  123. data/lib/middleman-core/extension.rb +26 -25
  124. data/lib/middleman-core/extension_manager.rb +1 -1
  125. data/lib/middleman-core/extensions.rb +8 -7
  126. data/lib/middleman-core/extensions/asset_hash.rb +24 -22
  127. data/lib/middleman-core/extensions/asset_host.rb +10 -10
  128. data/lib/middleman-core/extensions/automatic_alt_tags.rb +1 -1
  129. data/lib/middleman-core/extensions/automatic_image_sizes.rb +3 -3
  130. data/lib/middleman-core/extensions/cache_buster.rb +2 -2
  131. data/lib/middleman-core/extensions/directory_indexes.rb +1 -1
  132. data/lib/middleman-core/extensions/external_pipeline.rb +14 -9
  133. data/lib/middleman-core/extensions/gzip.rb +7 -5
  134. data/lib/middleman-core/extensions/lorem.rb +9 -9
  135. data/lib/middleman-core/extensions/minify_css.rb +9 -9
  136. data/lib/middleman-core/extensions/minify_javascript.rb +10 -10
  137. data/lib/middleman-core/extensions/relative_assets.rb +8 -8
  138. data/lib/middleman-core/file_renderer.rb +6 -5
  139. data/lib/middleman-core/load_paths.rb +10 -10
  140. data/lib/middleman-core/logger.rb +2 -3
  141. data/lib/middleman-core/meta_pages.rb +1 -1
  142. data/lib/middleman-core/preview_server.rb +21 -22
  143. data/lib/middleman-core/preview_server/checks.rb +1 -1
  144. data/lib/middleman-core/preview_server/information.rb +13 -13
  145. data/lib/middleman-core/preview_server/network_interface_inventory.rb +3 -3
  146. data/lib/middleman-core/preview_server/server_information.rb +1 -1
  147. data/lib/middleman-core/preview_server/server_url.rb +1 -1
  148. data/lib/middleman-core/preview_server/tcp_port_prober.rb +1 -1
  149. data/lib/middleman-core/rack.rb +1 -1
  150. data/lib/middleman-core/renderers/coffee_script.rb +2 -2
  151. data/lib/middleman-core/renderers/haml.rb +1 -4
  152. data/lib/middleman-core/renderers/less.rb +1 -1
  153. data/lib/middleman-core/renderers/liquid.rb +2 -1
  154. data/lib/middleman-core/renderers/markdown.rb +7 -7
  155. data/lib/middleman-core/renderers/redcarpet.rb +2 -2
  156. data/lib/middleman-core/renderers/sass.rb +5 -5
  157. data/lib/middleman-core/renderers/sass_functions.rb +5 -5
  158. data/lib/middleman-core/renderers/slim.rb +2 -2
  159. data/lib/middleman-core/sitemap/extensions/ignores.rb +2 -4
  160. data/lib/middleman-core/sitemap/extensions/import.rb +1 -1
  161. data/lib/middleman-core/sitemap/extensions/on_disk.rb +1 -1
  162. data/lib/middleman-core/sitemap/extensions/proxies.rb +2 -1
  163. data/lib/middleman-core/sitemap/extensions/redirects.rb +1 -1
  164. data/lib/middleman-core/sitemap/extensions/request_endpoints.rb +1 -1
  165. data/lib/middleman-core/sitemap/extensions/traversal.rb +80 -25
  166. data/lib/middleman-core/sitemap/resource.rb +21 -20
  167. data/lib/middleman-core/sitemap/store.rb +3 -3
  168. data/lib/middleman-core/sources.rb +12 -12
  169. data/lib/middleman-core/sources/source_watcher.rb +16 -10
  170. data/lib/middleman-core/step_definitions/builder_steps.rb +23 -23
  171. data/lib/middleman-core/step_definitions/commandline_steps.rb +5 -5
  172. data/lib/middleman-core/step_definitions/middleman_steps.rb +13 -14
  173. data/lib/middleman-core/step_definitions/server_steps.rb +14 -16
  174. data/lib/middleman-core/template_context.rb +17 -10
  175. data/lib/middleman-core/template_renderer.rb +34 -32
  176. data/lib/middleman-core/util.rb +2 -2
  177. data/lib/middleman-core/util/binary.rb +3 -1
  178. data/lib/middleman-core/util/data.rb +2 -2
  179. data/lib/middleman-core/util/files.rb +2 -2
  180. data/lib/middleman-core/util/paths.rb +47 -44
  181. data/lib/middleman-core/util/rack.rb +3 -3
  182. data/lib/middleman-core/util/uri_templates.rb +1 -0
  183. data/lib/middleman-core/version.rb +1 -1
  184. data/middleman-core.gemspec +3 -2
  185. data/spec/middleman-core/callbacks_spec.rb +15 -14
  186. data/spec/middleman-core/core_extensions/data_spec.rb +70 -74
  187. data/spec/middleman-core/dns_resolver_spec.rb +6 -6
  188. data/spec/middleman-core/util_spec.rb +81 -86
  189. data/spec/support/given.rb +11 -15
  190. metadata +44 -6
@@ -24,7 +24,7 @@ module Middleman
24
24
  include Contracts
25
25
 
26
26
  # Types which could cause output to change.
27
- OUTPUT_TYPES = [:source, :locales, :data].freeze
27
+ OUTPUT_TYPES = %i[source locales data].freeze
28
28
 
29
29
  # Types which require a reload to eval ruby
30
30
  CODE_TYPES = [:reload].freeze
@@ -56,7 +56,7 @@ module Middleman
56
56
  # @param [Hash] options Global options.
57
57
  # @param [Array] watchers Default watchers.
58
58
  Contract IsA['Middleman::Application'], Maybe[Hash], Maybe[Array] => Any
59
- def initialize(app, _options={}, watchers=[])
59
+ def initialize(app, _options = {}, watchers = [])
60
60
  @app = app
61
61
  @watchers = watchers
62
62
  @sorted_watchers = @watchers.dup.freeze
@@ -88,7 +88,7 @@ module Middleman
88
88
  # @param [Proc] block Ignore by block evaluation.
89
89
  # @return [void]
90
90
  Contract Symbol, Symbol, Or[Regexp, Proc] => Any
91
- def ignore(name, type, regex=nil, &block)
91
+ def ignore(name, type, regex = nil, &block)
92
92
  @ignores = @ignores.put(name, type: type,
93
93
  validator: (block_given? ? block : regex))
94
94
 
@@ -116,13 +116,13 @@ module Middleman
116
116
  # @param [Hash] options The watcher options.
117
117
  # @return [#changed, #deleted]
118
118
  Contract Or[Symbol, HANDLER], Maybe[Hash] => HANDLER
119
- def watch(type_or_handler, options={})
119
+ def watch(type_or_handler, options = {})
120
120
  handler = if type_or_handler.is_a? Symbol
121
- path = File.expand_path(options.delete(:path), app.root)
122
- SourceWatcher.new(self, type_or_handler, path, options)
123
- else
124
- type_or_handler
125
- end
121
+ path = File.expand_path(options.delete(:path), app.root)
122
+ SourceWatcher.new(self, type_or_handler, path, options)
123
+ else
124
+ type_or_handler
125
+ end
126
126
 
127
127
  @watchers << handler
128
128
 
@@ -188,7 +188,7 @@ module Middleman
188
188
  # @param [Boolean] glob If the path contains wildcard or glob characters.
189
189
  # @return [Middleman::SourceFile, nil]
190
190
  Contract Or[Symbol, ArrayOf[Symbol], SetOf[Symbol]], Or[Pathname, String], Maybe[Bool] => Maybe[SourceFile]
191
- def find(types, path, glob=false)
191
+ def find(types, path, glob = false)
192
192
  array_of_types = Array(types)
193
193
 
194
194
  watchers
@@ -277,7 +277,7 @@ module Middleman
277
277
  #
278
278
  # @param [nil,Regexp] matcher A Regexp to match the change path against
279
279
  Contract Maybe[Matcher] => Any
280
- def changed(matcher=nil, &_block)
280
+ def changed(matcher = nil, &_block)
281
281
  on_change OUTPUT_TYPES do |updated, _removed|
282
282
  updated
283
283
  .select { |f| matcher.nil? ? true : matches?(matcher, f) }
@@ -289,7 +289,7 @@ module Middleman
289
289
  #
290
290
  # @param [nil,Regexp] matcher A Regexp to match the change path against
291
291
  Contract Maybe[Matcher] => Any
292
- def deleted(matcher=nil, &_block)
292
+ def deleted(matcher = nil, &_block)
293
293
  on_change OUTPUT_TYPES do |_updated, removed|
294
294
  removed
295
295
  .select { |f| matcher.nil? ? true : matches?(matcher, f) }
@@ -15,7 +15,7 @@ module Listen
15
15
  # return true unless only_patterns.any? { |pattern| path =~ pattern }
16
16
  # end
17
17
 
18
- return !only_patterns.any? { |pattern| path =~ pattern } if only_patterns
18
+ return only_patterns.none? { |pattern| path =~ pattern } if only_patterns
19
19
 
20
20
  ignore_patterns.any? { |pattern| path =~ pattern }
21
21
  end
@@ -50,7 +50,7 @@ module Middleman
50
50
  # Reference to lower level listener
51
51
  attr_reader :listener
52
52
 
53
- IGNORED_DIRECTORIES = Set.new(%w(.git node_modules .sass-cache vendor/bundle .bundle))
53
+ IGNORED_DIRECTORIES = Set.new(%w[.git node_modules .sass-cache vendor/bundle .bundle])
54
54
 
55
55
  # Construct a new SourceWatcher
56
56
  #
@@ -59,7 +59,7 @@ module Middleman
59
59
  # @param [String] directory The on-disk path to watch.
60
60
  # @param [Hash] options Configuration options.
61
61
  Contract IsA['Middleman::Sources'], Symbol, String, Hash => Any
62
- def initialize(parent, type, directory, options={})
62
+ def initialize(parent, type, directory, options = {})
63
63
  @parent = parent
64
64
  @options = options
65
65
 
@@ -103,7 +103,7 @@ module Middleman
103
103
  poll_once!
104
104
  end
105
105
 
106
- def update_config(options={})
106
+ def update_config(options = {})
107
107
  without_listener_running do
108
108
  @disable_watcher = options.fetch(:disable_watcher, false)
109
109
  @force_polling = options.fetch(:force_polling, false)
@@ -134,13 +134,19 @@ module Middleman
134
134
  # @param [Boolean] glob If the path contains wildcard characters.
135
135
  # @return [Middleman::SourceFile, nil]
136
136
  Contract Or[String, Pathname], Maybe[Bool] => Maybe[IsA['Middleman::SourceFile']]
137
- def find(path, glob=false)
137
+ def find(path, glob = false)
138
138
  path = path.to_s.encode!('UTF-8', 'UTF-8-MAC') if RUBY_PLATFORM =~ /darwin/
139
139
 
140
140
  p = Pathname(path)
141
141
 
142
142
  return nil if p.absolute? && !p.to_s.start_with?(@directory.to_s)
143
143
 
144
+ destination_dir = @options[:destination_dir]
145
+ if destination_dir.present? && p.to_s.start_with?(destination_dir)
146
+ path_without_destination_dir = p.to_s[destination_dir.to_s.length + 1..-1]
147
+ p = Pathname(path_without_destination_dir)
148
+ end
149
+
144
150
  p = @directory + p if p.relative?
145
151
 
146
152
  if glob
@@ -357,16 +363,16 @@ module Middleman
357
363
  private
358
364
 
359
365
  def without_listener_running
360
- listener_running = @listener && @listener.processing?
366
+ listener_running = @listener&.processing?
361
367
 
362
368
  stop_listener! if listener_running
363
369
 
364
370
  yield
365
371
 
366
- if listener_running
367
- poll_once!
368
- listen!
369
- end
372
+ return unless listener_running
373
+
374
+ poll_once!
375
+ listen!
370
376
  end
371
377
  end
372
378
  end
@@ -1,57 +1,57 @@
1
1
  require 'fileutils'
2
2
 
3
3
  Before do
4
- @modification_times = Hash.new
4
+ @modification_times = {}
5
5
  end
6
6
 
7
7
  Given /^a built app at "([^\"]*)"$/ do |path|
8
- step %Q{a fixture app "#{path}"}
8
+ step %(a fixture app "#{path}")
9
9
 
10
10
  cwd = File.expand_path(aruba.current_directory)
11
- step %Q{I set the environment variable "MM_ROOT" to "#{cwd}"}
11
+ step %(I set the environment variable "MM_ROOT" to "#{cwd}")
12
12
 
13
- step %Q{I run `middleman build --verbose`}
13
+ step %(I run `middleman build --verbose`)
14
14
  end
15
15
 
16
16
  Given /^was successfully built$/ do
17
- step %Q{the output should contain "Project built successfully."}
18
- step %Q{the exit status should be 0}
19
- step %Q{a directory named "build" should exist}
17
+ step %(the output should contain "Project built successfully.")
18
+ step %(the exit status should be 0)
19
+ step %(a directory named "build" should exist)
20
20
  end
21
21
 
22
22
  Given /^was not successfully built$/ do
23
- step %Q{the output should not contain "Project built successfully."}
24
- step %Q{the exit status should be 1}
25
- step %Q{a directory named "build" should not exist}
23
+ step %(the output should not contain "Project built successfully.")
24
+ step %(the exit status should be 1)
25
+ step %(a directory named "build" should not exist)
26
26
  end
27
27
 
28
28
  Given /^a successfully built app at "([^\"]*)"$/ do |path|
29
- step %Q{a built app at "#{path}"}
30
- step %Q{was successfully built}
29
+ step %(a built app at "#{path}")
30
+ step %(was successfully built)
31
31
  end
32
32
 
33
33
  Given /^a built app at "([^\"]*)" with flags "([^\"]*)"$/ do |path, flags|
34
- step %Q{a fixture app "#{path}"}
35
-
34
+ step %(a fixture app "#{path}")
35
+
36
36
  cwd = File.expand_path(aruba.current_directory)
37
- step %Q{I set the environment variable "MM_ROOT" to "#{cwd}"}
37
+ step %(I set the environment variable "MM_ROOT" to "#{cwd}")
38
38
 
39
- step %Q{I run `middleman build #{flags}`}
39
+ step %(I run `middleman build #{flags}`)
40
40
  end
41
41
 
42
42
  Given /^a successfully built app at "([^\"]*)" with flags "([^\"]*)"$/ do |path, flags|
43
- step %Q{a built app at "#{path}" with flags "#{flags}"}
44
- step %Q{was successfully built}
43
+ step %(a built app at "#{path}" with flags "#{flags}")
44
+ step %(was successfully built)
45
45
  end
46
46
 
47
47
  Given /^I run the interactive middleman console$/ do
48
48
  cwd = File.expand_path(aruba.current_directory)
49
- step %Q{I set the environment variable "MM_ROOT" to "#{cwd}"}
50
- step %Q{I run `middleman console` interactively}
49
+ step %(I set the environment variable "MM_ROOT" to "#{cwd}")
50
+ step %(I run `middleman console` interactively)
51
51
  end
52
52
 
53
53
  Given /^I run the interactive middleman server$/ do
54
54
  cwd = File.expand_path(aruba.current_directory)
55
- step %Q{I set the environment variable "MM_ROOT" to "#{cwd}"}
56
- step %Q{I run `middleman server` interactively}
57
- end
55
+ step %(I set the environment variable "MM_ROOT" to "#{cwd}")
56
+ step %(I run `middleman server` interactively)
57
+ end
@@ -1,11 +1,11 @@
1
- When /^I stop (?:middleman|all commands) if the output( of the last command)? contains:$/ do |last_command, expected|
1
+ When /^I stop (?:middleman|all commands) if the output( of the last command)? contains:$/ do |_last_command, expected|
2
2
  begin
3
3
  Timeout.timeout(aruba.config.exit_timeout) do
4
4
  loop do
5
- fail "You need to start middleman interactively first." unless @interactive
5
+ raise 'You need to start middleman interactively first.' unless @interactive
6
6
 
7
- if sanitize_text(@interactive.output) =~ Regexp.new(sanitize_text(expected))
8
- all_commands.each { |p| p.terminate }
7
+ if sanitize_text(@interactive.output)&.match?(Regexp.new(sanitize_text(expected)))
8
+ all_commands.each(&:terminate)
9
9
  break
10
10
  end
11
11
 
@@ -80,7 +80,7 @@ end
80
80
 
81
81
  # Make sure each and every process is really dead
82
82
  After do
83
- all_commands.each { |p| p.terminate }
83
+ all_commands.each(&:terminate)
84
84
  end
85
85
 
86
86
  Before '@ruby-2.1' do
@@ -1,15 +1,14 @@
1
1
  require 'fileutils'
2
2
 
3
- Given /^app "([^\"]*)" is using config "([^\"]*)"$/ do |path, config_name|
4
- target = File.join(PROJECT_ROOT_PATH, 'fixtures', path)
5
- config_path = File.join(expand_path("."), "config-#{config_name}.rb")
6
- config_dest = File.join(expand_path("."), 'config.rb')
3
+ Given /^app "([^\"]*)" is using config "([^\"]*)"$/ do |_path, config_name|
4
+ config_path = File.join(expand_path('.'), "config-#{config_name}.rb")
5
+ config_dest = File.join(expand_path('.'), 'config.rb')
7
6
  FileUtils.cp(config_path, config_dest)
8
7
  end
9
8
 
10
9
  Given /^an empty app$/ do
11
- step %Q{a directory named "empty_app"}
12
- step %Q{I cd to "empty_app"}
10
+ step %(a directory named "empty_app")
11
+ step %(I cd to "empty_app")
13
12
  ENV['MM_ROOT'] = nil
14
13
  end
15
14
 
@@ -18,14 +17,14 @@ Given /^a fixture app "([^\"]*)"$/ do |path|
18
17
 
19
18
  # This step can be reentered from several places but we don't want
20
19
  # to keep re-copying and re-cd-ing into ever-deeper directories
21
- next if File.basename(expand_path(".")) == path
20
+ next if File.basename(expand_path('.')) == path
22
21
 
23
- step %Q{a directory named "#{path}"}
22
+ step %(a directory named "#{path}")
24
23
 
25
24
  target_path = File.join(PROJECT_ROOT_PATH, 'fixtures', path)
26
- FileUtils.cp_r(target_path, expand_path("."))
25
+ FileUtils.cp_r(target_path, expand_path('.'))
27
26
 
28
- step %Q{I cd to "#{path}"}
27
+ step %(I cd to "#{path}")
29
28
  end
30
29
 
31
30
  Then /^the file "([^\"]*)" has the contents$/ do |path, contents|
@@ -35,18 +34,18 @@ Then /^the file "([^\"]*)" has the contents$/ do |path, contents|
35
34
  end
36
35
 
37
36
  Then /^the file "([^\"]*)" is removed$/ do |path|
38
- step %Q{I remove the file "#{path}"}
37
+ step %(I remove the file "#{path}")
39
38
 
40
39
  @server_inst.files.poll_once!
41
40
  end
42
41
 
43
42
  Given /^a modification time for a file named "([^\"]*)"$/ do |file|
44
- target = File.join(expand_path("."), file)
43
+ target = File.join(expand_path('.'), file)
45
44
  @modification_times[target] = File.mtime(target)
46
45
  end
47
46
 
48
47
  Then /^the file "([^\"]*)" should not have been updated$/ do |file|
49
- target = File.join(expand_path("."), file)
48
+ target = File.join(expand_path('.'), file)
50
49
  expect(File.mtime(target)).to eq(@modification_times[target])
51
50
  end
52
51
 
@@ -56,5 +55,5 @@ Then /^the file "([^"]*)" should contain '([^']*)'$/ do |file, partial_content|
56
55
  end
57
56
 
58
57
  And /the file "(.*)" should be gzipped/ do |file|
59
- expect(File.binread(File.join(expand_path("."), file), 2)).to eq(['1F8B'].pack('H*'))
58
+ expect(File.binread(File.join(expand_path('.'), file), 2)).to eq(['1F8B'].pack('H*'))
60
59
  end
@@ -10,9 +10,7 @@ end
10
10
  Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state|
11
11
  @activation_commands ||= []
12
12
 
13
- if state == 'enabled'
14
- @activation_commands << lambda { activate(feature.to_sym) }
15
- end
13
+ @activation_commands << -> { activate(feature.to_sym) } if state == 'enabled'
16
14
  end
17
15
 
18
16
  Given /^"([^\"]*)" feature is "enabled" with "([^\"]*)"$/ do |feature, options_str|
@@ -20,7 +18,7 @@ Given /^"([^\"]*)" feature is "enabled" with "([^\"]*)"$/ do |feature, options_s
20
18
 
21
19
  options = eval("{#{options_str}}")
22
20
 
23
- @activation_commands << lambda { activate(feature.to_sym, options) }
21
+ @activation_commands << -> { activate(feature.to_sym, options) }
24
22
  end
25
23
 
26
24
  Given /^"([^\"]*)" is set to "([^\"]*)"$/ do |variable, value|
@@ -31,13 +29,13 @@ Given /^"([^\"]*)" is set to "([^\"]*)"$/ do |variable, value|
31
29
  end
32
30
 
33
31
  Given /^the Server is running$/ do
34
- root_dir = File.expand_path(expand_path("."))
32
+ root_dir = File.expand_path(expand_path('.'))
35
33
 
36
- if File.exists?(File.join(root_dir, 'source'))
37
- ENV['MM_SOURCE'] = 'source'
38
- else
39
- ENV['MM_SOURCE'] = ''
40
- end
34
+ ENV['MM_SOURCE'] = if File.exist?(File.join(root_dir, 'source'))
35
+ 'source'
36
+ else
37
+ ''
38
+ end
41
39
 
42
40
  ENV['MM_ROOT'] = root_dir
43
41
 
@@ -54,7 +52,7 @@ Given /^the Server is running$/ do
54
52
 
55
53
  app.after_configuration_eval do
56
54
  activation_commands.each do |p|
57
- app.config_context.instance_exec(&p)
55
+ instance_exec(&p)
58
56
  end
59
57
  end
60
58
  end
@@ -63,12 +61,12 @@ Given /^the Server is running$/ do
63
61
  end
64
62
 
65
63
  Given /^the Server is running at "([^\"]*)"$/ do |app_path|
66
- step %Q{a fixture app "#{app_path}"}
67
- step %Q{the Server is running}
64
+ step %(a fixture app "#{app_path}")
65
+ step %(the Server is running)
68
66
  end
69
67
 
70
68
  Given /^a template named "([^\"]*)" with:$/ do |name, string|
71
- step %Q{a file named "source/#{name}" with:}, string
69
+ step %(a file named "source/#{name}" with:), string
72
70
  end
73
71
 
74
72
  When /^I go to "([^\"]*)"$/ do |url|
@@ -76,7 +74,7 @@ When /^I go to "([^\"]*)"$/ do |url|
76
74
  end
77
75
 
78
76
  Then /^going to "([^\"]*)" should not raise an exception$/ do |url|
79
- expect{ visit(URI.encode(url).to_s) }.to_not raise_exception
77
+ expect { visit(URI.encode(url).to_s) }.to_not raise_exception
80
78
  end
81
79
 
82
80
  Then /^the content type should be "([^\"]*)"$/ do |expected|
@@ -120,5 +118,5 @@ Then /^the status code should be "([^\"]*)"$/ do |expected|
120
118
  end
121
119
 
122
120
  Then /^I should see "([^\"]*)" lines$/ do |lines|
123
- expect(page.body.chomp.split($/).length).to eq lines.to_i
121
+ expect(page.body.chomp.split($INPUT_RECORD_SEPARATOR).length).to eq lines.to_i
124
122
  end
@@ -30,7 +30,7 @@ module Middleman
30
30
  # @param [Middleman::Application] app
31
31
  # @param [Hash] locs
32
32
  # @param [Hash] opts
33
- def initialize(app, locs={}, opts={})
33
+ def initialize(app, locs = {}, opts = {})
34
34
  @app = app
35
35
  @locs = locs
36
36
  @opts = opts
@@ -42,7 +42,8 @@ module Middleman
42
42
  # @api private
43
43
  # @return [String] The old buffer.
44
44
  def save_buffer
45
- @_out_buf, buf_was = '', @_out_buf
45
+ buf_was = @_out_buf
46
+ @_out_buf = ''
46
47
  buf_was
47
48
  end
48
49
 
@@ -100,7 +101,7 @@ module Middleman
100
101
  # @param [Proc] block A block will be evaluated to return internal contents.
101
102
  # @return [String]
102
103
  Contract Any, Or[Symbol, String], Hash => String, Maybe[Proc] => String
103
- def render(_, name, options={}, &block)
104
+ def render(_, name, options = {}, &block)
104
105
  name = name.to_s
105
106
 
106
107
  partial_file = locate_partial(name, false) || locate_partial(name, true)
@@ -126,30 +127,35 @@ module Middleman
126
127
  # @param [String] partial_path
127
128
  # @return [String]
128
129
  Contract String, Maybe[Bool] => Maybe[IsA['Middleman::SourceFile']]
129
- def locate_partial(partial_path, try_static=true)
130
+ def locate_partial(partial_path, try_static = true)
130
131
  partial_file = nil
131
132
  lookup_stack = []
132
133
  non_root = partial_path.to_s.sub(/^\//, '')
133
134
  non_root_no_underscore = non_root.sub(/^_/, '').sub(/\/_/, '/')
134
135
 
135
- if resource = current_resource
136
+ if current_resource
137
+ resource = current_resource
136
138
  current_dir = resource.file_descriptor[:relative_path].dirname
137
139
  relative_dir = current_dir + Pathname(non_root)
138
140
  relative_dir_no_underscore = current_dir + Pathname(non_root_no_underscore)
139
- end
140
141
 
141
- if relative_dir
142
- lookup_stack.push [relative_dir.to_s,
143
- { preferred_engine: resource.file_descriptor[:relative_path]
144
- .extname[1..-1].to_sym }]
142
+ if relative_dir
143
+ lookup_stack.push [relative_dir.to_s,
144
+ { preferred_engine: resource.file_descriptor[:relative_path]
145
+ .extname[1..-1].to_sym }]
146
+ end
145
147
  end
148
+
146
149
  lookup_stack.push [non_root]
150
+
147
151
  lookup_stack.push [non_root,
148
152
  { try_static: try_static }]
153
+
149
154
  if relative_dir_no_underscore
150
155
  lookup_stack.push [relative_dir_no_underscore.to_s,
151
156
  { try_static: try_static }]
152
157
  end
158
+
153
159
  lookup_stack.push [non_root_no_underscore,
154
160
  { try_static: try_static }]
155
161
 
@@ -169,6 +175,7 @@ module Middleman
169
175
  # @return [Middleman::Sitemap::Resource]
170
176
  def current_resource
171
177
  return nil unless current_path
178
+
172
179
  sitemap.find_resource_by_destination_path(current_path)
173
180
  end
174
181
  alias current_page current_resource