middleman-core 4.0.0.alpha.2 → 4.0.0.alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/features/asset_hash.feature +26 -8
  3. data/features/chained_templates.feature +88 -1
  4. data/features/cli_init.feature +0 -18
  5. data/features/collections.feature +145 -0
  6. data/features/console.feature +11 -0
  7. data/features/front-matter.feature +11 -0
  8. data/features/paginate.feature +204 -0
  9. data/features/partials.feature +0 -5
  10. data/features/slim.feature +1 -1
  11. data/features/working_directory.feature +33 -0
  12. data/fixtures/asset-hash-app/source/api.json.erb +1 -0
  13. data/fixtures/asset-hash-app/source/images/200px.jpg +0 -0
  14. data/fixtures/asset-hash-app/source/images/300px.jpg +0 -0
  15. data/fixtures/asset-hash-app/source/index.html.erb +1 -1
  16. data/fixtures/asset-hash-app/source/subdir/api.json.erb +1 -0
  17. data/fixtures/collections-app/config.rb +16 -0
  18. data/fixtures/collections-app/source/blog1/2011-01-01-new-article.html.markdown +7 -0
  19. data/fixtures/collections-app/source/blog1/2011-01-02-another-article.html.markdown +9 -0
  20. data/fixtures/collections-app/source/blog2/2011-01-01-new-article.html.markdown +7 -0
  21. data/fixtures/collections-app/source/blog2/2011-01-02-another-article.html.markdown +8 -0
  22. data/fixtures/collections-app/source/index.html.erb +26 -0
  23. data/fixtures/frontmatter-app/source/front-matter-pandoc.html.md.erb +13 -0
  24. data/fixtures/generator-test/config.rb +2 -7
  25. data/fixtures/multiple-data-sources-app/source/index.html.erb +0 -5
  26. data/fixtures/{more-instance-vars-app → paginate-app}/config.rb +0 -0
  27. data/fixtures/paginate-app/source/archive/2011/index.html.erb +20 -0
  28. data/fixtures/paginate-app/source/blog/2011-01-01-test-article.html.markdown +6 -0
  29. data/fixtures/paginate-app/source/blog/2011-01-02-test-article.html.markdown +6 -0
  30. data/fixtures/paginate-app/source/blog/2011-01-03-test-article.html.markdown +6 -0
  31. data/fixtures/paginate-app/source/blog/2011-01-04-test-article.html.markdown +6 -0
  32. data/fixtures/paginate-app/source/blog/2011-01-05-test-article.html.markdown +6 -0
  33. data/fixtures/paginate-app/source/blog/2011-02-01-test-article.html.markdown +6 -0
  34. data/fixtures/paginate-app/source/blog/2011-02-02-test-article.html.markdown +6 -0
  35. data/fixtures/paginate-app/source/index.html.erb +15 -0
  36. data/fixtures/paginate-app/source/tag.html.erb +23 -0
  37. data/fixtures/partial-chained_templates-app/config.rb +0 -0
  38. data/lib/middleman-core/application.rb +28 -1
  39. data/lib/middleman-core/builder.rb +2 -0
  40. data/lib/middleman-core/contracts.rb +19 -1
  41. data/lib/middleman-core/core_extensions.rb +5 -0
  42. data/lib/middleman-core/core_extensions/collections.rb +82 -0
  43. data/lib/middleman-core/core_extensions/collections/lazy_root.rb +30 -0
  44. data/lib/middleman-core/core_extensions/collections/lazy_step.rb +48 -0
  45. data/lib/middleman-core/core_extensions/collections/pagination.rb +59 -0
  46. data/lib/middleman-core/core_extensions/collections/step_context.rb +26 -0
  47. data/lib/middleman-core/core_extensions/data.rb +1 -1
  48. data/lib/middleman-core/core_extensions/default_helpers.rb +1 -2
  49. data/lib/middleman-core/core_extensions/front_matter.rb +10 -3
  50. data/lib/middleman-core/core_extensions/i18n.rb +6 -7
  51. data/lib/middleman-core/core_extensions/show_exceptions.rb +1 -1
  52. data/lib/middleman-core/extension.rb +1 -1
  53. data/lib/middleman-core/extensions/automatic_image_sizes.rb +0 -2
  54. data/lib/middleman-core/file_renderer.rb +3 -1
  55. data/lib/middleman-core/load_paths.rb +2 -1
  56. data/lib/middleman-core/logger.rb +1 -1
  57. data/lib/middleman-core/meta_pages/sitemap_resource.rb +1 -1
  58. data/lib/middleman-core/preview_server.rb +1 -1
  59. data/lib/middleman-core/renderers/sass.rb +1 -1
  60. data/lib/middleman-core/renderers/slim.rb +2 -2
  61. data/lib/middleman-core/sitemap/extensions/on_disk.rb +1 -1
  62. data/lib/middleman-core/sitemap/extensions/proxies.rb +36 -50
  63. data/lib/middleman-core/sitemap/resource.rb +42 -3
  64. data/lib/middleman-core/sitemap/store.rb +5 -0
  65. data/lib/middleman-core/sources.rb +64 -24
  66. data/lib/middleman-core/sources/source_watcher.rb +47 -23
  67. data/lib/middleman-core/step_definitions/server_steps.rb +52 -21
  68. data/lib/middleman-core/template_context.rb +26 -5
  69. data/lib/middleman-core/template_renderer.rb +50 -33
  70. data/lib/middleman-core/util.rb +94 -1
  71. data/lib/middleman-core/util/hash_with_indifferent_access.rb +1 -1
  72. data/lib/middleman-core/version.rb +1 -1
  73. data/middleman-core.gemspec +2 -0
  74. metadata +90 -15
  75. data/features/more-instance_vars.feature +0 -18
  76. data/fixtures/more-instance-vars-app/source/_vartial.erb +0 -5
  77. data/fixtures/more-instance-vars-app/source/instance-var-set.html.erb +0 -2
  78. data/fixtures/more-instance-vars-app/source/layout.erb +0 -3
  79. data/fixtures/more-instance-vars-app/source/no-instance-var.html.erb +0 -1
