sassy-math 0.1.8.5 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sassy-math.rb +104 -2
- data/sassy-math.gemspec +4 -3
- metadata +18 -6
data/lib/sassy-math.rb
CHANGED
@@ -1,9 +1,111 @@
|
|
1
1
|
require 'compass'
|
2
|
+
require 'fraction'
|
2
3
|
Compass::Frameworks.register("sassy-math", :path => "#{File.dirname(__FILE__)}/..")
|
3
4
|
|
5
|
+
# Sassy math Functions
|
6
|
+
module Sass::Script::Functions
|
7
|
+
# Computational Functions
|
8
|
+
# Fraction Functions
|
9
|
+
def numerator(number)
|
10
|
+
Sass::Script::Number.new(number.value.fraction.first)
|
11
|
+
end
|
12
|
+
def denominator(number)
|
13
|
+
num, den = number.value.fraction
|
14
|
+
Sass::Script::Number.new(den)
|
15
|
+
end
|
16
|
+
def to_fraction(number)
|
17
|
+
result = numerator(number).to_s + '/' + denominator(number).to_s
|
18
|
+
Sass::Script::String.new(result)
|
19
|
+
end
|
20
|
+
def to_decimal(fraction)
|
21
|
+
fraction = fraction.value.to_f
|
22
|
+
Sass::Script::Number.new(fraction)
|
23
|
+
end
|
24
|
+
# Exponent Functions
|
25
|
+
def exponent(base, powerNum, powerDen)
|
26
|
+
base = base.value.to_f
|
27
|
+
powerNum = powerNum.value.to_f
|
28
|
+
powerDen = powerDen.value.to_f
|
29
|
+
result = base ** (powerNum / powerDen)
|
30
|
+
Sass::Script::Number.new(result)
|
31
|
+
end
|
32
|
+
def power(base, exponent)
|
33
|
+
base = base.value.to_f
|
34
|
+
exponent = exponent.value.to_f
|
35
|
+
result = base ** exponent
|
36
|
+
Sass::Script::Number.new(result)
|
37
|
+
end
|
38
|
+
def sqrt(number)
|
39
|
+
number = number.value.to_f
|
40
|
+
result = Math.sqrt(number)
|
41
|
+
Sass::Script::Number.new(result)
|
42
|
+
end
|
43
|
+
def nth_root(number, root)
|
44
|
+
number = number.value.to_f
|
45
|
+
root = root.value.to_f
|
46
|
+
result = number ** (1.0 / root)
|
47
|
+
Sass::Script::Number.new(result)
|
48
|
+
end
|
49
|
+
# Factorial
|
50
|
+
def factorial(number)
|
51
|
+
result = 1
|
52
|
+
number = number.value
|
53
|
+
if number > 0
|
54
|
+
(1..number).each do |i|
|
55
|
+
result = result * i
|
56
|
+
end
|
57
|
+
end
|
58
|
+
Sass::Script::Number.new(result)
|
59
|
+
end
|
60
|
+
# Log Functions
|
61
|
+
def ln(num)
|
62
|
+
result = Math.log(num.value)
|
63
|
+
Sass::Script::Number.new(result)
|
64
|
+
end
|
65
|
+
def log(num)
|
66
|
+
result = Math.log10(num.value)
|
67
|
+
Sass::Script::Number.new(result)
|
68
|
+
end
|
69
|
+
# Constants
|
70
|
+
def pi
|
71
|
+
pi = Math::PI
|
72
|
+
Sass::Script::Number.new(pi)
|
73
|
+
end
|
74
|
+
def e
|
75
|
+
e = Math::E
|
76
|
+
Sass::Script::Number.new(e)
|
77
|
+
end
|
78
|
+
def rand
|
79
|
+
Sass::Script::Number.new(4)
|
80
|
+
end
|
81
|
+
def golden_ratio()
|
82
|
+
result = (1.0 / 2.0) + (Math.sqrt(5) / 2.0)
|
83
|
+
Sass::Script::Number.new(result)
|
84
|
+
end
|
85
|
+
# Comparative Functions
|
86
|
+
def is_int(number)
|
87
|
+
number = number.value.to_f
|
88
|
+
if number - number.floor != 0
|
89
|
+
result = false
|
90
|
+
else
|
91
|
+
result = true
|
92
|
+
end
|
93
|
+
Sass::Script::Bool.new(result)
|
94
|
+
end
|
95
|
+
def is_float(number)
|
96
|
+
number = number.value
|
97
|
+
if number - number.floor != 0
|
98
|
+
result = true
|
99
|
+
else
|
100
|
+
result = false
|
101
|
+
end
|
102
|
+
Sass::Script::Bool.new(result)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
4
106
|
module SassyMath
|
5
107
|
|
6
|
-
VERSION = "
|
7
|
-
DATE = "2012-
|
108
|
+
VERSION = "1.0"
|
109
|
+
DATE = "2012-06-03"
|
8
110
|
|
9
111
|
end
|
data/sassy-math.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{sassy-math}
|
5
|
-
s.version = "
|
5
|
+
s.version = "1.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5")
|
8
8
|
s.authors = ["Sam Richard", "Mario Valencia", "Scott Kellum"]
|
9
|
-
s.date = %q{2012-01
|
9
|
+
s.date = %q{2012-06-01}
|
10
10
|
s.description = %q{Use advanced mathematical functions in Compass.}
|
11
11
|
s.email = %w{scott@scottkellum.com}
|
12
12
|
s.has_rdoc = false
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
s.rubyforge_project = %q{sassy-math}
|
21
21
|
s.rubygems_version = %q{1.3.6}
|
22
|
-
s.summary = %q{
|
22
|
+
s.summary = %q{Advanced math functions for Compass.}
|
23
23
|
s.add_dependency(%q<compass>, ["~> 0.11"])
|
24
|
+
s.add_dependency("fraction", [">=0.3.2"])
|
24
25
|
end
|
metadata
CHANGED
@@ -3,11 +3,9 @@ name: sassy-math
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
-
- 0
|
7
6
|
- 1
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.1.8.5
|
7
|
+
- 0
|
8
|
+
version: "1.0"
|
11
9
|
platform: ruby
|
12
10
|
authors:
|
13
11
|
- Sam Richard
|
@@ -17,7 +15,7 @@ autorequire:
|
|
17
15
|
bindir: bin
|
18
16
|
cert_chain: []
|
19
17
|
|
20
|
-
date: 2012-01
|
18
|
+
date: 2012-06-01 00:00:00 -04:00
|
21
19
|
default_executable:
|
22
20
|
dependencies:
|
23
21
|
- !ruby/object:Gem::Dependency
|
@@ -33,6 +31,20 @@ dependencies:
|
|
33
31
|
version: "0.11"
|
34
32
|
type: :runtime
|
35
33
|
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: fraction
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 3
|
44
|
+
- 2
|
45
|
+
version: 0.3.2
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
36
48
|
description: Use advanced mathematical functions in Compass.
|
37
49
|
email:
|
38
50
|
- scott@scottkellum.com
|
@@ -77,6 +89,6 @@ rubyforge_project: sassy-math
|
|
77
89
|
rubygems_version: 1.3.6
|
78
90
|
signing_key:
|
79
91
|
specification_version: 3
|
80
|
-
summary:
|
92
|
+
summary: Advanced math functions for Compass.
|
81
93
|
test_files: []
|
82
94
|
|