front_matter_parser 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/.yardopts +2 -0
- data/COPYING.LESSER +165 -0
- data/COPYING.txt +674 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +123 -0
- data/Rakefile +6 -0
- data/bin/autospec +16 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/front_matter_parser.gemspec +24 -0
- data/lib/front_matter_parser.rb +103 -0
- data/lib/front_matter_parser/parsed.rb +18 -0
- data/lib/front_matter_parser/version.rb +3 -0
- data/spec/fixtures/example.coffee +4 -0
- data/spec/fixtures/example.foo +0 -0
- data/spec/fixtures/example.haml +5 -0
- data/spec/fixtures/example.html +6 -0
- data/spec/fixtures/example.liquid +6 -0
- data/spec/fixtures/example.md +4 -0
- data/spec/fixtures/example.sass +4 -0
- data/spec/fixtures/example.scss +4 -0
- data/spec/fixtures/example.slim +5 -0
- data/spec/front_matter_parser/parsed_spec.rb +28 -0
- data/spec/front_matter_parser_spec.rb +192 -0
- data/spec/spec_helper.rb +2 -0
- metadata +141 -0
@@ -0,0 +1,192 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FrontMatterParser do
|
4
|
+
let(:sample) { {'title' => 'hello'} }
|
5
|
+
|
6
|
+
it 'has a version number' do
|
7
|
+
expect(FrontMatterParser::VERSION).to_not be_nil
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#parse" do
|
11
|
+
context "when the string has both front matter and content" do
|
12
|
+
let(:string) { %Q(
|
13
|
+
---
|
14
|
+
title: hello
|
15
|
+
---
|
16
|
+
Content) }
|
17
|
+
let(:parsed) { FrontMatterParser.parse(string) }
|
18
|
+
|
19
|
+
it "parses the front matter as a hash" do
|
20
|
+
expect(parsed.front_matter).to eq(sample)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "parses the content as a string" do
|
24
|
+
expect(parsed.content).to eq("Content")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when the string only has front matter" do
|
29
|
+
let(:string) { %Q(
|
30
|
+
---
|
31
|
+
title: hello
|
32
|
+
---
|
33
|
+
) }
|
34
|
+
let(:parsed) { FrontMatterParser.parse(string) }
|
35
|
+
|
36
|
+
it "parses the front matter as a hash" do
|
37
|
+
expect(parsed.front_matter).to eq(sample)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "parses the content as an empty string" do
|
41
|
+
expect(parsed.content).to eq('')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when an empty front matter is supplied" do
|
46
|
+
let(:string) { %Q(Hello) }
|
47
|
+
let(:parsed) { FrontMatterParser.parse(string) }
|
48
|
+
|
49
|
+
it "parses the front matter as an empty hash" do
|
50
|
+
expect(parsed.front_matter).to eq({})
|
51
|
+
end
|
52
|
+
|
53
|
+
it "parses the content as the whole string" do
|
54
|
+
expect(parsed.content).to eq(string)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when an empty string is supplied" do
|
59
|
+
let(:parsed) { FrontMatterParser.parse('') }
|
60
|
+
|
61
|
+
it "parses the front matter as an empty hash" do
|
62
|
+
expect(parsed.front_matter).to eq({})
|
63
|
+
end
|
64
|
+
|
65
|
+
it "parses the content as an empty string" do
|
66
|
+
expect(parsed.content).to eq('')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when the end multiline comment delimiter is provided but not the start one" do
|
71
|
+
it "raises an ArgumentError" do
|
72
|
+
string = %Q(
|
73
|
+
<!--
|
74
|
+
---
|
75
|
+
title: hello
|
76
|
+
---
|
77
|
+
-->
|
78
|
+
Content)
|
79
|
+
expect {FrontMatterParser.parse(string, end_comment: '-->')}.to raise_error(ArgumentError)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#parse_file" do
|
85
|
+
context "when autodetect is true" do
|
86
|
+
{
|
87
|
+
slim: ['slim', nil, '/', nil],
|
88
|
+
coffee: ['coffee', '#', nil, nil],
|
89
|
+
html: ['html', nil, '<!--', '-->'],
|
90
|
+
haml: ['haml', nil, '-#', nil],
|
91
|
+
liquid: ['liquid', nil, '<% comment %>', '<% endcomment %>'],
|
92
|
+
sass: ['sass', '//', nil, nil],
|
93
|
+
scss: ['scss', '//', nil, nil],
|
94
|
+
md: ['md', nil, nil, nil],
|
95
|
+
}.each_pair do |format, prop|
|
96
|
+
it "can detect a #{format} file" do
|
97
|
+
expect(FrontMatterParser).to receive(:parse).with(File.read(File.expand_path("../fixtures/example.#{prop[0]}", __FILE__)), comment: prop[1], start_comment: prop[2], end_comment: prop[3])
|
98
|
+
FrontMatterParser.parse_file(File.expand_path("../fixtures/example.#{prop[0]}", __FILE__), autodetct: true)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "when the file extension is unknown" do
|
103
|
+
it "raises a RuntimeError" do
|
104
|
+
expect {FrontMatterParser.parse_file(File.expand_path('../fixtures/example.foo', __FILE__), autodetect: true)}.to raise_error(RuntimeError)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when autodetect is false" do
|
110
|
+
it "calls #parse with the content of the file and given comment delimiters" do
|
111
|
+
expect(FrontMatterParser).to receive(:parse).with(File.read(File.expand_path('../fixtures/example.md', __FILE__)), comment: nil, start_comment: nil, end_comment: nil)
|
112
|
+
FrontMatterParser.parse_file(File.expand_path('../fixtures/example.md', __FILE__), autodetect: false)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "the front matter" do
|
119
|
+
let(:sample) { {'title' => 'hello'} }
|
120
|
+
|
121
|
+
it "can be indented" do
|
122
|
+
string = %Q(
|
123
|
+
---
|
124
|
+
title: hello
|
125
|
+
---
|
126
|
+
Content)
|
127
|
+
expect(FrontMatterParser.parse(string).front_matter).to eq(sample)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "can have each line commented" do
|
131
|
+
string = %Q(
|
132
|
+
#---
|
133
|
+
#title: hello
|
134
|
+
#---
|
135
|
+
Content)
|
136
|
+
expect(FrontMatterParser.parse(string, comment: '#').front_matter).to eq(sample)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "can be indented after the comment delimiter" do
|
140
|
+
string = %Q(
|
141
|
+
# ---
|
142
|
+
# title: hello
|
143
|
+
# ---
|
144
|
+
Content)
|
145
|
+
expect(FrontMatterParser.parse(string, comment: '#').front_matter).to eq(sample)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "can be between a multiline comment" do
|
149
|
+
string = %Q(
|
150
|
+
<!--
|
151
|
+
---
|
152
|
+
title: hello
|
153
|
+
---
|
154
|
+
-->
|
155
|
+
Content)
|
156
|
+
expect(FrontMatterParser.parse(string, start_comment: '<!--', end_comment: '-->').front_matter).to eq(sample)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "can have the multiline comment delimiters indented" do
|
160
|
+
string = %Q(
|
161
|
+
<!--
|
162
|
+
---
|
163
|
+
title: hello
|
164
|
+
---
|
165
|
+
-->
|
166
|
+
Content)
|
167
|
+
expect(FrontMatterParser.parse(string, start_comment: '<!--', end_comment: '-->').front_matter).to eq(sample)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "can have empty lines between the multiline comment delimiters and the front matter" do
|
171
|
+
string = %Q(
|
172
|
+
<!--
|
173
|
+
|
174
|
+
---
|
175
|
+
title: hello
|
176
|
+
---
|
177
|
+
|
178
|
+
-->
|
179
|
+
Content)
|
180
|
+
expect(FrontMatterParser.parse(string, start_comment: '<!--', end_comment: '-->').front_matter).to eq(sample)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "can have multiline comment delimited by indentation" do
|
184
|
+
string = %Q(
|
185
|
+
/
|
186
|
+
---
|
187
|
+
title: hello
|
188
|
+
---
|
189
|
+
Content)
|
190
|
+
expect(FrontMatterParser.parse(string, start_comment: '/').front_matter).to eq(sample)
|
191
|
+
end
|
192
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: front_matter_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- marc
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.6'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.5'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.6'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '10.1'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '10.1'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.14'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.14'
|
61
|
+
description: Library to parse files or strings with YAML front matters with syntax
|
62
|
+
autodetection.
|
63
|
+
email:
|
64
|
+
- marc@lamarciana.com
|
65
|
+
executables:
|
66
|
+
- autospec
|
67
|
+
- rake
|
68
|
+
- rspec
|
69
|
+
extensions: []
|
70
|
+
extra_rdoc_files: []
|
71
|
+
files:
|
72
|
+
- ".gitignore"
|
73
|
+
- ".rspec"
|
74
|
+
- ".ruby-version"
|
75
|
+
- ".travis.yml"
|
76
|
+
- ".yardopts"
|
77
|
+
- COPYING.LESSER
|
78
|
+
- COPYING.txt
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/autospec
|
84
|
+
- bin/rake
|
85
|
+
- bin/rspec
|
86
|
+
- front_matter_parser.gemspec
|
87
|
+
- lib/front_matter_parser.rb
|
88
|
+
- lib/front_matter_parser/parsed.rb
|
89
|
+
- lib/front_matter_parser/version.rb
|
90
|
+
- spec/fixtures/example.coffee
|
91
|
+
- spec/fixtures/example.foo
|
92
|
+
- spec/fixtures/example.haml
|
93
|
+
- spec/fixtures/example.html
|
94
|
+
- spec/fixtures/example.liquid
|
95
|
+
- spec/fixtures/example.md
|
96
|
+
- spec/fixtures/example.sass
|
97
|
+
- spec/fixtures/example.scss
|
98
|
+
- spec/fixtures/example.slim
|
99
|
+
- spec/front_matter_parser/parsed_spec.rb
|
100
|
+
- spec/front_matter_parser_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: https://github.com/laMarciana/front_matter_parser
|
103
|
+
licenses:
|
104
|
+
- LGPL3
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.2.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: FrontMatterParser is a library to parse files or strings with YAML front
|
126
|
+
matters. When working with files, it can automatically detect the syntax of a file
|
127
|
+
from its extension and it supposes that the front matter is marked as that syntax
|
128
|
+
comments.
|
129
|
+
test_files:
|
130
|
+
- spec/fixtures/example.coffee
|
131
|
+
- spec/fixtures/example.foo
|
132
|
+
- spec/fixtures/example.haml
|
133
|
+
- spec/fixtures/example.html
|
134
|
+
- spec/fixtures/example.liquid
|
135
|
+
- spec/fixtures/example.md
|
136
|
+
- spec/fixtures/example.sass
|
137
|
+
- spec/fixtures/example.scss
|
138
|
+
- spec/fixtures/example.slim
|
139
|
+
- spec/front_matter_parser/parsed_spec.rb
|
140
|
+
- spec/front_matter_parser_spec.rb
|
141
|
+
- spec/spec_helper.rb
|