@@ -11,11 +11,6 @@ Feature: Provide Sane Defaults for Partial Behavior
11
11
  When I go to "/sub/index.html"
12
12
  Then I should see "Header"
13
13
  And I should see "Footer"
14
-
15
- Scenario: Finds shared partials without _ prefix
16
- Given the Server is running at "partials-app"
17
- When I go to "/using_snippet.html"
18
- Then I should see "Snippet"
19
14
 
20
15
  Scenario: Prefers partials of the same engine type
21
16
  Given the Server is running at "partials-app"
@@ -78,4 +78,4 @@ Feature: Support slim templating language
78
78
  When I go to "/sass.html"
79
79
  Then I should see "html,body,div"
80
80
  When I go to "/error.html"
81
- Then I should see "Syntax error"
81
+ Then I should see "Error: Invalid"
@@ -0,0 +1,33 @@
1
+ Feature: Honour working directory
2
+ Honour the working directory during testing
3
+ In order to support helpers which work with the current directories
4
+
5
+ Scenario: Set working directory for helpers in tests
6
+ Given a fixture app "empty-app"
7
+ And a file named "source/index.html.erb" with:
8
+ """
9
+ <%= Dir.getwd %>
10
+ """
11
+ And the Server is running
12
+ When I go to "/index.html"
13
+ Then I should see:
14
+ """
15
+ aruba
16
+ """
17
+
18
+ Scenario: Set working directory for config.rb in tests
19
+ Given a fixture app "empty-app"
20
+ And a file named "config.rb" with:
21
+ """
22
+ set :my_working_directory, Dir.getwd
23
+ """
24
+ And a file named "source/index.html.erb" with:
25
+ """
26
+ <%= config[:my_working_directory] %>
27
+ """
28
+ And the Server is running
29
+ When I go to "/index.html"
30
+ Then I should see:
31
+ """
32
+ aruba
33
+ """
@@ -0,0 +1 @@
1
+ <%= {gif: image_path('100px.gif'), jpg: image_path('100px.jpg'), png: image_path('100px.png')}.to_json %>
@@ -3,7 +3,7 @@
3
3
  <% end %>
