middleman-core 3.0.0 → 3.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/.cane +2 -0
  2. data/.cane-exclusions.yml +5 -0
  3. data/Rakefile +1 -1
  4. data/bin/middleman +9 -55
  5. data/features/cli_extension.feature +1 -0
  6. data/features/frontmatter_page_settings.feature +11 -1
  7. data/features/instance_vars.feature +9 -0
  8. data/features/step_definitions/page_layout_steps.rb +3 -3
  9. data/features/strip_url.feature +40 -0
  10. data/features/support/env.rb +1 -1
  11. data/fixtures/automatic-directory-matcher-app/config.rb +1 -1
  12. data/fixtures/basic-data-app/config.rb +1 -1
  13. data/fixtures/build-with-errors-app/config.rb +1 -1
  14. data/fixtures/clean-app/config-complications.rb +1 -1
  15. data/fixtures/clean-app/config.rb +1 -1
  16. data/fixtures/current-page-app/config.rb +1 -1
  17. data/fixtures/custom-layout-app/config.rb +1 -1
  18. data/fixtures/data-app/config.rb +1 -1
  19. data/fixtures/external-helpers/config.rb +1 -1
  20. data/fixtures/external-helpers/helpers/derp.rb +1 -1
  21. data/fixtures/external-helpers/helpers/four_helpers.rb +1 -1
  22. data/fixtures/external-helpers/helpers/one_helper.rb +1 -1
  23. data/fixtures/external-helpers/helpers/yet_another_thingy.rb +1 -1
  24. data/fixtures/external-helpers/lib/hello_helper.rb +1 -1
  25. data/fixtures/feature-params-app/config.rb +1 -1
  26. data/fixtures/frontmatter-settings-app/config.rb +3 -1
  27. data/fixtures/frontmatter-settings-app/source/layouts/override.erb +2 -0
  28. data/fixtures/frontmatter-settings-app/source/override_layout.html.erb +4 -0
  29. data/fixtures/frontmatter-settings-app/source/page_mentioned.html.erb +4 -0
  30. data/fixtures/generator-test/config.rb +10 -10
  31. data/fixtures/glob-app/config.rb +1 -1
  32. data/fixtures/instance-vars-app/config.rb +7 -0
  33. data/fixtures/instance-vars-app/source/content.html.erb +2 -0
  34. data/fixtures/instance-vars-app/source/layout.erb +1 -0
  35. data/fixtures/large-build-app/config.rb +1 -1
  36. data/fixtures/large-build-app/source/images/Child folder/regular_file(example).txt +1 -1
  37. data/fixtures/large-build-app/source/images/Read me (example).txt +1 -1
  38. data/fixtures/manual-layout-missing/config.rb +1 -1
  39. data/fixtures/manual-layout-override/config.rb +1 -1
  40. data/fixtures/manual-layout/config.rb +1 -1
  41. data/fixtures/page-helper-layout-block-app/config.rb +1 -1
  42. data/fixtures/sinatra-app/config.rb +1 -1
  43. data/fixtures/strip-url-app/config.rb +0 -0
  44. data/fixtures/strip-url-app/source/index.html.erb +1 -0
  45. data/fixtures/strip-url-app/source/other.html.erb +1 -0
  46. data/fixtures/strip-url-app/source/subdir/index.html.erb +1 -0
  47. data/fixtures/traversal-app/config.rb +1 -1
  48. data/fixtures/wildcard-app/config.rb +1 -1
  49. data/lib/middleman-core.rb +3 -3
  50. data/lib/middleman-core/application.rb +12 -11
  51. data/lib/middleman-core/cli.rb +23 -10
  52. data/lib/middleman-core/cli/build.rb +65 -54
  53. data/lib/middleman-core/cli/bundler.rb +7 -7
  54. data/lib/middleman-core/cli/extension.rb +25 -12
  55. data/lib/middleman-core/cli/init.rb +19 -19
  56. data/lib/middleman-core/cli/server.rb +25 -16
  57. data/lib/middleman-core/core_extensions/builder.rb +3 -3
  58. data/lib/middleman-core/core_extensions/data.rb +28 -28
  59. data/lib/middleman-core/core_extensions/extensions.rb +24 -25
  60. data/lib/middleman-core/core_extensions/external_helpers.rb +7 -7
  61. data/lib/middleman-core/core_extensions/file_watcher.rb +41 -38
  62. data/lib/middleman-core/core_extensions/front_matter.rb +36 -33
  63. data/lib/middleman-core/core_extensions/rendering.rb +49 -46
  64. data/lib/middleman-core/core_extensions/request.rb +34 -33
  65. data/lib/middleman-core/core_extensions/routing.rb +17 -17
  66. data/lib/middleman-core/core_extensions/ruby_encoding.rb +1 -1
  67. data/lib/middleman-core/core_extensions/show_exceptions.rb +5 -5
  68. data/lib/middleman-core/extensions.rb +4 -4
  69. data/lib/middleman-core/load_paths.rb +56 -0
  70. data/lib/middleman-core/logger.rb +29 -0
  71. data/lib/middleman-core/preview_server.rb +35 -34
  72. data/lib/middleman-core/profiling.rb +58 -0
  73. data/lib/middleman-core/renderers/coffee_script.rb +8 -6
  74. data/lib/middleman-core/renderers/erb.rb +5 -5
  75. data/lib/middleman-core/renderers/haml.rb +5 -5
  76. data/lib/middleman-core/renderers/less.rb +14 -10
  77. data/lib/middleman-core/renderers/liquid.rb +7 -7
  78. data/lib/middleman-core/renderers/markdown.rb +13 -14
  79. data/lib/middleman-core/renderers/redcarpet.rb +31 -11
  80. data/lib/middleman-core/renderers/sass.rb +38 -22
  81. data/lib/middleman-core/renderers/slim.rb +15 -7
  82. data/lib/middleman-core/sitemap.rb +25 -28
  83. data/lib/middleman-core/sitemap/extensions/ignores.rb +13 -13
  84. data/lib/middleman-core/sitemap/extensions/on_disk.rb +12 -12
  85. data/lib/middleman-core/sitemap/extensions/proxies.rb +26 -20
  86. data/lib/middleman-core/sitemap/extensions/traversal.rb +10 -10
  87. data/lib/middleman-core/sitemap/resource.rb +47 -50
  88. data/lib/middleman-core/sitemap/store.rb +38 -36
  89. data/lib/middleman-core/step_definitions.rb +1 -1
  90. data/lib/middleman-core/step_definitions/builder_steps.rb +1 -1
  91. data/lib/middleman-core/step_definitions/middleman_steps.rb +3 -3
  92. data/lib/middleman-core/step_definitions/server_steps.rb +5 -5
  93. data/lib/middleman-core/templates.rb +12 -12
  94. data/lib/middleman-core/templates/default.rb +11 -11
  95. data/lib/middleman-core/templates/extension/Gemfile +14 -1
  96. data/lib/middleman-core/templates/extension/Rakefile +3 -1
  97. data/lib/middleman-core/templates/extension/features/support/env.rb +1 -1
  98. data/lib/middleman-core/templates/extension/gitignore +2 -0
  99. data/lib/middleman-core/templates/extension/lib/lib.rb +11 -11
  100. data/lib/middleman-core/templates/extension/lib/middleman_extension.rb +1 -1
  101. data/lib/middleman-core/templates/html5.rb +10 -10
  102. data/lib/middleman-core/templates/html5/source/humans.txt +0 -0
  103. data/lib/middleman-core/templates/html5/source/robots.txt +0 -0
  104. data/lib/middleman-core/templates/local.rb +4 -4
  105. data/lib/middleman-core/templates/mobile.rb +3 -3
  106. data/lib/middleman-core/templates/mobile/source/humans.txt +0 -0
  107. data/lib/middleman-core/templates/mobile/source/robots.txt +0 -0
  108. data/lib/middleman-core/templates/shared/config.ru +1 -1
  109. data/lib/middleman-core/templates/shared/config.tt +10 -10
  110. data/lib/middleman-core/util.rb +30 -6
  111. data/lib/middleman-core/vendor/hooks-0.2.0/lib/hooks.rb +19 -19
  112. data/lib/middleman-core/vendor/hooks-0.2.0/lib/hooks/inheritable_attribute.rb +2 -2
  113. data/lib/middleman-core/vendor/hooks-0.2.0/test/hooks_test.rb +29 -29
  114. data/lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb +11 -11
  115. data/lib/middleman-core/version.rb +1 -1
  116. data/lib/middleman/rack.rb +4 -0
  117. data/middleman-core-x86-mingw32.gemspec +38 -0
  118. data/middleman-core.gemspec +3 -2
  119. metadata +72 -11
