compass-core 1.0.0.alpha.15 → 1.0.0.alpha.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,13 +4,13 @@ module Compass::Core::SassExtensions::Functions::ImageSize
4
4
  # Returns the width of the image relative to the images directory
5
5
  def image_width(image_file)
6
6
  width, _ = image_dimensions(image_file)
7
- Sass::Script::Number.new(width,["px"])
7
+ number(width, "px")
8
8
  end
9
9
 
10
10
  # Returns the height of the image relative to the images directory
11
11
  def image_height(image_file)
12
12
  _, height = image_dimensions(image_file)
13
- Sass::Script::Number.new(height, ["px"])
13
+ number(height, "px")
14
14
  end
15
15
 
16
16
  class ImageProperties
@@ -12,16 +12,16 @@ module Compass::Core::SassExtensions::Functions::InlineImage
12
12
  path = path.value
13
13
  real_path = File.join(Compass.configuration.fonts_path, path)
14
14
  data = inline_image_string(data(real_path), compute_mime_type(path))
15
- files << "#{data} format('#{type}')"
15
+ files << list(data, unquoted_string("format('#{type}')"), :space)
16
16
  end
17
- Sass::Script::String.new(files.join(", "))
17
+ list(files, :comma)
18
18
  end
19
19
 
20
20
  protected
21
21
  def inline_image_string(data, mime_type)
22
22
  data = [data].flatten.pack('m').gsub("\n","")
23
23
  url = "url('data:#{mime_type};base64,#{data}')"
24
- Sass::Script::String.new(url)
24
+ unquoted_string(url)
25
25
  end
26
26
 
27
27
  private
@@ -3,26 +3,26 @@ module Compass::Core::SassExtensions::Functions::Lists
3
3
  # Returns true when the object is false, an empty string, or an empty list
4
4
  def blank(obj)
5
5
  case obj
6
- when Sass::Script::Bool
7
- Sass::Script::Bool.new !obj.to_bool
8
- when Sass::Script::String
9
- Sass::Script::Bool.new obj.value.strip.size == 0
10
- when Sass::Script::List
11
- Sass::Script::Bool.new obj.value.size == 0 || obj.value.all?{|el| blank(el).to_bool}
6
+ when Sass::Script::Value::Bool, Sass::Script::Value::Null
7
+ bool(!obj.to_bool)
8
+ when Sass::Script::Value::String
9
+ bool(obj.value.strip.size == 0)
10
+ when Sass::Script::Value::List
11
+ bool(obj.value.size == 0 || obj.value.all?{|el| blank(el).to_bool})
12
12
  else
13
- Sass::Script::Bool.new false
13
+ bool(false)
14
14
  end
15
15
  end
16
16
 
17
17
  # Returns a new list after removing any non-true values
18
18
  def compact(*args)
19
19
  sep = :comma
20
- if args.size == 1 && args.first.is_a?(Sass::Script::List)
20
+ if args.size == 1 && args.first.is_a?(Sass::Script::Value::List)
21
21
  list = args.first
22
22
  args = list.value
23
23
  sep = list.separator
24
24
  end
25
- Sass::Script::List.new(args.reject{|a| !a.to_bool}, sep)
25
+ list(args.reject{|a| !a.to_bool}, sep)
26
26
  end
27
27
 
28
28
  # Get the nth value from a list
@@ -41,49 +41,50 @@ module Compass::Core::SassExtensions::Functions::Lists
41
41
  # This can be used to unpack a space separated list that got turned
42
42
  # into a string by sass before it was passed to a mixin.
43
43
  def _compass_list(arg)
44
- if arg.is_a?(Sass::Script::List)
45
- Sass::Script::List.new(arg.value.dup, arg.separator)
44
+ if arg.is_a?(Sass::Script::Value::List)
45
+ list(arg.value.dup, arg.separator)
46
46
  else
47
- Sass::Script::List.new([arg], :space)
47
+ list(arg, :space)
48
48
  end
49
49
  end
50
50
 
51
51
  # If the argument is a list, it will return a new list that is space delimited
52
52
  # Otherwise it returns a new, single element, space-delimited list.
53
53
  def _compass_space_list(list)
54
- if list.is_a?(Sass::Script::List)
55
- Sass::Script::List.new(list.value.dup, :space)
54
+ if list.is_a?(Sass::Script::Value::List)
55
+ list(list.value.dup, :space)
56
56
  else
