Class: JekyllImgFlow::Config
- Inherits:
-
Object
- Object
- JekyllImgFlow::Config
- Defined in:
- lib/jekyll-imgflow/config.rb
Instance Attribute Summary collapse
-
#backend_priority ⇒ Object
readonly
Returns the value of attribute backend_priority.
-
#flyimg_url ⇒ Object
readonly
Returns the value of attribute flyimg_url.
-
#formats ⇒ Object
readonly
Returns the value of attribute formats.
-
#image_compressor_url ⇒ Object
readonly
Returns the value of attribute image_compressor_url.
-
#imgproxy_url ⇒ Object
readonly
Returns the value of attribute imgproxy_url.
-
#input_formats ⇒ Object
readonly
Returns the value of attribute input_formats.
-
#optimize_qualities ⇒ Object
readonly
Returns the value of attribute optimize_qualities.
-
#originals ⇒ Object
readonly
Returns the value of attribute originals.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#quality ⇒ Object
readonly
Returns the value of attribute quality.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
-
#sizes ⇒ Object
readonly
Returns the value of attribute sizes.
-
#weserv_url ⇒ Object
readonly
Returns the value of attribute weserv_url.
Instance Method Summary collapse
- #cache_dir ⇒ Object
-
#determine_version_type(params) ⇒ Symbol
Determine if params represent a default or specialized version.
- #docker_config ⇒ Object
- #docker_enabled ⇒ Object
-
#initialize(site) ⇒ Config
constructor
A new instance of Config.
-
#normalized_input_formats ⇒ Object
Get normalized format lists.
- #normalized_output_formats ⇒ Object
- #sharp_url ⇒ Object
-
#supported_input_format?(format) ⇒ Boolean
Format validation methods.
- #supported_output_format?(format) ⇒ Boolean
- #validate_input_format!(format) ⇒ Object
- #validate_output_format!(format) ⇒ Object
Constructor Details
#initialize(site) ⇒ Config
Returns a new instance of Config.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/jekyll-imgflow/config.rb', line 10 def initialize(site) shared = site.config["shared_images_configs"] || {} overrides = site.config["imgflow"] || {} cfg = shared.merge(overrides) @site = site @originals = cfg["originals"] @output = cfg["output"] @input_formats = cfg["input_formats"] @sizes = cfg["sizes"] @formats = cfg["formats"] @quality = cfg["quality"] @backend_priority = cfg["backend_priority"] # Validate required config fields raise ArgumentError, "No originals configured in unified config" unless @originals raise ArgumentError, "No output configured in unified config" unless @output raise ArgumentError, "No input_formats configured in unified config" unless @input_formats raise ArgumentError, "No formats configured in unified config" unless @formats raise ArgumentError, "No sizes configured in unified config" unless @sizes @imgproxy_url = cfg["imgproxy_url"] @image_compressor_url = cfg["image_compressor_url"] @weserv_url = cfg["weserv_url"] @flyimg_url = cfg["flyimg_url"] @optimize_qualities = cfg["optimize_qualities"] || { "low" => 30, "medium" => 50, # Uses default quality "high" => 85, # Uses default quality "maximum" => 95, "default" => 75 } validate_backend_priority! end |
Instance Attribute Details
#backend_priority ⇒ Object (readonly)
Returns the value of attribute backend_priority.
5 6 7 |
# File 'lib/jekyll-imgflow/config.rb', line 5 def backend_priority @backend_priority end |
#flyimg_url ⇒ Object (readonly)
Returns the value of attribute flyimg_url.
5 6 7 |
# File 'lib/jekyll-imgflow/config.rb', line 5 def flyimg_url @flyimg_url end |
#formats ⇒ Object (readonly)
Returns the value of attribute formats.
5 6 7 |
# File 'lib/jekyll-imgflow/config.rb', line 5 def formats @formats end |
#image_compressor_url ⇒ Object (readonly)
Returns the value of attribute image_compressor_url.
5 6 7 |
# File 'lib/jekyll-imgflow/config.rb', line 5 def image_compressor_url @image_compressor_url end |
#imgproxy_url ⇒ Object (readonly)
Returns the value of attribute imgproxy_url.
5 6 7 |
# File 'lib/jekyll-imgflow/config.rb', line 5 def imgproxy_url @imgproxy_url end |
#input_formats ⇒ Object (readonly)
Returns the value of attribute input_formats.
5 6 7 |
# File 'lib/jekyll-imgflow/config.rb', line 5 def input_formats @input_formats end |
#optimize_qualities ⇒ Object (readonly)
Returns the value of attribute optimize_qualities.
5 6 7 |
# File 'lib/jekyll-imgflow/config.rb', line 5 def optimize_qualities @optimize_qualities end |
#originals ⇒ Object (readonly)
Returns the value of attribute originals.
5 6 7 |
# File 'lib/jekyll-imgflow/config.rb', line 5 def originals @originals end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
5 6 7 |
# File 'lib/jekyll-imgflow/config.rb', line 5 def output @output end |
#quality ⇒ Object (readonly)
Returns the value of attribute quality.
5 6 7 |
# File 'lib/jekyll-imgflow/config.rb', line 5 def quality @quality end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
5 6 7 |
# File 'lib/jekyll-imgflow/config.rb', line 5 def site @site end |
#sizes ⇒ Object (readonly)
Returns the value of attribute sizes.
5 6 7 |
# File 'lib/jekyll-imgflow/config.rb', line 5 def sizes @sizes end |
#weserv_url ⇒ Object (readonly)
Returns the value of attribute weserv_url.
5 6 7 |
# File 'lib/jekyll-imgflow/config.rb', line 5 def weserv_url @weserv_url end |
Instance Method Details
#cache_dir ⇒ Object
46 47 48 |
# File 'lib/jekyll-imgflow/config.rb', line 46 def cache_dir merged_config["cache_dir"] || ".cache/imgflow" end |
#determine_version_type(params) ⇒ Symbol
Determine if params represent a default or specialized version
74 75 76 77 78 79 80 81 82 |
# File 'lib/jekyll-imgflow/config.rb', line 74 def determine_version_type(params) if params[:width] && @sizes.value?(params[:width]) && (!params[:format] || @formats.include?(params[:format])) && (!params[:quality] || params[:quality] == @quality) :default else :specialized end end |
#docker_config ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/jekyll-imgflow/config.rb', line 50 def docker_config { enabled: merged_config.key?("imgproxy_url") || merged_config.key?("weserv_url") || merged_config.key?("flyimg_url") || merged_config.key?("image_compressor_url"), imgproxy_url: @imgproxy_url, weserv_url: @weserv_url, flyimg_url: @flyimg_url, image_compressor_url: @image_compressor_url } end |
#docker_enabled ⇒ Object
63 64 65 |
# File 'lib/jekyll-imgflow/config.rb', line 63 def docker_enabled docker_config[:enabled] end |
#normalized_input_formats ⇒ Object
Get normalized format lists
110 111 112 |
# File 'lib/jekyll-imgflow/config.rb', line 110 def normalized_input_formats @input_formats.map(&:downcase) end |
#normalized_output_formats ⇒ Object
114 115 116 |
# File 'lib/jekyll-imgflow/config.rb', line 114 def normalized_output_formats @formats.map(&:downcase) end |
#sharp_url ⇒ Object
67 68 69 |
# File 'lib/jekyll-imgflow/config.rb', line 67 def sharp_url merged_config["sharp_url"] end |
#supported_input_format?(format) ⇒ Boolean
Format validation methods
85 86 87 88 |
# File 'lib/jekyll-imgflow/config.rb', line 85 def supported_input_format?(format) normalized_format = format.to_s.downcase.delete(".") @input_formats.map(&:downcase).include?(normalized_format) end |
#supported_output_format?(format) ⇒ Boolean
90 91 92 93 |
# File 'lib/jekyll-imgflow/config.rb', line 90 def supported_output_format?(format) normalized_format = format.to_s.downcase.delete(".") @formats.map(&:downcase).include?(normalized_format) end |
#validate_input_format!(format) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/jekyll-imgflow/config.rb', line 95 def validate_input_format!(format) return if supported_input_format?(format) raise ArgumentError, "Unsupported input format '#{format}'. Supported formats: #{@input_formats.join(', ')}" end |
#validate_output_format!(format) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/jekyll-imgflow/config.rb', line 102 def validate_output_format!(format) return if supported_output_format?(format) raise ArgumentError, "Unsupported output format '#{format}'. Supported formats: #{@formats.join(', ')}" end |