builder_quill_content 0.1.6 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe2c846562262a36f629a2ef2f85fb3ded5c64468063d8b5bb23fe87193ad4bc
4
- data.tar.gz: e38958119f562cc0a9e8048e4153b9617a4270be433b23f61a98ca8da7b6f893
3
+ metadata.gz: d69e69b06a06aeafa2bc2f53750a5eba9636ab4cfbeeb93ffb11aafebf16cc1d
4
+ data.tar.gz: bf3bea2def8c509934b210386bacdb32ffbcc1b011d019dc9d2270440e7551fe
5
5
  SHA512:
6
- metadata.gz: 2c2016d43304a764d3fae7ebcd77114d58ef5397cdb5fb0fb58384edc330f40f63dfb2e0e5fbed3a877d1efdd19e685220401dc21b19b05067c217b9e4a4d912
7
- data.tar.gz: 318fc9d378cfe82a9b0bec943e8edd16ec97ec59e55fe274d5f7025c285c14de086acb476cc4b12cce4be3dcb60e2e0dbabbf195bf2c4f0ab9f1c7119e5c5b87
6
+ metadata.gz: 62dfd4769ac786e5dbfca6290b8bdd0fbb896433c7cffbf2358061c7b29fe3a6f54b7c9d0897e77f77625bd772cd6e5fe28baad7388fe1a78a71c3aa80e754e8
7
+ data.tar.gz: baac23da0c5c0c7ac2a8decea56286785636391d0ba40367fa868675bf65f756f25908626590bdacb745f6048a99f29c0de3c11ce4181091964885798901282c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- builder_quill_content (0.1.6)
4
+ builder_quill_content (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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.6'
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
- include BuilderQuillContent
24
+ BuilderQuillContent.new(quill_content, { title: 'for blank caption' }).to_html
25
25
  ```
26
26
 
27
- then
27
+ ## ChangeLog
28
28
 
29
- ```ruby
30
- to_html(quill_content)
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/michaelt0520/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/michaelt0520/builder_quill_content/blob/master/CODE_OF_CONDUCT.md).
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/michaelt0520/builder_quill_content/blob/master/CODE_OF_CONDUCT.md).
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).
@@ -1,14 +1,14 @@
1
1
  require_relative 'lib/builder_quill_content/version'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.name = "builder_quill_content"
4
+ spec.name = 'builder_quill_content'
5
5
  spec.version = BuilderQuillContent::VERSION
6
- spec.authors = ["Michael Tran"]
7
- spec.email = ["mictran205@gmail.com"]
6
+ spec.authors = ['Michael Tran']
7
+ spec.email = ['mictran205@gmail.com']
8
8
 
9
- spec.summary = "Convert quill content to html for wakuwaku"
10
- spec.homepage = "https://github.com/1PACVietnam/wakuwaku-builder_quill_content"
11
- spec.license = "MIT"
9
+ spec.summary = 'Convert quill content to html for wakuwaku'
10
+ spec.homepage = 'https://github.com/1PACVietnam/wakuwaku-builder_quill_content'
11
+ spec.license = 'MIT'
12
12
  # spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
13
 
14
14
  # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
23
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
24
  end
25
- spec.bindir = "exe"
25
+ spec.bindir = 'exe'
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
27
+ spec.require_paths = ['lib']
28
28
  end
@@ -1,61 +1,65 @@
1
- require "builder_quill_content/version"
2
- require "json"
3
- require "convert_inline"
1
+ require 'builder_quill_content/version'
2
+ require 'json'
3
+ require 'convert_inline'
4
4
 
5
- module BuilderQuillContent
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 to_html(input)
12
- content_json = JSON.parse(input)
13
- line = content = ''
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
- content, line = end_of_line(content, line, node['attributes'])
26
+ end_of_line(node['attributes'])
20
27
  elsif node['insert'].include?("\n")
21
- content, line = break_line(content, line, node['insert'])
28
+ break_line(node['insert'])
22
29
  else
23
- content, line = inline(content, line, node)
30
+ inline(node)
24
31
  end
25
32
  end
26
33
 
