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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3bedf49806d2f2f5319f238c5d1b63207a41b5ad2e38977e74516a3ddf9c7d8
4
- data.tar.gz: a00e4081875eae7be5d02654cc983d95c599199aa26f77dd8888d22fdbdcca3f
3
+ metadata.gz: 945d0a2a34a669ead1e062b571c88d906e47a3c9a4c2680fdef542374b35c646
4
+ data.tar.gz: cc9c891b010fb627d4f6dcc14f0a9a1eb6ee0527c926dbeb6290b13c79a25604
5
5
  SHA512:
6
- metadata.gz: 8227785a68ec0d480b9aac58df8d15c6d4e6b39f5fad87ee38eced5bbd0fcbca14efd9306d2adc8727f90470b6c73470184f770909c8d070ccbe29c27e268087
7
- data.tar.gz: 73742b8136ee0292521f81b7c441801d1e8d0f689d1f6ccb66eac606ee355e04903c6eea44c5372c4c2e96ffd4ff26d116135df4e278de1139cacba075016ee8
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', git: 'git@github.com:Vchekryzhov/html-to.git'
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
- 1)Создать html.erb файл со стилями в самом файле и путями до картинки на сервере.
18
- > /app/view/share/post.html.erb
19
- ``` html
20
- <p> <%= obj.title %> </p>
21
- <img src="obj.preview_image.path" >
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
- 2) В модели куда будут подключены шеры подключить модуль, указать путь до html и указать имя аплодера
31
- ``` ruby
32
- include HtmlTo
33
- @@share_template = 'share/post'
34
- @@share_uploader = 'meta_image'
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.2'
6
- s.date = '2019-08-31'
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', '~> 4'
14
+ s.add_dependency 'sidekiq'
15
+ s.add_dependency 'carrierwave'
15
16
  end
data/lib/html_to.rb CHANGED
@@ -1,11 +1,18 @@
1
- class HtmlTo < Module
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
@@ -0,0 +1,7 @@
1
+ class HtmlTo::ShareUploader < CarrierWave::Uploader::Base
2
+ include CarrierWave::MiniMagick
3
+ def store_dir
4
+ "storage/#{model.class.base_class.name.underscore}/#{model.id}/share"
5
+ end
6
+ process resize_to_limit: [1200, 630]
7
+ end
@@ -3,6 +3,7 @@ class HtmlTo::SharingImageGenerate
3
3
  require 'sidekiq'
4
4
  include Sidekiq::Worker
5
5
  sidekiq_options queue: 'default'
6
+
6
7
  def perform(id, class_name)
7
8
  @obj = class_name.constantize.find(id)
8
9
  HtmlTo::HtmlHeadless.new.to_image(@obj)
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.2
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: 2019-08-31 00:00:00.000000000 Z
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: '4'
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: '4'
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: