quill-builder 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/quill-builder-test +125 -0
- data/lib/quill/builder.rb +7 -0
- data/lib/quill/builder/base.rb +6 -0
- data/lib/quill/builder/html.rb +99 -0
- data/lib/quill/builder/version.rb +5 -0
- data/quill-builder.gemspec +27 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16830c61b44922a9075f810673a145569c9e24be
|
4
|
+
data.tar.gz: c6bd9f454ce7b61ac9ab0b2e2c8645c27e9b1331
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8bcf99442c0ce970254f172711eee0031f1d7c297537a39519ba82d8ece5bc867a8dd19b15ec38b09d8c5382a5d03e439bd66563fc52c69423770edf6cd17317
|
7
|
+
data.tar.gz: 3a79f1e2057be2d26bf9d68884ad44fd52dcce1c75538522677c89fdc0cd586d64600587419d88e2307a27077951bf14534a3109136d073b1366823edcab57a9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Code Ahss
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# QuillBuilder
|
2
|
+
|
3
|
+
QuillBuilder is converter from Quill.js output to HTML and so on.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'quill-builder'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install quill-builder
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/quill-builder.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "quill/builder"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# vim: filetype=ruby
|
3
|
+
$: << File.expand_path('../../lib/', __FILE__)
|
4
|
+
|
5
|
+
require 'socket'
|
6
|
+
require 'quill/builder/html'
|
7
|
+
|
8
|
+
class QuillBuilderTest
|
9
|
+
def initialize
|
10
|
+
server = TCPServer.new 1916
|
11
|
+
loop do
|
12
|
+
client = server.accept
|
13
|
+
headers = []
|
14
|
+
until (header = client.gets&.chomp)&.empty?
|
15
|
+
headers << header
|
16
|
+
end
|
17
|
+
body = nil
|
18
|
+
begin
|
19
|
+
body = client.read_nonblock(16677216)
|
20
|
+
rescue IO::WaitReadable
|
21
|
+
end
|
22
|
+
|
23
|
+
if headers.first.upcase.start_with?('GET')
|
24
|
+
client.puts toppage
|
25
|
+
elsif headers.first.upcase.start_with?('POST')
|
26
|
+
builder = Quill::Builder::HTML.new(body)
|
27
|
+
client.puts response(builder.convert)
|
28
|
+
else
|
29
|
+
end
|
30
|
+
client.close
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def response(body)
|
35
|
+
<<-RESPONSE
|
36
|
+
HTTP/1.0 200 OK
|
37
|
+
Content-Type: text/html
|
38
|
+
|
39
|
+
#{body}
|
40
|
+
RESPONSE
|
41
|
+
end
|
42
|
+
|
43
|
+
def toppage
|
44
|
+
<<-RESPONSE
|
45
|
+
HTTP/1.0 200 OK
|
46
|
+
Content-Type: text/html
|
47
|
+
|
48
|
+
<!DOCTYPE html>
|
49
|
+
<html>
|
50
|
+
<head>
|
51
|
+
<link href="//cdn.quilljs.com/1.3.3/quill.snow.css" rel="stylesheet">
|
52
|
+
<script src="//cdn.quilljs.com/1.3.3/quill.js" type="text/javascript"></script>
|
53
|
+
<style>
|
54
|
+
.ql-toolbar {
|
55
|
+
width: 400px;
|
56
|
+
}
|
57
|
+
#editor {
|
58
|
+
width: 400px;
|
59
|
+
height: 200px;
|
60
|
+
}
|
61
|
+
</style>
|
62
|
+
</head>
|
63
|
+
<body>
|
64
|
+
|
65
|
+
<div id="editor"></div>
|
66
|
+
<button id="save" type="submit">Save</button>
|
67
|
+
|
68
|
+
<p id="preview"></p>
|
69
|
+
|
70
|
+
<script>
|
71
|
+
var quill = new Quill('#editor', {
|
72
|
+
modules: {
|
73
|
+
toolbar: [
|
74
|
+
['bold', 'italic', 'underline', 'strike'],
|
75
|
+
[{ 'color': [] }, { 'background': [] }],
|
76
|
+
['link', 'blockquote', 'code-block', 'image'],
|
77
|
+
[{ list: 'ordered' }, { list: 'bullet' }]
|
78
|
+
]
|
79
|
+
},
|
80
|
+
placeholder: 'Edit...',
|
81
|
+
theme: 'snow'
|
82
|
+
});
|
83
|
+
var button = document.querySelector('button#save');
|
84
|
+
button.onclick = function() {
|
85
|
+
var xhr = new XMLHttpRequest();
|
86
|
+
xhr.onreadystatechange = function() {
|
87
|
+
switch (xhr.readyState) {
|
88
|
+
case 0:
|
89
|
+
console.log('uninitialized!');
|
90
|
+
break;
|
91
|
+
case 1:
|
92
|
+
console.log('loading...');
|
93
|
+
break;
|
94
|
+
case 2:
|
95
|
+
console.log('loaded.');
|
96
|
+
break;
|
97
|
+
case 3:
|
98
|
+
console.log('interactive... ' + xhr.responseText.length + ' bytes.');
|
99
|
+
break;
|
100
|
+
case 4:
|
101
|
+
if (xhr.status == 200 || xhr.status == 304) {
|
102
|
+
var data = xhr.responseText;
|
103
|
+
console.log('COMPLETE! :' + data);
|
104
|
+
var preview = document.querySelector('p#preview');
|
105
|
+
preview.innerHTML = data;
|
106
|
+
} else {
|
107
|
+
console.log('Failed. HttpStatus: ' + xhr.statusText);
|
108
|
+
}
|
109
|
+
break;
|
110
|
+
}
|
111
|
+
};
|
112
|
+
xhr.open('POST', '/', false);
|
113
|
+
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
114
|
+
xhr.send(JSON.stringify(quill.getContents()));
|
115
|
+
xhr.abort();
|
116
|
+
};
|
117
|
+
</script>
|
118
|
+
|
119
|
+
</body>
|
120
|
+
</html>
|
121
|
+
RESPONSE
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
QuillBuilderTest.new
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'quill/builder/base'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Quill::Builder
|
5
|
+
class HTML < Base
|
6
|
+
def initialize(text)
|
7
|
+
@text = text
|
8
|
+
end
|
9
|
+
|
10
|
+
def convert
|
11
|
+
convert_to_lines.map { |block|
|
12
|
+
outer_tag = block[:block]
|
13
|
+
inner = block[:inlines].inject('') { |memo, inline|
|
14
|
+
text = inline[:text].nil? ? '' : inline[:text]
|
15
|
+
text = text[0..-2] if text[-1] == "\n"
|
16
|
+
text = ' ' if text.empty? && block[:inlines].size == 1
|
17
|
+
memo + inline[:attrs].inject(text) { |memo, tag_pair|
|
18
|
+
"#{tag_pair.first}#{memo}#{tag_pair.last}"
|
19
|
+
}
|
20
|
+
}
|
21
|
+
case outer_tag
|
22
|
+
when Symbol
|
23
|
+
"<#{outer_tag}>#{inner}</#{outer_tag}>\n"
|
24
|
+
when Array
|
25
|
+
outer_tag.inject(inner) { |memo, tag|
|
26
|
+
"<#{tag}>#{memo}</#{tag}>"
|
27
|
+
} + "\n"
|
28
|
+
end
|
29
|
+
}.join
|
30
|
+
end
|
31
|
+
|
32
|
+
def convert_to_lines
|
33
|
+
json = JSON.parse(@text)
|
34
|
+
lines = json['ops'].inject([{ block: :p, inlines: [] }]) do |lines, item|
|
35
|
+
if item['attributes']&.keys&.include?('blockquote')
|
36
|
+
lines.last[:block] = [ :p, :blockquote ]
|
37
|
+
lines << { block: :p, inlines: [] }
|
38
|
+
elsif item['attributes']&.keys&.include?('code-block')
|
39
|
+
lines.last[:block] = :pre
|
40
|
+
lines << { block: :p, inlines: [] }
|
41
|
+
else
|
42
|
+
unless item['insert'] == "\n"
|
43
|
+
converted = convert_inline(item['insert'], item['attributes'])
|
44
|
+
partition_item_to_each_lines(lines, converted)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
lines
|
48
|
+
end
|
49
|
+
lines.pop if lines.last[:inlines].nil? || lines.last[:inlines].empty?
|
50
|
+
lines
|
51
|
+
end
|
52
|
+
|
53
|
+
def partition_item_to_each_lines(lines, converted)
|
54
|
+
if converted[:text].include?("\n")
|
55
|
+
splitted = converted[:text].split(/(?<=\n)/)
|
56
|
+
lines.last[:inlines] << {
|
57
|
+
text: splitted.shift,
|
58
|
+
attrs: converted[:attrs]
|
59
|
+
}
|
60
|
+
splitted.each do |l|
|
61
|
+
lines << { block: :p, inlines: [] }
|
62
|
+
lines.last[:inlines] << {
|
63
|
+
text: l,
|
64
|
+
attrs: converted[:attrs]
|
65
|
+
}
|
66
|
+
end
|
67
|
+
lines << { block: :p, inlines: [] } if converted[:text][-1] == "\n"
|
68
|
+
else
|
69
|
+
lines.last[:inlines] << converted
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def convert_inline(text, attributes)
|
74
|
+
attrs = []
|
75
|
+
if attributes
|
76
|
+
attributes.each_pair do |key, value|
|
77
|
+
case key
|
78
|
+
when 'bold'
|
79
|
+
attrs << ['<b>', '</b>']
|
80
|
+
when 'italic'
|
81
|
+
attrs << ['<i>', '</i>']
|
82
|
+
when 'underline'
|
83
|
+
attrs << ['<u>', '</u>']
|
84
|
+
when 'strike'
|
85
|
+
attrs << ['<s>', '</s>']
|
86
|
+
when 'background'
|
87
|
+
attrs << [%Q|<span style="background-color: #{value}">|, '</span>']
|
88
|
+
when 'color'
|
89
|
+
attrs << [%Q|<span style="color: #{value}">|, '</span>']
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
{
|
94
|
+
text: text,
|
95
|
+
attrs: attrs
|
96
|
+
}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "quill/builder/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "quill-builder"
|
8
|
+
spec.version = Quill::Builder::VERSION
|
9
|
+
spec.authors = ["Code Ahss"]
|
10
|
+
spec.email = ["aycabta@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{QuillBuilder is converter from Quill.js output to HTML and so on.}
|
13
|
+
spec.description = %q{QuillBuilder is converter from Quill.js output to HTML and so on.}
|
14
|
+
spec.homepage = "https://github.com/space-pirates-llc/quill-builder"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^test/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "test-unit", "~> 3.2"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quill-builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Code Ahss
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
description: QuillBuilder is converter from Quill.js output to HTML and so on.
|
56
|
+
email:
|
57
|
+
- aycabta@gmail.com
|
58
|
+
executables:
|
59
|
+
- quill-builder-test
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- exe/quill-builder-test
|
72
|
+
- lib/quill/builder.rb
|
73
|
+
- lib/quill/builder/base.rb
|
74
|
+
- lib/quill/builder/html.rb
|
75
|
+
- lib/quill/builder/version.rb
|
76
|
+
- quill-builder.gemspec
|
77
|
+
homepage: https://github.com/space-pirates-llc/quill-builder
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.6.13
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: QuillBuilder is converter from Quill.js output to HTML and so on.
|
101
|
+
test_files: []
|