sassy-fractions 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/sassy-fractions.rb +42 -0
  2. metadata +91 -0
@@ -0,0 +1,42 @@
1
+ require 'compass'
2
+ require 'fraction'
3
+
4
+ extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
5
+ Compass::Frameworks.register('sassy-fractions', :path => extension_path)
6
+
7
+ module SassyFractions
8
+ VERSION = "1.0"
9
+ DATE = "2012-08-21"
10
+ end
11
+
12
+ # Sassy math Functions
13
+ module Sass::Script::Functions
14
+ # Fractions
15
+ def numerator(number)
16
+ Sass::Script::Number.new(number.value.fraction.first)
17
+ end
18
+ def denominator(number)
19
+ num, den = number.value.fraction
20
+ Sass::Script::Number.new(den)
21
+ end
22
+ def to_fraction(number)
23
+ result = numerator(number).to_s + '/' + denominator(number).to_s
24
+ Sass::Script::String.new(result)
25
+ end
26
+ def to_decimal(fraction)
27
+ fraction = fraction.value.to_f
28
+ Sass::Script::Number.new(fraction)
29
+ end
30
+ # From http://coryodaniel.com/index.php/2009/12/30/ruby-and-numbers-scaling-greatest-common-denominator-least-common-multiple/
31
+ def gcd(a, b)
32
+ a = a.value
33
+ b = b.value
34
+ a,b = b,a if a < b
35
+ a,b = b,a%b while a%b != 0
36
+ Sass::Script::Number.new(b)
37
+ end
38
+ def lcm(a, b)
39
+ result = (a.value * b.value) / gcd(a, b)
40
+ Sass::Script::Number.new(result)
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sassy-fractions
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ version: "1.0"
9
+ platform: ruby
10
+ authors:
11
+ - Sam Richard
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2012-08-21 00:00:00 +02:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: compass
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 0
28
+ - 13
29
+ - alpha
30
+ - 0
31
+ version: 0.13.alpha.0
32
+ type: :runtime
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
48
+ description: Fractions for Sass
49
+ email:
50
+ - snugug@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - lib/sassy-fractions.rb
59
+ has_rdoc: true
60
+ homepage: https://github.com/Snugug/sassy-fractions
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options: []
65
+
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 1
81
+ - 2
82
+ version: "1.2"
83
+ requirements: []
84
+
85
+ rubyforge_project: sassy-fractions
86
+ rubygems_version: 1.3.6
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Fraction functions spun out of Sassy Math
90
+ test_files: []
91
+