snippr 0.15.17 → 0.15.19

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: 9a8c5202bb47c0c71055a5052cb4be7544026e58
4
- data.tar.gz: 0533cb0bc06a2721170a79cd94d0692aa17520bd
3
+ metadata.gz: 566f9eaf54ec97f8798e00a5c6f39fd8025d70cf
4
+ data.tar.gz: dc5b9310b774e6867a160e5cccbceea2677f6430
5
5
  SHA512:
6
- metadata.gz: 821e137bcb4c7df4d3756dab8eff7d87aec08f4ebc3f536f3857126e464aef8e7b029f952700b6f0769b17a8f04502d1b80cca2fdb7adefb93f1924a0b423e09
7
- data.tar.gz: 31bacedcc7177ac83a30a97404ed2919c7c01b405730638df3996baa11649575a7ecd2bbbc370510ec97fff5f63e1874893bae64f3136e6a8f75313bc061dff4
6
+ metadata.gz: a77b2ea7277bfe2c8865730e08499886a805ac65c25bac36459778c14b817e27783a6d890aa951d45753f58efa6309d8980dbeb43c04b699975ef88d27632d89
7
+ data.tar.gz: 5a31458383d4c464f03ec25ff141f4839c878bd98124444a0fe0655f9ee61f38b172a0d493a5b7d351ca6fe31982e4bd05ed9a7c0b5871e487bcb7de3d36c016
data/.gitignore CHANGED
@@ -11,3 +11,4 @@ coverage
11
11
  spec/reports
12
12
  Gemfile.lock
13
13
  .rvmrc
14
+ .ruby-version
data/.travis.yml CHANGED
@@ -2,7 +2,6 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - jruby-19mode # JRuby in 1.9 mode
5
- - 2.0.0
6
5
  - 2.1.0
7
6
  notifications:
8
7
  email: false
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, @meta = MetaData.extract(names, raw_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(@unprocessed_content).content
30
- content = Processor.process content, opts
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
@@ -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.17"
4
+ s.version = '0.15.19'
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 @@
1
+ <p>So meta!</p>
@@ -0,0 +1,10 @@
1
+ ---
2
+ description: Die mit dem Fluegli
3
+ keywords: blau Mobilfunk GmbH, blau.de, blauworld, handy, sim
4
+ ---
5
+ <p>So meta!</p>
6
+ ==== valid_from: 1099-05-01 09:00:00 ====
7
+ ---
8
+ description: neues meta
9
+ ---
10
+ <p>neuer content</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
@@ -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
- "description" => "Die mit dem Fluegli",
60
- "keywords" => "blau Mobilfunk GmbH, blau.de, blauworld, handy, sim"
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
- "description" => "Die mit dem Fluegli",
67
- "keywords" => "blau Mobilfunk GmbH, blau.de, blauworld, handy, sim"
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
- "description" => "Die mit dem Fluegli",
87
- "keywords" => "blau Mobilfunk GmbH, blau.de, blauworld, handy, sim"
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 \[:meta, :broken\]/)
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; end.should == 0
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.17
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-03-18 00:00:00.000000000 Z
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