middleman-core 3.0.14 → 3.1.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/features/clean_build.feature +4 -5
  2. data/features/content_type.feature +43 -0
  3. data/features/data.feature +9 -4
  4. data/features/front-matter-neighbor.feature +151 -0
  5. data/features/queryable.feature +31 -0
  6. data/features/step_definitions/queryable_steps.rb +123 -0
  7. data/fixtures/content-type-app/config.rb +1 -0
  8. data/fixtures/content-type-app/source/.htaccess +1 -0
  9. data/fixtures/content-type-app/source/README +1 -0
  10. data/fixtures/content-type-app/source/images/blank.gif +0 -0
  11. data/fixtures/content-type-app/source/index.html +1 -0
  12. data/fixtures/content-type-app/source/javascripts/app.js +1 -0
  13. data/fixtures/content-type-app/source/override.html +5 -0
  14. data/fixtures/content-type-app/source/stylesheets/site.css +1 -0
  15. data/fixtures/frontmatter-neighbor-app/config.rb +0 -0
  16. data/fixtures/frontmatter-neighbor-app/source/front-matter-2.php.erb +2 -0
  17. data/fixtures/frontmatter-neighbor-app/source/front-matter-2.php.erb.frontmatter +4 -0
  18. data/fixtures/frontmatter-neighbor-app/source/front-matter-auto.erb +1 -0
  19. data/fixtures/frontmatter-neighbor-app/source/front-matter-auto.erb.frontmatter +4 -0
  20. data/fixtures/frontmatter-neighbor-app/source/front-matter-change.html.erb +1 -0
  21. data/fixtures/frontmatter-neighbor-app/source/front-matter-change.html.erb.frontmatter +4 -0
  22. data/fixtures/frontmatter-neighbor-app/source/front-matter-encoding.html.erb +1 -0
  23. data/fixtures/frontmatter-neighbor-app/source/front-matter-encoding.html.erb.frontmatter +5 -0
  24. data/fixtures/frontmatter-neighbor-app/source/json-front-matter-2.php.erb +2 -0
  25. data/fixtures/frontmatter-neighbor-app/source/json-front-matter-2.php.erb.frontmatter +4 -0
  26. data/fixtures/frontmatter-neighbor-app/source/json-front-matter-auto.erb +1 -0
  27. data/fixtures/frontmatter-neighbor-app/source/json-front-matter-auto.erb.frontmatter +4 -0
  28. data/fixtures/frontmatter-neighbor-app/source/json-front-matter.html.erb +1 -0
  29. data/fixtures/frontmatter-neighbor-app/source/json-front-matter.html.erb.frontmatter +4 -0
  30. data/fixtures/frontmatter-neighbor-app/source/raw-front-matter.html +1 -0
  31. data/fixtures/frontmatter-neighbor-app/source/raw-front-matter.html.frontmatter +4 -0
  32. data/fixtures/frontmatter-neighbor-app/source/raw-front-matter.php +1 -0
  33. data/fixtures/frontmatter-neighbor-app/source/raw-front-matter.php.frontmatter +4 -0
  34. data/fixtures/frontmatter-settings-neighbor-app/config.rb +4 -0
  35. data/fixtures/frontmatter-settings-neighbor-app/source/alternate_layout.html.erb +1 -0
  36. data/fixtures/frontmatter-settings-neighbor-app/source/alternate_layout.html.erb.frontmatter +3 -0
  37. data/fixtures/frontmatter-settings-neighbor-app/source/ignored.html.erb +1 -0
  38. data/fixtures/frontmatter-settings-neighbor-app/source/ignored.html.erb.frontmatter +3 -0
  39. data/fixtures/frontmatter-settings-neighbor-app/source/layouts/alternate.erb +3 -0
  40. data/fixtures/frontmatter-settings-neighbor-app/source/layouts/override.erb +2 -0
  41. data/fixtures/frontmatter-settings-neighbor-app/source/override_layout.html.erb +1 -0
  42. data/fixtures/frontmatter-settings-neighbor-app/source/override_layout.html.erb.frontmatter +3 -0
  43. data/fixtures/frontmatter-settings-neighbor-app/source/page_mentioned.html.erb +1 -0
  44. data/fixtures/frontmatter-settings-neighbor-app/source/page_mentioned.html.erb.frontmatter +3 -0
  45. data/fixtures/nested-data-app/config.rb +1 -0
  46. data/fixtures/nested-data-app/data/examples/test.yml +1 -0
  47. data/fixtures/nested-data-app/source/test.html.erb +1 -0
  48. data/fixtures/queryable-app/config.rb +0 -0
  49. data/fixtures/queryable-app/source/2010-08-08-test-document-file.html.markdown +8 -0
  50. data/fixtures/queryable-app/source/2010-08-09-another-test-document.html.markdown +10 -0
  51. data/fixtures/queryable-app/source/2011-12-26-some-test-document.html.markdown +6 -0
  52. data/fixtures/queryable-app/source/document_with_date_in_yaml.html.markdown +7 -0
  53. data/fixtures/queryable-app/source/document_without_date.html.markdown +7 -0
  54. data/lib/middleman-core/application.rb +52 -84
  55. data/lib/middleman-core/cli.rb +3 -2
  56. data/lib/middleman-core/cli/build.rb +5 -7
  57. data/lib/middleman-core/cli/bundler.rb +1 -1
  58. data/lib/middleman-core/cli/console.rb +46 -0
  59. data/lib/middleman-core/configuration.rb +235 -0
  60. data/lib/middleman-core/core_extensions.rb +0 -6
  61. data/lib/middleman-core/core_extensions/data.rb +34 -11
  62. data/lib/middleman-core/core_extensions/extensions.rb +31 -35
  63. data/lib/middleman-core/core_extensions/external_helpers.rb +7 -7
  64. data/lib/middleman-core/core_extensions/file_watcher.rb +1 -1
  65. data/lib/middleman-core/core_extensions/front_matter.rb +44 -38
  66. data/lib/middleman-core/core_extensions/rendering.rb +27 -21
  67. data/lib/middleman-core/core_extensions/request.rb +41 -73
  68. data/lib/middleman-core/core_extensions/routing.rb +7 -24
  69. data/lib/middleman-core/core_extensions/show_exceptions.rb +6 -8
  70. data/lib/middleman-core/extensions.rb +35 -0
  71. data/lib/middleman-core/logger.rb +9 -0
  72. data/lib/middleman-core/meta_pages.rb +93 -0
  73. data/lib/middleman-core/meta_pages/assets/config.css +36 -0
  74. data/lib/middleman-core/meta_pages/assets/glyphicons-halflings.png +0 -0
  75. data/lib/middleman-core/meta_pages/assets/jquery-1.8.2.min.js +2 -0
  76. data/lib/middleman-core/meta_pages/assets/jquery.details-1.6.min.js +6 -0
  77. data/lib/middleman-core/meta_pages/assets/meta.css +368 -0
  78. data/lib/middleman-core/meta_pages/assets/sitemap.css +635 -0
  79. data/lib/middleman-core/meta_pages/assets/sitemap.js +0 -0
  80. data/lib/middleman-core/meta_pages/config_setting.rb +39 -0
  81. data/lib/middleman-core/meta_pages/sitemap_resource.rb +52 -0
  82. data/lib/middleman-core/meta_pages/sitemap_tree.rb +73 -0
  83. data/lib/middleman-core/meta_pages/templates/config.html.erb +59 -0
  84. data/lib/middleman-core/meta_pages/templates/index.html.erb +21 -0
  85. data/lib/middleman-core/meta_pages/templates/sitemap.html.erb +31 -0
  86. data/lib/middleman-core/preview_server.rb +18 -7
  87. data/lib/middleman-core/profiling.rb +1 -1
  88. data/lib/middleman-core/renderers/erb.rb +5 -5
  89. data/lib/middleman-core/renderers/less.rb +3 -3
  90. data/lib/middleman-core/renderers/markdown.rb +10 -9
  91. data/lib/middleman-core/renderers/redcarpet.rb +16 -21
  92. data/lib/middleman-core/renderers/sass.rb +4 -5
  93. data/lib/middleman-core/renderers/slim.rb +4 -1
  94. data/lib/middleman-core/sitemap.rb +3 -3
  95. data/lib/middleman-core/sitemap/extensions/content_type.rb +16 -0
  96. data/lib/middleman-core/sitemap/extensions/on_disk.rb +2 -2
  97. data/lib/middleman-core/sitemap/extensions/proxies.rb +26 -16
  98. data/lib/middleman-core/sitemap/queryable.rb +148 -0
  99. data/lib/middleman-core/sitemap/resource.rb +14 -2
  100. data/lib/middleman-core/sitemap/store.rb +8 -7
  101. data/lib/middleman-core/step_definitions/builder_steps.rb +3 -0
  102. data/lib/middleman-core/step_definitions/server_steps.rb +6 -1
  103. data/lib/middleman-core/templates/default/source/layouts/layout.erb +1 -1
  104. data/lib/middleman-core/templates/extension/lib/lib.rb +17 -26
  105. data/lib/middleman-core/templates/html5/source/layouts/layout.erb +1 -1
  106. data/lib/middleman-core/templates/shared/Gemfile.tt +6 -1
  107. data/lib/middleman-core/util.rb +7 -5
  108. data/lib/middleman-core/version.rb +1 -1
  109. data/middleman-core.gemspec +1 -1
  110. metadata +126 -28
  111. data/lib/middleman-core/core_extensions/builder.rb +0 -17
  112. data/lib/middleman-core/core_extensions/ruby_encoding.rb +0 -25
  113. data/middleman-core-x86-mingw32.gemspec +0 -38
