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
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/object/try'
2
+ require 'memoist'
1
3
  require 'middleman-core/contracts'
2
4
 
3
5
  # Minify CSS Extension
@@ -30,6 +32,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
30
32
 
31
33
  # Rack middleware to look for CSS and compress it
32
34
  class Rack
35
+ extend Memoist
33
36
  include Contracts
34
37
  INLINE_CSS_REGEX = /(<style[^>]*>\s*(?:\/\*<!\[CDATA\[\*\/\n)?)(.*?)((?:(?:\n\s*)?\/\*\]\]>\*\/)?\s*<\/style>)/m
35
38
 
@@ -82,8 +85,9 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
82
85
  # @param [String] path
83
86
  # @return [Boolean]
84
87
  def ignore?(path)
85
- @ignore.any? { |ignore| Middleman::Util.path_match(ignore, path) }
88
+ @ignore.any? { |ignore| ::Middleman::Util.path_match(ignore, path) }
86
89
  end
90
+ memoize :ignore?
87
91
 
88
92
  # Whether this type of content can be minified
89
93
  # @param [String, nil] content_type
@@ -91,6 +95,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
91
95
  def minifiable?(content_type)
92
96
  @content_types.include?(content_type)
93
97
  end
98
+ memoize :minifiable?
94
99
 
95
100
  # Whether this type of content contains inline content that can be minified
96
101
  # @param [String, nil] content_type
@@ -98,6 +103,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
98
103
  def minifiable_inline?(content_type)
99
104
  @inline_content_types.include?(content_type)
100
105
  end
106
+ memoize :minifiable_inline?
101
107
 
102
108
  # Minify the content
103
109
  # @param [String] content
@@ -105,6 +111,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
105
111
  def minify(content)
106
112
  @compressor.compress(content)
107
113
  end
114
+ memoize :minify
108
115
 
109
116
  # Detect and minify inline content
110
117
  # @param [String] content
@@ -114,5 +121,6 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension
114
121
  $1 + minify($2) + $3
115
122
  end
116
123
  end
124
+ memoize :minify_inline
117
125
  end
118
126
  end
@@ -1,4 +1,6 @@
1
+ require 'active_support/core_ext/object/try'
1
2
  require 'middleman-core/contracts'
3
+ require 'memoist'
2
4
 
3
5
  # Minify Javascript Extension
4
6
  class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
@@ -22,6 +24,7 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
22
24
 
23
25
  # Rack middleware to look for JS and compress it
24
26
  class Rack
27
+ extend Memoist
25
28
  include Contracts
26
29
  INLINE_JS_REGEX = /(<script[^>]*>\s*(?:\/\/(?:(?:<!--)|(?:<!\[CDATA\[))\n)?)(.*?)((?:(?:\n\s*)?\/\/(?:(?:-->)|(?:\]\]>)))?\s*<\/script>)/m
27
30
 
@@ -76,6 +79,7 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
76
79
  def ignore?(path)
77
80
  @ignore.any? { |ignore| Middleman::Util.path_match(ignore, path) }
78
81
  end
82
+ memoize :ignore?
79
83
 
80
84
  # Whether this type of content can be minified
81
85
  # @param [String, nil] content_type
@@ -83,6 +87,7 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
83
87
  def minifiable?(content_type)
84
88
  @content_types.include?(content_type)
85
89
  end
90
+ memoize :minifiable?
86
91
 
87
92
  # Whether this type of content contains inline content that can be minified
88
93
  # @param [String, nil] content_type
@@ -90,6 +95,7 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
90
95
  def minifiable_inline?(content_type)
91
96
  @inline_content_types.include?(content_type)
92
97
  end
98
+ memoize :minifiable_inline?
93
99
 
94
100
  # Minify the content
95
101
  # @param [String] content
@@ -100,6 +106,7 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
100
106
  warn "WARNING: Couldn't compress JavaScript in #{@path}: #{e.message}"
