jekyll-gensocial 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce45a392c7a7483af49f360f0fc7b4b87abe2e554732f241007f597d2a0a56f0
4
- data.tar.gz: 1e5ab8538cec2f157c62fc43d47b0138c290ee262e1d016e4908c9fb1fd854dc
3
+ metadata.gz: ef354c90190e2f2f97135142004b6f22120202d5aeb186fc434b53fd9d090f6e
4
+ data.tar.gz: e2530f8c7ec966fb98a4dc86ca91dfc25aee937db78e5e1cfb906bb2ddaf9ce8
5
5
  SHA512:
6
- metadata.gz: 5f7def175a5c5c5cd83ee4c3266bd296d2966c5e1e83aaad5043c1ded971d35b56ffabc505d1f2ec4f580b9100817745f6dc5173b3af57c33ab0bd2dae3d55ab
7
- data.tar.gz: d11c957220e7e479f9852de144cc692ed7035bd5458fd4a9fec43ceeab6c363cabd35cf24d6105270418c33b6e655d5ff41189a864666ad5b58a783ecf1d55dc
6
+ metadata.gz: ebc55a209be45bdef4f0210109a15af9f8f6e123e422cc54eb9379c2a08eed80dd2eee9bb744a5242b32d04126953c6c21e9a1c7f02254a9d2581fc17630a673
7
+ data.tar.gz: 8d1399f1fcf76c0efb0c2020e4b0edef2ff6e452c90e6627a01adf9fc47ba5f896bfa817235ba8797ddb0ac62a0bb5210286427fb7fee95699757b8cd3cf46db
@@ -7,12 +7,15 @@ module Jekyll
7
7
  priority :lowest
8
8
 
9
9
  def generate(site)
10
- config = Utils.deep_merge_hashes(Gensocial::DEFAULTS, site.config.fetch("jekyll-gensocial", {}))
10
+ config = Utils.deep_merge_hashes(
11
+ Gensocial::DEFAULTS,
12
+ site.config.fetch("jekyll-gensocial", {})
13
+ )
11
14
 
12
15
  return unless config["enabled"] == true
13
16
 
14
- process_docs(site.pages, site: site, config: config)
15
- process_docs(site.posts.docs, site: site, config: config)
17
+ process_docs(site.pages, :site => site, :config => config)
18
+ process_docs(site.posts.docs, :site => site, :config => config)
16
19
  end
17
20
 
18
21
  private
@@ -20,47 +23,58 @@ module Jekyll
20
23
  def process_docs(docs, site:, config:)
21
24
  docs.each do |doc|
22
25
  doc_config = Utils.deep_merge_hashes(config, doc.data.fetch("jekyll-gensocial", {}))
26
+ process_doc(doc, :site => site, :config => doc_config)
27
+ end
28
+ end
23
29
 
24
- image_size = Geometry::Size.new(doc_config["size"])
25
- text_config = ImageCreator::TextLayerConfig.new(doc_config["text"], base_path: site.source)
26
- bg_config = ImageCreator::BackgroundLayerConfig.new(doc_config["background"], base_path: site.source)
30
+ def image_config(config, base_path:)
31
+ {
32
+ :size => Geometry::Size.new(config["size"]),
33
+ :text => ImageCreator::TextLayerConfig.new(
34
+ config["text"],
35
+ :base_path => base_path
36
+ ),
37
+ :bg => ImageCreator::BackgroundLayerConfig.new(
38
+ config["background"],
39
+ :base_path => base_path
40
+ ),
41
+ }
42
+ end
27
43
 
28
- text = doc.data["title"] || text_config.string
29
- image_path = doc.data["image"]
44
+ def process_doc(doc, site:, config:)
45
+ image_config = image_config(config, :base_path => site.source)
30
46
 
31
- next if text.nil? || image_path.nil?
47
+ text = doc.data["title"] || image_config[:text].string
48
+ image_path = doc.data["image"]
32
49
 
33
- write_image(
34
- path: site.in_source_dir(image_path),
35
- text: text,
36
- image_size: image_size,
37
- text_config: text_config,
38
- bg_config: bg_config
39
- )
50
+ return if text.nil? || image_path.nil?
40
51
 
41
- base = site.source
42
- dir = File.dirname(image_path)
43
- name = File.basename(image_path)
52
+ write_image(
53
+ :path => site.in_source_dir(image_path),
54
+ :text => text,
55
+ :image_config => image_config
56
+ )
44
57
 
