front_matter_parser 0.1.0 → 0.1.1

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: 13c37dbe3e0903b91a2e77bfbbd1c9f9688dcbc9
4
- data.tar.gz: 9eabdd6757046433de4737ffd79d1b228e75093e
3
+ metadata.gz: 5d5e6ab289e911c8eef0b4890f1dd8ff48f9d21a
4
+ data.tar.gz: 29aac6299a32dcfcc18bd770f3b078b440767455
5
5
  SHA512:
6
- metadata.gz: b0b6dfc6756089ac5740a5f55429c83189219dbabc9e07ab05a25dd666765a57d9fba55c6d34e65da5148ce5c7761aaec5e6666d5892a119b7952f5892e19f71
7
- data.tar.gz: 8d8461da5eb3bb983ec19e1ec7e11b59d4028b6484e6fcb574bf0e30a7d4c2c52bf56898371cf93bb2d4ada80bd78aa572890daa1b87a85d721e4939677bdca3
6
+ metadata.gz: cf889dea7373a1441d733deb02812fe0894aa1b549f53ddbad3229cb4ebeae1a108debc562e4bc7b0d6eb949ef6b8afcda9d7399c3cab6bca0979a30fed71954
7
+ data.tar.gz: 81803add1d8eea7140d4e9c8a3cd559ce8b2f2ab191e9bec3e98def6c28fb5780471b341cc476712aaf763a53801414c6a6eea5b334374ab35634c4702e14e27
@@ -0,0 +1,9 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ ## [0.1.1] - 2017-07-19
8
+ ### Fixed
9
+ - Don't be greedy with front matter end delimiters
data/README.md CHANGED
@@ -95,7 +95,7 @@ You can as well parse a string providing manually the syntax:
95
95
 
96
96
  ```ruby
97
97
  string = File.read('example.slim')
98
- FrontMatterParser::Parser.new(:slim).parse(string)
98
+ FrontMatterParser::Parser.new(:slim).call(string)
99
99
  ```
100
100
 
101
101
  ### Custom parsers
@@ -117,7 +117,7 @@ slim_parser = SlimParser.new
117
117
  FrontMatterParser::Parser.parse_file('example.slim', syntax_parser: slim_parser)
118
118
 
119
119
  # For a string
120
- FrontMatterParser::Parser.new(slim_parser).parse(string)
120
+ FrontMatterParser::Parser.new(slim_parser).call(string)
121
121
  ```
122
122
 
123
123
  For more complex scenarios, a parser can be anything responding to a method `call(string)` which returns a hash interface with `:front_matter` and `:content` keys, or `nil` if no front matter is found.
@@ -133,7 +133,7 @@ json_loader = ->(string) { JSON.load(string) }
133
133
  FrontMatterParser::Parser.parse_file('example.md', loader: json_loader)
134
134
 
135
135
  # For a string
136
- FrontMatterParser::Parser.new(:md, loader: json_loader).parse(string)
136
+ FrontMatterParser::Parser.new(:md, loader: json_loader).call(string)
137
137
  ```
138
138
 
139
139
  ## Development
@@ -36,7 +36,7 @@ module FrontMatterParser
36
36
  #{delimiter}
37
37
  [[:space:]]*
38
38
  ---
39
- (?<front_matter>.*)
39
+ (?<front_matter>.*?)
40
40
  ---
41
41
  [[:blank:]]*$[\n\r]
42
42
  (?<content>.*)
@@ -35,7 +35,7 @@ module FrontMatterParser
35
35
  #{start_delimiter}
36
36
  [[:space:]]*
37
37
  ---
38
- (?<front_matter>.*)
38
+ (?<front_matter>.*?)
39
39
  ---
40
40
  [[:space:]]*
41
41
  #{end_delimiter}
@@ -50,7 +50,7 @@ module FrontMatterParser
50
50
  [[:space:]]*
51
51
  #{delimiter}[[:blank:]]*
52
52
  ---
53
- (?<front_matter>.*)
53
+ (?<front_matter>.*?)
54
54
  ^[[:blank:]]*#{delimiter}[[:blank:]]*
55
55
  ---
56
56
  [[:blank:]]*$[\n\r]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FrontMatterParser
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  describe FrontMatterParser::Loader::Yaml do
6
6
  describe '::call' do
7
7
  it 'loads using yaml parser' do
8
- string = "{title: 'hello'}"
8
+ string = "title: 'hello'"
9
9
 
10
10
  expect(described_class.call(string)).to eq(
11
11
  'title' => 'hello'
@@ -138,6 +138,26 @@ describe FrontMatterParser::SyntaxParser::IndentationComment do
138
138
  end
139
139
  end
140
140
 
141
+ context 'with front matter delimiter chars in the content' do
142
+ let(:syntax) { :slim }
143
+ let(:string) do
144
+ <<~eos
145
+ /
146
+ ---
147
+ title: hello
148
+ ---
149
+ Content
150
+ ---
151
+ eos
152
+ end
153
+
154
+ it 'is not greedy' do
155
+ front_matter = { 'title' => 'hello' }
156
+
157
+ expect(parsed).to be_parsed_result_with(front_matter, "Content\n---\n")
158
+ end
159
+ end
160
+
141
161
  it 'returns nil if no front matter is found' do
142
162
  string = 'Content'
143
163
 
@@ -241,6 +241,24 @@ describe FrontMatterParser::SyntaxParser::MultiLineComment do
241
241
  end
242
242
  end
243
243
 
244
+ context 'with front matter delimiter chars in the content' do
245
+ let(:syntax) { :md }
246
+ let(:string) do
247
+ <<~eos
248
+ ---
249
+ title: hello
250
+ ---
251
+ Content---
252
+ eos
253
+ end
254
+
255
+ it 'is not greedy' do
256
+ front_matter = { 'title' => 'hello' }
257
+
258
+ expect(parsed).to be_parsed_result_with(front_matter, "Content---\n")
259
+ end
260
+ end
261
+
244
262
  it 'returns nil if no front matter is found' do
245
263
  string = 'Content'
246
264
 
@@ -148,6 +148,25 @@ describe FrontMatterParser::SyntaxParser::SingleLineComment do
148
148
  end
149
149
  end
150
150
 
151
+ context 'with front matter delimiter chars in the content' do
152
+ let(:syntax) { :sass }
153
+ let(:string) do
154
+ <<~eos
155
+ //---
156
+ //title: hello
157
+ //---
158
+ //---
159
+ Content
160
+ eos
161
+ end
162
+
163
+ it 'is not greedy' do
164
+ front_matter = { 'title' => 'hello' }
165
+
166
+ expect(parsed).to be_parsed_result_with(front_matter, "//---\nContent\n")
167
+ end
168
+ end
169
+
151
170
  it 'returns nil if no front matter is found' do
152
171
  string = 'Content'
153
172
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: front_matter_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - marc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-30 00:00:00.000000000 Z
11
+ date: 2017-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -112,6 +112,7 @@ files:
112
112
  - ".ruby-version"
113
113
  - ".travis.yml"
114
114
  - ".yardopts"
115
+ - CHANGELOG.md
115
116
  - COPYING.LESSER
116
117
  - COPYING.txt
117
118
  - Dockerfile