builder_quill_content 0.1.5 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +15 -7
- data/builder_quill_content.gemspec +1 -1
- data/lib/builder_quill_content.rb +29 -25
- data/lib/builder_quill_content/version.rb +2 -2
- data/lib/convert_inline.rb +20 -17
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2526f9efaf6443135a7b094de1946b440873fa78c32090b89bfbfed95318eaf9
|
4
|
+
data.tar.gz: 7df88bad7d6f0e5199985f028d659ce0ac20ad5cf0f590d299ee19831e296fb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adc3f8c32b9a324978866582820f5321dec0fbf76339a23fdccec80ff8d2749f98329fae730d653ea6c5084f85a0ec4e2a599fb83a7ca8753072760bf6adc539
|
7
|
+
data.tar.gz: bbc989cf463c3cd74861f3d536c8d308bb8352872d261ac8921924360768fcdd834ba8637d0f8b44bec1623216c005bf4d0adf8aa7ccfa164ed09bc7800c276a
|
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'
|
10
|
+
gem 'builder_quill_content', '~> 1.2.0'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -21,13 +21,21 @@ Or install it yourself as:
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
|
24
|
+
BuilderQuillContent.new(quill_content, { title: 'for blank caption' }).to_html
|
25
25
|
```
|
26
26
|
|
27
|
-
|
27
|
+
## ChangeLog
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
### Version 1.2 - 11/12/2020
|
30
|
+
|
31
|
+
```
|
32
|
+
Modify value of image alt to image's caption or post's title
|
33
|
+
```
|
34
|
+
|
35
|
+
### Version 1.1 - 03/12/2020
|
36
|
+
|
37
|
+
```
|
38
|
+
Fix bug add to content if the input have only 1 node and not include "\n"
|
31
39
|
```
|
32
40
|
|
33
41
|
## Development
|
@@ -38,7 +46,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
38
46
|
|
39
47
|
## Contributing
|
40
48
|
|
41
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/1PACVietnam/wakuwaku-builder_quill_content. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/1PACVietnam/wakuwaku-builder_quill_content/blob/master/CODE_OF_CONDUCT.md).
|
42
50
|
|
43
51
|
|
44
52
|
## License
|
@@ -47,4 +55,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
47
55
|
|
48
56
|
## Code of Conduct
|
49
57
|
|
50
|
-
Everyone interacting in the BuilderQuillContent project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
58
|
+
Everyone interacting in the BuilderQuillContent project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/1PACVietnam/wakuwaku-builder_quill_content/blob/master/CODE_OF_CONDUCT.md).
|
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.email = ["mictran205@gmail.com"]
|
8
8
|
|
9
9
|
spec.summary = "Convert quill content to html for wakuwaku"
|
10
|
-
spec.homepage = "https://github.com/
|
10
|
+
spec.homepage = "https://github.com/1PACVietnam/wakuwaku-builder_quill_content"
|
11
11
|
spec.license = "MIT"
|
12
12
|
# spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
13
|
|
@@ -1,61 +1,65 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'builder_quill_content/version'
|
2
|
+
require 'json'
|
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, :args
|
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
|
-
|
13
|
+
def initialize(input, args = {})
|
14
|
+
@input = input
|
15
|
+
@args = args
|
16
|
+
@line = @content = ''
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_html
|
20
|
+
content_json = JSON.parse(@input)
|
14
21
|
|
15
22
|
while content_json.length.positive?
|
16
23
|
node = content_json.shift
|
17
24
|
|
18
25
|
if node['insert'] == "\n"
|
19
|
-
|
26
|
+
end_of_line(node['attributes'])
|
20
27
|
elsif node['insert'].include?("\n")
|
21
|
-
|
28
|
+
break_line(node['insert'])
|
22
29
|
else
|
23
|
-
|
30
|
+
inline(node)
|
24
31
|
end
|
25
32
|
end
|
26
33
|
|
27
|
-
content.
|
34
|
+
@content += @line unless @line.strip.empty?
|
35
|
+
@content.gsub('</ul><ul>', '')
|
28
36
|
rescue JSON::ParserError
|
29
37
|
'No content'
|
30
38
|
end
|
31
39
|
|
32
|
-
def end_of_line(
|
33
|
-
content += attributes.nil? ? "<p>#{line}</p>" : ConvertInline.new('insert' => line, 'attributes' => attributes).convert
|
34
|
-
|
40
|
+
def end_of_line(attributes)
|
41
|
+
@content += attributes.nil? ? "<p>#{@line}</p>" : ConvertInline.new({ 'insert' => @line, 'attributes' => attributes }, args).convert
|
42
|
+
@line = ''
|
35
43
|
end
|
36
44
|
|
37
|
-
def break_line(
|
45
|
+
def break_line(insert)
|
38
46
|
insert.split(/(?<=\n)/).each do |text|
|
39
47
|
if text.end_with?("\n")
|
40
|
-
content += "<p>#{line}#{text.delete("\n")}</p>"
|
41
|
-
line = ''
|
48
|
+
@content += "<p>#{@line}#{text.delete("\n")}</p>"
|
49
|
+
@line = ''
|
42
50
|
else
|
43
|
-
line += text
|
51
|
+
@line += text
|
44
52
|
end
|
45
53
|
end
|
46
|
-
[content, line]
|
47
54
|
end
|
48
55
|
|
49
|
-
def inline(
|
50
|
-
|
51
|
-
|
52
|
-
[content, line + ConvertInline.new(node).convert]
|
56
|
+
def inline(node)
|
57
|
+
embed_node?(node) ? @content += ConvertInline.new(node, args).convert : @line += ConvertInline.new(node, args).convert
|
53
58
|
end
|
54
59
|
|
55
60
|
def embed_node?(node)
|
56
61
|
return false if node['insert'].is_a?(String)
|
57
|
-
return false unless node['insert'].keys.find { |k| EMBED_KEYS.include?(k) }
|
58
62
|
|
59
|
-
|
63
|
+
node['insert'].keys.find { |k| EMBED_KEYS.include?(k) }
|
60
64
|
end
|
61
65
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION =
|
1
|
+
class BuilderQuillContent
|
2
|
+
VERSION = '1.2.0'
|
3
3
|
end
|
data/lib/convert_inline.rb
CHANGED
@@ -2,26 +2,27 @@ class ConvertInline
|
|
2
2
|
class Error < StandardError; end
|
3
3
|
# Your code goes here...
|
4
4
|
|
5
|
-
attr_accessor :node, :insert, :attributes
|
5
|
+
attr_accessor :node, :insert, :attributes, :args
|
6
6
|
|
7
|
-
def initialize(node)
|
7
|
+
def initialize(node, args = {})
|
8
8
|
@node = node
|
9
9
|
@insert = @node['insert']
|
10
10
|
@attributes = @node['attributes']
|
11
|
+
@args = args
|
11
12
|
end
|
12
13
|
|
13
14
|
def convert
|
14
15
|
return @insert if @insert.is_a?(String) && @attributes.nil?
|
15
16
|
|
16
|
-
content = ''
|
17
|
-
|
18
17
|
if @insert.is_a?(String)
|
19
|
-
@attributes.
|
18
|
+
@attributes.each_key { |attr| @insert = send(attr) }
|
20
19
|
else
|
21
|
-
|
20
|
+
@insert = @insert.keys.first == 'wk-image' ? image : embed(@insert.keys.first)
|
22
21
|
end
|
23
22
|
|
24
|
-
|
23
|
+
@insert
|
24
|
+
rescue NoMethodError
|
25
|
+
@insert
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
@@ -43,7 +44,7 @@ class ConvertInline
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def link
|
46
|
-
'<a href="'
|
47
|
+
'<a href="' << @attributes['link'] << '" target="_blank">' << @insert << '</a>'
|
47
48
|
end
|
48
49
|
|
49
50
|
def list
|
@@ -53,17 +54,19 @@ class ConvertInline
|
|
53
54
|
def embed(key)
|
54
55
|
return '<hr>' if key == 'wk-divider'
|
55
56
|
|
56
|
-
'<div data-id="'
|
57
|
+
'<div data-id="' << key << '" data-src="' << @insert[key] << '"></div>'
|
57
58
|
end
|
58
59
|
|
59
60
|
def image
|
60
|
-
img_src = @insert['wk-image']['src']
|
61
|
-
img_cap = @insert['wk-image']['caption']
|
62
|
-
img_alt = @
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
</
|
61
|
+
img_src = @insert['wk-image']['src'] || @attributes['src'] || @insert['wk-image']
|
62
|
+
img_cap = @insert['wk-image']['caption'].strip.empty? ? '' : @insert['wk-image']['caption']
|
63
|
+
img_alt = @insert['wk-image']['caption'].strip.empty? ? args[:title] : @insert['wk-image']['caption']
|
64
|
+
return '' if img_src.nil?
|
65
|
+
|
66
|
+
data = '<figure class="post-content-image-container">'
|
67
|
+
data << '<img class="post-content-image lazy blur" data-src="' << img_src << '" alt="' << img_alt << '">'
|
68
|
+
data << '<figcaption class="post-image-caption u-text-center">' << img_cap << '</figcaption>'
|
69
|
+
data << '</figure>'
|
70
|
+
data
|
68
71
|
end
|
69
72
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: builder_quill_content
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Tran
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description:
|
14
14
|
email:
|
15
15
|
- mictran205@gmail.com
|
16
16
|
executables: []
|
@@ -30,11 +30,11 @@ files:
|
|
30
30
|
- lib/builder_quill_content.rb
|
31
31
|
- lib/builder_quill_content/version.rb
|
32
32
|
- lib/convert_inline.rb
|
33
|
-
homepage: https://github.com/
|
33
|
+
homepage: https://github.com/1PACVietnam/wakuwaku-builder_quill_content
|
34
34
|
licenses:
|
35
35
|
- MIT
|
36
36
|
metadata: {}
|
37
|
-
post_install_message:
|
37
|
+
post_install_message:
|
38
38
|
rdoc_options: []
|
39
39
|
require_paths:
|
40
40
|
- lib
|
@@ -49,8 +49,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '0'
|
51
51
|
requirements: []
|
52
|
-
rubygems_version: 3.1.
|
53
|
-
signing_key:
|
52
|
+
rubygems_version: 3.1.4
|
53
|
+
signing_key:
|
54
54
|
specification_version: 4
|
55
55
|
summary: Convert quill content to html for wakuwaku
|
56
56
|
test_files: []
|