45
- site.static_files << Jekyll::StaticFile.new(site, base, dir, name)
46
- end
58
+ base = site.source
59
+ dir = File.dirname(image_path)
60
+ name = File.basename(image_path)
61
+
62
+ site.static_files << Jekyll::StaticFile.new(site, base, dir, name)
47
63
  end
48
64
 
49
- def write_image(path:, text:, image_size:, text_config: , bg_config:)
65
+ def write_image(path:, text:, image_config:)
50
66
  image = get_image_creator(
51
- text: text,
52
- image_size: image_size,
53
- bg_config: bg_config,
54
- text_config: text_config
67
+ :text => text,
68
+ :image_config => image_config
55
69
  ).image
56
70
 
57
71
  image.write(path)
58
72
  end
59
73
 
60
- def get_image_creator(text:, image_size:, bg_config:, text_config:)
61
- image_creator = ImageCreator::Composer.new(image_size: image_size)
62
- image_creator.add_bg_layer(config: bg_config)
63
- image_creator.add_text_layer(text, config: text_config)
74
+ def get_image_creator(text:, image_config:)
75
+ image_creator = ImageCreator::Composer.new(:image_size => image_config[:size])
76
+ image_creator.add_bg_layer(:config => image_config[:bg])
77
+ image_creator.add_text_layer(text, :config => image_config[:text])
64
78
 
65
79
  image_creator
66
80
  end
@@ -3,8 +3,8 @@
3
3
  module Jekyll
4
4
  module Gensocial
5
5
  module Geometry
6
- Size = Struct.new(:width, :height, keyword_init: true)
7
- Point = Struct.new(:x, :y, keyword_init: true)
6
+ Size = Struct.new(:width, :height, :keyword_init => true)
7
+ Point = Struct.new(:x, :y, :keyword_init => true)
8
8
 
9
9
  class Rect
10
10
  attr_reader :size, :origin
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rmagick'
4
- include Magick
3
+ require "rmagick"
5
4
 
6
5
  module Jekyll
7
6
  module Gensocial
8
7
  module ImageCreator
9
8
  class Composer
9
+ include Magick
10
10
  attr_reader :image
11
11
 
12
12
  def initialize(image_size:)
@@ -28,13 +28,13 @@ module Jekyll
28
28
  origin = config.rect.origin
29
29
  size = config.rect.size
30
30
 
31
- text_layer = Magick::Image.read("caption:#{text}") {
31
+ text_layer = Magick::Image.read("caption:#{text}") do
32
32
  self.fill = config.fill
33
33
  self.font = config.font_path unless config.font_path.nil?
34
34
  self.pointsize = config.pointsize
35
35
  self.size = "#{size.width}x#{size.height}"
36
36
  self.background_color = "none"
37
- }.first
37
+ end.first
38
38
 
39
39
  @image.composite!(text_layer, NorthWestGravity, origin.x, origin.y, OverCompositeOp)
40
40
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jekyll
4
- module Gensocial
5
- VERSION = "1.0.0"
4
+ module Gensocial
5
+ VERSION = "1.0.1"
6
6
  end
7
7
  end
@@ -8,31 +8,33 @@ require "jekyll-gensocial/image_creator"
8
8
 
9
9
  module Jekyll
10
10
  module Gensocial
11
- DEFAULTS = {
12
- "enabled" => true,
13
- "size" => {
14
- "width" => 1920,
15
- "height" => 1080
11
+ # rubocop:disable Layout/HashAlignment
12
+ DEFAULTS = {
13
+ "enabled" => true,
14
+ "size" => {
15
+ "width" => 1920,
16
+ "height" => 1080,
17
+ },
18
+ "background" => {
19
+ "path" => nil,
20
+ },
21
+ "text" => {
22
+ "string" => nil,
23
+ "font_path" => nil,
24
+ "pointsize" => 100,
25
+ "fill" => "#000000",
26
+ "rect" => {
27
+ "size" => {
28
+ "width" => 1600,
29
+ "height" => 500,
30
+ },
31
+ "origin" => {
32
+ "x" => 150,
33
+ "y" => 100,
34
+ },
16
35
  },
17
- "background" => {
18
- "path" => nil
19
- },
20
- "text" => {
21
- "string" => nil,
22
- "font_path" => nil,
23
- "pointsize" => 100,
24
- "fill" => "#000000",
25
- "rect" => {
26
- "size" => {
27
- "width" => 1600,
28
- "height" => 500,
29
- },
30
- "origin" => {
31
- "x" => 150,
32
- "y" => 100
33
- }
34
- }
35
- }
36
- }.freeze
36
+ },
37
+ }.freeze
38
+ # rubocop:enable Layout/HashAlignment
37
39
  end
38
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-gensocial
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boy van Amstel