4
4
 
5
5
  <h2>Image url:</h2>
6
- <img src="<%= image_path('100px.jpg') %>">
6
+ <img src="<%= image_path('100px.jpg') %>" srcset="<%= image_path('100px.jpg') %> 1x, <%= image_path('200px.jpg') %> 2x, <%= image_path('300px.jpg') %> 3x">
7
7
 
8
8
  <h2>Ignored path:</h2>
9
9
  <link rel="apple-touch-icon" href="apple-touch-icon.png">
@@ -0,0 +1 @@
1
+ <%= {gif: image_path('100px.gif'), jpg: image_path('100px.jpg'), png: image_path('100px.png')}.to_json %>
@@ -0,0 +1,16 @@
1
+ collection :articles,
2
+ where: proc { |resource|
3
+ uri_match resource.url, 'blog/{year}-{month}-{day}-{title}.html'
4
+ }
5
+
6
+ collection :tags,
7
+ where: proc { |resource|
8
+ resource.data.tags
9
+ },
10
+ group_by: proc { |resource|
11
+ if resource.data.tags.is_a? String
12
+ resource.data.tags.split(',').map(&:strip)
13
+ else
14
+ resource.data.tags
15
+ end
16
+ }
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: "Blog1 Newer Article"
3
+ date: 2011-01-01
4
+ tags: foo, bar
5
+ ---
6
+
7
+ Newer Article Content
@@ -0,0 +1,9 @@
1
+ ---
2
+ title: "Blog1 Another Article"
3
+ date: 2011-01-02
4
+ tags:
5
+ - foo
6
+ - 120
7
+ ---
8
+
9
+ Another Article Content
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: "Blog2 Newer Article"
3
+ date: 2011-01-01
4
+ tags: foo, bar
5
+ ---
6
+
7
+ Newer Article Content
@@ -0,0 +1,8 @@
1
+ ---
2
+ title: "Blog2 Another Article"
3
+ date: 2011-01-02
4
+ tags:
5
+ - foo
6
+ ---
7
+
8
+ Another Article Content
@@ -0,0 +1,26 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ </head>
5
+ <body>
6
+
7
+ <!-- ARTICLES -->
8
+ <% collected.articles.each do |article| %>
9
+ <li>
10
+ <a href="<%= article.url %>">Article: <%= article.data.title %></a>
11
+ <time><%= article.data.date.strftime('%b %e') %></time>
12
+ </li>
13
+ <% end %>
14
+
15
+ <!-- TAGS -->
16
+ <% collected[:tags].each do |k, items| %>
17
+ <li>
18
+ <%= k %>
19
+ <% items.each do |article| %>
20
+ <%= article.data.title %>
21
+ <% end %>
22
+ </li>
23
+ <% end %>
24
+
25
+ </body>
26
+ </html>
@@ -0,0 +1,13 @@
1
+ ---
2
+ layout: false
3
+ title: Pandoc likes trailing dots...
4
+ dotty_string: "..."
5
+ famous_quote: To be or not to be
6
+ popular_number: 42
7
+ ...
8
+
9
+ # This is a document
10
+
11
+ <%= current_page.data.famous_quote %>
12
+
13
+ The meaning of life is <%= current_page.data.popular_number %>.
@@ -51,12 +51,12 @@
51
51
  # Change the images directory
52
52
  # set :images_dir, "alternative_image_directory"
53
53
 
54
- # Production build configuration
54
+ # Production configuration
55
55
  configure :production do
56
56
  # For example, change the Compass output style for deployment
57
57
  # activate :minify_css
58
58
 
59
- # Minify Javascript on build
59
+ # Minify Javascript
60
60
  # activate :minify_javascript
61
61
 
62
62
  # Enable cache buster
@@ -65,11 +65,6 @@ configure :production do
65
65
  # Use relative URLs
