snippr 0.15.24 → 0.16.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: eae2d0b5629b7140a0d8b124a4e16299c0b9ded4
4
- data.tar.gz: 8b6c014d9e147e85f0243a1b76ef4d2e33a6c0d2
3
+ metadata.gz: 04987e98947b0190ff1c5d80e54f0f10d5261c79
4
+ data.tar.gz: a901855ac7e59a75c478b9d5fdd26f7efe7a55fe
5
5
  SHA512:
6
- metadata.gz: d4ad49375b5ab78a91a1a626769f30911289050a616cbb9b74fb2d039b8201e37cd763bc0bf8c681ad6db511305ffeeac058042ddefb3b2f38f9e47b9817a8cb
7
- data.tar.gz: d5f6b0fd8c8c939a70f61f9991ebefa25f2e666ad8d5532ae5a1854b86f472e3a152399bee0752831b18967d3c2c3aedc2d2153e861aa786ce305153f4ff8497
6
+ metadata.gz: 726583051abb204696a534c43e9eed5d4e6ed59af7e1f88b9f2bd871747b6594c66defd52070e64001bd8ef6d25bfd6bd81f58165c296e15909ceeb370317f64
7
+ data.tar.gz: b2df93eef30d90fe05410c9e95f6aef81b22f5c4fbad7cb7cfc63440689168c239761a4e7a8749a8c1baa7cea571afbdcc2e46792479e8d036b488d381805b14
data/README.md CHANGED
@@ -119,14 +119,29 @@ The data itself is parsed as YAML:
119
119
  Or with Segmentfilter:
120
120
 
121
121
  ---
122
- a_yaml: old
123
- ---
124
- old snippet content comes here until before segment filter
125
- ==== valid_from: 2013-05-17 13:15:00 ====
126
- ---
127
- a_yaml: new
128
- ---
129
- new snippet content after segment filter
122
+ a_yaml: old
123
+ ---
124
+ old snippet content comes here until before segment filter
125
+ ==== valid_from: 2013-05-17 13:15:00 ====
126
+ ---
127
+ a_yaml: new
128
+ ---
129
+ new snippet content after segment filter
130
+
131
+ You call also include other front matter blocks from another snippet with the magic `_include` YAML construct.
132
+ If you have a snippet `a/path/snippet.snip`:
133
+
134
+ ---
135
+ _include:
136
+ - path/from/root/to/snippet
137
+ - ./relative/to/this/snippet
138
+ ---
139
+
140
+ This would merge the metadata from `path/from/root/to/snippet.snip` and `a/path/relative/to/this/snippet.snip` into the containing snippets metadata.
141
+ If there are duplicate keys the metadata in the main/base snippet is chosen.
142
+
143
+ Be aware that the `_include` key is *removed* from the metadata after including.
144
+
130
145
 
131
146
  ### Including snippr files inside other files
132
147
 
@@ -9,10 +9,21 @@ module Snippr
9
9
 
10
10
  class MetaData
11
11
 
12
- def self.extract(name, content)
12
+ INCLUDE = "_include"
13
+
14
+ def self.extract(name, content, snippet=nil)
13
15
  if content =~ /^(---\s*\n.*?\n?)^(---\s*$?)/m
14
16
  content = Regexp.last_match.post_match.strip
15
17
  meta = yaml_load(name, $1)
