snippr 0.15.17 → 0.15.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +0 -1
- data/README.md +13 -1
- data/lib/snippr/snip.rb +6 -3
- data/snippr.gemspec +1 -1
- data/spec/fixtures/meta/onlyContent_de.snip +1 -0
- data/spec/fixtures/meta/withContentAndSegmentfilter.snip +10 -0
- data/spec/snippr/meta_data_spec.rb +40 -0
- data/spec/snippr/segment_parser_spec.rb +8 -0
- data/spec/snippr/snip_spec.rb +10 -0
- data/spec/snippr/view_helper_spec.rb +17 -19
- metadata +8 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 566f9eaf54ec97f8798e00a5c6f39fd8025d70cf
|
|
4
|
+
data.tar.gz: dc5b9310b774e6867a160e5cccbceea2677f6430
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a77b2ea7277bfe2c8865730e08499886a805ac65c25bac36459778c14b817e27783a6d890aa951d45753f58efa6309d8980dbeb43c04b699975ef88d27632d89
|
|
7
|
+
data.tar.gz: 5a31458383d4c464f03ec25ff141f4839c878bd98124444a0fe0655f9ee61f38b172a0d493a5b7d351ca6fe31982e4bd05ed9a7c0b5871e487bcb7de3d36c016
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
|
@@ -105,7 +105,7 @@ A snippet can not only hold content but also meta infos for this snippet.
|
|
|
105
105
|
Inspired by [jekyll](http://jekyllrb.com) a snippet can host metadata that is accessable via the `.meta` method on a loaded snippet.
|
|
106
106
|
`.meta' will return an empty hash when no data was found.
|
|
107
107
|
|
|
108
|
-
Metadata must be placed at the top of the snippet and is delimited with three dashed.
|
|
108
|
+
Metadata must be placed at the top of the snippet or directly after the segment filter and is delimited with three dashed.
|
|
109
109
|
The data itself is parsed as YAML:
|
|
110
110
|
|
|
111
111
|
---
|
|
@@ -113,6 +113,18 @@ The data itself is parsed as YAML:
|
|
|
113
113
|
---
|
|
114
114
|
normal snippet content comes here until the end of the file
|
|
115
115
|
|
|
116
|
+
Or with Segmentfilter:
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
a_yaml: old
|
|
120
|
+
---
|
|
121
|
+
old snippet content comes here until before segment filter
|
|
122
|
+
==== valid_from: 2013-05-17 13:15:00 ====
|
|
123
|
+
---
|
|
124
|
+
a_yaml: new
|
|
125
|
+
---
|
|
126
|
+
new snippet content after segment filter
|
|
127
|
+
|
|
116
128
|
### Including snippr files inside other files
|
|
117
129
|
|
|
118
130
|
A snippr file can include another snippr file:
|
data/lib/snippr/snip.rb
CHANGED
|
@@ -14,7 +14,9 @@ module Snippr
|
|
|
14
14
|
@opts.symbolize_keys!
|
|
15
15
|
@name = "#{Path.normalize_name(*names)}#{ I18n.locale(@opts[:i18n]) }"
|
|
16
16
|
@path = Path.path_from_name @name, (@opts[:extension] || FILE_EXTENSION)
|
|
17
|
-
@unprocessed_content
|
|
17
|
+
@unprocessed_content = raw_content
|
|
18
|
+
@meta = {}
|
|
19
|
+
content
|
|
18
20
|
after_initialize
|
|
19
21
|
end
|
|
20
22
|
|
|
@@ -26,8 +28,9 @@ module Snippr
|
|
|
26
28
|
if missing?
|
|
27
29
|
"<!-- missing snippr: #{name} -->"
|
|
28
30
|
else
|
|
29
|
-
content = SegmentParser.new(
|
|
30
|
-
|
|
31
|
+
content = SegmentParser.new(raw_content).content
|
|
32
|
+
@unprocessed_content, @meta = MetaData.extract(name, content)
|
|
33
|
+
content = Processor.process @unprocessed_content, opts
|
|
31
34
|
"<!-- starting snippr: #{name} -->\n#{content}\n<!-- closing snippr: #{name} -->"
|
|
32
35
|
end
|
|
33
36
|
end
|
data/snippr.gemspec
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<p>So meta!</p>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
|
2
|
+
require "spec_helper"
|
|
3
|
+
|
|
4
|
+
describe Snippr::MetaData do
|
|
5
|
+
include Snippr::ViewHelper
|
|
6
|
+
|
|
7
|
+
TEST_CONTENT = 'Hier ist jede Menge Content.'
|
|
8
|
+
TEST_CONTENT_WITH_METABLOCK = "---\nyml_key: yml_value\n---\n#{TEST_CONTENT}"
|
|
9
|
+
|
|
10
|
+
describe '.extract' do
|
|
11
|
+
it 'returns an array with 2 elements [contentstring, metahash]' do
|
|
12
|
+
result = Snippr::MetaData.extract([:content], TEST_CONTENT)
|
|
13
|
+
expect(result).to be_a Array
|
|
14
|
+
expect(result).to have(2).items
|
|
15
|
+
expect(result.first).to be_a String
|
|
16
|
+
expect(result.second).to be_a Hash
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'returns raw content for non existing metablock' do
|
|
20
|
+
result = Snippr::MetaData.extract([:content], TEST_CONTENT)
|
|
21
|
+
expect(result.first).to eq TEST_CONTENT
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'returns empty hash for non existing metablock' do
|
|
25
|
+
result = Snippr::MetaData.extract([:content], TEST_CONTENT)
|
|
26
|
+
expect(result.second).to eq({})
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'returns a hash from given metablock' do
|
|
30
|
+
result = Snippr::MetaData.extract([:content], TEST_CONTENT_WITH_METABLOCK)
|
|
31
|
+
expect(result.second).to eq({'yml_key' => 'yml_value'})
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it 'returns content as content without metablock' do
|
|
35
|
+
result = Snippr::MetaData.extract([:content], TEST_CONTENT_WITH_METABLOCK)
|
|
36
|
+
expect(result.first).to eq TEST_CONTENT
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
@@ -34,4 +34,12 @@ describe "SegmentParser" do
|
|
|
34
34
|
it "chooses the correct segment even with \r\n" do
|
|
35
35
|
Snippr::SegmentParser.new("alt\r\n==== valid_from: 1099-05-01 09:00:00 ====\r\nneu\r\n").content.should == "neu"
|
|
36
36
|
end
|
|
37
|
+
|
|
38
|
+
it 'works with yml block in old block' do
|
|
39
|
+
Snippr::SegmentParser.new("---\nyml_key: yml_value\nalt\n==== valid_from: 1099-05-01 09:00:00 ====\nneu\n").content.should == "neu"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'works with yml block in new block' do
|
|
43
|
+
Snippr::SegmentParser.new("---\nyml_key: yml_value\n---\nalt\n==== valid_from: 1099-05-01 09:00:00 ====\n---\nyml_key: yml_value\n---\nneu\n").content.should == "---\nyml_key: yml_value\n---\nneu"
|
|
44
|
+
end
|
|
37
45
|
end
|
data/spec/snippr/snip_spec.rb
CHANGED
|
@@ -176,4 +176,14 @@ describe Snippr::Snip do
|
|
|
176
176
|
|
|
177
177
|
end
|
|
178
178
|
|
|
179
|
+
describe '#meta' do
|
|
180
|
+
it 'returns metadata from valid segment' do
|
|
181
|
+
expect(Snippr::Snip.new(:meta, :with_content_and_segmentfilter).meta).to eq({'description' => 'neues meta'})
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
it 'initializes meta with empty hash' do
|
|
185
|
+
expect(Snippr::Snip.new(:meta, :missing_snippet).meta).to eq({})
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
179
189
|
end
|
|
@@ -51,22 +51,19 @@ describe Snippr::ViewHelper do
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
context "snippr with meta data" do
|
|
54
|
-
|
|
55
54
|
context "and content" do
|
|
56
|
-
|
|
57
55
|
it "returns a Hash of meta information" do
|
|
58
56
|
snippr(:meta, :with_content).meta.should == {
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
"description" => "Die mit dem Fluegli",
|
|
58
|
+
"keywords" => "blau Mobilfunk GmbH, blau.de, blauworld, handy, sim"
|
|
61
59
|
}
|
|
62
60
|
end
|
|
63
61
|
|
|
64
62
|
it "returns a hash ofmeta information even if the YAML Fron Matter BLock ends without newline" do
|
|
65
63
|
snippr(:meta, :with_content_no_newline).meta.should == {
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
"description" => "Die mit dem Fluegli",
|
|
65
|
+
"keywords" => "blau Mobilfunk GmbH, blau.de, blauworld, handy, sim"
|
|
68
66
|
}
|
|
69
|
-
|
|
70
67
|
end
|
|
71
68
|
|
|
72
69
|
it "accepts a key to search for" do
|
|
@@ -76,36 +73,37 @@ describe Snippr::ViewHelper do
|
|
|
76
73
|
it "returns the content without meta information" do
|
|
77
74
|
snippr(:meta, :with_content).to_s.should == "<!-- starting snippr: meta/withContent -->\n<p>So meta!</p>\n<!-- closing snippr: meta/withContent -->"
|
|
78
75
|
end
|
|
79
|
-
|
|
80
76
|
end
|
|
81
77
|
|
|
82
78
|
context "and no content" do
|
|
83
|
-
|
|
84
79
|
it "still returns a Hash of meta information" do
|
|
85
80
|
snippr(:meta, :with_no_content).meta.should == {
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
"description" => "Die mit dem Fluegli",
|
|
82
|
+
"keywords" => "blau Mobilfunk GmbH, blau.de, blauworld, handy, sim"
|
|
88
83
|
}
|
|
89
84
|
end
|
|
90
|
-
|
|
91
85
|
end
|
|
92
86
|
|
|
87
|
+
context 'with segmentfilter' do
|
|
88
|
+
it 'uses new meta data and new content' do
|
|
89
|
+
# snippr(:meta, :with_content).to_s.should == "<!-- starting snippr: meta/withContentandSegmentfilter -->\n<p>So meta!</p>\n<!-- closing snippr: meta/withContentandSegmentfilter -->"
|
|
90
|
+
expect(snippr(:meta, :with_content_and_segmentfilter).to_s).to eq "<!-- starting snippr: meta/withContentAndSegmentfilter -->\n<p>neuer content</p>\n<!-- closing snippr: meta/withContentAndSegmentfilter -->"
|
|
91
|
+
expect(snippr(:meta, :with_content_and_segmentfilter).meta('description')).to eq 'neues meta'
|
|
92
|
+
end
|
|
93
|
+
end
|
|
93
94
|
end
|
|
94
95
|
|
|
95
96
|
context "snippr with broken meta data" do
|
|
96
|
-
|
|
97
97
|
it "logs a warning and acts as if no meta information exist" do
|
|
98
|
-
expect(Snippr.logger).to receive(:warn).with(/Unable to extract meta data from Snip \
|
|
98
|
+
expect(Snippr.logger).to receive(:warn).with(/Unable to extract meta data from Snip \"meta\/broken\"/)
|
|
99
99
|
|
|
100
100
|
snip = snippr(:meta, :broken)
|
|
101
101
|
snip.meta.should == {}
|
|
102
102
|
snip.to_s.should == "<!-- starting snippr: meta/broken -->\n<p>Broken!</p>\n<!-- closing snippr: meta/broken -->"
|
|
103
103
|
end
|
|
104
|
-
|
|
105
104
|
end
|
|
106
105
|
|
|
107
106
|
context "existing snippr" do
|
|
108
|
-
|
|
109
107
|
it "calls html_safe and return html safe value" do
|
|
110
108
|
content = snippr(:home)
|
|
111
109
|
content.should == "<!-- starting snippr: home -->\n<p>Home</p>\n<!-- closing snippr: home -->"
|
|
@@ -122,7 +120,9 @@ describe Snippr::ViewHelper do
|
|
|
122
120
|
end
|
|
123
121
|
|
|
124
122
|
it "returns 0 with block" do
|
|
125
|
-
snippr(:home) do
|
|
123
|
+
snippr(:home) do
|
|
124
|
+
;
|
|
125
|
+
end.should == 0
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
end
|
|
@@ -223,7 +223,5 @@ describe Snippr::ViewHelper do
|
|
|
223
223
|
snippr_with_path(:deeper, :nested, :snippet).should == "<!-- missing snippr: withUnderscore/andUnderscore/deeper/nested/snippet -->"
|
|
224
224
|
end
|
|
225
225
|
end
|
|
226
|
-
|
|
227
226
|
end
|
|
228
|
-
|
|
229
227
|
end
|
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.
|
|
4
|
+
version: 0.15.19
|
|
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-
|
|
13
|
+
date: 2014-05-21 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: i18n
|
|
@@ -156,7 +156,9 @@ files:
|
|
|
156
156
|
- spec/fixtures/i18n/shop_de.snip
|
|
157
157
|
- spec/fixtures/i18n/shop_en.snip
|
|
158
158
|
- spec/fixtures/meta/broken.snip
|
|
159
|
+
- spec/fixtures/meta/onlyContent_de.snip
|
|
159
160
|
- spec/fixtures/meta/withContent.snip
|
|
161
|
+
- spec/fixtures/meta/withContentAndSegmentfilter.snip
|
|
160
162
|
- spec/fixtures/meta/withContentNoNewline.snip
|
|
161
163
|
- spec/fixtures/meta/withNoContent.snip
|
|
162
164
|
- spec/fixtures/topup/someError.snip
|
|
@@ -167,6 +169,7 @@ files:
|
|
|
167
169
|
- spec/snippr/clock_spec.rb
|
|
168
170
|
- spec/snippr/i18n_spec.rb
|
|
169
171
|
- spec/snippr/links_spec.rb
|
|
172
|
+
- spec/snippr/meta_data_spec.rb
|
|
170
173
|
- spec/snippr/normalizer/camelizer_spec.rb
|
|
171
174
|
- spec/snippr/normalizer/de_rester_spec.rb
|
|
172
175
|
- spec/snippr/normalizer_spec.rb
|
|
@@ -222,7 +225,9 @@ test_files:
|
|
|
222
225
|
- spec/fixtures/i18n/shop_de.snip
|
|
223
226
|
- spec/fixtures/i18n/shop_en.snip
|
|
224
227
|
- spec/fixtures/meta/broken.snip
|
|
228
|
+
- spec/fixtures/meta/onlyContent_de.snip
|
|
225
229
|
- spec/fixtures/meta/withContent.snip
|
|
230
|
+
- spec/fixtures/meta/withContentAndSegmentfilter.snip
|
|
226
231
|
- spec/fixtures/meta/withContentNoNewline.snip
|
|
227
232
|
- spec/fixtures/meta/withNoContent.snip
|
|
228
233
|
- spec/fixtures/topup/someError.snip
|
|
@@ -233,6 +238,7 @@ test_files:
|
|
|
233
238
|
- spec/snippr/clock_spec.rb
|
|
234
239
|
- spec/snippr/i18n_spec.rb
|
|
235
240
|
- spec/snippr/links_spec.rb
|
|
241
|
+
- spec/snippr/meta_data_spec.rb
|
|
236
242
|
- spec/snippr/normalizer/camelizer_spec.rb
|
|
237
243
|
- spec/snippr/normalizer/de_rester_spec.rb
|
|
238
244
|
- spec/snippr/normalizer_spec.rb
|