middleman-core 3.4.0 → 3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -7
- data/features/clean_build.feature +18 -0
- data/features/cli/preview_server-hook.feature +17 -0
- data/features/cli/preview_server.feature +20 -20
- data/features/data.feature +28 -0
- data/features/step_definitions/queryable_steps.rb +122 -45
- data/features/stylus.feature +1 -1
- data/fixtures/asciidoc-app/source/hello-with-title.adoc +1 -0
- data/fixtures/clean-app/config-hidden-dir-after.rb +5 -0
- data/fixtures/clean-app/config-hidden-dir-before.rb +1 -0
- data/fixtures/preview-server-hook-app/config.rb +19 -0
- data/fixtures/preview-server-hook-app/source/index.html.erb +9 -0
- data/lib/middleman-core.rb +0 -4
- data/lib/middleman-core/application.rb +3 -0
- data/lib/middleman-core/cli.rb +1 -1
- data/lib/middleman-core/cli/build.rb +1 -1
- data/lib/middleman-core/cli/server.rb +1 -1
- data/lib/middleman-core/configuration.rb +1 -1
- data/lib/middleman-core/core_extensions/data.rb +4 -8
- data/lib/middleman-core/core_extensions/data/file_loader.rb +71 -0
- data/lib/middleman-core/core_extensions/rendering.rb +8 -8
- data/lib/middleman-core/core_extensions/show_exceptions.rb +1 -1
- data/lib/middleman-core/dns_resolver/basic_network_resolver.rb +2 -2
- data/lib/middleman-core/extensions.rb +0 -2
- data/lib/middleman-core/meta_pages/sitemap_resource.rb +2 -0
- data/lib/middleman-core/meta_pages/sitemap_tree.rb +1 -1
- data/lib/middleman-core/preview_server.rb +9 -10
- data/lib/middleman-core/preview_server/server_information.rb +12 -3
- data/lib/middleman-core/preview_server/server_information_callback_proxy.rb +35 -0
- data/lib/middleman-core/preview_server/server_url.rb +17 -4
- data/lib/middleman-core/renderers/asciidoc.rb +1 -1
- data/lib/middleman-core/renderers/liquid.rb +1 -1
- data/lib/middleman-core/sitemap/extensions/content_type.rb +1 -1
- data/lib/middleman-core/sitemap/store.rb +9 -8
- data/lib/middleman-core/step_definitions.rb +1 -1
- data/lib/middleman-core/step_definitions/builder_steps.rb +10 -12
- data/lib/middleman-core/step_definitions/commandline_steps.rb +9 -9
- data/lib/middleman-core/step_definitions/middleman_steps.rb +10 -2
- data/lib/middleman-core/step_definitions/server_steps.rb +50 -30
- data/lib/middleman-core/templates/shared/Gemfile.tt +2 -2
- data/lib/middleman-core/templates/shared/config.ru +0 -1
- data/lib/middleman-core/templates/shared/gitignore +3 -0
- data/lib/middleman-core/util.rb +1 -1
- data/lib/middleman-core/version.rb +1 -1
- data/lib/middleman-more/core_extensions/default_helpers.rb +13 -2
- data/lib/middleman-more/extensions/cache_buster.rb +1 -1
- data/middleman-core.gemspec +4 -2
- metadata +15 -5
- data/.gemtest +0 -0
- data/.rspec +0 -1
data/features/stylus.feature
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
set :build_dir, ".build"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
set :layout, false
|
2
|
+
|
3
|
+
class MyFeature < Middleman::Extension
|
4
|
+
def initialize(app, options_hash = {}, &block)
|
5
|
+
super
|
6
|
+
|
7
|
+
app.before_server do |server_information|
|
8
|
+
puts "/// #{server_information.listeners.first} ///"
|
9
|
+
puts "/// #{server_information.port} ///"
|
10
|
+
puts "/// #{server_information.server_name} ///"
|
11
|
+
puts "/// #{server_information.site_addresses.first} ///"
|
12
|
+
puts "/// ### END ### ///"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
::Middleman::Extensions.register(:my_feature, MyFeature)
|
18
|
+
|
19
|
+
activate :my_feature
|
data/lib/middleman-core.rb
CHANGED
@@ -41,6 +41,9 @@ module Middleman
|
|
41
41
|
# Runs after the build is finished
|
42
42
|
define_hook :after_build
|
43
43
|
|
44
|
+
# Runs before the preview server is started
|
45
|
+
define_hook :before_server
|
46
|
+
|
44
47
|
# Mix-in helper methods. Accepts either a list of Modules
|
45
48
|
# and/or a block to be evaluated
|
46
49
|
# @return [void]
|
data/lib/middleman-core/cli.rb
CHANGED
@@ -167,7 +167,7 @@ module Middleman::Cli
|
|
167
167
|
paths = ::Middleman::Util.all_files_under(@build_dir).map(&:realpath).select(&:file?)
|
168
168
|
|
169
169
|
@to_clean += paths.select do |path|
|
170
|
-
path.to_s !~ /\/\./ || path.to_s =~ /\.(htaccess|htpasswd)/
|
170
|
+
path.relative_path_from(@build_dir.realpath).to_s !~ /\/\./ || path.to_s =~ /\.(htaccess|htpasswd)/
|
171
171
|
end
|
172
172
|
|
173
173
|
return unless RUBY_PLATFORM =~ /darwin/
|
@@ -16,7 +16,7 @@ module Middleman::Cli
|
|
16
16
|
desc: 'The port Middleman will listen on'
|
17
17
|
method_option :server_name,
|
18
18
|
aliases: '-s',
|
19
|
-
desc: 'The server name
|
19
|
+
desc: 'The server name Middleman will use'
|
20
20
|
method_option :bind_address,
|
21
21
|
aliases: '-b',
|
22
22
|
desc: 'The bind address Middleman will listen on'
|
@@ -7,9 +7,7 @@ module Middleman
|
|
7
7
|
class << self
|
8
8
|
# @private
|
9
9
|
def registered(app)
|
10
|
-
|
11
|
-
require 'yaml'
|
12
|
-
require 'json'
|
10
|
+
require 'middleman-core/core_extensions/data/file_loader'
|
13
11
|
|
14
12
|
app.config.define_setting :data_dir, 'data', 'The directory data files are stored in'
|
15
13
|
app.send :include, InstanceMethods
|
@@ -95,11 +93,9 @@ module Middleman
|
|
95
93
|
|
96
94
|
data_path = full_path.relative_path_from(root + @app.config[:data_dir])
|
97
95
|
|
98
|
-
|
99
|
-
data =
|
100
|
-
|
101
|
-
data = JSON.parse(full_path.read)
|
102
|
-
else
|
96
|
+
begin
|
97
|
+
data = FileLoader.new.load(full_path)
|
98
|
+
rescue FileLoader::NoFileLoaderFoundError
|
103
99
|
return
|
104
100
|
end
|
105
101
|
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Middleman
|
5
|
+
module CoreExtensions
|
6
|
+
module Data
|
7
|
+
# Load data files
|
8
|
+
class FileLoader
|
9
|
+
# No parser available
|
10
|
+
class NoFileLoaderFoundError < StandardError; end
|
11
|
+
|
12
|
+
# Load yaml files
|
13
|
+
class YamlFileLoader
|
14
|
+
def match?(file)
|
15
|
+
%w(.yaml .yml).include? File.extname(file)
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param [Pathname] file
|
19
|
+
def load(file)
|
20
|
+
YAML.load_file(file)
|
21
|
+
rescue Psych::SyntaxError, StandardError => e
|
22
|
+
$stderr.puts %(Loading data file "#{file}" failed due to an error: #{e.message})
|
23
|
+
{}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Load json files
|
28
|
+
class JsonFileLoader
|
29
|
+
def match?(file)
|
30
|
+
'.json' == File.extname(file)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param [Pathname] file
|
34
|
+
def load(file)
|
35
|
+
JSON.parse(file.read)
|
36
|
+
rescue => e
|
37
|
+
$stderr.puts %(Loading data file "#{file}" failed due to an error: #{e.message})
|
38
|
+
{}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Default loader
|
43
|
+
#
|
44
|
+
# Always fails
|
45
|
+
class NilFileLoader
|
46
|
+
def match?(file)
|
47
|
+
raise NoFileLoaderFoundError
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
attr_reader :loaders
|
54
|
+
|
55
|
+
public
|
56
|
+
|
57
|
+
def initialize
|
58
|
+
@loaders = []
|
59
|
+
@loaders << YamlFileLoader.new
|
60
|
+
@loaders << JsonFileLoader.new
|
61
|
+
@loaders << NilFileLoader.new
|
62
|
+
end
|
63
|
+
|
64
|
+
# Load file using loader
|
65
|
+
def load(file)
|
66
|
+
loaders.find { |l| l.match? file }.load(file)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -214,7 +214,7 @@ module Middleman
|
|
214
214
|
locals = options[:locals]
|
215
215
|
|
216
216
|
if ::Tilt[found_partial]
|
217
|
-
# Render the partial if found,
|
217
|
+
# Render the partial if found, otherwise throw exception
|
218
218
|
_render_with_all_renderers(found_partial, locals, self, options, &block)
|
219
219
|
else
|
220
220
|
read_template_file(found_partial)
|
@@ -265,7 +265,7 @@ module Middleman
|
|
265
265
|
# Try to work around: https://github.com/middleman/middleman/issues/501
|
266
266
|
locs = locs.dup
|
267
267
|
|
268
|
-
# Detect the
|
268
|
+
# Detect the rendering engine from the extension
|
269
269
|
extension = File.extname(path)
|
270
270
|
engine = extension[1..-1].to_sym
|
271
271
|
|
@@ -296,10 +296,10 @@ module Middleman
|
|
296
296
|
# Allow hooks to manipulate the template before render
|
297
297
|
self.class.callbacks_for_hook(:before_render).each do |callback|
|
298
298
|
# Uber::Options::Value doesn't respond to call
|
299
|
-
newbody = if callback.
|
300
|
-
callback.call(body, path, locs, template_class)
|
299
|
+
newbody = if callback.is_a? ::Uber::Options::Value
|
300
|
+
callback.call(self, body, path, locs, template_class)
|
301
301
|
elsif callback.respond_to?(:evaluate)
|
302
|
-
callback.
|
302
|
+
callback.call(body, path, locs, template_class)
|
303
303
|
end
|
304
304
|
body = newbody if newbody # Allow the callback to return nil to skip it
|
305
305
|
end
|
@@ -315,10 +315,10 @@ module Middleman
|
|
315
315
|
# Allow hooks to manipulate the result after render
|
316
316
|
self.class.callbacks_for_hook(:after_render).each do |callback|
|
317
317
|
# Uber::Options::Value doesn't respond to call
|
318
|
-
newcontent = if callback.
|
319
|
-
|
318
|
+
newcontent = if callback.is_a? ::Uber::Options::Value
|
319
|
+
callback.call(self, content, path, locs, template_class)
|
320
320
|
elsif callback.respond_to?(:evaluate)
|
321
|
-
|
321
|
+
callback.call(content, path, locs, template_class)
|
322
322
|
end
|
323
323
|
content = newcontent if newcontent # Allow the callback to return nil to skip it
|
324
324
|
end
|
@@ -21,7 +21,7 @@ module Middleman
|
|
21
21
|
# Array of Names
|
22
22
|
def getnames(ip)
|
23
23
|
resolver.getnames(ip.to_s).map(&:to_s)
|
24
|
-
rescue Resolv::ResolvError, Errno::EADDRNOTAVAIL
|
24
|
+
rescue Resolv::ResolvError, Errno::EADDRNOTAVAIL, Errno::ENETUNREACH
|
25
25
|
[]
|
26
26
|
end
|
27
27
|
|
@@ -34,7 +34,7 @@ module Middleman
|
|
34
34
|
# Array of ipaddresses
|
35
35
|
def getaddresses(name)
|
36
36
|
resolver.getaddresses(name.to_s).map(&:to_s)
|
37
|
-
rescue Resolv::ResolvError, Errno::EADDRNOTAVAIL
|
37
|
+
rescue Resolv::ResolvError, Errno::EADDRNOTAVAIL, Errno::ENETUNREACH
|
38
38
|
[]
|
39
39
|
end
|
40
40
|
|
@@ -59,7 +59,7 @@ module Middleman
|
|
59
59
|
|
60
60
|
if path_parts.size == 1
|
61
61
|
sitemap_class = SitemapResource
|
62
|
-
# Allow special sitemap resources to use custom metadata view
|
62
|
+
# Allow special sitemap resources to use custom metadata view classes
|
63
63
|
sitemap_class = resource.meta_pages_class if resource.respond_to? :meta_pages_class
|
64
64
|
|
65
65
|
@children[first_part] = sitemap_class.new(resource)
|
@@ -5,6 +5,7 @@ require 'middleman-core/meta_pages'
|
|
5
5
|
require 'middleman-core/logger'
|
6
6
|
require 'middleman-core/preview_server/server_information'
|
7
7
|
require 'middleman-core/preview_server/server_url'
|
8
|
+
require 'middleman-core/preview_server/server_information_callback_proxy'
|
8
9
|
|
9
10
|
# rubocop:disable GlobalVars
|
10
11
|
module Middleman
|
@@ -13,10 +14,6 @@ module Middleman
|
|
13
14
|
attr_reader :app, :ssl_certificate, :ssl_private_key, :environment, :server_information
|
14
15
|
delegate :logger, to: :app
|
15
16
|
|
16
|
-
def https?
|
17
|
-
@https
|
18
|
-
end
|
19
|
-
|
20
17
|
# Start an instance of Middleman::Application
|
21
18
|
# @return [void]
|
22
19
|
def start(opts={})
|
@@ -26,6 +23,7 @@ module Middleman
|
|
26
23
|
|
27
24
|
@options = opts
|
28
25
|
@server_information = ServerInformation.new
|
26
|
+
@server_information.https = (@options[:https] == true)
|
29
27
|
|
30
28
|
# New app evaluates the middleman configuration. Since this can be
|
31
29
|
# invalid as well, we need to evaluate the configuration BEFORE
|
@@ -42,9 +40,9 @@ module Middleman
|
|
42
40
|
|
43
41
|
logger.debug %(== Server information is provided by #{server_information.handler})
|
44
42
|
logger.debug %(== The Middleman is running in "#{environment}" environment)
|
45
|
-
logger.debug format('== The Middleman preview server is
|
46
|
-
logger.info format('== View your site at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: https?).to_urls.join(', '))
|
47
|
-
logger.info format('== Inspect your site configuration at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: https?).to_config_urls.join(', '))
|
43
|
+
logger.debug format('== The Middleman preview server is bound to %s', ServerUrl.new(hosts: server_information.listeners, port: server_information.port, https: server_information.https?).to_bind_addresses.join(', '))
|
44
|
+
logger.info format('== View your site at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: server_information.https?).to_urls.join(', '))
|
45
|
+
logger.info format('== Inspect your site configuration at %s', ServerUrl.new(hosts: server_information.site_addresses, port: server_information.port, https: server_information.https?).to_config_urls.join(', '))
|
48
46
|
|
49
47
|
@initialized ||= false
|
50
48
|
return if @initialized
|
@@ -56,6 +54,8 @@ module Middleman
|
|
56
54
|
# reloading later on.
|
57
55
|
::Middleman::Profiling.report('server_start')
|
58
56
|
|
57
|
+
app.run_hook(:before_server, ServerInformationCallbackProxy.new(server_information))
|
58
|
+
|
59
59
|
loop do
|
60
60
|
@webrick.start
|
61
61
|
|
@@ -153,7 +153,6 @@ module Middleman
|
|
153
153
|
|
154
154
|
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
|
155
155
|
|
156
|
-
@https = @app.config[:https]
|
157
156
|
@environment = @app.config[:environment]
|
158
157
|
|
159
158
|
@ssl_certificate = @app.config[:ssl_certificate]
|
@@ -199,7 +198,7 @@ module Middleman
|
|
199
198
|
@listener.start
|
200
199
|
end
|
201
200
|
|
202
|
-
# Trap some
|
201
|
+
# Trap some interrupt signals and shut down smoothly
|
203
202
|
# @return [void]
|
204
203
|
def register_signal_handlers
|
205
204
|
%w(INT HUP TERM QUIT).each do |sig|
|
@@ -224,7 +223,7 @@ module Middleman
|
|
224
223
|
DoNotReverseLookup: true
|
225
224
|
}
|
226
225
|
|
227
|
-
if https?
|
226
|
+
if server_information.https?
|
228
227
|
http_opts[:SSLEnable] = true
|
229
228
|
|
230
229
|
if ssl_certificate || ssl_private_key
|
@@ -20,6 +20,8 @@ module Middleman
|
|
20
20
|
|
21
21
|
public
|
22
22
|
|
23
|
+
attr_writer :https
|
24
|
+
|
23
25
|
def initialize(opts={})
|
24
26
|
@resolver = opts.fetch(:resolver, DnsResolver.new)
|
25
27
|
@validator = opts.fetch(:validator, ServerInformationValidator.new)
|
@@ -64,13 +66,15 @@ module Middleman
|
|
64
66
|
@bind_address = config[:bind_address]
|
65
67
|
@port = config[:port]
|
66
68
|
@server_name = config[:server_name]
|
69
|
+
@https = config[:https]
|
67
70
|
|
68
71
|
config[:bind_address] = bind_address
|
69
|
-
config[:port]
|
70
|
-
config[:server_name]
|
72
|
+
config[:port] = port
|
73
|
+
config[:server_name] = server_name
|
74
|
+
config[:https] = https?
|
71
75
|
end
|
72
76
|
|
73
|
-
# Make information of internal server class
|
77
|
+
# Make information of internal server class available to make debugging
|
74
78
|
# easier. This can be used to log the class which was used to determine
|
75
79
|
# the preview server settings
|
76
80
|
#
|
@@ -139,6 +143,11 @@ module Middleman
|
|
139
143
|
def listeners
|
140
144
|
information.listeners
|
141
145
|
end
|
146
|
+
|
147
|
+
# Is https enabled?
|
148
|
+
def https?
|
149
|
+
@https == true
|
150
|
+
end
|
142
151
|
end
|
143
152
|
end
|
144
153
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Middleman
|
2
|
+
class PreviewServer
|
3
|
+
# This class wraps server information to be used in call back
|
4
|
+
#
|
5
|
+
# * listeners
|
6
|
+
# * port
|
7
|
+
# * server name
|
8
|
+
# * site_addresses
|
9
|
+
#
|
10
|
+
# All information is "dupped" and the callback is not meant to be used to
|
11
|
+
# modify these information.
|
12
|
+
class ServerInformationCallbackProxy
|
13
|
+
attr_reader :server_name, :port, :site_addresses, :listeners
|
14
|
+
|
15
|
+
def initialize(server_information)
|
16
|
+
@listeners = ServerUrl.new(
|
17
|
+
hosts: server_information.listeners,
|
18
|
+
port: server_information.port,
|
19
|
+
https: server_information.https?,
|
20
|
+
format_output: false
|
21
|
+
).to_bind_addresses
|
22
|
+
|
23
|
+
@port = server_information.port
|
24
|
+
@server_name = server_information.server_name.dup unless server_information.server_name == nil
|
25
|
+
|
26
|
+
@site_addresses = ServerUrl.new(
|
27
|
+
hosts: server_information.site_addresses,
|
28
|
+
port: server_information.port,
|
29
|
+
https: server_information.https?,
|
30
|
+
format_output: false
|
31
|
+
).to_urls
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|