booklab-toc 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 +4 -4
- data/lib/booklab/toc/version.rb +1 -1
- data/lib/booklab-toc.rb +26 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dcff03faea9255ce3e885606b9e3525424ca713c68c4f95e243118744222dc3
|
4
|
+
data.tar.gz: 9b4a848863736348b8eb7b13912eb79640592146595fb97e4ad67d5fabed5685
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28d3a4fa6ebc7b55d0aea9d46bf7db5e861c6ad9f9a14841c261e404a02eb77871ed25c9bddce8ac53e6c597e144b4c13410ebe25a449f19e7ef1ef2f3f8e38e
|
7
|
+
data.tar.gz: 404e6d25c860389a251015b6ca2568c92cca598214fadae1381e40f0a48ba0ce702562f99079c93800cd07aa6d30a9ed95dd5d7e288693e58255b1bd38f132f9
|
data/lib/booklab/toc/version.rb
CHANGED
data/lib/booklab-toc.rb
CHANGED
@@ -5,28 +5,37 @@ require "booklab/toc/format/markdown"
|
|
5
5
|
|
6
6
|
module BookLab
|
7
7
|
module Toc
|
8
|
+
class FormatError < Exception; end
|
9
|
+
|
8
10
|
extend ActiveSupport::Autoload
|
9
11
|
|
12
|
+
class << self
|
13
|
+
delegate :logger, to: Rails
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
def parse(raw, format: :yml, strict: false)
|
16
|
+
items = []
|
17
|
+
datas = []
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
case format
|
20
|
+
when :yml
|
21
|
+
datas = YAML.load(raw)
|
22
|
+
when :json
|
23
|
+
datas = JSON.load(raw)
|
24
|
+
when :markdown
|
25
|
+
datas = Format::Markdown.load(raw)
|
26
|
+
else
|
27
|
+
raise "format: #{format} not implement"
|
28
|
+
end
|
25
29
|
|
26
|
-
|
27
|
-
|
30
|
+
datas.each do |obj|
|
31
|
+
items << ListItem.new(obj.to_hash.deep_symbolize_keys)
|
32
|
+
end
|
33
|
+
Content.new(items)
|
34
|
+
rescue => e
|
35
|
+
raise FormatError.new(e.message) if strict
|
36
|
+
logger.warn "BookLab::Toc.parse error:\n#{e.inspect}"
|
37
|
+
Content.new([])
|
28
38
|
end
|
29
|
-
Content.new(items)
|
30
39
|
end
|
31
40
|
end
|
32
|
-
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: booklab-toc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|