Module: Sass::Script::Functions
- Defined in:
- lib/modular-scale.rb
Overview
This is where any custom SassScript should be placed. The functions will be
available on require of your extension without the need for users to import
any partials. Uncomment below.
Instance Method Summary collapse
- #ms_gem_func(value, bases, ratios) ⇒ Object
-
#ms_gem_installed ⇒ Object
Let MS know that extra functionality is avalible.
Instance Method Details
#ms_gem_func(value, bases, ratios) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/modular-scale.rb', line 34 def ms_gem_func(value, bases, ratios) # Convert to native ruby things rvalue = value.value.to_i if bases.class == Sass::Script::Number bases = [] << bases else bases = bases.value.to_a end if ratios.class == Sass::Script::Number ratios = [] << ratios else ratios = ratios.value.to_a end # Convert items in arrays to floating point numbers rbases = [] rratios = [] bases.each do |num| rbases << num.value.to_f end ratios.each do |num| rratios << num.value.to_f end # Blank array for return r = [rbases[0]] # loop through all possibilities # NOTE THIS IS NOT FULLY FUNCTIONAL YET # ONLY LOOPS THROUGH SOME/MOST OF THE POSSIBILITES rratios.each do |ratio| rbases.each do |base| base_counter = 0 # Seed list with an initial value r << base # Find values on a positive scale if rvalue >= 0 # Find higher values on the scale i = 0; while ((ratio ** i) * base) >= (rbases[0]) r << (ratio ** i) * base i = i - 1; end # Find lower possible values on the scale i = 0; while ((ratio ** i) * base) <= ((ratio ** (rvalue + 1)) * base) r << (ratio ** i) * base i = i + 1; end else # Find lower values on the scale i = 0; while ((ratio ** i) * base) <= (rbases[0]) r << (ratio ** i) * base i = i + 1; end # Find higher possible values on the scale i = 0; while ((ratio ** i) * base) >= ((ratio ** (rvalue - 1)) * base) r << (ratio ** i) * base i = i - 1; end end end end # Sort and trim r.sort! r.uniq! if rvalue < 0 r = r.keep_if { |a| a <= rbases[0] } # Final value r = r[(rvalue - 1)] else r = r[rvalue] end Sass::Script::Number.new(r) end |
#ms_gem_installed ⇒ Object
Let MS know that extra functionality is avalible
30 31 32 |
# File 'lib/modular-scale.rb', line 30 def ms_gem_installed() Sass::Script::Bool.new(true) end |