66
66
  # activate :relative_assets
67
67
 
68
- # Compress PNGs after build
69
- # First: gem install middleman-smusher
70
- # require "middleman-smusher"
71
- # activate :smusher
72
-
73
68
  # Or use a different image path
74
69
  # set :http_prefix, "/Content/images/"
75
70
  end
@@ -1,10 +1,5 @@
1
1
  Default: <%= data.data.title %>
2
2
  Data 1: <%= data.data1.title %>
3
3
  Data 2: <%= data.data2.title %>
4
- <<<<<<< HEAD
5
4
  Override in Two: <%= data.two.title %>
6
5
  Override in One: <%= data.one.title %>
7
- =======
8
- Override in One: <%= data.one.title %>
9
- Override in Two: <%= data.two.title %>
10
- >>>>>>> Add external command support
@@ -0,0 +1,20 @@
1
+ Year: '<%#= year %>'
2
+
3
+ Paginate: <%= !!pagination %>
4
+ Article Count: <%= items.length %>
5
+ <% if pagination %>
6
+ Page Num: <%= pagination.page_number %>
7
+ Num Pages: <%= pagination.num_pages %>
8
+ Per Page: <%= pagination.per_page %>
9
+ Page Start: <%= pagination.page_start %>
10
+ Page End: <%= pagination.page_end %>
11
+ Next Page: '<%= sitemap.find_resource_by_destination_path(next_page).url if next_page %>'
12
+ Prev Page: '<%= sitemap.find_resource_by_destination_path(prev_page).url if prev_page %>'
13
+ <% end %>
14
+
15
+ <% items.each do |article| %>
16
+ <article>
17
+ <%= article.data.title %>
18
+ <%= article.url %>
19
+ </article>
20
+ <% end %>
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "Test Article"
3
+ date: 2011-01-01
4
+ tags: foo
5
+ ---
6
+ Test Article Content
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "Test Article"
3
+ date: 2011-01-02
4
+ tags: foo
5
+ ---
6
+ Test Article Content
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "Test Article"
3
+ date: 2011-01-03
4
+ tags: bar
5
+ ---
6
+ Test Article Content
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "Test Article"
3
+ date: 2011-01-04
4
+ tags: bar
5
+ ---
6
+ Test Article Content
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "Test Article"
3
+ date: 2011-01-05
4
+ tags: bar
5
+ ---
6
+ Test Article Content
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "Test Article"
3
+ date: 2011-02-01
4
+ tags: bar
5
+ ---
6
+ Test Article Content
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: "Test Article"
3
+ date: 2011-02-02
4
+ tags: bar
5
+ ---
6
+ Test Article Content
@@ -0,0 +1,15 @@
1
+ Paginate: <%= paginate %>
2
+ Article Count: <%= page_articles.size %>
3
+ <% if paginate %>
4
+ Page Num: <%= page_number %>
5
+ Num Pages: <%= num_pages %>
6
+ Per Page: <%= per_page %>
7
+ Page Start: <%= page_start %>
8
+ Page End: <%= page_end %>
9
+ Next Page: '<%= next_page.url if next_page %>'
10
+ Prev Page: '<%= prev_page.url if prev_page %>'
11
+ <% end %>
12
+
13
+ <% page_articles.each do |article| %>
14
+ <li><a href="<%= article.url %>"><%= article.title %></a> <time><%= article.date.strftime('%b %e') %></time></li>
15
+ <% end %>
@@ -0,0 +1,23 @@
1
+ ---
2
+ pageable: true
3
+ per_page: 2
4
+ ---
5
+ Tag: <%= tagname %>
6
+
7
+ Paginate: <%= paginate %>
8
+ Article Count: <%= page_articles.size %>
9
+ <% if paginate %>
10
+ Page Num: <%= page_number %>
11
+ Num Pages: <%= num_pages %>
12
+ Per Page: <%= per_page %>
13
+ Page Start: <%= page_start %>
14
+ Page End: <%= page_end %>
15
+ Next Page: '<%= next_page.url if next_page %>'
16
+ Prev Page: '<%= prev_page.url if prev_page %>'
17
+ <% end %>
18
+
19
+ <% if page_articles %>
20
+ <% page_articles.each do |article| %>
21
+ <li><a href="<%= article.url %>"><%= article.title %></a> <time><%= article.date.strftime('%b %e') %></time></li>
22
+ <% end %>
23
+ <% end %>
File without changes
@@ -163,7 +163,7 @@ module Middleman
163
163
 
