simple-compass 0.0.1
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.
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +26 -0
- data/Rakefile +8 -0
- data/lib/simple-compass.rb +17 -0
- data/lib/simple-compass/sass/functions/display.rb +27 -0
- data/lib/simple-compass/sass/functions/lists.rb +101 -0
- data/lib/simple-compass/sass/functions/selectors.rb +64 -0
- data/lib/simple-compass/sass/functions/sprites.rb +218 -0
- data/lib/simple-compass/version.rb +3 -0
- data/sass/compass.scss +1 -0
- data/sass/compass/_css3.scss +20 -0
- data/sass/compass/_layout.scss +3 -0
- data/sass/compass/_reset-legacy.scss +3 -0
- data/sass/compass/_reset.scss +3 -0
- data/sass/compass/_support.scss +40 -0
- data/sass/compass/_typography.scss +4 -0
- data/sass/compass/_utilities.scss +9 -0
- data/sass/compass/css3/_appearance.scss +17 -0
- data/sass/compass/css3/_background-clip.scss +43 -0
- data/sass/compass/css3/_background-origin.scss +42 -0
- data/sass/compass/css3/_background-size.scss +26 -0
- data/sass/compass/css3/_border-radius.scss +130 -0
- data/sass/compass/css3/_box-shadow.scss +76 -0
- data/sass/compass/css3/_box-sizing.scss +13 -0
- data/sass/compass/css3/_box.scss +111 -0
- data/sass/compass/css3/_columns.scss +157 -0
- data/sass/compass/css3/_filter.scss +23 -0
- data/sass/compass/css3/_font-face.scss +48 -0
- data/sass/compass/css3/_hyphenation.scss +77 -0
- data/sass/compass/css3/_images.scss +132 -0
- data/sass/compass/css3/_inline-block.scss +22 -0
- data/sass/compass/css3/_opacity.scss +19 -0
- data/sass/compass/css3/_pie.scss +73 -0
- data/sass/compass/css3/_regions.scss +22 -0
- data/sass/compass/css3/_shared.scss +38 -0
- data/sass/compass/css3/_text-shadow.scss +87 -0
- data/sass/compass/css3/_transform-legacy.scss +87 -0
- data/sass/compass/css3/_transform.scss +598 -0
- data/sass/compass/css3/_transition.scss +221 -0
- data/sass/compass/css3/_user-interface.scss +17 -0
- data/sass/compass/layout/_grid-background.scss +178 -0
- data/sass/compass/layout/_sticky-footer.scss +23 -0
- data/sass/compass/layout/_stretching.scss +24 -0
- data/sass/compass/reset/_utilities-legacy.scss +135 -0
- data/sass/compass/reset/_utilities.scss +142 -0
- data/sass/compass/typography/_links.scss +3 -0
- data/sass/compass/typography/_lists.scss +4 -0
- data/sass/compass/typography/_text.scss +4 -0
- data/sass/compass/typography/_vertical_rhythm.scss +221 -0
- data/sass/compass/typography/links/_hover-link.scss +5 -0
- data/sass/compass/typography/links/_link-colors.scss +28 -0
- data/sass/compass/typography/links/_unstyled-link.scss +7 -0
- data/sass/compass/typography/lists/_bullets.scss +34 -0
- data/sass/compass/typography/lists/_horizontal-list.scss +61 -0
- data/sass/compass/typography/lists/_inline-block-list.scss +50 -0
- data/sass/compass/typography/lists/_inline-list.scss +44 -0
- data/sass/compass/typography/text/_ellipsis.scss +25 -0
- data/sass/compass/typography/text/_force-wrap.scss +12 -0
- data/sass/compass/typography/text/_nowrap.scss +2 -0
- data/sass/compass/typography/text/_replacement.scss +68 -0
- data/sass/compass/utilities/_color.scss +1 -0
- data/sass/compass/utilities/_general.scss +6 -0
- data/sass/compass/utilities/_links.scss +5 -0
- data/sass/compass/utilities/_lists.scss +6 -0
- data/sass/compass/utilities/_print.scss +17 -0
- data/sass/compass/utilities/_sprites.scss +2 -0
- data/sass/compass/utilities/_tables.scss +3 -0
- data/sass/compass/utilities/_text.scss +5 -0
- data/sass/compass/utilities/color/_contrast.scss +28 -0
- data/sass/compass/utilities/general/_clearfix.scss +44 -0
- data/sass/compass/utilities/general/_float.scss +30 -0
- data/sass/compass/utilities/general/_hacks.scss +46 -0
- data/sass/compass/utilities/general/_min.scss +16 -0
- data/sass/compass/utilities/general/_reset.scss +2 -0
- data/sass/compass/utilities/general/_tabs.scss +1 -0
- data/sass/compass/utilities/general/_tag-cloud.scss +18 -0
- data/sass/compass/utilities/links/_hover-link.scss +3 -0
- data/sass/compass/utilities/links/_link-colors.scss +3 -0
- data/sass/compass/utilities/links/_unstyled-link.scss +3 -0
- data/sass/compass/utilities/lists/_bullets.scss +3 -0
- data/sass/compass/utilities/lists/_horizontal-list.scss +3 -0
- data/sass/compass/utilities/lists/_inline-block-list.scss +3 -0
- data/sass/compass/utilities/lists/_inline-list.scss +3 -0
- data/sass/compass/utilities/sprites/_base.scss +66 -0
- data/sass/compass/utilities/sprites/_sprite-img.scss +79 -0
- data/sass/compass/utilities/tables/_alternating-rows-and-columns.scss +22 -0
- data/sass/compass/utilities/tables/_borders.scss +33 -0
- data/sass/compass/utilities/tables/_scaffolding.scss +9 -0
- data/sass/compass/utilities/text/_ellipsis.scss +3 -0
- data/sass/compass/utilities/text/_nowrap.scss +3 -0
- data/sass/compass/utilities/text/_replacement.scss +3 -0
- data/simple-compass.gemspec +21 -0
- data/spec/fixtures/headings_test.sass +2 -0
- data/spec/fixtures/opacity_test.sass +7 -0
- data/spec/fixtures/reset_test.sass +1 -0
- data/spec/headings_spec.rb +9 -0
- data/spec/opacity_spec.rb +9 -0
- data/spec/reset_spec.rb +9 -0
- data/spec/spec_helper.rb +7 -0
- metadata +169 -0
data/.gitignore
ADDED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
simple-compass (0.0.1)
|
|
5
|
+
sass
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: http://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
diff-lcs (1.2.1)
|
|
11
|
+
rspec (2.13.0)
|
|
12
|
+
rspec-core (~> 2.13.0)
|
|
13
|
+
rspec-expectations (~> 2.13.0)
|
|
14
|
+
rspec-mocks (~> 2.13.0)
|
|
15
|
+
rspec-core (2.13.0)
|
|
16
|
+
rspec-expectations (2.13.0)
|
|
17
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
|
18
|
+
rspec-mocks (2.13.0)
|
|
19
|
+
sass (3.2.6)
|
|
20
|
+
|
|
21
|
+
PLATFORMS
|
|
22
|
+
ruby
|
|
23
|
+
|
|
24
|
+
DEPENDENCIES
|
|
25
|
+
rspec
|
|
26
|
+
simple-compass!
|
data/Rakefile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'sass'
|
|
2
|
+
|
|
3
|
+
module Compass
|
|
4
|
+
module Frameworks
|
|
5
|
+
def self.register(name, options = {})
|
|
6
|
+
Sass.load_paths << options[:stylesheets_directory]
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
root_dir = File.join(File.dirname(__FILE__), '..')
|
|
12
|
+
|
|
13
|
+
sass_dir = File.expand_path File.join root_dir, 'sass'
|
|
14
|
+
Sass.load_paths << sass_dir
|
|
15
|
+
|
|
16
|
+
functions_dir = File.expand_path File.join root_dir, 'lib', 'simple-compass', 'sass', 'functions'
|
|
17
|
+
Dir[File.join(functions_dir, "**/*.rb")].each { |f| require f }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Sass::Script::Functions
|
|
2
|
+
DEFAULT_DISPLAY = {
|
|
3
|
+
:block => %w{address article aside blockquote center dir div dd details dl dt fieldset
|
|
4
|
+
figcaption figure form footer frameset h1 h2 h3 h4 h5 h6 hr header hgroup
|
|
5
|
+
isindex menu nav noframes noscript ol p pre section summary ul},
|
|
6
|
+
:inline => %w{a abbr acronym audio b basefont bdo big br canvas cite code command
|
|
7
|
+
datalist dfn em embed font i img input keygen kbd label mark meter output
|
|
8
|
+
progress q rp rt ruby s samp select small span strike strong sub
|
|
9
|
+
sup textarea time tt u var video wbr},
|
|
10
|
+
:"inline-block" => %w{img},
|
|
11
|
+
:table => %w{table},
|
|
12
|
+
:"list-item" => %w{li},
|
|
13
|
+
:"table-row-group" => %w{tbody},
|
|
14
|
+
:"table-header-group" => %w{thead},
|
|
15
|
+
:"table-footer-group" => %w{tfoot},
|
|
16
|
+
:"table-row" => %w{tr},
|
|
17
|
+
:"table-cell" => %w{th td},
|
|
18
|
+
:"html5-block" => %w{article aside details figcaption figure footer header hgroup menu nav section summary},
|
|
19
|
+
:"html5-inline" => %w{audio canvas command datalist embed keygen mark meter output progress rp rt ruby time video wbr},
|
|
20
|
+
}
|
|
21
|
+
DEFAULT_DISPLAY[:html5] = (DEFAULT_DISPLAY[:"html5-block"] + DEFAULT_DISPLAY[:"html5-inline"]).sort
|
|
22
|
+
# returns a comma delimited string for all the
|
|
23
|
+
# elements according to their default css3 display value.
|
|
24
|
+
def elements_of_type(display)
|
|
25
|
+
Sass::Script::String.new(DEFAULT_DISPLAY.fetch(display.value.to_sym).join(", "))
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
module Sass::Script::Functions
|
|
2
|
+
|
|
3
|
+
# Returns true when the object is false, an empty string, or an empty list
|
|
4
|
+
def blank(obj)
|
|
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}
|
|
12
|
+
else
|
|
13
|
+
Sass::Script::Bool.new false
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Returns a new list after removing any non-true values
|
|
18
|
+
def compact(*args)
|
|
19
|
+
sep = :comma
|
|
20
|
+
if args.size == 1 && args.first.is_a?(Sass::Script::List)
|
|
21
|
+
list = args.first
|
|
22
|
+
args = list.value
|
|
23
|
+
sep = list.separator
|
|
24
|
+
end
|
|
25
|
+
Sass::Script::List.new(args.reject{|a| !a.to_bool}, sep)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Get the nth value from a list
|
|
29
|
+
def _compass_nth(list, place)
|
|
30
|
+
assert_type list, :List
|
|
31
|
+
if place.value == "first"
|
|
32
|
+
list.value.first
|
|
33
|
+
elsif place.value == "last"
|
|
34
|
+
list.value.last
|
|
35
|
+
else
|
|
36
|
+
list.value[place.value - 1]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Returns a list object from a value that was passed.
|
|
41
|
+
# This can be used to unpack a space separated list that got turned
|
|
42
|
+
# into a string by sass before it was passed to a mixin.
|
|
43
|
+
def _compass_list(arg)
|
|
44
|
+
if arg.is_a?(Sass::Script::List)
|
|
45
|
+
Sass::Script::List.new(arg.value.dup, arg.separator)
|
|
46
|
+
else
|
|
47
|
+
Sass::Script::List.new([arg], :space)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# If the argument is a list, it will return a new list that is space delimited
|
|
52
|
+
# Otherwise it returns a new, single element, space-delimited list.
|
|
53
|
+
def _compass_space_list(list)
|
|
54
|
+
if list.is_a?(Sass::Script::List)
|
|
55
|
+
Sass::Script::List.new(list.value.dup, :space)
|
|
56
|
+
else
|
|
57
|
+
Sass::Script::List.new([list], :space)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Returns the size of the list.
|
|
62
|
+
def _compass_list_size(list)
|
|
63
|
+
assert_list list
|
|
64
|
+
Sass::Script::Number.new(list.value.size)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# slice a sublist from a list
|
|
68
|
+
def _compass_slice(list, start_index, end_index = nil)
|
|
69
|
+
end_index ||= Sass::Script::Number.new(-1)
|
|
70
|
+
start_index = start_index.value
|
|
71
|
+
end_index = end_index.value
|
|
72
|
+
start_index -= 1 unless start_index < 0
|
|
73
|
+
end_index -= 1 unless end_index < 0
|
|
74
|
+
Sass::Script::List.new list.values[start_index..end_index], list.separator
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# removes the given values from the list.
|
|
78
|
+
def reject(list, *values)
|
|
79
|
+
Sass::Script::List.new(list.value.reject{|v| values.any?{|o| v == o}}, list.separator)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# returns the first value of a space delimited list.
|
|
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)
|
|
87
|
+
list.value.first
|
|
88
|
+
else
|
|
89
|
+
list
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
protected
|
|
94
|
+
|
|
95
|
+
def assert_list(value)
|
|
96
|
+
unless value.is_a?(Sass::Script::List)
|
|
97
|
+
raise ArgumentError.new("#{value.inspect} is not a list")
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module Sass::Script::Functions
|
|
2
|
+
COMMA_SEPARATOR = /\s*,\s*/
|
|
3
|
+
|
|
4
|
+
# Permute multiple selectors each of which may be comma delimited, the end result is
|
|
5
|
+
# a new selector that is the equivalent of nesting each under the previous selector.
|
|
6
|
+
# To illustrate, the following mixins are equivalent:
|
|
7
|
+
# =mixin-a(!selector1, !selector2, !selector3)
|
|
8
|
+
# #{!selector1}
|
|
9
|
+
# #{selector2}
|
|
10
|
+
# #{selector3}
|
|
11
|
+
# width: 2px
|
|
12
|
+
# =mixin-b(!selector1, !selector2)
|
|
13
|
+
# #{nest(!selector, !selector2, !selector3)}
|
|
14
|
+
# width: 2px
|
|
15
|
+
def nest(*arguments)
|
|
16
|
+
nested = arguments.map{|a| a.value}.inject do |memo,arg|
|
|
17
|
+
ancestors = memo.split(COMMA_SEPARATOR)
|
|
18
|
+
descendants = arg.split(COMMA_SEPARATOR)
|
|
19
|
+
ancestors.map{|a| descendants.map{|d| "#{a} #{d}"}.join(", ")}.join(", ")
|
|
20
|
+
end
|
|
21
|
+
Sass::Script::String.new(nested)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Permute two selectors, the first may be comma delimited.
|
|
25
|
+
# The end result is a new selector that is the equivalent of nesting the second
|
|
26
|
+
# 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
|
|
35
|
+
def append_selector(selector, to_append)
|
|
36
|
+
ancestors = selector.value.split(COMMA_SEPARATOR)
|
|
37
|
+
descendants = to_append.value.split(COMMA_SEPARATOR)
|
|
38
|
+
nested = ancestors.map{|a| descendants.map{|d| "#{a}#{d}"}.join(", ")}.join(", ")
|
|
39
|
+
Sass::Script::String.new(nested)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Return the header selectors for the levels indicated
|
|
43
|
+
# Defaults to all headers h1 through h6
|
|
44
|
+
# For example:
|
|
45
|
+
# headers(all) => h1, h2, h3, h4, h5, h6
|
|
46
|
+
# headers(4) => h1, h2, h3, h4
|
|
47
|
+
# headers(2,4) => h2, h3, h4
|
|
48
|
+
def headers(from = nil, to = nil)
|
|
49
|
+
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)
|
|
53
|
+
else
|
|
54
|
+
to = from
|
|
55
|
+
from = Sass::Script::Number.new(1)
|
|
56
|
+
end
|
|
57
|
+
else
|
|
58
|
+
from ||= Sass::Script::Number.new(1)
|
|
59
|
+
to ||= Sass::Script::Number.new(6)
|
|
60
|
+
end
|
|
61
|
+
Sass::Script::String.new((from.value..to.value).map{|n| "h#{n}"}.join(", "))
|
|
62
|
+
end
|
|
63
|
+
alias headings headers
|
|
64
|
+
end
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
module Sass::Script::Functions
|
|
2
|
+
ZERO = Sass::Script::Number::new(0)
|
|
3
|
+
VALID_SELECTORS = %w(hover active target)
|
|
4
|
+
# Provides a consistent interface for getting a variable in ruby
|
|
5
|
+
# from a keyword argument hash that accounts for underscores/dash equivalence
|
|
6
|
+
# and allows the caller to pass a symbol instead of a string.
|
|
7
|
+
module VariableReader
|
|
8
|
+
def get_var(variable_name)
|
|
9
|
+
self[variable_name.to_s.gsub(/-/,"_")]
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
#Returns a list of all sprite names
|
|
14
|
+
def sprite_names(map)
|
|
15
|
+
Sass::Script::List.new(map.sprite_names.map { |f| Sass::Script::String.new(f) }, ' ')
|
|
16
|
+
end
|
|
17
|
+
Sass::Script::Functions.declare :sprite_names, [:map]
|
|
18
|
+
|
|
19
|
+
# Returns the system path of the sprite file
|
|
20
|
+
def sprite_path(map)
|
|
21
|
+
Sass::Script::String.new(map.name_and_hash)
|
|
22
|
+
end
|
|
23
|
+
Sass::Script::Functions.declare :sprite_path, [:map]
|
|
24
|
+
|
|
25
|
+
# Returns the sprite file as an inline image
|
|
26
|
+
# @include "icon/*.png";
|
|
27
|
+
# #{$icon-sprite-base-class} {
|
|
28
|
+
# background-image: inline-sprite($icon-sprites);
|
|
29
|
+
# }
|
|
30
|
+
def inline_sprite(map)
|
|
31
|
+
verify_map(map, "sprite-url")
|
|
32
|
+
map.generate
|
|
33
|
+
inline_image(sprite_path(map))
|
|
34
|
+
end
|
|
35
|
+
Sass::Script::Functions.declare :inline_sprite, [:map]
|
|
36
|
+
|
|
37
|
+
# Creates a Compass::SassExtensions::Sprites::SpriteMap object. A sprite map, when used in a property is the same
|
|
38
|
+
# as calling sprite-url. So the following background properties are equivalent:
|
|
39
|
+
#
|
|
40
|
+
# $icons: sprite-map("icons/*.png");
|
|
41
|
+
# background: sprite-url($icons) no-repeat;
|
|
42
|
+
# background: $icons no-repeat;
|
|
43
|
+
#
|
|
44
|
+
# The sprite map object will generate the sprite map image, if necessary,
|
|
45
|
+
# the first time it is converted to a url. Simply constructing it has no side-effects.
|
|
46
|
+
def sprite_map(glob, kwargs = {})
|
|
47
|
+
kwargs.extend VariableReader
|
|
48
|
+
Compass::SassExtensions::Sprites::SpriteMap.from_uri(glob, self, kwargs)
|
|
49
|
+
end
|
|
50
|
+
Sass::Script::Functions.declare :sprite_map, [:glob], :var_kwargs => true
|
|
51
|
+
|
|
52
|
+
# Returns the image and background position for use in a single shorthand property:
|
|
53
|
+
#
|
|
54
|
+
# $icons: sprite-map("icons/*.png"); // contains icons/new.png among others.
|
|
55
|
+
# background: sprite($icons, new) no-repeat;
|
|
56
|
+
#
|
|
57
|
+
# Becomes:
|
|
58
|
+
#
|
|
59
|
+
# background: url('/images/icons.png?12345678') 0 -24px no-repeat;
|
|
60
|
+
def sprite(map, sprite, offset_x = ZERO, offset_y = ZERO)
|
|
61
|
+
sprite = convert_sprite_name(sprite)
|
|
62
|
+
verify_map(map)
|
|
63
|
+
unless sprite.is_a?(Sass::Script::String)
|
|
64
|
+
raise Sass::SyntaxError, %Q(The second argument to sprite() must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
|
|
65
|
+
end
|
|
66
|
+
url = sprite_url(map)
|
|
67
|
+
position = sprite_position(map, sprite, offset_x, offset_y)
|
|
68
|
+
Sass::Script::List.new([url] + position.value, :space)
|
|
69
|
+
end
|
|
70
|
+
Sass::Script::Functions.declare :sprite, [:map, :sprite]
|
|
71
|
+
Sass::Script::Functions.declare :sprite, [:map, :sprite, :offset_x]
|
|
72
|
+
Sass::Script::Functions.declare :sprite, [:map, :sprite, :offset_x, :offset_y]
|
|
73
|
+
|
|
74
|
+
# Returns the name of a sprite map
|
|
75
|
+
# The name is derived from the folder than contains the sprites.
|
|
76
|
+
def sprite_map_name(map)
|
|
77
|
+
verify_map(map, "sprite-map-name")
|
|
78
|
+
Sass::Script::String.new(map.name)
|
|
79
|
+
end
|
|
80
|
+
Sass::Script::Functions.declare :sprite_name, [:sprite]
|
|
81
|
+
|
|
82
|
+
# Returns the path to the original image file for the sprite with the given name
|
|
83
|
+
def sprite_file(map, sprite)
|
|
84
|
+
sprite = convert_sprite_name(sprite)
|
|
85
|
+
verify_map(map, "sprite")
|
|
86
|
+
verify_sprite(sprite)
|
|
87
|
+
if image = map.image_for(sprite.value)
|
|
88
|
+
Sass::Script::String.new(image.file)
|
|
89
|
+
else
|
|
90
|
+
missing_image!(map, sprite)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
Sass::Script::Functions.declare :sprite_file, [:map, :sprite]
|
|
94
|
+
|
|
95
|
+
# Returns boolean if sprite has a parent
|
|
96
|
+
def sprite_does_not_have_parent(map, sprite)
|
|
97
|
+
sprite = convert_sprite_name(sprite)
|
|
98
|
+
verify_map map
|
|
99
|
+
verify_sprite sprite
|
|
100
|
+
Sass::Script::Bool.new map.image_for(sprite.value).parent.nil?
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
Sass::Script::Functions.declare :sprite_does_not_have_parent, [:map, :sprite]
|
|
104
|
+
|
|
105
|
+
# Returns boolean if sprite has the selector
|
|
106
|
+
def sprite_has_selector(map, sprite, selector)
|
|
107
|
+
sprite = convert_sprite_name(sprite)
|
|
108
|
+
verify_map map
|
|
109
|
+
verify_sprite sprite
|
|
110
|
+
unless VALID_SELECTORS.include?(selector.value)
|
|
111
|
+
raise Sass::SyntaxError, "Invalid Selctor did you mean one of: #{VALID_SELECTORS.join(', ')}"
|
|
112
|
+
end
|
|
113
|
+
Sass::Script::Bool.new map.send(:"has_#{selector.value}?", sprite.value)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
Sass::Script::Functions.declare :sprite_has_selector, [:map, :sprite, :selector]
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
# Returns a url to the sprite image.
|
|
120
|
+
def sprite_url(map)
|
|
121
|
+
verify_map(map, "sprite-url")
|
|
122
|
+
map.generate
|
|
123
|
+
generated_image_url(Sass::Script::String.new("#{map.path}-s#{map.uniqueness_hash}.png"))
|
|
124
|
+
end
|
|
125
|
+
Sass::Script::Functions.declare :sprite_url, [:map]
|
|
126
|
+
|
|
127
|
+
# Returns the position for the original image in the sprite.
|
|
128
|
+
# This is suitable for use as a value to background-position:
|
|
129
|
+
#
|
|
130
|
+
# $icons: sprite-map("icons/*.png");
|
|
131
|
+
# background-position: sprite-position($icons, new);
|
|
132
|
+
#
|
|
133
|
+
# Might generate something like:
|
|
134
|
+
#
|
|
135
|
+
# background-position: 0 -34px;
|
|
136
|
+
#
|
|
137
|
+
# You can adjust the background relative to this position by passing values for
|
|
138
|
+
# `$offset-x` and `$offset-y`:
|
|
139
|
+
#
|
|
140
|
+
# $icons: sprite-map("icons/*.png");
|
|
141
|
+
# background-position: sprite-position($icons, new, 3px, -2px);
|
|
142
|
+
#
|
|
143
|
+
# Would change the above output to:
|
|
144
|
+
#
|
|
145
|
+
# background-position: 3px -36px;
|
|
146
|
+
def sprite_position(map, sprite = nil, offset_x = ZERO, offset_y = ZERO)
|
|
147
|
+
assert_type offset_x, :Number
|
|
148
|
+
assert_type offset_y, :Number
|
|
149
|
+
sprite = convert_sprite_name(sprite)
|
|
150
|
+
verify_map(map, "sprite-position")
|
|
151
|
+
unless sprite && sprite.is_a?(Sass::Script::String)
|
|
152
|
+
raise Sass::SyntaxError, %Q(The second argument to sprite-position must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
|
|
153
|
+
end
|
|
154
|
+
image = map.image_for(sprite.value)
|
|
155
|
+
unless image
|
|
156
|
+
missing_image!(map, sprite)
|
|
157
|
+
end
|
|
158
|
+
if offset_x.unit_str == "%"
|
|
159
|
+
x = offset_x # CE: Shouldn't this be a percentage of the total width?
|
|
160
|
+
else
|
|
161
|
+
x = offset_x.value - image.left
|
|
162
|
+
x = Sass::Script::Number.new(x, x == 0 ? [] : ["px"])
|
|
163
|
+
end
|
|
164
|
+
y = offset_y.value - image.top
|
|
165
|
+
y = Sass::Script::Number.new(y, y == 0 ? [] : ["px"])
|
|
166
|
+
Sass::Script::List.new([x, y],:space)
|
|
167
|
+
end
|
|
168
|
+
Sass::Script::Functions.declare :sprite_position, [:map]
|
|
169
|
+
Sass::Script::Functions.declare :sprite_position, [:map, :sprite]
|
|
170
|
+
Sass::Script::Functions.declare :sprite_position, [:map, :sprite, :offset_x]
|
|
171
|
+
Sass::Script::Functions.declare :sprite_position, [:map, :sprite, :offset_x, :offset_y]
|
|
172
|
+
|
|
173
|
+
def sprite_image(*args)
|
|
174
|
+
raise Sass::SyntaxError, %Q(The sprite-image() function has been replaced by sprite(). See http://compass-style.org/help/tutorials/spriting/ for more information.)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
protected
|
|
178
|
+
|
|
179
|
+
def reversed_color_names
|
|
180
|
+
if Sass::Script::Color.const_defined?(:HTML4_COLORS_REVERSE)
|
|
181
|
+
Sass::Script::Color::HTML4_COLORS_REVERSE
|
|
182
|
+
else
|
|
183
|
+
Sass::Script::Color::COLOR_NAMES_REVERSE
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def convert_sprite_name(sprite)
|
|
188
|
+
case sprite
|
|
189
|
+
when Sass::Script::Color
|
|
190
|
+
Sass::Script::String.new(reversed_color_names[sprite.rgb])
|
|
191
|
+
when Sass::Script::Bool
|
|
192
|
+
Sass::Script::String.new(sprite.to_s)
|
|
193
|
+
else
|
|
194
|
+
sprite
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def verify_map(map, error = "sprite")
|
|
199
|
+
unless map.is_a?(Compass::SassExtensions::Sprites::SpriteMap)
|
|
200
|
+
missing_sprite!(error)
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def verify_sprite(sprite)
|
|
205
|
+
unless sprite.is_a?(Sass::Script::String)
|
|
206
|
+
raise Sass::SyntaxError, %Q(The second argument to sprite() must be a sprite name. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def missing_image!(map, sprite)
|
|
211
|
+
raise Sass::SyntaxError, "No sprite called #{sprite} found in sprite map #{map.path}/#{map.name}. Did you mean one of: #{map.sprite_names.join(", ")}"
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def missing_sprite!(function_name)
|
|
215
|
+
raise Sass::SyntaxError, %Q(The first argument to #{function_name}() must be a sprite map. See http://beta.compass-style.org/help/tutorials/spriting/ for more information.)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
end
|