101
107
  content
102
108
  end
109
+ memoize :minify
103
110
 
104
111
  # Detect and minify inline content
105
112
  # @param [String] content
@@ -119,5 +126,6 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension
119
126
  end
120
127
  end
121
128
  end
129
+ memoize :minify_inline
122
130
  end
123
131
  end
@@ -2,38 +2,62 @@ require 'addressable/uri'
2
2
 
3
3
  # Relative Assets extension
4
4
  class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
5
- option :exts, %w(.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2 .eot), 'List of extensions that get cache busters strings appended to them.'
5
+ option :exts, nil, 'List of extensions that get converted to relative paths.'
6
6
  option :sources, %w(.css .htm .html .xhtml), 'List of extensions that are searched for relative assets.'
7
- option :ignore, [], 'Regexes of filenames to skip adding query strings to'
8
- option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
7
+ option :ignore, [], 'Regexes of filenames to skip converting to relative paths.'
8
+ option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites.'
9
+ option :helpers_only, false, 'Allow only Ruby helpers to change paths.'
9
10
 
10
11
  def initialize(app, options_hash={}, &block)
11
12
  super
12
13
 
13
- app.rewrite_inline_urls id: :asset_hash,
14
- url_extensions: options.exts,
14
+ return if options[:helpers_only]
15
+
16
+ app.rewrite_inline_urls id: :relative_assets,
17
+ url_extensions: options.exts || app.config[:asset_extensions],
15
18
  source_extensions: options.sources,
16
19
  ignore: options.ignore,
17
20
  rewrite_ignore: options.rewrite_ignore,
18
21
  proc: method(:rewrite_url)
19
22
  end
20
23
 
24
+ def mark_as_relative(file_path, opts, current_resource)
25
+ result = opts.dup
26
+
27
+ valid_exts = options.sources
28
+
29
+ return result unless current_resource
30
+ return result unless valid_exts.include?(current_resource.ext)
31
+
32
+ rewrite_ignores = Array(options.rewrite_ignore || [])
33
+
34
+ path = current_resource.destination_path
35
+ return result if rewrite_ignores.any? do |i|
36
+ ::Middleman::Util.path_match(i, path) || ::Middleman::Util.path_match(i, "/#{path}")
37
+ end
38
+
39
+ return result if Array(options.ignore || []).any? do |r|
40
+ ::Middleman::Util.should_ignore?(r, file_path)
41
+ end
42
+
43
+ result[:relative] = true unless result.key?(:relative)
44
+
45
+ result
46
+ end
47
+
21
48
  helpers do
22
- # asset_url override for relative assets
23
- # @param [String] path
24
- # @param [String] prefix
25
- # @param [Hash] options Additional options.
26
- # @return [String]
27
49
  def asset_url(path, prefix='', options={})
28
- options[:relative] = true unless options.key?(:relative)
50
+ super(path, prefix, app.extensions[:relative_assets].mark_as_relative(super, options, current_resource))
51
+ end
29
52
 
30
- super(path, prefix, options)
53
+ def asset_path(kind, source, options={})
54
+ super(kind, source, app.extensions[:relative_assets].mark_as_relative(super, options, current_resource))
31
55
  end
32
56
  end
33
57
 
34
58
  Contract String, Or[String, Pathname], Any => Maybe[String]
35
59
  def rewrite_url(asset_path, dirpath, request_path)
36
- uri = ::Addressable::URI.parse(asset_path)
60
+ uri = ::Middleman::Util.parse_uri(asset_path)
37
61
 
38
62
  return if uri.path[0..0] != '/'
39
63
 
@@ -50,4 +74,5 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension
50
74
 
51
75
  result
52
76
  end
77
+ memoize :rewrite_url
53
78
  end
@@ -59,7 +59,7 @@ module Middleman
59
59
  # Overwrite with frontmatter options
