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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -7
  3. data/features/clean_build.feature +18 -0
  4. data/features/cli/preview_server-hook.feature +17 -0
  5. data/features/cli/preview_server.feature +20 -20
  6. data/features/data.feature +28 -0
  7. data/features/step_definitions/queryable_steps.rb +122 -45
  8. data/features/stylus.feature +1 -1
  9. data/fixtures/asciidoc-app/source/hello-with-title.adoc +1 -0
  10. data/fixtures/clean-app/config-hidden-dir-after.rb +5 -0
  11. data/fixtures/clean-app/config-hidden-dir-before.rb +1 -0
  12. data/fixtures/preview-server-hook-app/config.rb +19 -0
  13. data/fixtures/preview-server-hook-app/source/index.html.erb +9 -0
  14. data/lib/middleman-core.rb +0 -4
  15. data/lib/middleman-core/application.rb +3 -0
  16. data/lib/middleman-core/cli.rb +1 -1
  17. data/lib/middleman-core/cli/build.rb +1 -1
  18. data/lib/middleman-core/cli/server.rb +1 -1
  19. data/lib/middleman-core/configuration.rb +1 -1
  20. data/lib/middleman-core/core_extensions/data.rb +4 -8
  21. data/lib/middleman-core/core_extensions/data/file_loader.rb +71 -0
  22. data/lib/middleman-core/core_extensions/rendering.rb +8 -8
  23. data/lib/middleman-core/core_extensions/show_exceptions.rb +1 -1
  24. data/lib/middleman-core/dns_resolver/basic_network_resolver.rb +2 -2
  25. data/lib/middleman-core/extensions.rb +0 -2
  26. data/lib/middleman-core/meta_pages/sitemap_resource.rb +2 -0
  27. data/lib/middleman-core/meta_pages/sitemap_tree.rb +1 -1
  28. data/lib/middleman-core/preview_server.rb +9 -10
  29. data/lib/middleman-core/preview_server/server_information.rb +12 -3
  30. data/lib/middleman-core/preview_server/server_information_callback_proxy.rb +35 -0
  31. data/lib/middleman-core/preview_server/server_url.rb +17 -4
  32. data/lib/middleman-core/renderers/asciidoc.rb +1 -1
  33. data/lib/middleman-core/renderers/liquid.rb +1 -1
  34. data/lib/middleman-core/sitemap/extensions/content_type.rb +1 -1
  35. data/lib/middleman-core/sitemap/store.rb +9 -8
  36. data/lib/middleman-core/step_definitions.rb +1 -1
  37. data/lib/middleman-core/step_definitions/builder_steps.rb +10 -12
  38. data/lib/middleman-core/step_definitions/commandline_steps.rb +9 -9
  39. data/lib/middleman-core/step_definitions/middleman_steps.rb +10 -2
  40. data/lib/middleman-core/step_definitions/server_steps.rb +50 -30
  41. data/lib/middleman-core/templates/shared/Gemfile.tt +2 -2
  42. data/lib/middleman-core/templates/shared/config.ru +0 -1
  43. data/lib/middleman-core/templates/shared/gitignore +3 -0
  44. data/lib/middleman-core/util.rb +1 -1
  45. data/lib/middleman-core/version.rb +1 -1
  46. data/lib/middleman-more/core_extensions/default_helpers.rb +13 -2
  47. data/lib/middleman-more/extensions/cache_buster.rb +1 -1
  48. data/middleman-core.gemspec +4 -2
  49. metadata +15 -5
  50. data/.gemtest +0 -0
  51. data/.rspec +0 -1
@@ -1,4 +1,4 @@
1
- @nojava
1
+ @wip @nojava
2
2
  Feature: Stylus Updates and Partials
3
3
  Scenario: The preview server should update stylesheets when Stylus changes
4
4
  Given the Server is running at "stylus-preview-app"
@@ -1,4 +1,5 @@
1
1
  = Page Title
2
+ :showtitle:
2
3
  :page-layout: default
3
4
 
4
5
  Hello, AsciiDoc!
@@ -0,0 +1,5 @@
1
+ set :build_dir, ".build"
2
+
3
+ ignore "/should_be_ignored.html"
4
+ page "/should_be_ignored2.html", :ignore => true
5
+ page "/target_ignore.html", :proxy => "/should_be_ignored3.html", :ignore => true
@@ -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
@@ -0,0 +1,9 @@
1
+ <html>
2
+ <head>
3
+ <meta charset="utf-8">
4
+ <title>preview-server-hook-app</title>
5
+ </head>
6
+ <body>
7
+ <h1>preview-server-hook-app</h1>
8
+ </body>
9
+ </html>
@@ -1,9 +1,5 @@
1
1
  # rubocop:disable FileName
2
2
 
3
- # Setup our load paths
4
- libdir = File.expand_path(File.dirname(__FILE__))
5
- $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
6
-
7
3
  # Top-level Middleman namespace
8
4
  module Middleman
9
5
  # Backwards compatibility namespace
@@ -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]
@@ -5,7 +5,7 @@ require 'thor/group'
5
5
  # CLI Module
6
6
  module Middleman
7
7
  module Cli
8
- # The base task from which everything else etends
8
+ # The base task from which everything else extends
9
9
  class Base < Thor
10
10
  class << self
11
11
  def start(*args)
@@ -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 name Middleman will use'
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'
@@ -48,7 +48,7 @@ module Middleman
48
48
  self.class.config
49
49
  end
50
50
 
51
- # Backwards compatibilty with old Sinatra template interface
51
+ # Backwards compatibility with old Sinatra template interface
52
52
  #
53
53
  # @deprecated Prefer accessing settings through "config".
54
54
  #
@@ -7,9 +7,7 @@ module Middleman
7
7
  class << self
8
8
  # @private
9
9
  def registered(app)
10
- # Data formats
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
- if %w(.yaml .yml).include?(extension)
99
- data = YAML.load_file(full_path)
100
- elsif extension == '.json'
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, otherwide throw exception
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 remdering engine from the extension
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.respond_to?(:call)
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.evaluate(self, body, path, locs, template_class)
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.respond_to?(:call)
319
- content = callback.call(content, path, locs, template_class)
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
- content = callback.evaluate(self, content, path, locs, template_class)
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
@@ -15,7 +15,7 @@ module Middleman
15
15
 
16
16
  # When in dev
17
17
  app.configure :development do
18
- # Include middlemare
18
+ # Include middleware
19
19
  use ::Rack::ShowExceptions if config[:show_exceptions]
20
20
  end
21
21
  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
 
@@ -56,8 +56,6 @@ module Middleman
56
56
  #
57
57
  # @private
58
58
  def load_extensions_in_path
59
- require 'rubygems'
60
-
61
59
  extensions = rubygems_latest_specs.select do |spec|
62
60
  spec_has_file?(spec, EXTENSION_FILE)
63
61
  end
@@ -1,4 +1,6 @@
1
1
  require 'padrino-helpers'
2
+ require 'padrino-helpers/output_helpers'
3
+ require 'padrino-helpers/tag_helpers'
2
4
 
3
5
  module Middleman
4
6
  module MetaPages
@@ -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 calsses
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 bind to %s', ServerUrl.new(hosts: server_information.listeners, port: server_information.port, https: https?).to_bind_addresses.join(', '))
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 interupt signals and shut down smoothly
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] = port
70
- config[:server_name] = 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 avaible to make debugging
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