Module: Imglab
- Extended by:
- Imglab
- Included in:
- Imglab
- Defined in:
- lib/imglab/url.rb,
lib/imglab/srcset.rb,
lib/imglab/version.rb
Defined Under Namespace
Modules: Color, Position, Sequence, Signature, Srcset, Url Classes: Source
Constant Summary collapse
- FLUID_CLASSES =
[Array, Range].freeze
- DEFAULT_DPRS =
[1, 2, 3, 4, 5, 6].freeze
- DEFAULT_WIDTHS =
Sequence.sequence(100, 8192).freeze
- VERSION =
"0.3.0"
Instance Method Summary collapse
-
#srcset(source, path, params = {}) ⇒ String
Returns a formatted srcset ‘string` with the specified parameters.
-
#url(source, path, params = {}) ⇒ String
Returns a formatted URL ‘string` with the specified arguments.
Instance Method Details
#srcset(source, path, params = {}) ⇒ String
Returns a formatted srcset ‘string` with the specified parameters.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/imglab/srcset.rb', line 25 def srcset(source, path, params = {}) params = Srcset::Utils.normalize_params(params) width, height, dpr = params.values_at("width", "height", "dpr") case when is_fluid?(width) if is_fluid?(dpr) raise ArgumentError, "dpr as #{dpr.class} is not allowed when width is Array or Range" end srcset_width(source, path, params) when width || height if is_fluid?(height) raise ArgumentError, "height as #{height.class} is not allowed when width is not an Array or Range" end srcset_dpr(source, path, params.merge("dpr" => dprs(params))) else if is_fluid?(dpr) raise ArgumentError, "dpr as #{dpr.class} is not allowed without specifying width or height" end srcset_width(source, path, params.merge("width" => DEFAULT_WIDTHS)) end end |
#url(source, path, params = {}) ⇒ String
Returns a formatted URL ‘string` with the specified arguments.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/imglab/url.rb', line 16 def url(source, path, params = {}) case source when String url_for_source(Source.new(source), path, params) when Source url_for_source(source, path, params) else raise ArgumentError, "Invalid source name or source. A string or a #{Source.name} instance is expected" end end |