middleman-data_source 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85df268b12b267b0188e48c25197f71e010d8fb1
4
- data.tar.gz: ff9ba310306744a80915886e1e49ac64c0e24e9b
3
+ metadata.gz: a1740b08c31a4760f0ab73077c0aa67c7e20bbb1
4
+ data.tar.gz: b8d7771afa4af37eb51e11043c201bbb14dc4e5a
5
5
  SHA512:
6
- metadata.gz: 13f802e2a98a282a811b285d6c1333feb82a1cd49661e38d72210dbb0d79754e484d8c28a31d6bd9c8c979fd20d1265a328b5c3e04dfbfe9ac7d38126aaab8dc
7
- data.tar.gz: 332500e03df8e1c0a1e9e28edbc29106554f5f8a3e493a91f35bbaa522b38890df0bb4217c6dd2368e33b7491697a5ecd85b5bd37362e6bd3e909d29d04aed5b
6
+ metadata.gz: 459a8197ac39ed4bc0e38eccc64a7f7e0397381d2b65dc3ab9fabc07b2dd876d09725730ec275274ad1123662e99d0550b2e99df7d8bf50bb56efc56bb34ce95
7
+ data.tar.gz: 678fd4d620a23691270fa5f780cf2eee58f99c853364519fbdcaf86ec8bb79e3a2844ace266d9adc5d2e503502164c3460997e70922bafffa727b340cefea0b4
data/changelog.md CHANGED
@@ -1,2 +1,10 @@
1
+ # 0.2.0
2
+ - add support for specifying file resources as a hash so you can do
3
+ ```ruby
4
+ c.files = {
5
+ "/url/for/resource" => "data_key"
6
+ }
7
+ ```
8
+
1
9
  # 0.1.0
2
10
  - initial release supporting rack or borrower discovered assets parsed with YAML or JSON.
@@ -12,11 +12,23 @@ module Middleman
12
12
  @_rack_app ||= ::Rack::Test::Session.new( ::Rack::MockSession.new( options.rack_app ) )
13
13
  end
14
14
 
15
+ # files = [
16
+ # '/url' => 'data/name'
17
+ # ]
18
+
15
19
  def after_configuration
16
- options.files.each do |remote_file|
17
- extension = File.extname remote_file
18
- basename = File.basename remote_file, extension
19
- parts = remote_file.split(File::SEPARATOR)[0..-2]
20
+ remote_datas = if options.files.respond_to? :keys
21
+ options.files
22
+ else
23
+ Hash[options.files.map do |remote_file|
24
+ [remote_file, remote_file]
25
+ end]
26
+ end
27
+
28
+ remote_datas.each do |remote_file, local_representation|
29
+ extension = File.extname remote_file
30
+ parts = local_representation.split(File::SEPARATOR)
31
+ basename = File.basename parts.pop, extension
20
32
 
21
33
  if parts.empty?
22
34
  original_callback = app.data.callbacks[basename]
@@ -1,7 +1,7 @@
1
1
  module Middleman
2
2
  module DataSource
3
3
 
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
 
6
6
  end
7
7
  end
data/readme.md CHANGED
@@ -34,6 +34,18 @@ And access them like any other data:
34
34
  = data.some.title
35
35
  ```
36
36
 
37
+ You can also specify data resources as a hash to map the name:
38
+
39
+ ```ruby
40
+ # config.rb (in data_source activation block)
41
+ c.files = {
42
+ "/url/to/resource.json" => "my_resource"
43
+ }
44
+
45
+ # source/index.html
46
+ = data.my_resource
47
+ ```
48
+
37
49
  You can fetch your data in two ways:
38
50
  1. from the file system or web with [Borrower](http://github.com/stevenosloan/borrower)
39
51
  2. with a rack app
@@ -0,0 +1,14 @@
1
+ set :environment, :test
2
+ set :show_exceptions, false
3
+
4
+ activate :data_source do |c|
5
+
6
+ c.root = File.join( Dir.pwd, 'remote_data' )
7
+
8
+ c.files = {
9
+ "/deeply/nested.json" => "mapped_nested",
10
+ "/in_yaml.yml" => "mapped_in_yaml",
11
+ "/in_json.json" => "mapped_in_json"
12
+ }
13
+
14
+ end
@@ -87,4 +87,22 @@ describe Middleman::DataSource::Extension do
87
87
  end
88
88
  end
89
89
 
90
+ context "with files specified as hash" do
91
+ before :each do
92
+ Given.fixture 'files_as_hash'
93
+ @mm = Middleman::Fixture.app
94
+ @extension = @mm.extensions[:data_source]
95
+ end
96
+
97
+ after :each do
98
+ Given.cleanup!
99
+ end
100
+
101
+ it "maps correctly between route & data name" do
102
+ expect( @mm.data.mapped_nested["nestable"] ).to eq "data"
103
+ expect( @mm.data.mapped_in_yaml ).to eq ["data","in","yaml"]
104
+ expect( @mm.data.mapped_in_json ).to eq ["data","in","json"]
105
+ end
106
+ end
107
+
90
108
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-data_source
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Sloan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-17 00:00:00.000000000 Z
11
+ date: 2014-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman
@@ -53,6 +53,7 @@ files:
53
53
  - readme.md
54
54
  - spec/fixtures/base/config.rb
55
55
  - spec/fixtures/borrower/config.rb
56
+ - spec/fixtures/files_as_hash/config.rb
56
57
  - spec/fixtures/multiple_instances/config.rb
57
58
  - spec/fixtures/unsupported_extension/config.rb
58
59
  - spec/lib/middleman-data_source_spec.rb
@@ -89,6 +90,7 @@ summary: Allow for loading data in middleman from remote sources
89
90
  test_files:
90
91
  - spec/fixtures/base/config.rb
91
92
  - spec/fixtures/borrower/config.rb
93
+ - spec/fixtures/files_as_hash/config.rb
92
94
  - spec/fixtures/multiple_instances/config.rb
93
95
  - spec/fixtures/unsupported_extension/config.rb
94
96
  - spec/lib/middleman/data_source/extension_spec.rb