Module: Flint

Defined in:
lib/flint.rb,
lib/flint/version.rb,
lib/flint/functions.rb

Constant Summary collapse

VERSION =
"2.0.8"

Class Method Summary collapse

Instance Method Summary collapse

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_list_to_string(list, glue) ⇒ String

Joins all elements of list with passed glue

Parameters:

  • list (List)
  • glue (String)

Returns:

  • (String)


44
45
46
47
48
49
# File 'lib/flint/functions.rb', line 44

def flint_ruby_list_to_string(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

Parameters:

  • map (Map)
    • map to fetch value from

  • keys (ArgList)
    • list of keys to traverse

Returns:

  • (*)


24
25
26
27
28
29
30
31
32
33
# 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_replace_substring(string, find, replace) ⇒ String

Replace substring with string

Parameters:

  • string (String)
    • string that contains substring

  • find (String)
    • substring to replace

  • replace (String)
    • new string to replace sub with

Returns:

  • (String)


84
85
86
87
88
89
# File 'lib/flint/functions.rb', line 84

def flint_ruby_replace_substring(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_string_to_list(string, separator, ignore) ⇒ List

Turn string into a flat list

Parameters:

  • string (String)
    • string to operate on

  • separator (String)
    • item to find which separates substrings

  • ignore (String)
    • removes remaining string beyond item

Returns:

  • (List)


61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/flint/functions.rb', line 61

def flint_ruby_string_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_rubyBool

Use ruby functions

Returns:

  • (Bool)


12
13
14
# File 'lib/flint/functions.rb', line 12

def flint_use_ruby()
    Sass::Script::Bool.new(true)
end