Module: Flint
- Defined in:
- lib/flint.rb,
lib/flint/version.rb,
lib/flint/functions.rb
Constant Summary collapse
- VERSION =
"2.3.1"
Class Method Summary collapse
Instance Method Summary collapse
-
#flint_ruby_exists(map, key) ⇒ Bool
Check if key exists in map.
-
#flint_ruby_list_to_str(list, glue) ⇒ String
Joins all elements of list with passed glue.
-
#flint_ruby_map_fetch(map, *keys) ⇒ *
Fetch value from map.
-
#flint_ruby_str_replace(string, find, replace) ⇒ String
Replace substring with string.
-
#flint_ruby_str_to_list(string, separator, ignore) ⇒ List
Turn string into a flat list.
-
#flint_use_ruby ⇒ Bool
Use ruby functions.
Class Method Details
.declare(*args) ⇒ Object
3 4 5 |
# File 'lib/flint/functions.rb', line 3 def self.declare(*args) Sass::Script::Functions.declare(*args) end |
Instance Method Details
#flint_ruby_exists(map, key) ⇒ Bool
Check if key exists in map
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/flint/functions.rb', line 107 def flint_ruby_exists(map, key) assert_type map, :Map, :map assert_type key, :String, :key hash = map.to_h if hash.fetch(key, false) return Sass::Script::Bool.new(true) else hash.each do |_, value| if value.is_a?(Sass::Script::Value::Map) return Sass::Script::Bool.new(true) if flint_ruby_exists(value, key).value end end end Sass::Script::Bool.new(false) end |
#flint_ruby_list_to_str(list, glue) ⇒ String
Joins all elements of list with passed glue
46 47 48 49 50 51 52 53 |
# File 'lib/flint/functions.rb', line 46 def flint_ruby_list_to_str(list, glue) assert_type list, :List, :list assert_type glue, :String, :glue arr = list.to_a.flatten.map { |item| item.value } Sass::Script::String.new(arr.join(glue.value)) end |
#flint_ruby_map_fetch(map, *keys) ⇒ *
Fetch value from map
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/flint/functions.rb', line 24 def flint_ruby_map_fetch(map, *keys) assert_type map, :Map, :map result = map keys.each { |key| result.nil? ? break : result = result.to_h.fetch(key, nil) } unless result.nil? result else Sass::Script::Bool.new(false) end end |
#flint_ruby_str_replace(string, find, replace) ⇒ String
Replace substring with string
90 91 92 93 94 95 96 |
# File 'lib/flint/functions.rb', line 90 def flint_ruby_str_replace(string, find, replace) assert_type string, :String, :string assert_type find, :String, :find assert_type replace, :String, :replace Sass::Script::String.new(string.value.gsub(find.value, replace.value)) end |
#flint_ruby_str_to_list(string, separator, ignore) ⇒ List
Turn string into a flat list
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/flint/functions.rb', line 65 def flint_ruby_str_to_list(string, separator, ignore) assert_type string, :String, :string assert_type separator, :String, :separator assert_type ignore, :String, :ignore # Remove everything after ignore, split with separator items = string.value[/[^#{ignore}]+/].split(separator.value) if items.count == 1 Sass::Script::String.new(items[0], :comma) else Sass::Script::List.new(items.map { |i| Sass::Script::String.new(i) }, :comma) end end |
#flint_use_ruby ⇒ Bool
Use ruby functions
12 13 14 |
# File 'lib/flint/functions.rb', line 12 def flint_use_ruby() Sass::Script::Bool.new(true) end |