builder_quill_content 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +19 -0
- data/README.md +11 -5
- data/lib/builder_quill_content/version.rb +1 -1
- data/lib/builder_quill_content.rb +2 -1
- data/lib/convert_inline.rb +69 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e023af34330b25deb4a0bed2dd70414fac750e402db0444f2716f10d956ccdf
|
4
|
+
data.tar.gz: d8fea6d216a75af9320b539327420ab5467fcfc66c2482af858c249b49172dc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dff753fd24aae483d6a82fbcd73fb973c9fffbc30eb8d42ebf79058639f6bd84eb303f39e287394eb3ab8d9ee5f2411925e98450825a9b878663abb61de0f78f
|
7
|
+
data.tar.gz: 8788aa0e659704fa80cf82421fbf03fbb3127dd2c64782d78c0c189701005eac4bb76fdcad5d70c76ba0887e2b04f4ec79122f3ab3bbfdc349db986ff73d6d62
|
data/Gemfile.lock
ADDED
data/README.md
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/builder_quill_content`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
5
|
## Installation
|
8
6
|
|
9
7
|
Add this line to your application's Gemfile:
|
@@ -22,7 +20,15 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
```ruby
|
24
|
+
include BuilderQuillContent
|
25
|
+
```
|
26
|
+
|
27
|
+
then
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
to_html(quill_content)
|
31
|
+
```
|
26
32
|
|
27
33
|
## Development
|
28
34
|
|
@@ -32,7 +38,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
38
|
|
33
39
|
## Contributing
|
34
40
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
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).
|
36
42
|
|
37
43
|
|
38
44
|
## License
|
@@ -41,4 +47,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
41
47
|
|
42
48
|
## Code of Conduct
|
43
49
|
|
44
|
-
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/
|
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).
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require "builder_quill_content/version"
|
2
2
|
require "json"
|
3
|
-
require "convert_inline"
|
4
3
|
|
5
4
|
module BuilderQuillContent
|
6
5
|
class Error < StandardError; end
|
@@ -25,6 +24,8 @@ module BuilderQuillContent
|
|
25
24
|
end
|
26
25
|
|
27
26
|
content.gsub('</ul><ul>', '')
|
27
|
+
rescue JSON::ParserError
|
28
|
+
'No content'
|
28
29
|
end
|
29
30
|
|
30
31
|
def end_of_line(content, line, attributes)
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class ConvertInline
|
2
|
+
class Error < StandardError; end
|
3
|
+
# Your code goes here...
|
4
|
+
|
5
|
+
attr_accessor :node, :insert, :attributes
|
6
|
+
|
7
|
+
def initialize(node)
|
8
|
+
@node = node
|
9
|
+
@insert = @node['insert']
|
10
|
+
@attributes = @node['attributes']
|
11
|
+
end
|
12
|
+
|
13
|
+
def convert
|
14
|
+
return @insert if @insert.is_a?(String) && @attributes.nil?
|
15
|
+
|
16
|
+
content = ''
|
17
|
+
|
18
|
+
if @insert.is_a?(String)
|
19
|
+
@attributes.keys.each { |attr| content += send(attr) }
|
20
|
+
else
|
21
|
+
content = @insert.keys.first == 'wk-image' ? image : embed(@insert.keys.first)
|
22
|
+
end
|
23
|
+
|
24
|
+
content
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def italic
|
30
|
+
"<em>#{@insert}</em>"
|
31
|
+
end
|
32
|
+
|
33
|
+
def bold
|
34
|
+
"<strong>#{@insert}</strong>"
|
35
|
+
end
|
36
|
+
|
37
|
+
def header
|
38
|
+
"<h#{@attributes['header']}>#{@insert}</h#{@attributes['header']}>"
|
39
|
+
end
|
40
|
+
|
41
|
+
def blockquote
|
42
|
+
"<blockquote>#{@insert}</blockquote>"
|
43
|
+
end
|
44
|
+
|
45
|
+
def link
|
46
|
+
'<a href="' + @attributes['link'] + '" target="_blank">' + @insert + '</a>'
|
47
|
+
end
|
48
|
+
|
49
|
+
def list
|
50
|
+
"<ul><li>#{@insert}</li></ul>"
|
51
|
+
end
|
52
|
+
|
53
|
+
def embed(key)
|
54
|
+
return '<hr>' if key == 'wk-divider'
|
55
|
+
|
56
|
+
'<div data-id="' + key + '" data-src="' + @insert[key] + '"></div>'
|
57
|
+
end
|
58
|
+
|
59
|
+
def image
|
60
|
+
img_src = @insert['wk-image']['src']
|
61
|
+
img_cap = @insert['wk-image']['caption']
|
62
|
+
img_alt = @attributes['alt']
|
63
|
+
|
64
|
+
'<figure class="post-content-image-container">
|
65
|
+
<img class="post-content-image lazy" data-src="' + img_src + '" alt="' + img_alt + '">
|
66
|
+
<figcaption class="post-image-caption u-text-center">' + img_cap + '</figcaption>
|
67
|
+
</figure>'
|
68
|
+
end
|
69
|
+
end
|
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.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Tran
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- ".gitignore"
|
21
21
|
- CODE_OF_CONDUCT.md
|
22
22
|
- Gemfile
|
23
|
+
- Gemfile.lock
|
23
24
|
- LICENSE.txt
|
24
25
|
- README.md
|
25
26
|
- Rakefile
|
@@ -28,6 +29,7 @@ files:
|
|
28
29
|
- builder_quill_content.gemspec
|
29
30
|
- lib/builder_quill_content.rb
|
30
31
|
- lib/builder_quill_content/version.rb
|
32
|
+
- lib/convert_inline.rb
|
31
33
|
homepage: https://github.com/michaelt0520/builder_quill_content
|
32
34
|
licenses:
|
33
35
|
- MIT
|