Class: JekyllOgImage::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll_og_image/configuration.rb

Overview

require “anyway_config”

Constant Summary collapse

Canvas =
Data.define(:background_color, :background_image) do
  def initialize(background_color: "#FFFFFF", background_image: nil)
    super
  end
end
Header =
Data.define(:font_family, :color) do
  def initialize(font_family: "Helvetica, Bold", color: "#2f313d")
    super
  end
end
Content =
Data.define(:font_family, :color) do
  def initialize(font_family: "Helvetica, Regular", color: "#535358")
    super
  end
end
Border =
Data.define(:width, :fill) do
  def initialize(width: 0, fill: nil)
    fill.is_a?(Array) ? fill : [ fill ]
    super(width: width, fill: fill)
  end
end

Instance Method Summary collapse

Constructor Details

#initialize(raw_config) ⇒ Configuration

Returns a new instance of Configuration.



31
32
33
# File 'lib/jekyll_og_image/configuration.rb', line 31

def initialize(raw_config)
  @raw_config = raw_config
end

Instance Method Details

#==(other) ⇒ Object



48
49
50
# File 'lib/jekyll_og_image/configuration.rb', line 48

def ==(other)
  to_h == other.to_h
end

#border_bottomObject



88
89
90
# File 'lib/jekyll_og_image/configuration.rb', line 88

def border_bottom
  @raw_config["border_bottom"] ? Border.new(**Jekyll::Utils.symbolize_hash_keys(@raw_config["border_bottom"])) : nil
end

#canvasObject



68
69
70
# File 'lib/jekyll_og_image/configuration.rb', line 68

def canvas
  @raw_config["canvas"] ? Canvas.new(**Jekyll::Utils.symbolize_hash_keys(@raw_config["canvas"])) : Canvas.new
end

#contentObject



76
77
78
# File 'lib/jekyll_og_image/configuration.rb', line 76

def content
  @raw_config["content"] ? Content.new(**Jekyll::Utils.symbolize_hash_keys(@raw_config["content"])) : Content.new
end

#domainObject



84
85
86
# File 'lib/jekyll_og_image/configuration.rb', line 84

def domain
  @raw_config["domain"]
end

#force?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/jekyll_og_image/configuration.rb', line 56

def force?
  @raw_config["force"].nil? ? false : @raw_config["force"]
end

#headerObject



72
73
74
# File 'lib/jekyll_og_image/configuration.rb', line 72

def header
  @raw_config["header"] ? Header.new(**Jekyll::Utils.symbolize_hash_keys(@raw_config["header"])) : Header.new
end

#imageObject



80
81
82
# File 'lib/jekyll_og_image/configuration.rb', line 80

def image
  @raw_config["image"]
end

#margin_bottomObject



92
93
94
# File 'lib/jekyll_og_image/configuration.rb', line 92

def margin_bottom
  80 + (border_bottom&.width || 0)
end

#merge!(other) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/jekyll_og_image/configuration.rb', line 35

def merge!(other)
  config = Jekyll::Utils.deep_merge_hashes(
    @raw_config,
    other.to_h
  )

  self.class.new(config)
end

#output_dirObject



52
53
54
# File 'lib/jekyll_og_image/configuration.rb', line 52

def output_dir
  @raw_config["output_dir"] || "assets/images/og"
end

#skip_drafts?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/jekyll_og_image/configuration.rb', line 64

def skip_drafts?
  @raw_config["skip_drafts"].nil? ? true : @raw_config["skip_drafts"]
end

#to_hObject



44
45
46
# File 'lib/jekyll_og_image/configuration.rb', line 44

def to_h
  @raw_config
end

#verbose?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/jekyll_og_image/configuration.rb', line 60

def verbose?
  @raw_config["verbose"].nil? ? false : @raw_config["verbose"]
end