html_to 0.0.2 → 0.7.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 +59 -17
- data/html_to.gemspec +4 -3
- data/lib/html_to.rb +9 -2
- data/lib/html_to/chromium_controll.rb +20 -0
- data/lib/html_to/html_headless.rb +2 -15
- data/lib/html_to/share_uploader.rb +7 -0
- data/lib/html_to/sharing_image_generate.rb +1 -0
- metadata +22 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 945d0a2a34a669ead1e062b571c88d906e47a3c9a4c2680fdef542374b35c646
|
4
|
+
data.tar.gz: cc9c891b010fb627d4f6dcc14f0a9a1eb6ee0527c926dbeb6290b13c79a25604
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f89275b24e49d19ab756d8bb750ca90105d7705ea7543305e01d2759dc33be8378083dcf49151b8bd22736a1052ef28c5e8d3b71fbde18b8b04c9db91373a89
|
7
|
+
data.tar.gz: '028fad20941e6ddf36ed8214f4a2a1980b70d0392ac3a493ffe51297f57605210864762b614a22b3dc3e203d7e789ff5bc1757b726a6cb6cb0f9c28afc1d2278'
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# html-to
|
2
2
|
# install
|
3
3
|
``` ruby
|
4
|
-
gem 'html_to'
|
4
|
+
gem 'html_to'
|
5
5
|
```
|
6
|
+
And also you need headless browser chrome
|
7
|
+
|
6
8
|
Ubuntu:
|
7
9
|
``` bash
|
8
10
|
sudo apt install -y chromium-browser
|
@@ -12,24 +14,64 @@ Debian:
|
|
12
14
|
```bash
|
13
15
|
apt-get install chromium chromium-l10n
|
14
16
|
```
|
17
|
+
|
15
18
|
# Get Started
|
19
|
+
### Prepare your model
|
20
|
+
1) do migrate string field for uploader
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
<style >
|
23
|
-
.
|
24
|
-
.
|
25
|
-
.
|
26
|
-
</style>
|
22
|
+
and add start to your model, what you want use
|
23
|
+
``` ruby
|
24
|
+
@@share_uploader = "share_image"
|
25
|
+
@@share_template = 'share/post'
|
26
|
+
include HtmlTo
|
27
27
|
```
|
28
|
-
Html в headless браузере будет запускатся из папки /public все шрифты и дополнительные файлы нужно класть туда.
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
### creating template file
|
30
|
+
|
31
|
+
you need create, on path ```@@share_template``` how example share/post will be ```app/views/share/post.html.erb```
|
32
|
+
|
33
|
+
######template file example:
|
34
|
+
``` html
|
35
|
+
<!DOCTYPE html>
|
36
|
+
<html lang="en">
|
37
|
+
<head>
|
38
|
+
<meta charset="UTF-8">
|
39
|
+
<title>Title</title>
|
40
|
+
<style>
|
41
|
+
|
42
|
+
body {
|
43
|
+
margin: 0;
|
44
|
+
}
|
45
|
+
.image {
|
46
|
+
background-size: cover;
|
47
|
+
position: absolute;
|
48
|
+
float: left;
|
49
|
+
top: 0px;
|
50
|
+
width: 1200px;
|
51
|
+
height: 630px;
|
52
|
+
object-fit: y-repeat;
|
53
|
+
|
54
|
+
}
|
55
|
+
.description{
|
56
|
+
position: absolute;
|
57
|
+
font-size: 48px;
|
58
|
+
z-index: 1;
|
59
|
+
}
|
60
|
+
|
61
|
+
</style>
|
62
|
+
</head>
|
63
|
+
<body>
|
64
|
+
<div class="root">
|
65
|
+
<img class='image' src="https://images.unsplash.com/photo-1593642702821-c8da6771f0c6?ixid=MXwxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1489&q=80">
|
66
|
+
<p class="description">
|
67
|
+
<%=obj.attributes%>
|
68
|
+
</p>
|
69
|
+
</div>
|
70
|
+
</body>
|
71
|
+
</html>
|
72
|
+
|
35
73
|
```
|
74
|
+
In your template file you has access to your object via @obj
|
75
|
+
|
76
|
+
###### Assets, font, etc
|
77
|
+
Headless browser will be start from Rails public path, all local assets should be access in the public folder.
|
data/html_to.gemspec
CHANGED
@@ -2,8 +2,8 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'html_to'
|
5
|
-
s.version = '0.0
|
6
|
-
s.date = '
|
5
|
+
s.version = '0.7.0'
|
6
|
+
s.date = '2021-04-07'
|
7
7
|
s.summary = 'Html-To transforms html to other format'
|
8
8
|
s.description = 'Simple gem for transforms html page through chromium headless.'
|
9
9
|
s.author = 'Chekryzhov Viktor'
|
@@ -11,5 +11,6 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = 'https://github.com/Vchekryzhov/html-to'
|
12
12
|
s.license = 'MIT'
|
13
13
|
s.files = `git ls-files`.split("\n")
|
14
|
-
s.add_dependency 'sidekiq'
|
14
|
+
s.add_dependency 'sidekiq'
|
15
|
+
s.add_dependency 'carrierwave'
|
15
16
|
end
|
data/lib/html_to.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module HtmlTo
|
3
2
|
extend ActiveSupport::Concern
|
3
|
+
require 'carrierwave'
|
4
4
|
require 'html_to/html_headless.rb'
|
5
5
|
require 'html_to/sharing_image_generate.rb'
|
6
|
+
require 'html_to/share_uploader.rb'
|
6
7
|
included do
|
7
8
|
after_commit :share_image_generate, unless: :skip_share_image_generate
|
8
9
|
attr_accessor :skip_share_image_generate
|
10
|
+
|
11
|
+
|
12
|
+
raise 'Message from html_to: @@share_uploader not present' if class_variable_get(:@@share_uploader).nil?
|
13
|
+
raise 'Message from html_to: @@share_template not present' if class_variable_get(:@@share_template).nil?
|
14
|
+
raise "Message from html_to: share template file #{Rails.root.join('app/views').join(class_variable_get(:@@share_template)+'.html.erb')} not exist" if !File.exist?(Rails.root.join('app/views').join(class_variable_get(:@@share_template)+".html.erb"))
|
15
|
+
mount_uploader class_variable_get(:@@share_uploader), -> { class_variable_get(:@@override_uploader) rescue HtmlTo::ShareUploader }.call
|
9
16
|
end
|
10
17
|
|
11
18
|
def share_image_generate
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module HtmlTo::ChromiumControll
|
2
|
+
def chrome
|
3
|
+
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
4
|
+
"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
|
5
|
+
elsif RbConfig::CONFIG['host_os'] =~ /linux/
|
6
|
+
release = IO.popen("lsb_release -i -s").read
|
7
|
+
if release == "Debian\n"
|
8
|
+
`dpkg -s chromium`
|
9
|
+
raise "html_to message: You don't have chromium, please do apt install chromium"if !$?.success?
|
10
|
+
'chromium'
|
11
|
+
else
|
12
|
+
`dpkg -s chromium-browser`
|
13
|
+
raise "html_to message: You don't have chromium, please do apt install chromium"if !$?.success?
|
14
|
+
'chromium-browser'
|
15
|
+
end
|
16
|
+
else
|
17
|
+
raise StandardError.new "host os don't detected"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
class HtmlTo::HtmlHeadless
|
2
2
|
require 'fileutils'
|
3
|
+
require 'html_to/chromium_controll.rb'
|
4
|
+
include HtmlTo::ChromiumControll
|
3
5
|
|
4
6
|
def to_image(obj, width=1200, height=630)
|
5
7
|
|
@@ -30,21 +32,6 @@ class HtmlTo::HtmlHeadless
|
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
|
-
def chrome
|
34
|
-
if RbConfig::CONFIG['host_os'] =~ /darwin/
|
35
|
-
"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
|
36
|
-
elsif RbConfig::CONFIG['host_os'] =~ /linux/
|
37
|
-
release = IO.popen("lsb_release -i -s").read
|
38
|
-
if release == "Debian\n"
|
39
|
-
'chromium'
|
40
|
-
else
|
41
|
-
'chromium-browser'
|
42
|
-
end
|
43
|
-
else
|
44
|
-
raise StandardError.new "host os don't detected"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
35
|
def html_file_path
|
49
36
|
@path ||= Rails.public_path.join(SecureRandom.urlsafe_base64.downcase + ".html")
|
50
37
|
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_to
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chekryzhov Viktor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: carrierwave
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: Simple gem for transforms html page through chromium headless.
|
28
42
|
email: chekryzhov@charmerstudio.com
|
29
43
|
executables: []
|
@@ -36,7 +50,9 @@ files:
|
|
36
50
|
- gemfile
|
37
51
|
- html_to.gemspec
|
38
52
|
- lib/html_to.rb
|
53
|
+
- lib/html_to/chromium_controll.rb
|
39
54
|
- lib/html_to/html_headless.rb
|
55
|
+
- lib/html_to/share_uploader.rb
|
40
56
|
- lib/html_to/sharing_image_generate.rb
|
41
57
|
homepage: https://github.com/Vchekryzhov/html-to
|
42
58
|
licenses:
|