Module: JekyllIS::Images::Context::Config
- Included in:
- JekyllIS::Images::Context, Error
- Defined in:
- lib/jekyll-is/images/context/config.rb
Defined Under Namespace
Classes: Options
Instance Method Summary collapse
- #cache_path ⇒ String
- #config(*path, check_default: false) ⇒ Object? (also: #[])
- #detect_format(source) ⇒ String
- #options(format, attrs = {}) ⇒ Options
- #target_path_prefix ⇒ String
Instance Method Details
#cache_path ⇒ String
145 146 147 |
# File 'lib/jekyll-is/images/context/config.rb', line 145 def cache_path @cache_path ||= config(CACHE_PATH_KEY) end |
#config(*path, check_default: false) ⇒ Object? Also known as: []
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/jekyll-is/images/context/config.rb', line 74 def config *path, check_default: false value = @page&.data&.dig CONFIG_KEY, *path return value if value value = @site&.config&.dig CONFIG_KEY, *path return value if value default = path.dup default[-1] = 'default' if check_default value = @page&.data&.dig CONFIG_KEY, *default return value if value value = @site&.config&.dig CONFIG_KEY, *default return value if value end value = DEFAULTS.dig(*path) return value if value if check_default value = DEFAULTS.dig(*default) return value if value end nil end |
#detect_format(source) ⇒ String
151 152 153 154 155 156 |
# File 'lib/jekyll-is/images/context/config.rb', line 151 def detect_format source source_format = source&.split('#')&.first&.split('?')&.first&.split('.')&.last&.downcase source_format = 'jpeg' if source_format == 'jpg' source_format = 'tiff' if source_format == 'tif' config(FORMATS_KEY, source_format, check_default: true) || source_format end |
#options(format, attrs = {}) ⇒ Options
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/jekyll-is/images/context/config.rb', line 113 def format, attrs = {} default_values = DEFAULTS.dig(OPTIONS_KEY, format) || {} page_values = @page&.data&.dig(CONFIG_KEY, OPTIONS_KEY, format) || {} site_values = @site&.config&.dig(CONFIG_KEY, OPTIONS_KEY, format) || {} config_values = {} config_values.merge! default_values config_values.merge! site_values config_values.merge! page_values quality = attrs['quality'] || config_values.delete('quality') defines = {} define_key = DEFINE_KEYS[format] || format config_values.each do |k, v| defines[define_key + ':' + k.tr('_', '-')] = v end attrs.each do |k, v| if k.start_with?(define_key + '-') defines[k.sub(define_key + '-', define_key + ':')] = v end end Options::new quality, defines.map { |k, v| "#{k}=#{v}" } end |
#target_path_prefix ⇒ String
140 141 142 |
# File 'lib/jekyll-is/images/context/config.rb', line 140 def target_path_prefix @target_path_prefix ||= config(TARGET_PREFIX_KEY) end |