builder_quill_content 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe2c846562262a36f629a2ef2f85fb3ded5c64468063d8b5bb23fe87193ad4bc
4
- data.tar.gz: e38958119f562cc0a9e8048e4153b9617a4270be433b23f61a98ca8da7b6f893
3
+ metadata.gz: 7a429496940cc799aac61e49327b570719c9404a481d7e6da525b2d24e1126e0
4
+ data.tar.gz: d176ab3862550fdc67f51c3c32242ee4eb71da1d63ea7a81b7e3869b31245dfb
5
5
  SHA512:
6
- metadata.gz: 2c2016d43304a764d3fae7ebcd77114d58ef5397cdb5fb0fb58384edc330f40f63dfb2e0e5fbed3a877d1efdd19e685220401dc21b19b05067c217b9e4a4d912
7
- data.tar.gz: 318fc9d378cfe82a9b0bec943e8edd16ec97ec59e55fe274d5f7025c285c14de086acb476cc4b12cce4be3dcb60e2e0dbabbf195bf2c4f0ab9f1c7119e5c5b87
6
+ metadata.gz: 8049f7391cd8d027535525f6c369a32654fa3f6b0007ffae78d63e91721a85e7bc894b294460f1066d5d16094c9faf721b1a8a4af53621157e6a9c295511afa2
7
+ data.tar.gz: 1427642ff5fd0c347c1568ebfbf73e2e42093be042f4723d606b828c7522f9b4812245b169cbcd0fbbb5965fdffc37e30c422e4c13eab8ff0244d4e8f01849e3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- builder_quill_content (0.1.6)
4
+ builder_quill_content (0.1.7)
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', '~> 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
- include BuilderQuillContent
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
- module BuilderQuillContent
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 to_html(input)
12
- content_json = JSON.parse(input)
13
- line = content = ''
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
- content, line = end_of_line(content, line, node['attributes'])
20
- elsif node['insert'].include?("\n")
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(content, line, attributes)
33
- content += attributes.nil? ? "<p>#{line}</p>" : ConvertInline.new('insert' => line, 'attributes' => attributes).convert
34
- [content, '']
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(content, line, insert)
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(content, line, node)
50
- return [content + ConvertInline.new(node).convert, line] if embed_node?(node)
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
- true
57
+ node['insert'].keys.find { |k| EMBED_KEYS.include?(k) }
60
58
  end
61
59
  end
@@ -1,3 +1,3 @@
1
1
  module BuilderQuillContent
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
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: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Tran