Expand collection laziness to data

This commit is contained in:
Thomas Reynolds 2015-04-26 13:22:58 -07:00
parent b127283040
commit 33cb9b3ba9
6 changed files with 62 additions and 6 deletions

View file

@ -143,3 +143,53 @@ Feature: Collections
When I go to "index.html"
And I should see 'Article: Blog3 Another Article'
And I should see 'Article: Blog2 Yet Another Article'
Scenario: Collected data update with file changes
Given a fixture app "collections-app"
And a file named "config.rb" with:
"""
data.articles.each_with_index do |a, i|
proxy "/#{i}.html", a
end
"""
And a file named "data/articles.yaml" with:
"""
---
- "/blog1/2011-01-01-new-article.html"
- "/blog2/2011-01-02-another-article.html"
"""
Given the Server is running at "collections-app"
When I go to "0.html"
Then I should see 'Newer Article Content'
When I go to "1.html"
Then I should see 'Another Article Content'
When I go to "2.html"
Then I should see 'Not Found'
When the file "data/articles.yaml" has the contents
"""
---
- "/blog1/2011-01-01-new-article.html"
"""
When I go to "0.html"
Then I should see 'Newer Article Content'
When I go to "1.html"
Then I should see 'Not Found'
When I go to "2.html"
Then I should see 'Not Found'
When the file "data/articles.yaml" has the contents
"""
---
- "/blog2/2011-01-02-another-article.html"
- "/blog1/2011-01-01-new-article.html"
- "/blog2/2011-01-01-new-article.html"
"""
When I go to "0.html"
Then I should see 'Another Article Content'
When I go to "1.html"
Then I should see 'Newer Article Content'
When I go to "2.html"
Then I should see 'Again'

View file

@ -5,3 +5,5 @@ tags: foo, bar
---
Newer Article Content
Again

View file

@ -7,7 +7,7 @@ module Middleman
attr_reader :app
# Whitelist methods that can reach out.
def_delegators :@app, :config, :logger, :use, :map, :mime_type, :data, :files, :root, :build?, :server?, :environment?
def_delegators :@app, :config, :logger, :use, :map, :mime_type, :files, :root, :build?, :server?, :environment?
def_delegator :"@app.extensions", :activate
def initialize(app, template_context_class)

View file

@ -16,7 +16,7 @@ module Middleman
# gets a chance to modify any new resources that get added.
self.resource_list_manipulator_priority = 110
attr_accessor :root_collector, :leaves
attr_accessor :sitemap_collector, :data_collector, :leaves
def initialize(app, options_hash={}, &block)
super
@ -25,14 +25,16 @@ module Middleman
@collectors_by_name = {}
@values_by_name = {}
@root_collector = LazyCollectorRoot.new(self)
@sitemap_collector = LazyCollectorRoot.new(self)
@data_collector = LazyCollectorRoot.new(self)
end
Contract Any
def before_configuration
@leaves.clear
app.add_to_config_context :resources, &method(:root_collector)
app.add_to_config_context :resources, &method(:sitemap_collector)
app.add_to_config_context :data, &method(:data_collector)
app.add_to_config_context :collection, &method(:register_collector)
end
@ -48,7 +50,8 @@ module Middleman
Contract ResourceList => ResourceList
def manipulate_resource_list(resources)
@root_collector.realize!(resources)
@sitemap_collector.realize!(resources)
@data_collector.realize!(app.data)
ctx = StepContext.new
leaves = @leaves.dup

View file

@ -14,11 +14,11 @@ module Middleman
def initialize(app, config={}, &block)
super
@data_store = DataStore.new(app, DATA_FILE_MATCHER)
app.config.define_setting :data_dir, 'data', 'The directory data files are stored in'
app.add_to_instance(:data, &method(:data_store))
app.add_to_config_context(:data, &method(:data_store))
start_watching(app.config[:data_dir])
end

View file

@ -24,6 +24,7 @@ module Middleman
super
# Setup Slim options to work with partials
::Slim::Engine.disable_option_validator!
::Slim::Engine.set_options(
buffer: '@_out_buf',
use_html_safe: true,