Data API test
This commit is contained in:
parent
c9e4d41533
commit
6a3de0768c
7
features/data.feature
Normal file
7
features/data.feature
Normal file
|
@ -0,0 +1,7 @@
|
|||
Feature: Local Data API
|
||||
In order to abstract content from structure
|
||||
|
||||
Scenario: Rendering html with the feature enabled
|
||||
Given the Server is running
|
||||
When I go to "/data.html"
|
||||
Then I should see "One:Two"
|
|
@ -3,6 +3,7 @@ with_layout false do
|
|||
page "/inline-js.html"
|
||||
page "/inline-coffeescript.html"
|
||||
page "/slim.html"
|
||||
page "/data.html"
|
||||
end
|
||||
|
||||
get "/page-class.html" do
|
||||
|
|
4
fixtures/test-app/data/test.yml
Normal file
4
fixtures/test-app/data/test.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
-
|
||||
title: "One"
|
||||
-
|
||||
title: "Two"
|
1
fixtures/test-app/source/data.html.erb
Normal file
1
fixtures/test-app/source/data.html.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<%= data.test.map { |r| r.title }.join(":") %>
|
|
@ -13,7 +13,7 @@ module Middleman::CoreExtensions::Data
|
|||
|
||||
module Helpers
|
||||
def data
|
||||
@@data ||= Middleman::CoreExtensions::Data::DataObject.new(self)
|
||||
@@data ||= DataObject.new(self)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -33,7 +33,7 @@ module Middleman::CoreExtensions::Data
|
|||
elsif @@remote_sources.has_key?(path.to_s)
|
||||
response = HTTParty.get(@@remote_sources[path.to_s]).parsed_response
|
||||
else
|
||||
file_path = File.join(@app.class.root, "data", "#{path}.yml")
|
||||
file_path = File.join(@app.class.root, "data", "#{path}.yml")
|
||||
if File.exists? file_path
|
||||
response = YAML.load_file(file_path)
|
||||
end
|
||||
|
@ -82,11 +82,11 @@ module Middleman::CoreExtensions::Data
|
|||
#
|
||||
# data.my_json
|
||||
def data_source(name, url)
|
||||
Middleman::CoreExtensions::Data::DataObject.add_source(name, url)
|
||||
DataObject.add_source(name, url)
|
||||
end
|
||||
|
||||
def data_content(name, content)
|
||||
Middleman::CoreExtensions::Data::DataObject.data_content(name, content)
|
||||
DataObject.data_content(name, content)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue