builder_quill_content 1.1.0 → 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/README.md +8 -2
- data/lib/builder_quill_content.rb +8 -7
- data/lib/builder_quill_content/version.rb +1 -1
- data/lib/convert_inline.rb +13 -12
- metadata +7 -7
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/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', '~> 1.
|
10
|
+
gem 'builder_quill_content', '~> 1.2.0'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -21,11 +21,17 @@ Or install it yourself as:
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
BuilderQuillContent.new(quill_content).to_html
|
24
|
+
BuilderQuillContent.new(quill_content, { title: 'for blank caption' }).to_html
|
25
25
|
```
|
26
26
|
|
27
27
|
## ChangeLog
|
28
28
|
|
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
|
+
|
29
35
|
### Version 1.1 - 03/12/2020
|
30
36
|
|
31
37
|
```
|
@@ -1,17 +1,18 @@
|
|
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
|
9
|
+
attr_accessor :input, :args
|
10
10
|
|
11
11
|
EMBED_KEYS = %w[wk-image wk-youtube wk-tweet wk-instagram wk-divider waku-post wk-maps].freeze
|
12
12
|
|
13
|
-
def initialize(input)
|
13
|
+
def initialize(input, args = {})
|
14
14
|
@input = input
|
15
|
+
@args = args
|
15
16
|
@line = @content = ''
|
16
17
|
end
|
17
18
|
|
@@ -37,7 +38,7 @@ class BuilderQuillContent
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def end_of_line(attributes)
|
40
|
-
@content += attributes.nil? ? "<p>#{@line}</p>" : ConvertInline.new('insert' => @line, 'attributes' => attributes).convert
|
41
|
+
@content += attributes.nil? ? "<p>#{@line}</p>" : ConvertInline.new({ 'insert' => @line, 'attributes' => attributes }, args).convert
|
41
42
|
@line = ''
|
42
43
|
end
|
43
44
|
|
@@ -53,7 +54,7 @@ class BuilderQuillContent
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def inline(node)
|
56
|
-
embed_node?(node) ? @content += ConvertInline.new(node).convert : @line += ConvertInline.new(node).convert
|
57
|
+
embed_node?(node) ? @content += ConvertInline.new(node, args).convert : @line += ConvertInline.new(node, args).convert
|
57
58
|
end
|
58
59
|
|
59
60
|
def embed_node?(node)
|
data/lib/convert_inline.rb
CHANGED
@@ -2,19 +2,20 @@ 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
17
|
if @insert.is_a?(String)
|
17
|
-
@attributes.
|
18
|
+
@attributes.each_key { |attr| @insert = send(attr) }
|
18
19
|
else
|
19
20
|
@insert = @insert.keys.first == 'wk-image' ? image : embed(@insert.keys.first)
|
20
21
|
end
|
@@ -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,19 +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
61
|
img_src = @insert['wk-image']['src'] || @attributes['src'] || @insert['wk-image']
|
61
|
-
img_cap = @insert['wk-image']['caption']
|
62
|
-
img_alt = @
|
63
|
-
|
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
64
|
return '' if img_src.nil?
|
65
65
|
|
66
|
-
'<figure class="post-content-image-container">
|
67
|
-
|
68
|
-
|
69
|
-
</figure>'
|
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
|
70
71
|
end
|
71
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: 1.
|
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: []
|
@@ -34,7 +34,7 @@ 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: []
|