57
- Sass::Script::List.new([list], :space)
57
+ list(list, :space)
58
58
  end
59
59
  end
60
60
 
61
61
  # Returns the size of the list.
62
62
  def _compass_list_size(list)
63
63
  assert_list list
64
- Sass::Script::Number.new(list.value.size)
64
+ number(list.value.size)
65
65
  end
66
66
 
67
67
  # slice a sublist from a list
68
68
  def _compass_slice(list, start_index, end_index = nil)
69
- end_index ||= Sass::Script::Number.new(-1)
69
+ end_index ||= number(-1)
70
70
  start_index = start_index.value
71
71
  end_index = end_index.value
72
72
  start_index -= 1 unless start_index < 0
73
73
  end_index -= 1 unless end_index < 0
74
- Sass::Script::List.new list.values[start_index..end_index], list.separator
74
+ list(list.values[start_index..end_index], list.separator)
75
75
  end
76
76
 
77
77
  # removes the given values from the list.
78
78
  def reject(list, *values)
79
- Sass::Script::List.new(list.value.reject{|v| values.any?{|o| v == o}}, list.separator)
79
+ list(list.value.reject{|v| values.any?{|o| v == o}}, list.separator)
80
80
  end
81
81
 
82
82
  # returns the first value of a space delimited list.
83
83
  def first_value_of(list)
84
- if list.is_a?(Sass::Script::String)
85
- Sass::Script::String.new(list.value.split(/\s+/).first)
86
- elsif defined?(Sass::Script::List) && list.is_a?(Sass::Script::List)
84
+ if list.is_a?(Sass::Script::Value::String)
85
+ r = list.value.split(/\s+/).first
86
+ list.type == :identifier ? identifier(r) : quoted_string(r)
87
+ elsif list.is_a?(Sass::Script::Value::List)
87
88
  list.value.first
88
89
  else
89
90
  list
@@ -93,7 +94,7 @@ module Compass::Core::SassExtensions::Functions::Lists
93
94
  protected
94
95
 
95
96
  def assert_list(value)
96
- unless value.is_a?(Sass::Script::List)
97
+ unless value.is_a?(Sass::Script::Value::List)
97
98
  raise ArgumentError.new("#{value.inspect} is not a list")
98
99
  end
99
100
  end
@@ -1,7 +1,10 @@
1
1
  module Compass::Core::SassExtensions::Functions::Math
2
2
  extend Compass::Core::SassExtensions::Functions::SassDeclarationHelper
3
+ extend Sass::Script::Value::Helpers
4
+
5
+ PI = number(Math::PI)
6
+ E = number(Math::E)
3
7
 
4
- PI = Sass::Script::Number.new(Math::PI)
5
8
  def pi()
6
9
  PI
7
10
  end
@@ -14,7 +17,7 @@ module Compass::Core::SassExtensions::Functions::Math
14
17
  range = (args.first.value..args.last.value).to_a
15
18
  range[rand(range.length)]
16
19
  end
17
- Sass::Script::Number.new(value)
20
+ number(value)
18
21
  end
19
22
  declare :random, [:limit]
20
23
  declare :random, [:start, :limit]
@@ -50,7 +53,7 @@ module Compass::Core::SassExtensions::Functions::Math
50
53
  declare :atan, [:number]
51
54
 
52
55
  def e
53
- Sass::Script::Number.new(Math::E)
56
+ E
54
57
  end
55
58
  declare :e, []
56
59
 
@@ -60,7 +63,7 @@ module Compass::Core::SassExtensions::Functions::Math
60
63
  raise Sass::SyntaxError, "base to logarithm must be unitless." unless base.unitless?
61
64
 
62
65
  result = Math.log(number.value, base.value) rescue Math.log(number.value) / Math.log(base.value)
63
- Sass::Script::Number.new(result, number.numerator_units, number.denominator_units)
66
+ number(result, number.unit_str)
64
67
  end
65
68
  declare :logarithm, [:number]
66
69
  declare :logarithm, [:number, :base]
@@ -77,16 +80,16 @@ module Compass::Core::SassExtensions::Functions::Math
77
80
  assert_type number, :Number
78
81
  assert_type exponent, :Number