60
60
  options = options.deep_merge(options[:renderer_options]) if options[:renderer_options]
61
61
 
62
- template_class = ::Tilt[path]
62
+ template_class = ::Middleman::Util.tilt_class(path)
63
63
 
64
64
  # Allow hooks to manipulate the template before render
65
65
  body = @app.callbacks_for(:before_render).reduce(body) do |sum, callback|
@@ -99,12 +99,12 @@ module Middleman
99
99
  def template_data_for_file
100
100
  file = @app.files.find(:source, @path)
101
101
 
102
- if @app.extensions[:front_matter] || (file && !file[:types].include?(:no_frontmatter))
102
+ if @app.extensions[:front_matter] && (file && !file[:types].include?(:no_frontmatter))
103
103
  result = @app.extensions[:front_matter].template_data_for_file(@path)
104
104
  return result unless result.nil?
105
105
  end
106
106
 
107
- file ? file.read : File.read(@path)
107
+ file ? file.read : ::File.read(@path)
108
108
  end
109
109
 
110
110
  protected
@@ -122,7 +122,7 @@ module Middleman
122
122
 
123
123
  # Find all the engines which handle this extension in tilt. Look for
124
124
  # config variables of that name and merge it
125
- extension_class = ::Tilt[ext]
125
+ extension_class = ::Middleman::Util.tilt_class(ext)
126
126
  ::Tilt.mappings.each do |mapping_ext, engines|
127
127
  next unless engines.include? extension_class
128
128
  engine_options = @app.config[mapping_ext.to_sym] || {}
@@ -22,7 +22,9 @@ module Middleman
22
22
 
23
23
  # Set BUNDLE_GEMFILE and run Bundler setup. Raises an exception if there is no Gemfile
24
24
  def setup_bundler
25
- ENV['BUNDLE_GEMFILE'] ||= File.join(findup('Gemfile', ENV['MM_ROOT']), 'Gemfile')
25
+ if found_gemfile_root = findup('Gemfile', ENV['MM_ROOT'])
26
+ ENV['BUNDLE_GEMFILE'] ||= File.join(found_gemfile_root, 'Gemfile')
27
+ end
26
28
 
27
29
  unless File.exist?(ENV['BUNDLE_GEMFILE'])
28
30
  ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../../Gemfile', __FILE__)
@@ -7,7 +7,7 @@ module Middleman
7
7
  # The Middleman Logger
8
8
  class Logger < ActiveSupport::Logger
9
9
  def self.singleton(*args)
10
- if !@_logger || args.length > 0
10
+ if !@_logger || !args.empty?
11
11
  if args.length == 1 && (args.first.is_a?(::String) || args.first.respond_to?(:write))
12
12
  args = [0, false, args.first]
13
13
  end
@@ -10,7 +10,9 @@
10
10
  <div class="container">
11
11
  <article id="main">
12
12
  <h1>Middleman Information</h1>
13
-
13
+ <p>
14
+ Middleman version <%= Middleman::VERSION %>
15
+ </p>
14
16
  <ul class="nav-list">
15
17
  <li>
16
18
  <a href="/__middleman/sitemap/">Sitemap</a>
@@ -18,12 +18,13 @@ module Middleman
18
18
 
19
19
  # Start an instance of Middleman::Application
20
20
  # @return [void]
21
- def start(opts={})
21
+ def start(opts={}, cli_options={})
22
22
  # Do not buffer output, otherwise testing of output does not work
23
23
  $stdout.sync = true
24
24
  $stderr.sync = true
25
25
 
26
26
  @options = opts
27
+ @cli_options = cli_options
27
28
  @server_information = ServerInformation.new
28
29
  @server_information.https = (@options[:https] == true)
29
30
 
@@ -102,6 +103,8 @@ module Middleman
102
103
  def reload
103
104
  app.logger.info '== The Middleman is reloading'
104
105
 
106
+ app.execute_callbacks(:reload)
107
+
105
108
  begin