18
+ if meta.keys.include?(INCLUDE)
19
+ Array(meta[INCLUDE]).each do |includePath|
20
+ if (snippet && includePath.start_with?("./"))
21
+ includePath = snippet.name.gsub(/\/.*?$/,"") + "/" + includePath.gsub(/^\.\//, "")
22
+ end
23
+ snippet = Snippr.load(includePath)
24
+ meta = snippet.meta.merge(meta)
25
+ end
26
+ end
16
27
  end
17
28
 
18
29
  meta = meta ? meta : {}
@@ -31,7 +31,8 @@ module Snippr
31
31
  "<!-- missing snippr: #{name} -->"
32
32
  else
33
33
  content = SegmentParser.new(raw_content).content
34
- @unprocessed_content, @meta = MetaData.extract(name, content)
34
+ @unprocessed_content, @meta = MetaData.extract(name, content, self)
35
+ @meta = @meta.reject { |key_from_meta| key_from_meta == MetaData::INCLUDE }
35
36
  content = Processor.process @unprocessed_content, opts, self
36
37
  "<!-- starting snippr: #{name} -->\n#{content}\n<!-- closing snippr: #{name} -->"
37
38
  end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "snippr"
4
- s.version = '0.15.24'
4
+ s.version = '0.16.0'
5
5
  s.date = Time.now
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Daniel Harrington", "Thomas Jachmann", "Frank Schumacher"]
@@ -0,0 +1,6 @@
1
+ ---
2
+ _include:
3
+ - include/test
4
+ - include/test2
5
+ ---
6
+ This tests the inclusion of yaml fron matter blocks
@@ -0,0 +1,4 @@
1
+ ---
2
+ this_is: included_from_include_test_snippet
3
+ test: include
4
+ ---
@@ -0,0 +1,4 @@
1
+ ---
2
+ this_is_also: included_from_include_test2_snippet
3
+ test: include2
4
+ ---
@@ -6,6 +6,8 @@ describe Snippr::MetaData do
6
6
 
7
7
  TEST_CONTENT = 'Hier ist jede Menge Content.'
8
8
  TEST_CONTENT_WITH_METABLOCK = "---\nyml_key: yml_value\n---\n#{TEST_CONTENT}"
9
+ TEST_CONTENT_WITH_INCLUDE = "---\n_include:\n - include/test\n - include/test2\ntest: main\n---"
10
+ TEST_CONTENT_WITH_RELATIVE_INCLUDE = "---\n_include:\n - ./test\n - ./test2\ntest: main\n---"
9
11
 
10
12
  describe '.extract' do
11
13
  it 'returns an array with 2 elements [contentstring, metahash]' do
@@ -35,6 +37,22 @@ describe Snippr::MetaData do
35
37
  result = Snippr::MetaData.extract([:content], TEST_CONTENT_WITH_METABLOCK)
36
38
  expect(result.first).to eq TEST_CONTENT
37
39
  end
40
+
41
+ it "includes other front matter via the _include key" do
42
+ result = Snippr::MetaData.extract([:content], TEST_CONTENT_WITH_INCLUDE)
43
+ expect(result.second).to eq({"this_is_also"=>"included_from_include_test2_snippet", "test"=>"main", "this_is"=>"included_from_include_test_snippet", "_include"=>["include/test", "include/test2"]})
44
+ end
45
+
46
+ it "includes metadata from relative include paths" do
47
+ snippet = Snippr.load("include/main")
48
+ result = Snippr::MetaData.extract([:content], TEST_CONTENT_WITH_RELATIVE_INCLUDE, snippet)
49
+ expect(result.second).to eq({"this_is_also"=>"included_from_include_test2_snippet", "test"=>"main", "this_is"=>"included_from_include_test_snippet", "_include"=>["./test", "./test2"]})
50
+ end
51
+
52
+ it "includes other front matter blocks but lets the main block win" do
53
+ result = Snippr::MetaData.extract([:content], TEST_CONTENT_WITH_INCLUDE)
54
+ expect(result.second).to eq({"this_is_also"=>"included_from_include_test2_snippet", "test"=>"main", "this_is"=>"included_from_include_test_snippet", "_include"=>["include/test", "include/test2"]})
55
+ end
38
56
  end
39
57
 
40
58
  end
@@ -142,6 +142,11 @@ describe Snippr::Snip do
142
142
  expect(Snippr::Processor).to receive(:process).never
143
143
  expect(Snippr::Snip.new(:doesnotexist, :a => :b).content).to eq('<!-- missing snippr: doesnotexist -->')
144
144
  end
145
+
146
+ it "removes the _include key from the metadata" do
147
+ snip = Snippr::Snip.new(:include, :main)
148
+ expect(snip.meta).to_not have_key("_include")
149
+ end
145
150
  end
146
151
 
147
152
  describe "#missing?" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snippr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.24
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Harrington
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-06-23 00:00:00.000000000 Z
13
+ date: 2014-07-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: i18n
@@ -155,6 +155,9 @@ files:
155
155
  - spec/fixtures/i18n/list_de.snip
156
156
  - spec/fixtures/i18n/shop_de.snip
157
157
  - spec/fixtures/i18n/shop_en.snip
158
+ - spec/fixtures/include/main.snip
159
+ - spec/fixtures/include/test.snip
160
+ - spec/fixtures/include/test2.snip
158
161
  - spec/fixtures/meta/broken.snip
159
162
  - spec/fixtures/meta/onlyContent_de.snip
160
163
  - spec/fixtures/meta/withContent.snip
@@ -218,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
221
  version: '0'
219
222
  requirements: []
220
223
  rubyforge_project: snippr
221
- rubygems_version: 2.2.2
224
+ rubygems_version: 2.4.1
222
225
  signing_key:
223
226
  specification_version: 4
224
227
  summary: File based content management
@@ -231,6 +234,9 @@ test_files:
231
234
  - spec/fixtures/i18n/list_de.snip
232
235
  - spec/fixtures/i18n/shop_de.snip
233
236
  - spec/fixtures/i18n/shop_en.snip
237
+ - spec/fixtures/include/main.snip
238
+ - spec/fixtures/include/test.snip
239
+ - spec/fixtures/include/test2.snip
234
240
  - spec/fixtures/meta/broken.snip
235
241
  - spec/fixtures/meta/onlyContent_de.snip
236
242
  - spec/fixtures/meta/withContent.snip