module Apropos::SassFunctions
A collection of methods mixed into Sass::Script::Functions
to allow Apropos
to be used from Sass
files. The primary method is `image-variants`, which generates the actual CSS rules. Configuration directly from the Sass
file is possible with the `add-dpi-image-variant` and `add-breakpoint-image-variant` methods, although the limitations of Sass
syntax require that the output of these functions be assigned to a dummy variable.
Public Class Methods
included(mod)
click to toggle source
# File lib/apropos/sass_functions.rb, line 14 def self.included(mod) ::Sass::Script::Functions.declare :image_variants, [] ::Sass::Script::Functions.declare :apropos_image_width, [:string] ::Sass::Script::Functions.declare :apropos_image_height, [:string] ::Sass::Script::Functions.declare :add_dpi_image_variant, [] ::Sass::Script::Functions.declare :add_breakpoint_image_variant, [] ::Sass::Script::Functions.declare :nth_polyfill, [:list, :index] ::Sass::Script::Functions.declare :str_contains, [:string, :substring] end
sass_function_exist?(meth)
click to toggle source
# File lib/apropos/sass_functions.rb, line 10 def self.sass_function_exist?(meth) Sass::Script::Functions.instance_methods.include? meth end
value(val)
click to toggle source
# File lib/apropos/sass_functions.rb, line 24 def self.value(val) val.respond_to?(:value) ? val.value : val end
Public Instance Methods
add_breakpoint_image_variant(id, query, sort=0)
click to toggle source
# File lib/apropos/sass_functions.rb, line 74 def add_breakpoint_image_variant(id, query, sort=0) sort = ::Apropos::SassFunctions.value(sort) ::Apropos.add_breakpoint_image_variant(id.value, query.value, sort) ::Sass::Script::Bool.new(false) end
add_dpi_image_variant(id, query, sort=0)
click to toggle source
# File lib/apropos/sass_functions.rb, line 68 def add_dpi_image_variant(id, query, sort=0) sort = ::Apropos::SassFunctions.value(sort) ::Apropos.add_dpi_image_variant(id.value, query.value, sort) ::Sass::Script::Bool.new(false) end
apropos_image_height(path)
click to toggle source
# File lib/apropos/sass_functions.rb, line 54 def apropos_image_height(path) assert_type path, :String height = image_height(path) if ::Apropos.hidpi_only ::Sass::Script::Number.new( (height.value / 2).floor, height.numerator_units, height.denominator_units ) else height end end
apropos_image_width(path)
click to toggle source
# File lib/apropos/sass_functions.rb, line 40 def apropos_image_width(path) assert_type path, :String width = image_width(path) if ::Apropos.hidpi_only ::Sass::Script::Number.new( (width.value / 2).floor, width.numerator_units, width.denominator_units ) else width end end
image_variants(path)
click to toggle source
# File lib/apropos/sass_functions.rb, line 28 def image_variants(path) assert_type path, :String set = ::Apropos.image_set(path.value) set.invalid_variants.each do |variant| message = "Ignoring unknown extensions " + "'#{variant.invalid_codes.join("', '")}' (#{variant.path})" ::Sass.logger.info message $stderr.puts message end ::Apropos.convert_to_sass_value(set.valid_variant_rules) end
nth_polyfill(list, index)
click to toggle source
Can be replaced with stock `nth` once dca1498 makes it into a Sass
release git.io/eGNOKA
# File lib/apropos/sass_functions.rb, line 82 def nth_polyfill(list, index) index = index.value list = list.value index = list.length + index + 1 if index < 0 list[index - 1] end
str_contains(string, substring)
click to toggle source
# File lib/apropos/sass_functions.rb, line 89 def str_contains(string, substring) assert_type string, :String, :string assert_type substring, :String, :substring ::Sass::Script::Bool.new(string.value.include?(substring.value)) end