164
164
  layout: proc { |file, _sitemap_app|
165
165
  file[:relative_path].to_s.start_with?('layout.') ||
166
- file[:relative_path].to_s.start_with?('layouts/')
166
+ file[:relative_path].to_s.start_with?('layouts/')
167
167
  }
168
168
  }, 'Callbacks that can exclude paths from the sitemap'
169
169
 
@@ -286,7 +286,11 @@ module Middleman
286
286
  config_context.instance_eval File.read(env_config), env_config, 1
287
287
  end
288
288
 
289
+ # Run any `configure` blocks for the current environment.
289
290
  config_context.execute_configure_callbacks(config[:environment])
291
+
292
+ # Run any `configure` blocks for the current mode.
293
+ config_context.execute_configure_callbacks(config[:mode])
290
294
  end
291
295
 
292
296
  def add_to_instance(name, &func)
@@ -315,6 +319,29 @@ module Middleman
315
319
  config[:environment] == key
316
320
  end
317
321
 
322
+ # Backwards compatible helper. What the current environment is.
323
+ # @return [Symbol]
324
+ def environment
325
+ config[:environment]
326
+ end
327
+
328
+ # Backwards compatible helper. Whether we're in dev mode.
329
+ # @return [Boolean]
330
+ def development?
331
+ environment?(:development)
332
+ end
333
+
334
+ # Backwards compatible helper. Whether we're in production mode.
335
+ # @return [Boolean]
336
+ def production?
337
+ environment?(:production)
338
+ end
339
+
340
+ # Backwards compatible helper. The full path to the default source dir.
341
+ def source_dir
342
+ Pathname(File.join(root, config[:source]))
343
+ end
344
+
318
345
  MiddlewareDescriptor = Struct.new(:class, :options, :block)
319
346
 
320
347
  # Use Rack middleware
@@ -50,7 +50,9 @@ module Middleman
50
50
 
51
51
  queue_current_paths if @cleaning
52
52
  prerender_css
53
+
53
54
  output_files
55
+
54
56
  clean if @cleaning
55
57
 
56
58
  ::Middleman::Profiling.report('build')
@@ -23,7 +23,7 @@ if ENV['TEST'] || ENV['CONTRACTS'] == 'true'
23
23
  end
24
24
 
25
25
  def valid?(val)
26
- (val.frozen? || val.nil?) && Contract.valid?(val, @contract)
26
+ (val.frozen? || val.nil? || [::TrueClass, ::FalseClass, ::Fixnum].include?(val.class)) && Contract.valid?(val, @contract)
27
27
  end
28
28
  end
29
29
 
@@ -59,6 +59,21 @@ if ENV['TEST'] || ENV['CONTRACTS'] == 'true'
59
59
  end
60
60
  end
61
61
 
62
+ # class MethodDefined
63
+ # def self.[](val)
64
+ # @lookup ||= {}
65
+ # @lookup[val] ||= new(val)
66
+ # end
67
+
68
+ # def initialize(val)
69
+ # @val = val
70
+ # end
71
+
72
+ # def valid?(val)
73
+ # val.method_defined? @val
74
+ # end
75
+ # end
76
+
62
77
  ResourceList = Contracts::ArrayOf[IsA['Middleman::Sitemap::Resource']]
63
78
  end
64
79
  else
@@ -141,6 +156,9 @@ else
141
156
 
142
157
  class Frozen < Callable
143
158
  end
159
+
160
+ # class MethodDefined < Callable
161
+ # end
144
162
  end
145
163
  end
146
164