106
109
  app = initialize_new_app
107
110
  rescue => e
@@ -131,6 +134,7 @@ module Middleman
131
134
 
132
135
  def initialize_new_app
133
136
  opts = @options.dup
137
+ cli_options = @cli_options.dup
134
138
 
135
139
  ::Middleman::Logger.singleton(
136
140
  opts[:debug] ? 0 : 1,
@@ -138,17 +142,9 @@ module Middleman
138
142
  )
139
143
 
140
144
  app = ::Middleman::Application.new do
141
- config[:environment] = opts[:environment].to_sym if opts[:environment]
142
- config[:watcher_disable] = opts[:disable_watcher]
143
- config[:watcher_force_polling] = opts[:force_polling]
144
- config[:watcher_latency] = opts[:latency]
145
-
146
- config[:port] = opts[:port] if opts[:port]
147
- config[:bind_address] = opts[:bind_address]
148
- config[:server_name] = opts[:server_name]
149
- config[:https] = opts[:https] unless opts[:https].nil?
150
- config[:ssl_certificate] = opts[:ssl_certificate] if opts[:ssl_certificate]
151
- config[:ssl_private_key] = opts[:ssl_private_key] if opts[:ssl_private_key]
145
+ config[:cli_options] = cli_options.each_with_object({}) do |(k, v), sum|
146
+ sum[k] = v unless v == :undefined
147
+ end
152
148
 
153
149
  ready do
154
150
  unless config[:watcher_disable]
@@ -177,18 +173,21 @@ module Middleman
177
173
  end
178
174
 
179
175
  # store configured port to make a check later on possible
180
- configured_port = app.config[:port]
176
+ configured_port = possible_from_cli(:port, app.config)
181
177
 
182
178
  # Use configuration values to set `bind_address` etc. in
183
179
  # `server_information`
184
- server_information.use app.config
180
+ server_information.use(bind_address: possible_from_cli(:bind_address, app.config),
181
+ port: possible_from_cli(:port, app.config),
182
+ server_name: possible_from_cli(:server_name, app.config),
183
+ https: possible_from_cli(:https, app.config))
185
184
 
186
- app.logger.warn format('== The Middleman uses a different port "%s" then the configured one "%s" because some other server is listening on that port.', server_information.port, configured_port) unless app.config[:port] == configured_port
185
+ app.logger.warn format('== The Middleman uses a different port "%s" then the configured one "%s" because some other server is listening on that port.', server_information.port, configured_port) unless server_information.port == configured_port
187
186
 
188
- @environment = app.config[:environment]
187
+ @environment = possible_from_cli(:environment, app.config)
189
188
 
190
- @ssl_certificate = app.config[:ssl_certificate]
191
- @ssl_private_key = app.config[:ssl_private_key]
189
+ @ssl_certificate = possible_from_cli(:ssl_certificate, app.config)
190
+ @ssl_private_key = possible_from_cli(:ssl_private_key, app.config)
192
191
 
193
192
  app.files.on_change :reload do
194
193
  $mm_reload = true
@@ -204,6 +203,14 @@ module Middleman
204
203
  app
205
204
  end
206
205
 
206
+ def possible_from_cli(key, config)
207
+ if @cli_options[key] && @cli_options[key] != :undefined
208
+ @cli_options[key]
209
+ else
210
+ config[key]
211
+ end
212
+ end
213
+
207
214
  # Trap some interupt signals and shut down smoothly
208
215
  # @return [void]
209
216
  def register_signal_handlers
@@ -2,6 +2,7 @@ require 'rack'
2
2
  require 'rack/file'
3
3
  require 'rack/lint'
4
4
  require 'rack/head'
5
+ require 'rack/utils'
5
6
 
6
7
  require 'middleman-core/util'
7
8
  require 'middleman-core/logger'
@@ -124,6 +125,7 @@ module Middleman
124
125
 