79
82
  raise Sass::SyntaxError, "exponent to pow must be unitless." unless exponent.unitless?
80
- Sass::Script::Number.new(number.value**exponent.value, number.numerator_units, number.denominator_units)
83
+ number(number.value**exponent.value, number.unit_str)
81
84
  end
82
85
  declare :pow, [:number, :exponent]
83
86
 
84
87
  private
85
88
  def trig(operation, number)
86
- if number.numerator_units == ["deg"] && number.denominator_units == []
87
- Sass::Script::Number.new(Math.send(operation, Math::PI * number.value / 180))
89
+ if number.unit_str == "deg"
90
+ number(Math.send(operation, Math::PI * number.value / 180))
88
91
  else
89
- Sass::Script::Number.new(Math.send(operation, number.value), number.numerator_units, number.denominator_units)
92
+ number(Math.send(operation, number.value), number.unit_str)
90
93
  end
91
94
  end
92
95
  end
@@ -4,39 +4,54 @@ module Compass::Core::SassExtensions::Functions::Selectors
4
4
  # Permute multiple selectors each of which may be comma delimited, the end result is
5
5
  # a new selector that is the equivalent of nesting each under the previous selector.
6
6
  # To illustrate, the following mixins are equivalent:
7
- # =mixin-a(!selector1, !selector2, !selector3)
8
- # #{!selector1}
9
- # #{selector2}
10
- # #{selector3}
7
+ #
8
+ # @include mixin-a($selector1, $selector2, $selector3) {
9
+ # #{$selector1} {
10
+ # #{$selector2} {
11
+ # #{$selector3} {
12
+ # width: 2px
13
+ # }
14
+ # }
15
+ # }
16
+ # }
17
+ # @include mixin-b($selector1, $selector2, $selector3) {
18
+ # #{nest($selector, $selector2, $selector3)} {
11
19
  # width: 2px
12
- # =mixin-b(!selector1, !selector2)
13
- # #{nest(!selector, !selector2, !selector3)}
14
- # width: 2px
20
+ # }
21
+ # }
15
22
  def nest(*arguments)
16
23
  nested = arguments.map{|a| a.value}.inject do |memo,arg|
17
24
  ancestors = memo.split(COMMA_SEPARATOR)
18
25
  descendants = arg.split(COMMA_SEPARATOR)
19
26
  ancestors.map{|a| descendants.map{|d| "#{a} #{d}"}.join(", ")}.join(", ")
20
27
  end
21
- Sass::Script::String.new(nested)
28
+ unquoted_string(nested)
22
29
  end
23
30
 
24
31
  # Permute two selectors, the first may be comma delimited.
25
32
  # The end result is a new selector that is the equivalent of nesting the second
26
33
  # selector under the first one in a sass file and preceding it with an &.
27
- # To illustrate, the following mixins are equivalent:
28
- # =mixin-a(!selector, !to_append)
29
- # #{!selector}
30
- # &#{!to_append}
31
- # width: 2px
32
- # =mixin-b(!selector, !to_append)
33
- # #{append_selector(!selector, !to_append)}
34
- # width: 2px
34
+ # To illustrate, the following mixins are equivalent, except the second
35
+ # mixin handles:
36
+ #
37
+ # @include mixin-a($selector, $to-append) {
38
+ # #{$selector} {
39
+ # &#{$to-append} {
40
+ # width: 2px
41
+ # }
42
+ # }
43
+ # }
44
+ #
45
+ # @include mixin-b($selector, $to-append) {
46
+ # #{append_selector($selector, $to-append)} {
47
+ # width: 2px
48
+ # }
49
+ # }
35
50
  def append_selector(selector, to_append)
36
51
  ancestors = selector.value.split(COMMA_SEPARATOR)
37
52
  descendants = to_append.value.split(COMMA_SEPARATOR)
38
53
  nested = ancestors.map{|a| descendants.map{|d| "#{a}#{d}"}.join(", ")}.join(", ")
39
- Sass::Script::String.new(nested)
54
+ unquoted_string(nested)
40
55
  end
41
56
 
42
57
  # Return the header selectors for the levels indicated
@@ -47,18 +62,18 @@ module Compass::Core::SassExtensions::Functions::Selectors
47
62
  # headers(2,4) => h2, h3, h4
48
63
  def headers(from = nil, to = nil)
49
64
  if from && !to