@@ -3,28 +3,36 @@ require "slim"
3
3
 
4
4
  module Middleman
5
5
  module Renderers
6
-
6
+
7
7
  # Slim renderer
8
8
  module Slim
9
-
9
+
10
10
  # Setup extension
11
11
  class << self
12
-
12
+
13
13
  # Once registered
14
14
  def registered(app)
15
15
  app.before_configuration do
16
16
  template_extensions :slim => :html
17
17
  end
18
-
18
+
19
19
  # Setup Slim options to work with partials
20
20
  ::Slim::Engine.set_default_options(
21
- :buffer => '@_out_buf',
21
+ :buffer => '@_out_buf',
22
22
  :generator => ::Temple::Generators::StringBuffer
23
23
  )
24
+
25
+ app.after_configuration do
26
+ sass_context_hack = {
27
+ :context => self
28
+ }
29
+ ::Slim::EmbeddedEngine.default_options[:sass] = sass_context_hack
30
+ ::Slim::EmbeddedEngine.default_options[:scss] = sass_context_hack
31
+ end
24
32
  end
25
-
33
+
26
34
  alias :included :registered
27
35
  end
28
36
  end
29
37
  end
30
- end
38
+ end
@@ -7,75 +7,72 @@ require "middleman-core/sitemap/extensions/ignores"
7
7
 