125
126
  # Halt request and return 404
126
127
  def not_found(res, path)
128
+ path = ::Rack::Utils.escape_html(path)
127
129
  res.status = 404
128
130
  res.write "<html><head></head><body><h1>File Not Found</h1><p>#{path}</p></body></html>"
129
131
  res.finish
@@ -76,7 +76,7 @@ module Middleman
76
76
  scope.image_tag(link, title: title, alt: alt_text)
77
77
  else
78
78
  link_string = link.dup
79
- link_string << %("#{title}") if title && title.length > 0 && title != alt_text
79
+ link_string << %("#{title}") if title && !title.empty? && title != alt_text
80
80
  "![#{alt_text}](#{link_string})"
81
81
  end
82
82
  end
@@ -89,7 +89,7 @@ module Middleman
89
89
  scope.link_to(content, link, attributes)
90
90
  else
91
91
  link_string = link.dup
92
- link_string << %("#{title}") if title && title.length > 0 && title != alt_text
92
+ link_string << %("#{title}") if title && !title.empty? && title != alt_text
93
93
  "[#{content}](#{link_string})"
94
94
  end
95
95
  end
@@ -105,10 +105,8 @@ module Middleman
105
105
  end
106
106
  end
107
107
 
108
- SASS_MODULE = if defined?(::SassC)
109
- ::SassC
110
- else
111
- ::Sass
108
+ if defined?(::SassC)
109
+ ::SassC::Script::Functions.send :include, ::Middleman::Sass::Functions
110
+ elsif defined?(::Sass)
111
+ ::Sass::Script::Functions.send :include, ::Middleman::Sass::Functions
112
112
  end
113
-
114
- SASS_MODULE::Script::Functions.send :include, ::Middleman::Sass::Functions
@@ -12,13 +12,9 @@ class ::Slim::Template
12
12
 
13
13
  def initialize(file, line, opts, &block)
14
14
  if opts.key?(:context)
15
- context_hack = {
16
- context: opts[:context]
17
- }
18
-
19
15
  ::Slim::Embedded::SassEngine.disable_option_validator!
20
16
  %w(sass scss markdown).each do |engine|
21
- ::Slim::Embedded.options[engine.to_sym] = context_hack
17
+ (::Slim::Embedded.options[engine.to_sym] ||= {})[:context] = opts[:context]
22
18
  end
23
19
  end
24
20
 
@@ -23,8 +23,8 @@ module Middleman
23
23
  ImportPathDescriptor = Struct.new(:from, :renameProc) do
24
24
  def execute_descriptor(app, resources)
25
25
  resources + ::Middleman::Util.glob_directory(File.join(from, '**/*'))
26
- .reject { |path| File.directory?(path) }
27
- .map do |path|
26
+ .reject { |path| File.directory?(path) }
27
+ .map do |path|
28
28
  target_path = Pathname(path).relative_path_from(Pathname(from).parent).to_s
29
29
 
30
30
  ::Middleman::Sitemap::Resource.new(
@@ -36,10 +36,13 @@ module Middleman
36
36
  md = metadata.dup
37
37
  should_ignore = md.delete(:ignore)
38
38
 
39
+ page_data = md.delete(:data) || {}
40
+ page_data[:id] = md.delete(:id) if md.key?(:id)
41
+
39
42
  r = ProxyResource.new(app.sitemap, path, target)
40
43
  r.add_metadata(
41
44
  locals: md.delete(:locals) || {},
42
- page: md.delete(:data) || {},
45
+ page: page_data || {},
43
46
  options: md
44
47
  )
45
48
 
@@ -53,8 +53,7 @@ module Middleman
53
53
  def render(*)
54
54
  url = ::Middleman::Util.url_for(@store.app, @request_path,
55
55
  relative: false,
56
- find_resource: true
57
- )
56
+ find_resource: true)
58
57
 
59
58
  if output
60
59
  output.call(path, url)