@@ -0,0 +1,4 @@
1
+ ---
2
+ layout: false
3
+ title: This is the title
4
+ ---
@@ -0,0 +1 @@
1
+ <h1><%= data.page.title %></h1>
@@ -0,0 +1,4 @@
1
+ ---
2
+ layout: false
3
+ title: This is the title
4
+ ---
@@ -0,0 +1 @@
1
+ <%= data.page.title %>
@@ -0,0 +1,4 @@
1
+ ---
2
+ title: Hola Mundo
3
+ layout: false
4
+ ---
@@ -0,0 +1 @@
1
+ <h1><%= data.page.title %></h1>
@@ -0,0 +1,5 @@
1
+ # encoding: UTF-8
2
+ ---
3
+ layout: false
4
+ title: This is the title
5
+ ---
@@ -0,0 +1,2 @@
1
+ <h1><%= data.page.title %></h1>
2
+ <?php echo "sup"; ?>
@@ -0,0 +1,4 @@
1
+ ;;;
2
+ "layout": false,
3
+ "title": "This is the title"
4
+ ;;;
@@ -0,0 +1 @@
1
+ <h1><%= data.page.title %></h1>
@@ -0,0 +1,4 @@
1
+ ;;;
2
+ "layout": false,
3
+ "title": "This is the title"
4
+ ;;;
@@ -0,0 +1 @@
1
+ <h1><%= data.page.title %></h1>
@@ -0,0 +1,4 @@
1
+ ;;;
2
+ "layout": false,
3
+ "title": "This is the title"
4
+ ;;;
@@ -0,0 +1 @@
1
+ <h1><%= data.page.title %></h1>
@@ -0,0 +1,4 @@
1
+ ---
2
+ layout: false
3
+ title: This is the title
4
+ ---
@@ -0,0 +1 @@
1
+ <?php echo "sup"; ?>
@@ -0,0 +1,4 @@
1
+ ---
2
+ layout: false
3
+ title: This is the title
4
+ ---
@@ -0,0 +1,4 @@
1
+ # Proxy ignored.html, which should ignore itself through a frontmatter
2
+ page 'proxied.html', :proxy => 'ignored.html'
3
+ page 'override_layout.html', :layout => :alternate
4
+ page 'page_mentioned.html'
@@ -0,0 +1 @@
1
+ This uses an alternate layout
@@ -0,0 +1 @@
1
+ This file ignores itself! But it can still be proxied.
@@ -0,0 +1,3 @@
1
+ Alternate layout!
2
+
3
+ <%= yield %>
@@ -0,0 +1,2 @@
1
+ <%= yield %>
2
+ Override.
@@ -0,0 +1 @@
1
+ set :layout, false
@@ -0,0 +1 @@
1
+ title: "Hello"
@@ -0,0 +1 @@
1
+ <%= data.examples.map { |k, r| [k, r.title].join(":") }.join %>
File without changes
@@ -0,0 +1,8 @@
1
+ ---
2
+ id: 1
3
+ title: Some fancy title
4
+ tags: [ruby]
5
+ status: :published
6
+ ---
7
+
8
+ I like being the demo text.
@@ -0,0 +1,10 @@
1
+ ---
2
+ id: 2
3
+ title: Another title, that's for sure
4
+ tags: [ruby, rails]
5
+ special_attribute: Yes!
6
+ friends: [Anton, Paul]
7
+ status: :published
8
+ ---
9
+
10
+ The body copy.
@@ -0,0 +1,6 @@
1
+ ---
2
+ id: 5
3
+ title: Some test document
4
+ ---
5
+
6
+ This is just some test document.
@@ -0,0 +1,7 @@
1
+ ---
2
+ id: 3
3
+ title: Document with date in YAML
4
+ date: 2011-04-05
5
+ ---
6
+
7
+ This document has no date in the filename, but in the YAML front matter.
@@ -0,0 +1,7 @@
1
+ ---
2
+ id: 4
3
+ title: This document has no date
4
+ seldom_attribute: is seldom
5
+ ---
6
+
7
+ This document has no date at all.
@@ -12,10 +12,14 @@ require "middleman-core/vendor/hooks-0.2.0/lib/hooks"
12
12
  require "middleman-core/sitemap"
