feedtxt 1.0.0 → 1.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 +4 -4
- data/README.md +50 -0
- data/lib/feedtxt.rb +4 -0
- data/lib/feedtxt/parser.rb +8 -8
- data/lib/feedtxt/parser/ini.rb +3 -2
- data/lib/feedtxt/parser/json.rb +2 -2
- data/lib/feedtxt/parser/yaml.rb +2 -2
- data/lib/feedtxt/version.rb +1 -1
- data/test/test_ini.rb +2 -2
- data/test/test_json.rb +2 -2
- data/test/test_yaml.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d789a406ff8c3b40a8796526c335f417b1d7bef7
|
4
|
+
data.tar.gz: bbb14f11154e100c1cf35df74d96de005d922bc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6989519e169db7a4b8cbb24ce8fad4529934627ce196c262e777c42b11fcbfd4aaff20cc8d42131abe46b47a8ba572129462b59ba027358fe5394261f92909b
|
7
|
+
data.tar.gz: 94ee18c107eb40be036311b89219cf5662fc94aa66453e44b405d7ad1d2993fc0893daacd1eaccef05c775467bcfe65a1f75655cd891280c3b6c1e70c5bb8951
|
data/README.md
CHANGED
@@ -207,6 +207,36 @@ item_content
|
|
207
207
|
Note: Feed.TXT supports alternative formats / styles for meta data blocks.
|
208
208
|
For now YAML, JSON and INI style
|
209
209
|
are built-in and shipping with the `feedtxt` gem.
|
210
|
+
To use a format-specific parser use:
|
211
|
+
|
212
|
+
- `Feedtxt::YAML.parse`
|
213
|
+
- `Feedtxt::JSON.parse`
|
214
|
+
- `Feedtxt::INI.parse`
|
215
|
+
|
216
|
+
Note: `Feedtxt.parse` will handle all formats auto-magically,
|
217
|
+
that is, it will check the text for the best matching (first)
|
218
|
+
feed begin marker
|
219
|
+
to find out what meta data format parser to use:
|
220
|
+
|
221
|
+
| Format | `FEED_BEGIN` |
|
222
|
+
|--------|--------------|
|
223
|
+
| YAML | `\|>>>` |
|
224
|
+
| JSON | `\|{` |
|
225
|
+
| INI | `[>>>` |
|
226
|
+
|
227
|
+
|
228
|
+
Or use the built-in text pattern (regular expression)
|
229
|
+
constants to find out:
|
230
|
+
|
231
|
+
``` ruby
|
232
|
+
Feedtxt::YAML::FEED_BEGIN
|
233
|
+
# => "^[ ]*\\|>>>+[ ]*$"
|
234
|
+
Feedtxt::JSON::FEED_BEGIN
|
235
|
+
# => "^[ ]*\\|{+[ ]*$"
|
236
|
+
Feedtxt::INI::FEED_BEGIN
|
237
|
+
# => "^[ ]*\\[>>>+[ ]*$"
|
238
|
+
```
|
239
|
+
|
210
240
|
|
211
241
|
|
212
242
|
### JSON Example
|
@@ -257,6 +287,26 @@ Hello, world!
|
|
257
287
|
<<<]
|
258
288
|
```
|
259
289
|
|
290
|
+
or
|
291
|
+
|
292
|
+
```
|
293
|
+
[>>>
|
294
|
+
title: My Example Feed
|
295
|
+
home_page_url: https://example.org/
|
296
|
+
feed_url: https://example.org/feed.txt
|
297
|
+
</>
|
298
|
+
id: 2
|
299
|
+
url: https://example.org/second-item
|
300
|
+
---
|
301
|
+
This is a second item.
|
302
|
+
</>
|
303
|
+
id: 1
|
304
|
+
url: https://example.org/initial-post
|
305
|
+
---
|
306
|
+
Hello, world!
|
307
|
+
<<<]
|
308
|
+
```
|
309
|
+
|
260
310
|
(Source: [`feeds/spec/example.ini.txt`](https://github.com/feedtxt/feedtxt/blob/master/test/feeds/spec/example.ini.txt))
|
261
311
|
|
262
312
|
|
data/lib/feedtxt.rb
CHANGED
@@ -33,6 +33,10 @@ module Feedtxt
|
|
33
33
|
def self.parse( text, opts={} )
|
34
34
|
Parser.parse( text, )
|
35
35
|
end
|
36
|
+
|
37
|
+
INI = IniParser ## note: add a shortcut; lets you use Feedtxt::INI.parse
|
38
|
+
YAML = YamlParser ## note: add a shortcut; lets you use Feedtxt::YAML.parse
|
39
|
+
JSON = JsonParser ## note: add a shortcut; lets you use Feedttxt::JSON.parse
|
36
40
|
end
|
37
41
|
|
38
42
|
|
data/lib/feedtxt/parser.rb
CHANGED
@@ -23,25 +23,25 @@ class Parser
|
|
23
23
|
## auto-detect format
|
24
24
|
## use "best" matching format (e.g. first match by pos(ition))
|
25
25
|
|
26
|
-
klass =
|
27
|
-
pos =
|
26
|
+
klass = YAML ## default to yamlparser for now
|
27
|
+
pos = 9_999_999 ## todo:use MAX INTEGER or something!!
|
28
28
|
|
29
|
-
json = @text.index( /#{
|
29
|
+
json = @text.index( /#{JSON::FEED_BEGIN}/ )
|
30
30
|
if json # found e.g. not nil? incl. 0
|
31
31
|
pos = json
|
32
|
-
klass =
|
32
|
+
klass = JSON
|
33
33
|
end
|
34
34
|
|
35
|
-
ini = @text.index( /#{
|
35
|
+
ini = @text.index( /#{INI::FEED_BEGIN}/ )
|
36
36
|
if ini && ini < pos # found e.g. not nil? and match before last?
|
37
37
|
pos = ini
|
38
|
-
klass =
|
38
|
+
klass = INI
|
39
39
|
end
|
40
40
|
|
41
|
-
yaml = @text.index( /#{
|
41
|
+
yaml = @text.index( /#{YAML::FEED_BEGIN}/ )
|
42
42
|
if yaml && yaml < pos # found e.g. not nil? and match before last?
|
43
43
|
pos = yaml
|
44
|
-
klass =
|
44
|
+
klass = YAML
|
45
45
|
end
|
46
46
|
|
47
47
|
feed = klass.parse( @text )
|
data/lib/feedtxt/parser/ini.rb
CHANGED
@@ -75,7 +75,7 @@ class IniParser
|
|
75
75
|
## 1st block is feed meta data
|
76
76
|
block1st = blocks.shift ## get/remove 1st block from blocks
|
77
77
|
block1st = block1st.strip ## strip leading and trailing whitespace
|
78
|
-
feed_metadata = INI.load( block1st )
|
78
|
+
feed_metadata = ::INI.load( block1st )
|
79
79
|
|
80
80
|
feed_items = []
|
81
81
|
blocks.each do |block|
|
@@ -87,7 +87,7 @@ class IniParser
|
|
87
87
|
|
88
88
|
item_metadata = s2.scan_until( /(?=#{FEED_META})/ )
|
89
89
|
item_metadata = item_metadata.strip # remove leading and trailing whitespace
|
90
|
-
item_metadata = INI.load( item_metadata ) ## convert to hash with inifile parser
|
90
|
+
item_metadata = ::INI.load( item_metadata ) ## convert to hash with inifile parser
|
91
91
|
|
92
92
|
feed_meta = s2.scan( /#{FEED_META}/ )
|
93
93
|
|
@@ -103,4 +103,5 @@ class IniParser
|
|
103
103
|
|
104
104
|
end # class IniParser
|
105
105
|
|
106
|
+
|
106
107
|
end # module Feedtxt
|
data/lib/feedtxt/parser/json.rb
CHANGED
@@ -79,7 +79,7 @@ class JsonParser
|
|
79
79
|
## 1st block is feed meta data
|
80
80
|
block1st = blocks.shift ## get/remove 1st block from blocks
|
81
81
|
block1st = block1st.strip # remove leading and trailing whitespaces
|
82
|
-
feed_metadata = JSON.parse( "{ #{block1st} }" )
|
82
|
+
feed_metadata = ::JSON.parse( "{ #{block1st} }" )
|
83
83
|
|
84
84
|
feed_items = []
|
85
85
|
blocks.each do |block|
|
@@ -91,7 +91,7 @@ class JsonParser
|
|
91
91
|
|
92
92
|
item_metadata = s2.scan_until( /(?=#{FEED_META})/ )
|
93
93
|
item_metadata = item_metadata.strip # remove leading and trailing whitespace
|
94
|
-
item_metadata = JSON.parse( "{ #{item_metadata} }" ) ## convert to hash with yaml
|
94
|
+
item_metadata = ::JSON.parse( "{ #{item_metadata} }" ) ## convert to hash with yaml
|
95
95
|
|
96
96
|
feed_meta = s2.scan( /#{FEED_META}/ )
|
97
97
|
|
data/lib/feedtxt/parser/yaml.rb
CHANGED
@@ -75,7 +75,7 @@ class YamlParser
|
|
75
75
|
## 1st block is feed meta data
|
76
76
|
block1st = blocks.shift ## get/remove 1st block from blocks
|
77
77
|
block1st = block1st.strip ## strip leading and trailing whitespace
|
78
|
-
feed_metadata = YAML.load( block1st )
|
78
|
+
feed_metadata = ::YAML.load( block1st )
|
79
79
|
|
80
80
|
feed_items = []
|
81
81
|
blocks.each do |block|
|
@@ -87,7 +87,7 @@ class YamlParser
|
|
87
87
|
|
88
88
|
item_metadata = s2.scan_until( /(?=#{FEED_META})/ )
|
89
89
|
item_metadata = item_metadata.strip # remove leading and trailing whitespace
|
90
|
-
item_metadata = YAML.load( item_metadata ) ## convert to hash with yaml
|
90
|
+
item_metadata = ::YAML.load( item_metadata ) ## convert to hash with yaml
|
91
91
|
|
92
92
|
feed_meta = s2.scan( /#{FEED_META}/ )
|
93
93
|
|
data/lib/feedtxt/version.rb
CHANGED
data/test/test_ini.rb
CHANGED
@@ -27,7 +27,7 @@ class TestIni < MiniTest::Test
|
|
27
27
|
"Hello, world!"
|
28
28
|
]]]
|
29
29
|
|
30
|
-
assert_equal exp, Feedtxt::
|
30
|
+
assert_equal exp, Feedtxt::INI.parse( text )
|
31
31
|
assert_equal exp, Feedtxt.parse( text ) ## try shortcut alias too
|
32
32
|
end
|
33
33
|
|
@@ -54,7 +54,7 @@ class TestIni < MiniTest::Test
|
|
54
54
|
"duration_in_seconds"=>"6629"}},
|
55
55
|
"Chris has worked at [Adobe][1] and as a founder of Rogue Sheep, which won an Apple Design Award for Postage.\nChris's new company is Aged & Distilled with Guy English - which shipped [Napkin](2),\na Mac app for visual collaboration. Chris is also the co-host of The Record.\nHe lives on [Bainbridge Island][3], a quick ferry ride from Seattle.\n\n[1]: http://adobe.com/\n[2]: http://aged-and-distilled.com/napkin/\n[3]: http://www.ci.bainbridge-isl.wa.us/"]]]
|
56
56
|
|
57
|
-
assert_equal exp, Feedtxt::
|
57
|
+
assert_equal exp, Feedtxt::INI.parse( text )
|
58
58
|
assert_equal exp, Feedtxt.parse( text ) ## try shortcut alias too
|
59
59
|
end
|
60
60
|
|
data/test/test_json.rb
CHANGED
@@ -27,7 +27,7 @@ class TestJson < MiniTest::Test
|
|
27
27
|
"Hello, world!"
|
28
28
|
]]]
|
29
29
|
|
30
|
-
assert_equal exp, Feedtxt::
|
30
|
+
assert_equal exp, Feedtxt::JSON.parse( text )
|
31
31
|
assert_equal exp, Feedtxt.parse( text ) ## try shortcut alias too
|
32
32
|
end
|
33
33
|
|
@@ -55,7 +55,7 @@ class TestJson < MiniTest::Test
|
|
55
55
|
"duration_in_seconds"=>6629}]},
|
56
56
|
"Chris has worked at [Adobe][1] and as a founder of Rogue Sheep, which won an Apple Design Award for Postage.\nChris's new company is Aged & Distilled with Guy English - which shipped [Napkin](2),\na Mac app for visual collaboration. Chris is also the co-host of The Record.\nHe lives on [Bainbridge Island][3], a quick ferry ride from Seattle.\n\n[1]: http://adobe.com/\n[2]: http://aged-and-distilled.com/napkin/\n[3]: http://www.ci.bainbridge-isl.wa.us/"]]]
|
57
57
|
|
58
|
-
assert_equal exp, Feedtxt::
|
58
|
+
assert_equal exp, Feedtxt::JSON.parse( text )
|
59
59
|
assert_equal exp, Feedtxt.parse( text ) ## try shortcut alias too
|
60
60
|
end
|
61
61
|
|
data/test/test_yaml.rb
CHANGED
@@ -27,7 +27,7 @@ class TestYaml < MiniTest::Test
|
|
27
27
|
"Hello, world!"
|
28
28
|
]]]
|
29
29
|
|
30
|
-
assert_equal exp, Feedtxt::
|
30
|
+
assert_equal exp, Feedtxt::YAML.parse( text )
|
31
31
|
assert_equal exp, Feedtxt.parse( text ) ## try shortcut alias too
|
32
32
|
end
|
33
33
|
|
@@ -55,7 +55,7 @@ class TestYaml < MiniTest::Test
|
|
55
55
|
"duration_in_seconds"=>6629}]},
|
56
56
|
"Chris has worked at [Adobe][1] and as a founder of Rogue Sheep, which won an Apple Design Award for Postage.\nChris's new company is Aged & Distilled with Guy English - which shipped [Napkin](2),\na Mac app for visual collaboration. Chris is also the co-host of The Record.\nHe lives on [Bainbridge Island][3], a quick ferry ride from Seattle.\n\n[1]: http://adobe.com/\n[2]: http://aged-and-distilled.com/napkin/\n[3]: http://www.ci.bainbridge-isl.wa.us/"]]]
|
57
57
|
|
58
|
-
assert_equal exp, Feedtxt::
|
58
|
+
assert_equal exp, Feedtxt::YAML.parse( text )
|
59
59
|
assert_equal exp, Feedtxt.parse( text ) ## try shortcut alias too
|
60
60
|
end
|
61
61
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feedtxt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|