50
- if from.is_a?(Sass::Script::String) && from.value == "all"
51
- from = Sass::Script::Number.new(1)
52
- to = Sass::Script::Number.new(6)
65
+ if from.is_a?(Sass::Script::Value::String) && from.value == "all"
66
+ from = number(1)
67
+ to = number(6)
53
68
  else
54
69
  to = from
55
- from = Sass::Script::Number.new(1)
70
+ from = number(1)
56
71
  end
57
72
  else
58
- from ||= Sass::Script::Number.new(1)
59
- to ||= Sass::Script::Number.new(6)
73
+ from ||= number(1)
74
+ to ||= number(6)
60
75
  end
61
- Sass::Script::String.new((from.value..to.value).map{|n| "h#{n}"}.join(", "))
76
+ list((from.value..to.value).map{|n| identifier("h#{n}")}, :comma)
62
77
  end
63
78
  alias headings headers
64
79
  end
@@ -19,7 +19,7 @@ module Compass::Core::SassExtensions::Functions::Urls
19
19
  base.declare :stylesheet_url, [:path, :only_path]
20
20
  end
21
21
  end
22
- def stylesheet_url(path, only_path = Sass::Script::Bool.new(false))
22
+ def stylesheet_url(path, only_path = bool(false))
23
23
  # Compute the path to the stylesheet, either root relative or stylesheet relative
24
24
  # or nil if the http_images_path is not set in the configuration.
25
25
  http_stylesheets_path = if relative?
@@ -32,7 +32,7 @@ module Compass::Core::SassExtensions::Functions::Urls
32
32
 
33
33
  path = "#{http_stylesheets_path}/#{path.value}"
34
34
  if only_path.to_bool
35
- Sass::Script::String.new(clean_path(path))
35
+ unquoted_string(clean_path(path))
36
36
  else
37
37
  clean_url(path)
38
38
  end
@@ -47,12 +47,12 @@ module Compass::Core::SassExtensions::Functions::Urls
47
47
  base.declare :font_url, [:path, :only_path, :cache_buster]
48
48
  end
49
49
  end
50
- def font_url(path, only_path = Sass::Script::Bool.new(false), cache_buster = Sass::Script::Bool.new(true))
50
+ def font_url(path, only_path = bool(false), cache_buster = bool(true))
51
51
  path = path.value # get to the string value of the literal.
52
52
 
53
53
  # Short curcuit if they have provided an absolute url.
54
54
  if absolute_path?(path)
55
- return Sass::Script::String.new("url(#{path})")
55
+ return unquoted_string("url(#{path})")
56
56
  end
57
57
 
58
58
  # Compute the path to the font file, either root relative or stylesheet relative
@@ -82,7 +82,7 @@ module Compass::Core::SassExtensions::Functions::Urls
82
82
  # Compute and append the cache buster if there is one.
83
83
  if cache_buster.to_bool
84
84
  path, anchor = path.split("#", 2)
85
- if cache_buster.is_a?(Sass::Script::String)
85
+ if cache_buster.is_a?(Sass::Script::Value::String)
86
86
  path += "?#{cache_buster.value}"
87
87
  else
88
88
  path = cache_busted_path(path, real_path)
@@ -94,7 +94,7 @@ module Compass::Core::SassExtensions::Functions::Urls
94
94
  path = "#{asset_host}#{'/' unless path[0..0] == "/"}#{path}" if asset_host
95
95
 
96
96
  if only_path.to_bool
97
- Sass::Script::String.new(clean_path(path))
97
+ unquoted_string(clean_path(path))
98
98
  else
99
99
  clean_url(path)
100
100
  end
@@ -109,7 +109,7 @@ module Compass::Core::SassExtensions::Functions::Urls
109
109
  base.declare :image_url, [:path, :only_path, :cache_buster]
110
110
  end
111
111
  end
112
- def image_url(path, only_path = Sass::Script::Bool.new(false), cache_buster = Sass::Script::Bool.new(true))
112
+ def image_url(path, only_path = bool(false), cache_buster = bool(true))
113
113
  path = path.value # get to the string value of the literal.
114
114
 