8
8
  # Core Sitemap Extensions
9
9
  module Middleman
10
-
10
+
11
11
  module Sitemap
12
-
12
+
13
13
  # Setup Extension
14
14
  class << self
15
-
15
+
16
16
  # Once registered
17
17
  def registered(app)
18
-
18
+
19
19
  app.register Middleman::Sitemap::Extensions::Proxies
20
20
  app.register Middleman::Sitemap::Extensions::Ignores
21
-
21
+
22
22
  # Set to automatically convert some characters into a directory
23
23
  app.set :automatic_directory_matcher, nil
24
-
24
+
25
25
  # Setup callbacks which can exclude paths from the sitemap
26
26
  app.set :ignored_sitemap_matchers, {
27
27
  # dotfiles and folders in the root
28
- :root_dotfiles => proc { |file, path| file.match(/^\./) },
29
-
28
+ :root_dotfiles => proc { |file| file.match(%r{^\.}) },
29
+
30
30
  # Files starting with an dot, but not .htaccess
31
- :source_dotfiles => proc { |file, path|
32
- (file.match(/\/\./) && !file.match(/\/\.htaccess/))
31
+ :source_dotfiles => proc { |file|
32
+ file.match(%r{/\.}) && !file.match(%r{/\.htaccess})
33
33
  },
34
-
34
+
35
35
  # Files starting with an underscore, but not a double-underscore
36
- :partials => proc { |file, path| (file.match(/\/_/) && !file.match(/\/__/)) },
37
-
38
- :layout => proc { |file, path|
39
- file.match(/^source\/layout\./) || file.match(/^source\/layouts\//)
40
- },
41
-
42
- # Files without any output extension (layouts, partials)
43
- # :extensionless => proc { |file, path| !path.match(/\./) },
36
+ :partials => proc { |file| file.match(%r{/_}) && !file.match(%r{/__}) },
37
+
38
+ :layout => proc { |file|
39
+ file.match(%r{^source/layout\.}) || file.match(%r{^source/layouts/})
40
+ }
44
41
  }
45
-
42
+
46
43
  # Include instance methods
47
44
  app.send :include, InstanceMethods
48
-
45
+
49
46
  # Initialize Sitemap
50
47
  app.before_configuration do
51
48
  sitemap
52
49
  end
53
50
  end
54
51
  alias :included :registered
55
-
52
+
56
53
  end
57
-
54
+
58
55
  # Sitemap instance methods
59
56
  module InstanceMethods
60
-
57
+
61
58
  # Get the sitemap class instance
62
59
  # @return [Middleman::Sitemap::Store]
63
60
  def sitemap
64
61
  @_sitemap ||= Store.new(self)
65
62
  end
66
-
63
+
67
64
  # Get the resource object for the current path
68
65
  # @return [Middleman::Sitemap::Resource]
69
66
  def current_page
70
67
  current_resource
71
68
  end
72
-
69
+
73
70
  # Get the resource object for the current path
74
71
  # @return [Middleman::Sitemap::Resource]
75
72
  def current_resource
76
73
  sitemap.find_resource_by_destination_path(current_path)
77
74
  end
78
-
75
+
79
76
  end
80
77
  end
81
- end
78
+ end
@@ -3,42 +3,42 @@ module Middleman
3
3
  module Sitemap
4
4
 
5
5
  module Extensions
6
-
6
+
7
7
  module Ignores
8
-
8
+
9
9
  # Setup extension
10
10
  class << self
11
-
11
+
12
12
  # Once registered
13
13
  def registered(app)
14
14
  # Include methods
15
15
  app.send :include, InstanceMethods
16
-
16
+
17
17
  ::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
18
18
  end
19
-
19
+
20
20
  alias :included :registered
21
21
  end
22
-
22
+
23
23
  # Helpers methods for Resources
24
24
  module ResourceInstanceMethods
25
-
25
+
26
26
  # Whether the Resource is ignored
27
27
  # @return [Boolean]
28
28
  def ignored?
29
- @app.ignore_manager.ignored?(path) ||
29
+ @app.ignore_manager.ignored?(path) ||
30
30
  (!proxy? &&
31
31
  @app.ignore_manager.ignored?(source_file.sub("#{@app.source_dir}/", ""))
32
32
  )
33
33
  end
34
34
  end
35
-
35
+
36
36
  # Ignore-related instance methods
37
37
  module InstanceMethods
38
38
  def ignore_manager
39
39
  @_ignore_manager ||= IgnoreManager.new(self)
40
40
  end
41
-
41
+
42
42
  # Ignore a path or add an ignore callback
43
43
  # @param [String, Regexp] path Path glob expression, or path regex
44
44
  # @return [void]
@@ -46,7 +46,7 @@ module Middleman
46
46
  ignore_manager.ignore(path, &block)
47
47
  end
48
48
  end
49
-
49
+
50
50
  # Class to handle managing ignores
51
51
  class IgnoreManager
52
52
  def initialize(app)
@@ -55,7 +55,7 @@ module Middleman
55
55
  # Array of callbacks which can ass ignored
56
56
  @ignored_callbacks = []
57
57
  end
58
-
58
+
59
59
  # Ignore a path or add an ignore callback
60
60
  # @param [String, Regexp] path Path glob expression, or path regex
61
61
  # @return [void]
@@ -88,4 +88,4 @@ module Middleman
88
88
  end
89
89
  end
90
90
  end
91
- end
91
+ end
@@ -1,11 +1,11 @@
1
1
  require 'set'
2
2
 
3
3
  module Middleman
4
-
4
+
5
5
  module Sitemap
6
-
6
+
7
7
  module Extensions
8
-
8
+
9
9
  class OnDisk
10
10
 
11
11
  attr_accessor :sitemap
@@ -14,22 +14,22 @@ module Middleman
14
14
  def initialize(sitemap)
15
15
  @sitemap = sitemap
16
16
  @app = @sitemap.app
17
-
17
+
18
18
  @file_paths_on_disk = Set.new
19
19
 
20
20
  scoped_self = self
21
21
  @waiting_for_ready = true
22
-
22
+
23
23
  # Register file change callback
24
24
  @app.files.changed do |file|
25
25
  scoped_self.touch_file(file, !scoped_self.waiting_for_ready)
26
26
  end
27
-
27
+
28
28
  # Register file delete callback
29
29
  @app.files.deleted do |file|
30
30
  scoped_self.remove_file(file, !scoped_self.waiting_for_ready)
31
31
  end
32
-
32
+
33
33
  @app.ready do
34
34
  scoped_self.waiting_for_ready = false
35
35
  scoped_self.sitemap.rebuild_resource_list!(:on_disk_ready)
@@ -40,13 +40,13 @@ module Middleman
40
40
  # @param [String] file
41
41
  # @return [Boolean]
42
42
  def touch_file(file, rebuild=true)
43
- return false if file == @app.source_dir || File.directory?(file)
43
+ return false if File.directory?(file)
44
44
 
45
45
  path = @sitemap.file_to_path(file)
46
46
  return false unless path
47
47
 
48
48
  ignored = @app.ignored_sitemap_matchers.any? do |name, callback|
49
- callback.call(file, path)
49
+ callback.call(file)
50
50
  end
51
51
 
52
52
  @file_paths_on_disk << file unless ignored
@@ -57,7 +57,7 @@ module Middleman
57
57
  # whether or not it belongs in the sitemap (like a partial)
58
58
  @sitemap.rebuild_resource_list!(:touched_file) if rebuild
59
59
  end
60
-
60
+
61
61
  # Remove a file from the store
62
62
  # @param [String] file
63
63
  # @return [void]
@@ -66,7 +66,7 @@ module Middleman
66
66
  @sitemap.rebuild_resource_list!(:removed_file) if rebuild
67
67
  end
68
68
  end
69
-
69
+
70
70
  # Update the main sitemap resource list
71
71
  # @return [void]
72
72
  def manipulate_resource_list(resources)
@@ -81,4 +81,4 @@ module Middleman
81
81
  end
82
82
  end
83
83
  end
84
- end
84
+ end
@@ -1,45 +1,47 @@
1
1
  module Middleman
2
2
 
3
3
  module Sitemap
4
-
4
+
5
5
  module Extensions
6
-
6
+
7
7
  module Proxies
8
-
8
+
9
9
  # Setup extension
10
10
  class << self
11
-
11
+
12
12
  # Once registered
13
13
  def registered(app)
14
14
  ::Middleman::Sitemap::Resource.send :include, ResourceInstanceMethods
15
-
15
+
16
16
  # Include methods
17
17
  app.send :include, InstanceMethods
18
18
  end
19
-
19
+
20
20
  alias :included :registered
21
21
  end
22
-
22
+
23
23
  module ResourceInstanceMethods
24
24
  # Whether this page is a proxy
25
25
  # @return [Boolean]
26
26
  def proxy?
27
27
  !!@proxied_to
28
28
  end
29
-
29
+
30
30
  # Set this page to proxy to a target path
31
31
  # @param [String] target
32
32
  # @return [void]
33
33
  def proxy_to(target)
34
+ target = ::Middleman::Util.normalize_path(target)
35
+ raise "You can't proxy #{path} to itself!" if target == path
34
36
  @proxied_to = target
35
37
  end
36
-
38
+
37
39
  # The path of the page this page is proxied to, or nil if it's not proxied.
38
40
  # @return [String]
39
41
  def proxied_to
40
42
  @proxied_to
41
43
  end
42
-
44
+
43
45
  # Whether this page has a template file
44
46
  # @return [Boolean]
45
47
  def template?
@@ -49,37 +51,41 @@ module Middleman
49
51
  super
50
52
  end
51
53
  end
52
-
54
+
53
55
  def get_source_file
54
56
  if proxy?
55
57
  proxy_resource = store.find_resource_by_path(proxied_to)
56
-
58
+
57
59
  unless proxy_resource
58
- raise "Path #{path} proxies to unknown file #{proxied_to}"
60
+ raise "Path #{path} proxies to unknown file #{proxied_to}:#{store.resources.map(&:path)}"
59
61
  end
60
-
62
+
63
+ if proxy_resource.proxy?
64
+ raise "You can't proxy #{path} to #{proxied_to} which is itself a proxy."
65
+ end
66
+
61
67
  proxy_resource.source_file
62
68
  end
63
69
  end
64
70
  end
65
-
71
+
66
72
  module InstanceMethods
67
73
  def proxy_manager
68
74
  @_proxy_manager ||= ProxyManager.new(self)
69
75
  end
70
-
76
+
71
77
  def proxy(*args)
72
78
  proxy_manager.proxy(*args)
73
79
  end
74
80
  end
75
-
81
+
76
82
  class ProxyManager
77
83
  def initialize(app)
78
84
  @app = app
79
-
85
+
80
86
  @proxy_paths = {}
81
87
  end
82
-
88
+
83
89
  # Setup a proxy from a path to a target
84
90
  # @param [String] path
85
91
  # @param [String] target
@@ -105,4 +111,4 @@ module Middleman
105
111
  end
106
112
  end
107
113
  end
108
- end
114
+ end
@@ -1,23 +1,23 @@
1
1
  module Middleman
2
2
 
3
3
  module Sitemap
4
-
4
+
5
5
  module Extensions
6
-
6
+
7
7
  module Traversal
8
8
  # This resource's parent resource
9
9
  # @return [Middleman::Sitemap::Resource, nil]
10
10
  def parent
11
11
  parts = path.split("/")
12
12
  parts.pop if path.include?(app.index_file)
13
-
13
+
14
14
  return nil if parts.length < 1
15
-
15
+
16
16
  parts.pop
17
17
  parts << app.index_file
18
-
18
+
19
19
  parent_path = "/" + parts.join("/")
20
-
20
+
21
21
  store.find_resource_by_destination_path(parent_path)
22
22
  end
23
23
 
@@ -57,13 +57,13 @@ module Middleman
57
57
  return [] unless parent
58
58
  parent.children.reject { |p| p == self }
59
59
  end
60
-
60
+
61
61
  # Whether this resource either a directory index, or has the same name as an existing directory in the source
62
62
  # @return [Boolean]
63
63
  def directory_index?
64
64
  path.include?(app.index_file) || path =~ /\/$/ || eponymous_directory?
65
65
  end
66
-
66
+
67
67
  # Whether the resource has the same name as a directory in the source
68
68
  # (e.g., if the resource is named 'gallery.html' and a path exists named 'gallery/', this would return true)
69
69
  # @return [Boolean]
@@ -71,7 +71,7 @@ module Middleman
71
71
  full_path = File.join(app.source_dir, eponymous_directory_path)
72
72
  !!(File.exists?(full_path) && File.directory?(full_path))
73
73
  end
74
-
74
+
75
75
  # The path for this resource if it were a directory, and not a file
76
76
  # (e.g., for 'gallery.html' this would return 'gallery/')
77
77
  # @return [String]
@@ -81,4 +81,4 @@ module Middleman
81
81
  end
82
82
  end
83
83
  end
84
- end
84
+ end