builder_quill_content 0.1.6 → 0.1.7
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/Gemfile.lock +1 -1
- data/README.md +2 -8
- data/lib/builder_quill_content.rb +24 -26
- data/lib/builder_quill_content/version.rb +1 -1
- data/lib/convert_inline.rb +5 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a429496940cc799aac61e49327b570719c9404a481d7e6da525b2d24e1126e0
|
4
|
+
data.tar.gz: d176ab3862550fdc67f51c3c32242ee4eb71da1d63ea7a81b7e3869b31245dfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8049f7391cd8d027535525f6c369a32654fa3f6b0007ffae78d63e91721a85e7bc894b294460f1066d5d16094c9faf721b1a8a4af53621157e6a9c295511afa2
|
7
|
+
data.tar.gz: 1427642ff5fd0c347c1568ebfbf73e2e42093be042f4723d606b828c7522f9b4812245b169cbcd0fbbb5965fdffc37e30c422e4c13eab8ff0244d4e8f01849e3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Welcome to your new gem! In this directory, you'll find the files you need to be
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'builder_quill_content', '~> 0.1.
|
10
|
+
gem 'builder_quill_content', '~> 0.1.7'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -21,13 +21,7 @@ Or install it yourself as:
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
|
25
|
-
```
|
26
|
-
|
27
|
-
then
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
to_html(quill_content)
|
24
|
+
BuilderQuillContent.new(quill_content).to_html
|
31
25
|
```
|
32
26
|
|
33
27
|
## Development
|
@@ -2,60 +2,58 @@ require "builder_quill_content/version"
|
|
2
2
|
require "json"
|
3
3
|
require "convert_inline"
|
4
4
|
|
5
|
-
|
5
|
+
class BuilderQuillContent
|
6
6
|
class Error < StandardError; end
|
7
7
|
# Your code goes here...
|
8
8
|
|
9
|
+
attr_accessor :input
|
10
|
+
|
9
11
|
EMBED_KEYS = %w[wk-image wk-youtube wk-tweet wk-instagram wk-divider waku-post wk-maps].freeze
|
10
12
|
|
11
|
-
def
|
12
|
-
|
13
|
-
line
|
13
|
+
def initialize(input)
|
14
|
+
@input = input
|
15
|
+
@line = @content = ''
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_html
|
19
|
+
content_json = JSON.parse(@input)
|
14
20
|
|
15
21
|
while content_json.length.positive?
|
16
22
|
node = content_json.shift
|
17
23
|
|
18
|
-
if node['insert'] == "\n"
|
19
|
-
|
20
|
-
|
21
|
-
content, line = break_line(content, line, node['insert'])
|
22
|
-
else
|
23
|
-
content, line = inline(content, line, node)
|
24
|
-
end
|
24
|
+
end_of_line(node['attributes']) && next if node['insert'] == "\n"
|
25
|
+
break_line(node['insert']) && next if node['insert'].include?("\n")
|
26
|
+
inline(node)
|
25
27
|
end
|
26
28
|
|
27
|
-
content.gsub('</ul><ul>', '')
|
29
|
+
@content.gsub('</ul><ul>', '')
|
28
30
|
rescue JSON::ParserError
|
29
31
|
'No content'
|
30
32
|
end
|
31
33
|
|
32
|
-
def end_of_line(
|
33
|
-
content += attributes.nil? ? "<p>#{line}</p>" : ConvertInline.new('insert' => line, 'attributes' => attributes).convert
|
34
|
-
|
34
|
+
def end_of_line(attributes)
|
35
|
+
@content += attributes.nil? ? "<p>#{@line}</p>" : ConvertInline.new('insert' => @line, 'attributes' => attributes).convert
|
36
|
+
@line = ''
|
35
37
|
end
|
36
38
|
|
37
|
-
def break_line(
|
39
|
+
def break_line(insert)
|
38
40
|
insert.split(/(?<=\n)/).each do |text|
|
39
41
|
if text.end_with?("\n")
|
40
|
-
content += "<p>#{line}#{text.delete("\n")}</p>"
|
41
|
-
line = ''
|
42
|
+
@content += "<p>#{@line}#{text.delete("\n")}</p>"
|
43
|
+
@line = ''
|
42
44
|
else
|
43
|
-
line += text
|
45
|
+
@line += text
|
44
46
|
end
|
45
47
|
end
|
46
|
-
[content, line]
|
47
48
|
end
|
48
49
|
|
49
|
-
def inline(
|
50
|
-
|
51
|
-
|
52
|
-
[content, line + ConvertInline.new(node).convert]
|
50
|
+
def inline(node)
|
51
|
+
embed_node?(node) ? @content += ConvertInline.new(node).convert : @line += ConvertInline.new(node).convert
|
53
52
|
end
|
54
53
|
|
55
54
|
def embed_node?(node)
|
56
55
|
return false if node['insert'].is_a?(String)
|
57
|
-
return false unless node['insert'].keys.find { |k| EMBED_KEYS.include?(k) }
|
58
56
|
|
59
|
-
|
57
|
+
node['insert'].keys.find { |k| EMBED_KEYS.include?(k) }
|
60
58
|
end
|
61
59
|
end
|
data/lib/convert_inline.rb
CHANGED
@@ -19,6 +19,8 @@ class ConvertInline
|
|
19
19
|
@insert = @insert.keys.first == 'wk-image' ? image : embed(@insert.keys.first)
|
20
20
|
end
|
21
21
|
|
22
|
+
@insert
|
23
|
+
rescue NoMethodError
|
22
24
|
@insert
|
23
25
|
end
|
24
26
|
|
@@ -55,9 +57,9 @@ class ConvertInline
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def image
|
58
|
-
img_src = @insert['wk-image']['src'] || @attributes['src']
|
59
|
-
img_cap = @insert['wk-image']['caption']
|
60
|
-
img_alt = @attributes['alt']
|
60
|
+
img_src = @insert['wk-image']['src'] || @attributes['src'] || @insert['wk-image']
|
61
|
+
img_cap = @insert['wk-image']['caption'] || "Writer's image"
|
62
|
+
img_alt = @attributes['alt'] || 'post content image'
|
61
63
|
|
62
64
|
return '' if img_src.nil?
|
63
65
|
|