27
- content.gsub('</ul><ul>', '')
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(content, line, attributes)
33
- content += attributes.nil? ? "<p>#{line}</p>" : ConvertInline.new('insert' => line, 'attributes' => attributes).convert
34
- [content, '']
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(content, line, insert)
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(content, line, node)
50
- return [content + ConvertInline.new(node).convert, line] if embed_node?(node)
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
- true
63
+ node['insert'].keys.find { |k| EMBED_KEYS.include?(k) }
60
64
  end
61
65
  end
@@ -1,3 +1,3 @@
1
- module BuilderQuillContent
2
- VERSION = "0.1.6"
1
+ class BuilderQuillContent
2
+ VERSION = '1.2.1'.freeze
3
3
  end
@@ -2,23 +2,26 @@ 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.keys.each { |attr| @insert = send(attr) }
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
21
22
 
23
+ @insert
24
+ rescue NoMethodError
22
25
  @insert
23
26
  end
24
27
 
@@ -41,7 +44,7 @@ class ConvertInline
41
44
  end
42
45
 
43
46
  def link
44
- '<a href="' + @attributes['link'] + '" target="_blank">' + @insert + '</a>'
47
+ '<a href="' << @attributes['link'] << '" target="_blank">' << @insert << '</a>'
45
48
  end
46
49
 
47
50
  def list
@@ -51,19 +54,20 @@ class ConvertInline
51
54
  def embed(key)
52
55
  return '<hr>' if key == 'wk-divider'
53
56
 
54
- '<div data-id="' + key + '" data-src="' + @insert[key] + '"></div>'
57
+ '<div data-id="' << key << '" data-src="' << @insert[key] << '"></div>'
55
58
  end
56
59
 
57
60
  def image
58
- img_src = @insert['wk-image']['src'] || @attributes['src']
59
- img_cap = @insert['wk-image']['caption']
60
- img_alt = @attributes['alt']
61
-
61
+ invalid_cap = @insert['wk-image']['caption'].nil? || @insert['wk-image']['caption'].strip.empty?
62
+ img_src = @insert['wk-image']['src'] || @attributes['src'] || @insert['wk-image']
63
+ img_cap = invalid_cap ? '' : @insert['wk-image']['caption']
64
+ img_alt = invalid_cap ? args[:title] : @insert['wk-image']['caption']
62
65
  return '' if img_src.nil?
63
66
 
64
- '<figure class="post-content-image-container">
65
- <img class="post-content-image lazy blur" data-src="' + img_src + '" alt="' + img_alt + '">
66
- <figcaption class="post-image-caption u-text-center">' + img_cap + '</figcaption>
67
- </figure>'
67
+ data = '<figure class="post-content-image-container">'
68
+ data << '<img class="post-content-image lazy blur" data-src="' << img_src << '" alt="' << img_alt << '">'
69
+ data << '<figcaption class="post-image-caption u-text-center">' << img_cap << '</figcaption>'
70
+ data << '</figure>'
71
+ data
68
72
  end
69
73
  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: 0.1.6
4
+ version: 1.2.1
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-03-04 00:00:00.000000000 Z
11
+ date: 2020-11-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description:
14
14
  email:
15
15
  - mictran205@gmail.com
16
16
  executables: []
@@ -26,6 +26,7 @@ files:
26
26
  - Rakefile
27
27
  - bin/console
28
28
  - bin/setup
29
+ - builder_quill_content-1.2.0.gem
29
30
  - builder_quill_content.gemspec
30
31
  - lib/builder_quill_content.rb
31
32
  - lib/builder_quill_content/version.rb
@@ -34,7 +35,7 @@ homepage: https://github.com/1PACVietnam/wakuwaku-builder_quill_content
34
35
  licenses:
35
36
  - MIT
36
37
  metadata: {}
37
- post_install_message:
38
+ post_install_message:
38
39
  rdoc_options: []
39
40
  require_paths:
40
41
  - lib
@@ -49,8 +50,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
50
  - !ruby/object:Gem::Version
50
51
  version: '0'
51
52
  requirements: []
52
- rubygems_version: 3.1.2
53
- signing_key:
53
+ rubygems_version: 3.1.4
54
+ signing_key:
54
55
  specification_version: 4
55
56
  summary: Convert quill content to html for wakuwaku
56
57
  test_files: []