13
13
 
14
14
  require "middleman-core/core_extensions"
15
+ require "middleman-core/configuration"
15
16
 
16
17
  # Core Middleman Class
17
18
  module Middleman
18
19
  class Application
20
+ # Global configuration
21
+ include Configuration::Global
22
+
19
23
  # Uses callbacks
20
24
  include Hooks
21
25
 
@@ -25,131 +29,96 @@ module Middleman
25
29
  # Ready (all loading and parsing of extensions complete) hook
26
30
  define_hook :ready
27
31
 
28
- class << self
29
-
30
- # Mix-in helper methods. Accepts either a list of Modules
31
- # and/or a block to be evaluated
32
- # @return [void]
33
- def helpers(*extensions, &block)
34
- class_eval(&block) if block_given?
35
- include(*extensions) if extensions.any?
36
- end
37
-
38
- # Access class-wide defaults
39
- #
40
- # @private
41
- # @return [Hash] Hash of default values
42
- def defaults
43
- @defaults ||= {}
44
- end
45
-
46
- # Set class-wide defaults
47
- #
48
- # @param [Symbol] key Unique key name
49
- # @param value Default value
50
- # @return [void]
51
- def set(key, value=nil, &block)
52
- @defaults ||= {}
53
- @defaults[key] = value
54
-
55
- @inst.set(key, value, &block) if @inst
56
- end
57
- end
58
-
59
- delegate :helpers, :to => :"self.class"
32
+ # Runs after the build is finished
33
+ define_hook :after_build
60
34
 