115
115
  if path =~ %r{^#{Regexp.escape(Compass.configuration.http_images_path)}/(.*)}
@@ -118,7 +118,7 @@ module Compass::Core::SassExtensions::Functions::Urls
118
118
  path = $1
119
119
  elsif absolute_path?(path)
120
120
  # Short curcuit if they have provided an absolute url.
121
- return Sass::Script::String.new("url(#{path})")
121
+ return unquoted_string("url(#{path})")
122
122
  end
123
123
 
124
124
  # Compute the path to the image, either root relative or stylesheet relative
@@ -152,7 +152,7 @@ module Compass::Core::SassExtensions::Functions::Urls
152
152
  # Compute and append the cache buster if there is one.
153
153
  if cache_buster.to_bool
154
154
  path, anchor = path.split("#", 2)
155
- if cache_buster.is_a?(Sass::Script::String)
155
+ if cache_buster.is_a?(Sass::Script::Value::String)
156
156
  path += "?#{cache_buster.value}"
157
157
  else
158
158
  path = cache_busted_path(path, real_path)
@@ -164,7 +164,7 @@ module Compass::Core::SassExtensions::Functions::Urls
164
164
  path = "#{asset_host}#{'/' unless path[0..0] == "/"}#{path}" if asset_host
165
165
 
166
166
  if only_path.to_bool
167
- Sass::Script::String.new(clean_path(path))
167
+ unquoted_string(clean_path(path))
168
168
  else
169
169
  clean_url(path)
170
170
  end
@@ -178,7 +178,7 @@ module Compass::Core::SassExtensions::Functions::Urls
178
178
  base.declare :generated_image_url, [:path, :cache_buster]
179
179
  end
180
180
  end
181
- def generated_image_url(path, cache_buster = Sass::Script::Bool.new(false))
181
+ def generated_image_url(path, cache_buster = bool(false))
182
182
  path = path.value # get to the string value of the literal.
183
183
 
184
184
  if path =~ %r{^#{Regexp.escape(Compass.configuration.http_generated_images_path)}/(.*)}
@@ -187,7 +187,7 @@ module Compass::Core::SassExtensions::Functions::Urls
187
187
  path = $1
188
188
  elsif absolute_path?(path)
189
189
  # Short curcuit if they have provided an absolute url.
190
- return Sass::Script::String.new("url(#{path})")
190
+ return unquoted_string("url(#{path})")
191
191
  end
192
192
 
193
193
  # Compute the path to the image, either root relative or stylesheet relative
@@ -221,7 +221,7 @@ module Compass::Core::SassExtensions::Functions::Urls
221
221
  # Compute and append the cache buster if there is one.
222
222
  if cache_buster.to_bool
223
223
  path, anchor = path.split("#", 2)
224
- if cache_buster.is_a?(Sass::Script::String)
224
+ if cache_buster.is_a?(Sass::Script::Value::String)
225
225
  path += "?#{cache_buster.value}"
226
226
  else
227
227
  path = cache_busted_path(path, real_path)
@@ -246,7 +246,7 @@ module Compass::Core::SassExtensions::Functions::Urls
246
246
 
247
247
  # Emits a url, taking off any leading "./"
248
248
  def clean_url(url)
249
- Sass::Script::String.new("url('#{clean_path(url)}')")
249
+ unquoted_string("url('#{clean_path(url)}')")
250
250
  end
251
251
 
252
252
  def relative?
@@ -50,6 +50,7 @@ module Sass::Script
50
50
  attr_accessor :name, :args
51
51
 
52
52
  include HasSimpleCrossBrowserFunctionSupport
53
+ include Sass::Script::Value::Helpers
53
54
 
54
55
  def initialize(name, args)
55
56
  self.name = name
@@ -81,9 +82,9 @@ module Sass::Script
81
82
  end
82
83
  contents = prefixed_args.join(', ')
83
84
  if contents.size > 0
84
- opts(Sass::Script::String.new("\#{prefixed_name}(\#{contents})"))
85
+ opts(identifier("\#{prefixed_name}(\#{contents})"))
85
86
  else
86
- opts(Sass::Script::String.new(""))
87
+ opts(null)
87
88
  end
88
89
  end
89
90
  RUBY
@@ -4,8 +4,8 @@
4
4
  @mixin inline-list {
5
5
  list-style-type: none;
6
6
  &, & li {
7
- margin: 0px;
8
- padding: 0px;
7
+ margin: 0;
8
+ padding: 0;
9
9
  display: inline;
10
10
  }
11
11
  }