61
- # Set attributes (global variables)
62
- #
63
- # @param [Symbol] key Name of the attribue
64
- # @param value Attribute value
35
+ # Mix-in helper methods. Accepts either a list of Modules
36
+ # and/or a block to be evaluated
65
37
  # @return [void]
66
- def set(key, value=nil, &block)
67
- setter = "#{key}=".to_sym
68
- self.class.send(:attr_accessor, key) if !respond_to?(setter)
69
- value = block if block_given?
70
- send(setter, value)
38
+ def self.helpers(*extensions, &block)
39
+ class_eval(&block) if block_given?
40
+ include(*extensions) if extensions.any?
71
41
  end
42
+ delegate :helpers, :to => :"self.class"
72
43
 
73
44
  # Root project directory (overwritten in middleman build/server)
74
45
  # @return [String]
75
- set :root, ENV["MM_ROOT"] || Dir.pwd
46
+ def self.root
47
+ ENV["MM_ROOT"] || Dir.pwd
48
+ end
49
+ delegate :root, :to => :"self.class"
76
50
 
77
51
  # Pathname-addressed root
78
- def root_path
79
- @_root_path ||= Pathname.new(root)
52
+ def self.root_path
53
+ Pathname(root)
80
54
  end
55
+ delegate :root_path, :to => :"self.class"
81
56
 
82
57
  # Name of the source directory
83
58
  # @return [String]
84
- set :source, "source"
59
+ config.define_setting :source, "source", 'Name of the source directory'
85
60
 
86
61
  # Middleman environment. Defaults to :development, set to :build by the build process
87
62
  # @return [String]
88
- set :environment, (ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development
63
+ config.define_setting :environment, ((ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :development), 'Middleman environment. Defaults to :development, set to :build by the build process'
89
64
 
90
65
  # Which file should be used for directory indexes
91
66
  # @return [String]
92
- set :index_file, "index.html"
67
+ config.define_setting :index_file, "index.html", 'Which file should be used for directory indexes'
93
68
 
94
69
  # Whether to strip the index file name off links to directory indexes
95
70
  # @return [Boolean]
96
- set :strip_index_file, true
71
+ config.define_setting :strip_index_file, true, 'Whether to strip the index file name off links to directory indexes'
97
72
 
98
73
  # Whether to include a trailing slash when stripping the index file
99
74
  # @return [Boolean]
100
- set :trailing_slash, true
75
+ config.define_setting :trailing_slash, true, 'Whether to include a trailing slash when stripping the index file'
101
76
 
102
77
  # Location of javascripts within source.
103
78
  # @return [String]
104
- set :js_dir, "javascripts"
79
+ config.define_setting :js_dir, "javascripts", 'Location of javascripts within source'
105
80
 
106
81
  # Location of stylesheets within source. Used by Compass.
107
82
  # @return [String]
108
- set :css_dir, "stylesheets"
83
+ config.define_setting :css_dir, "stylesheets", 'Location of stylesheets within source'
109
84
 
110
85
  # Location of images within source. Used by HTML helpers and Compass.
111
86
  # @return [String]
112
- set :images_dir, "images"
87
+ config.define_setting :images_dir, "images", 'Location of images within source'
113
88
 
114
89
  # Location of fonts within source. Used by Compass.
115
90
  # @return [String]
116
- set :fonts_dir, "fonts"
91
+ config.define_setting :fonts_dir, "fonts", 'Location of fonts within source'
117
92
 
118
- # Where to build output files
93
+ # Location of partials within source. Used by renderers.
119
94
  # @return [String]
120
- set :build_dir, "build"
95
+ config.define_setting :partials_dir, "", 'Location of partials within source'
121
96
 
122
- # Default prefix for building paths. Used by HTML helpers and Compass.
97
+ # Where to build output files
123
98
  # @return [String]
124
- set :http_prefix, "/"
99
+ config.define_setting :build_dir, "build", 'Where to build output files'
125
100
 
126
- # Default string encoding for templates and output.
101
+ # Default prefix for building paths. Used by HTML helpers and Compass.
127
102
  # @return [String]
128
- set :encoding, "utf-8"
129
-
130
- # Whether to catch and display exceptions
131
- # @return [Boolean]
132
- set :show_exceptions, true
103
+ config.define_setting :http_prefix, "/", 'Default prefix for building paths'
133
104
 
134
105
  # Default layout name
135
106
  # @return [String, Symbold]
136
- set :layout, :_auto_layout
107
+ config.define_setting :layout, :_auto_layout, 'Default layout name'
108
+
109
+ # Default string encoding for templates and output.
110
+ # @return [String]
111
+ config.define_setting :encoding, "utf-8", 'Default string encoding for templates and output'
137
112
 
138
113
  # Activate custom features and extensions
139
114
  include Middleman::CoreExtensions::Extensions
140
115
 
141
- # Manage Ruby string encodings
142
- include Middleman::CoreExtensions::RubyEncoding
143
-
144
116
  # Basic Rack Request Handling
145
117
  register Middleman::CoreExtensions::Request
146
118
 
147
119
  # Handle exceptions
148
120
  register Middleman::CoreExtensions::ShowExceptions
149
121
 
150
- # Add Builder Callbacks
151
- register Middleman::CoreExtensions::Builder
152
-
153
122
  # Add Watcher Callbacks
154
123
  register Middleman::CoreExtensions::FileWatcher
155
124
 
@@ -170,7 +139,7 @@ module Middleman
170
139
  register Middleman::CoreExtensions::ExternalHelpers
171
140
 
172
141
  # with_layout and page routing
173
- register Middleman::CoreExtensions::Routing
142
+ include Middleman::CoreExtensions::Routing
174
143
 
175
144
  # Initialize the Middleman project
176
145
  def initialize(&block)
@@ -178,12 +147,17 @@ module Middleman
178
147
  cache.clear
179
148
 
180
149
  # Setup the default values from calls to set before initialization
181
- self.class.superclass.defaults.each { |k,v| set(k,v) }
150
+ self.class.config.load_settings(self.class.superclass.config.all_settings)
151
+
152
+ if Object.const_defined?(:Encoding)
153
+ Encoding.default_internal = config[:encoding]
154
+ Encoding.default_external = config[:encoding]
155
+ end
182
156
 
183
157
  # Evaluate a passed block if given
184
158
  instance_exec(&block) if block_given?
185
159
 
186
- set :source, ENV["MM_SOURCE"] if ENV["MM_SOURCE"]
160
+ config[:source] = ENV["MM_SOURCE"] if ENV["MM_SOURCE"]
187
161
 
188
162
  super
189
163
  end
@@ -199,24 +173,17 @@ module Middleman
199
173
 
200
174
  # Whether we're in development mode
201
175
  # @return [Boolean] If we're in dev mode
202
- def development?; environment == :development; end
176
+ def development?; config[:environment] == :development; end
203
177
 
204
178
  # Whether we're in build mode
205
179
  # @return [Boolean] If we're in build mode
206
- def build?; environment == :build; end
207
-
208
- # Backwards compatibilty with old Sinatra template interface
209
- #
210
- # @return [Middleman::Application]
211
- def settings
212
- self
213
- end
180
+ def build?; config[:environment] == :build; end
214
181
 
215
182
  # The full path to the source directory
216
183
  #
217
184
  # @return [String]
218
185
  def source_dir
219
- File.join(root, source)
186
+ File.join(root, config[:source])
220
187
  end
221
188
 
222
189
  delegate :logger, :instrument, :to => ::Middleman::Util
@@ -228,6 +195,7 @@ module Middleman
228
195
  def to_s
229
196
  "#<Middleman::Application:0x#{object_id}>"
230
197
  end
198
+ alias :inspect :to_s # Ruby 2.0 calls inspect for NoMethodError instead of to_s
231
199
 
232
200
  # Expand a path to include the index file if it's a directory
233
201
  #
@@ -239,7 +207,7 @@ module Middleman
239
207
 
240
208
  if !resource
241
209
  # Try it with /index.html at the end
242
- indexed_path = File.join(path.sub(%r{/$}, ''), index_file)
210
+ indexed_path = File.join(path.sub(%r{/$}, ''), config[:index_file])
243
211
  resource = sitemap.find_resource_by_destination_path(indexed_path)
244
212
  end
245
213