haml-edge 2.3.93 → 2.3.94
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/EDGE_GEM_VERSION +1 -1
- data/README.md +1 -1
- data/Rakefile +17 -3
- data/VERSION +1 -1
- data/lib/haml/helpers.rb +1 -1
- data/lib/haml/html/erb.rb +1 -1
- data/lib/haml/precompiler.rb +28 -22
- data/lib/haml/util.rb +19 -0
- data/lib/sass/engine.rb +3 -3
- data/lib/sass/error.rb +37 -7
- data/lib/sass/files.rb +1 -0
- data/lib/sass/script/color.rb +6 -12
- data/lib/sass/script/functions.rb +24 -26
- data/lib/sass/script/lexer.rb +5 -5
- data/lib/sass/tree/directive_node.rb +3 -3
- data/lib/sass/tree/import_node.rb +23 -21
- data/lib/sass/tree/mixin_node.rb +24 -4
- data/lib/sass/tree/node.rb +74 -18
- data/lib/sass/tree/prop_node.rb +37 -27
- data/lib/sass/tree/root_node.rb +24 -9
- data/lib/sass/tree/rule_node.rb +98 -51
- data/test/haml/engine_test.rb +10 -0
- data/test/haml/util_test.rb +7 -0
- data/test/sass/engine_test.rb +162 -12
- data/test/sass/functions_test.rb +19 -17
- data/test/sass/script_test.rb +8 -0
- data/test/sass/templates/bork4.sass +2 -0
- data/test/sass/templates/mixin_bork.sass +5 -0
- data/test/sass/templates/nested_bork4.sass +2 -0
- data/test/sass/templates/nested_mixin_bork.sass +6 -0
- data/test/test_helper.rb +7 -3
- metadata +14 -34
data/EDGE_GEM_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3.
|
1
|
+
2.3.94
|
data/README.md
CHANGED
@@ -60,7 +60,7 @@ Then any Sass files in `public/stylesheets/sass`
|
|
60
60
|
will be compiled CSS files in `public/stylesheets` on every request.
|
61
61
|
|
62
62
|
To use Haml and Sass programatically,
|
63
|
-
check out the [YARD documentation](http://haml-lang.com/docs/yardoc).
|
63
|
+
check out the [YARD documentation](http://haml-lang.com/docs/yardoc/).
|
64
64
|
|
65
65
|
## Formatting
|
66
66
|
|
data/Rakefile
CHANGED
@@ -203,6 +203,7 @@ task :release_edge do
|
|
203
203
|
|
204
204
|
sh %{rubyforge login}
|
205
205
|
sh %{rubyforge add_release haml haml-edge "Bleeding Edge (v#{edge_version})" pkg/haml-edge-#{edge_version}.gem}
|
206
|
+
sh %{gem push pkg/haml-edge-#{edge_version}.gem}
|
206
207
|
end
|
207
208
|
end
|
208
209
|
|
@@ -222,6 +223,17 @@ end
|
|
222
223
|
begin
|
223
224
|
require 'yard'
|
224
225
|
|
226
|
+
namespace :yard do
|
227
|
+
task :sass do
|
228
|
+
require File.dirname(__FILE__) + '/lib/sass'
|
229
|
+
Dir[File.dirname(__FILE__) + "/yard/default/**/*.sass"].each do |sass|
|
230
|
+
File.open(sass.gsub(/sass$/, 'css'), 'w') do |f|
|
231
|
+
f.write(Sass::Engine.new(File.read(sass)).render)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
225
237
|
YARD::Rake::YardocTask.new do |t|
|
226
238
|
t.files = FileList.new('lib/**/*.rb') do |list|
|
227
239
|
list.exclude('lib/haml/template/*.rb')
|
@@ -231,12 +243,14 @@ begin
|
|
231
243
|
t.options += FileList.new('yard/*.rb').to_a.map {|f| ['-e', f]}.flatten
|
232
244
|
files = FileList.new('doc-src/*').to_a.sort_by {|s| s.size} + %w[MIT-LICENSE VERSION]
|
233
245
|
t.options << '--files' << files.join(',')
|
246
|
+
t.options << '--template-path' << File.dirname(__FILE__) + '/yard'
|
234
247
|
end
|
235
|
-
Rake::Task['
|
248
|
+
Rake::Task['yard'].prerequisites.insert(0, 'yard:sass')
|
249
|
+
Rake::Task['yard'].instance_variable_set('@comment', nil)
|
236
250
|
|
237
251
|
desc "Generate Documentation"
|
238
|
-
task :doc => :
|
239
|
-
task :redoc => :
|
252
|
+
task :doc => :yard
|
253
|
+
task :redoc => :yard
|
240
254
|
rescue LoadError
|
241
255
|
desc "Generate Documentation"
|
242
256
|
task :doc => :rdoc
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3.
|
1
|
+
2.3.94
|
data/lib/haml/helpers.rb
CHANGED
data/lib/haml/html/erb.rb
CHANGED
data/lib/haml/precompiler.rb
CHANGED
@@ -10,10 +10,10 @@ module Haml
|
|
10
10
|
# Designates an XHTML/XML element.
|
11
11
|
ELEMENT = ?%
|
12
12
|
|
13
|
-
# Designates a
|
13
|
+
# Designates a `<div>` element with the given class.
|
14
14
|
DIV_CLASS = ?.
|
15
15
|
|
16
|
-
# Designates a
|
16
|
+
# Designates a `<div>` element with the given id.
|
17
17
|
DIV_ID = ?#
|
18
18
|
|
19
19
|
# Designates an XHTML/XML comment.
|
@@ -77,7 +77,7 @@ module Haml
|
|
77
77
|
# - else
|
78
78
|
# %p no!
|
79
79
|
#
|
80
|
-
# The block is ended after
|
80
|
+
# The block is ended after `%p no!`, because `else`
|
81
81
|
# is a member of this array.
|
82
82
|
MID_BLOCK_KEYWORD_REGEX = /^-\s*(#{%w[else elsif rescue ensure when end].join('|')})\b/
|
83
83
|
|
@@ -201,7 +201,7 @@ END
|
|
201
201
|
# Processes a single line of Haml.
|
202
202
|
#
|
203
203
|
# This method doesn't return anything; it simply processes the line and
|
204
|
-
# adds the appropriate code to
|
204
|
+
# adds the appropriate code to `@precompiled`.
|
205
205
|
def process_line(text, index)
|
206
206
|
@index = index + 1
|
207
207
|
|
@@ -246,7 +246,13 @@ END
|
|
246
246
|
# It's important to preserve tabulation modification for keywords
|
247
247
|
# that involve choosing between posible blocks of code.
|
248
248
|
if %w[else elsif when].include?(keyword)
|
249
|
-
|
249
|
+
# @to_close_stack may not have a :script on top
|
250
|
+
# when the preceding "- if" has nothing nested
|
251
|
+
if @to_close_stack.last && @to_close_stack.last.first == :script
|
252
|
+
@dont_indent_next_line, @dont_tab_up_next_text = @to_close_stack.last[1..2]
|
253
|
+
else
|
254
|
+
push_and_tabulate([:script, @dont_indent_next_line, @dont_tab_up_next_text])
|
255
|
+
end
|
250
256
|
|
251
257
|
# when is unusual in that either it will be indented twice,
|
252
258
|
# or the case won't have created its own indentation
|
@@ -278,7 +284,7 @@ END
|
|
278
284
|
text[MID_BLOCK_KEYWORD_REGEX, 1]
|
279
285
|
end
|
280
286
|
|
281
|
-
# Evaluates
|
287
|
+
# Evaluates `text` in the context of the scope object, but
|
282
288
|
# does not output the result.
|
283
289
|
def push_silent(text, can_suppress = false)
|
284
290
|
flush_merged_text
|
@@ -286,7 +292,7 @@ END
|
|
286
292
|
@precompiled << "#{text};"
|
287
293
|
end
|
288
294
|
|
289
|
-
# Adds
|
295
|
+
# Adds `text` to `@buffer` with appropriate tabulation
|
290
296
|
# without parsing it.
|
291
297
|
def push_merged_text(text, tab_change = 0, indent = true)
|
292
298
|
text = !indent || @dont_indent_next_line || @options[:ugly] ? text : "#{' ' * @output_tabs}#{text}"
|
@@ -294,7 +300,7 @@ END
|
|
294
300
|
@dont_indent_next_line = false
|
295
301
|
end
|
296
302
|
|
297
|
-
# Concatenate
|
303
|
+
# Concatenate `text` to `@buffer` without tabulation.
|
298
304
|
def concat_merged_text(text)
|
299
305
|
@to_merge << [:text, text, 0]
|
300
306
|
end
|
@@ -356,18 +362,18 @@ END
|
|
356
362
|
end
|
357
363
|
end
|
358
364
|
|
359
|
-
# Adds +text+ to
|
365
|
+
# Adds +text+ to `@buffer` while flattening text.
|
360
366
|
def push_flat(line)
|
361
367
|
text = line.full.dup
|
362
368
|
text = "" unless text.gsub!(/^#{@flat_spaces}/, '')
|
363
369
|
@filter_buffer << "#{text}\n"
|
364
370
|
end
|
365
371
|
|
366
|
-
# Causes
|
367
|
-
# the scope object and the result to be added to
|
372
|
+
# Causes `text` to be evaluated in the context of
|
373
|
+
# the scope object and the result to be added to `@buffer`.
|
368
374
|
#
|
369
|
-
# If
|
370
|
-
# the result before it is added to
|
375
|
+
# If `opts[:preserve_script]` is true, Haml::Helpers#find_and_flatten is run on
|
376
|
+
# the result before it is added to `@buffer`
|
371
377
|
def push_script(text, opts = {})
|
372
378
|
raise SyntaxError.new("There's no Ruby code for = to evaluate.") if text.empty?
|
373
379
|
return if options[:suppress_eval]
|
@@ -400,7 +406,7 @@ END
|
|
400
406
|
!(opts[:in_tag] || opts[:nuke_inner_whitespace] || @options[:ugly])])
|
401
407
|
end
|
402
408
|
|
403
|
-
# Causes
|
409
|
+
# Causes `text` to be evaluated, and Haml::Helpers#find_and_flatten
|
404
410
|
# to be run on it afterwards.
|
405
411
|
def push_flat_script(text, options = {})
|
406
412
|
flush_merged_text
|
@@ -416,13 +422,13 @@ END
|
|
416
422
|
push_and_tabulate([:haml_comment])
|
417
423
|
end
|
418
424
|
|
419
|
-
# Closes the most recent item in
|
425
|
+
# Closes the most recent item in `@to_close_stack`.
|
420
426
|
def close
|
421
427
|
tag, *rest = @to_close_stack.pop
|
422
428
|
send("close_#{tag}", *rest)
|
423
429
|
end
|
424
430
|
|
425
|
-
# Puts a line in
|
431
|
+
# Puts a line in `@precompiled` that will add the closing tag of
|
426
432
|
# the most recently opened tag.
|
427
433
|
def close_element(value)
|
428
434
|
tag, nuke_outer_whitespace, nuke_inner_whitespace = value
|
@@ -474,8 +480,8 @@ END
|
|
474
480
|
@template_tabs -= 1
|
475
481
|
end
|
476
482
|
|
477
|
-
# Iterates through the classes and ids supplied through
|
478
|
-
# and
|
483
|
+
# Iterates through the classes and ids supplied through `.`
|
484
|
+
# and `#` syntax, and returns a hash with them as attributes,
|
479
485
|
# that can then be merged with another attributes hash.
|
480
486
|
def parse_class_and_id(list)
|
481
487
|
attributes = {}
|
@@ -672,7 +678,7 @@ END
|
|
672
678
|
end
|
673
679
|
|
674
680
|
# Parses a line that will render as an XHTML tag, and adds the code that will
|
675
|
-
# render that tag to
|
681
|
+
# render that tag to `@precompiled`.
|
676
682
|
def render_tag(line)
|
677
683
|
tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace,
|
678
684
|
nuke_inner_whitespace, action, value, last_line = parse_tag(line)
|
@@ -803,7 +809,7 @@ END
|
|
803
809
|
end
|
804
810
|
|
805
811
|
# Renders a line that creates an XHTML tag and has an implicit div because of
|
806
|
-
#
|
812
|
+
# `.` or `#`.
|
807
813
|
def render_div(line)
|
808
814
|
render_tag('%div' + line)
|
809
815
|
end
|
@@ -991,8 +997,8 @@ END
|
|
991
997
|
!flat? && @next_line.tabs > @line.tabs
|
992
998
|
end
|
993
999
|
|
994
|
-
# Pushes value onto
|
995
|
-
#
|
1000
|
+
# Pushes value onto `@to_close_stack` and increases
|
1001
|
+
# `@template_tabs`.
|
996
1002
|
def push_and_tabulate(value)
|
997
1003
|
@to_close_stack.push(value)
|
998
1004
|
@template_tabs += 1
|
data/lib/haml/util.rb
CHANGED
@@ -103,6 +103,17 @@ module Haml
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
+
# Restricts a number to falling within a given range.
|
107
|
+
# Returns the number if it falls within the range,
|
108
|
+
# or the closest value in the range if it doesn't.
|
109
|
+
#
|
110
|
+
# @param value [Numeric]
|
111
|
+
# @param range [Range<Numeric>]
|
112
|
+
# @return [Numeric]
|
113
|
+
def restrict(value, range)
|
114
|
+
[[value, range.first].max, range.last].min
|
115
|
+
end
|
116
|
+
|
106
117
|
# Concatenates all strings that are adjacent in an array,
|
107
118
|
# while leaving other elements as they are.
|
108
119
|
# For example:
|
@@ -186,6 +197,14 @@ module Haml
|
|
186
197
|
Haml::Util::RUBY_VERSION[0] == 1 && Haml::Util::RUBY_VERSION[1] < 9
|
187
198
|
end
|
188
199
|
|
200
|
+
# Checks that the encoding of a string is valid in Ruby 1.9.
|
201
|
+
# If it's not, yields an error string describing the invalid character
|
202
|
+
# and the line on which it occurrs.
|
203
|
+
#
|
204
|
+
# @param str [String] The string of which to check the encoding
|
205
|
+
# @yield [msg] A block in which an encoding error can be raised.
|
206
|
+
# Only yields if there is an encoding error
|
207
|
+
# @yieldparam msg [String] The error message to be raised
|
189
208
|
def check_encoding(str)
|
190
209
|
return if ruby1_8?
|
191
210
|
return if str.valid_encoding?
|
data/lib/sass/engine.rb
CHANGED
@@ -107,15 +107,15 @@ module Sass
|
|
107
107
|
# Includes named mixin declared using MIXIN_DEFINITION_CHAR
|
108
108
|
MIXIN_INCLUDE_CHAR = ?+
|
109
109
|
|
110
|
-
# The regex that matches properties of the form
|
110
|
+
# The regex that matches properties of the form `name: prop`.
|
111
111
|
PROPERTY_NEW_MATCHER = /^[^\s:"\[]+\s*[=:](\s|$)/
|
112
112
|
|
113
113
|
# The regex that matches and extracts data from
|
114
|
-
# properties of the form
|
114
|
+
# properties of the form `name: prop`.
|
115
115
|
PROPERTY_NEW = /^([^\s=:"]+)(\s*=|:)(?:\s+|$)(.*)/
|
116
116
|
|
117
117
|
# The regex that matches and extracts data from
|
118
|
-
# properties of the form
|
118
|
+
# properties of the form `:name prop`.
|
119
119
|
PROPERTY_OLD = /^:([^\s=:"]+)\s*(=?)(?:\s+|$)(.*)/
|
120
120
|
|
121
121
|
# The default options for Sass::Engine.
|
data/lib/sass/error.rb
CHANGED
@@ -31,6 +31,10 @@ module Sass
|
|
31
31
|
# : The name of the file in which the exception was raised,
|
32
32
|
# or `nil` if no filename is available.
|
33
33
|
#
|
34
|
+
# `:mixin`
|
35
|
+
# : The name of the mixin in which the exception was raised,
|
36
|
+
# or `nil` if it wasn't raised in a mixin.
|
37
|
+
#
|
34
38
|
# `:line`
|
35
39
|
# : The line of the file on which the error occurred. Never nil.
|
36
40
|
#
|
@@ -57,11 +61,19 @@ module Sass
|
|
57
61
|
# The name of the file in which the exception was raised.
|
58
62
|
# This could be `nil` if no filename is available.
|
59
63
|
#
|
60
|
-
# @return [String]
|
64
|
+
# @return [String, nil]
|
61
65
|
def sass_filename
|
62
66
|
sass_backtrace.first[:filename]
|
63
67
|
end
|
64
68
|
|
69
|
+
# The name of the mixin in which the error occurred.
|
70
|
+
# This could be `nil` if the error occurred outside a mixin.
|
71
|
+
#
|
72
|
+
# @return [Fixnum]
|
73
|
+
def sass_mixin
|
74
|
+
sass_backtrace.first[:mixin]
|
75
|
+
end
|
76
|
+
|
65
77
|
# The line of the Sass template on which the error occurred.
|
66
78
|
#
|
67
79
|
# @return [Fixnum]
|
@@ -77,15 +89,29 @@ module Sass
|
|
77
89
|
sass_backtrace << attrs.reject {|k, v| v.nil?}
|
78
90
|
end
|
79
91
|
|
80
|
-
# Modify the top Sass backtrace
|
92
|
+
# Modify the top Sass backtrace entries
|
93
|
+
# (that is, the most deeply nested ones)
|
81
94
|
# to have the given attributes.
|
82
|
-
#
|
83
|
-
#
|
95
|
+
#
|
96
|
+
# Specifically, this goes through the backtrace entries
|
97
|
+
# from most deeply nested to least,
|
98
|
+
# setting the given attributes for each entry.
|
99
|
+
# If an entry already has one of the given attributes set,
|
100
|
+
# the pre-existing attribute takes precedence
|
101
|
+
# and is not used for less deeply-nested entries
|
102
|
+
# (even if they don't have that attribute set).
|
84
103
|
#
|
85
104
|
# @param attrs [Hash<Symbol, Object>] The information to add to the backtrace entry.
|
86
105
|
# See \{#sass\_backtrace}
|
87
106
|
def modify_backtrace(attrs)
|
88
|
-
|
107
|
+
attrs = attrs.reject {|k, v| v.nil?}
|
108
|
+
# Move backwards through the backtrace
|
109
|
+
(0...sass_backtrace.size).to_a.reverse.each do |i|
|
110
|
+
entry = sass_backtrace[i]
|
111
|
+
sass_backtrace[i] = attrs.merge(entry)
|
112
|
+
attrs.reject! {|k, v| entry.include?(k)}
|
113
|
+
break if attrs.empty?
|
114
|
+
end
|
89
115
|
end
|
90
116
|
|
91
117
|
# @return [String] The error message
|
@@ -99,7 +125,10 @@ module Sass
|
|
99
125
|
# @return [Array<String>]
|
100
126
|
def backtrace
|
101
127
|
return nil if super.nil?
|
102
|
-
sass_backtrace.map
|
128
|
+
sass_backtrace.map do |h|
|
129
|
+
"#{h[:filename] || "(sass)"}:#{h[:line]}" +
|
130
|
+
(h[:mixin] ? ":in `#{h[:mixin]}'" : "")
|
131
|
+
end + super
|
103
132
|
end
|
104
133
|
|
105
134
|
# Returns a string representation of the Sass backtrace.
|
@@ -111,7 +140,8 @@ module Sass
|
|
111
140
|
"Syntax error: #{message}" +
|
112
141
|
Haml::Util.enum_with_index(sass_backtrace).map do |entry, i|
|
113
142
|
"\n #{i == 0 ? "on" : "from"} line #{entry[:line]}" +
|
114
|
-
" of #{entry[:filename] || default_filename}"
|
143
|
+
" of #{entry[:filename] || default_filename}" +
|
144
|
+
(entry[:mixin] ? ", in `#{entry[:mixin]}'" : "")
|
115
145
|
end.join
|
116
146
|
end
|
117
147
|
|
data/lib/sass/files.rb
CHANGED
data/lib/sass/script/color.rb
CHANGED
@@ -5,7 +5,7 @@ module Sass::Script
|
|
5
5
|
class Color < Literal
|
6
6
|
class << self; include Haml::Util; end
|
7
7
|
|
8
|
-
# A hash from color names to [red, green, blue] value arrays.
|
8
|
+
# A hash from color names to `[red, green, blue]` value arrays.
|
9
9
|
HTML4_COLORS = map_vals({
|
10
10
|
'black' => 0x000000,
|
11
11
|
'silver' => 0xc0c0c0,
|
@@ -24,7 +24,7 @@ module Sass::Script
|
|
24
24
|
'teal' => 0x008080,
|
25
25
|
'aqua' => 0x00ffff
|
26
26
|
}) {|color| (0..2).map {|n| color >> (n << 3) & 0xff}.reverse}
|
27
|
-
# A hash from [red, green, blue] value arrays to color names.
|
27
|
+
# A hash from `[red, green, blue]` value arrays to color names.
|
28
28
|
HTML4_COLORS_REVERSE = map_hash(HTML4_COLORS) {|k, v| [v, k]}
|
29
29
|
|
30
30
|
# Constructs an RGB or RGBA color object.
|
@@ -70,7 +70,7 @@ module Sass::Script
|
|
70
70
|
# This is 1 unless otherwise defined.
|
71
71
|
#
|
72
72
|
# @return [Fixnum]
|
73
|
-
|
73
|
+
attr_reader :alpha
|
74
74
|
|
75
75
|
# Returns whether this color object is translucent;
|
76
76
|
# that is, whether the alpha channel is non-1.
|
@@ -115,7 +115,7 @@ END
|
|
115
115
|
#
|
116
116
|
# For example:
|
117
117
|
#
|
118
|
-
# Color.new([10, 20, 30].with(:blue => 40)
|
118
|
+
# Color.new([10, 20, 30]).with(:blue => 40)
|
119
119
|
# #=> rgb(10, 40, 30)
|
120
120
|
# Color.new([126, 126, 126]).with(:red => 0, :green => 255)
|
121
121
|
# #=> rgb(0, 255, 126)
|
@@ -189,10 +189,7 @@ END
|
|
189
189
|
# {Color}
|
190
190
|
# : Multiplies each of the RGB color channels together.
|
191
191
|
#
|
192
|
-
#
|
193
|
-
# : See {Literal#times}.
|
194
|
-
#
|
195
|
-
# @param other [Literal] The right-hand side of the operator
|
192
|
+
# @param other [Number, Color] The right-hand side of the operator
|
196
193
|
# @return [Color] The resulting color
|
197
194
|
# @raise [Sass::SyntaxError] if `other` is a number with units
|
198
195
|
def times(other)
|
@@ -235,10 +232,7 @@ END
|
|
235
232
|
# {Color}
|
236
233
|
# : Takes each of this color's RGB color channels modulo the other color's.
|
237
234
|
#
|
238
|
-
#
|
239
|
-
# : See {Literal#mod}.
|
240
|
-
#
|
241
|
-
# @param other [Literal] The right-hand side of the operator
|
235
|
+
# @param other [Number, Color] The right-hand side of the operator
|
242
236
|
# @return [Color] The resulting color
|
243
237
|
# @raise [Sass::SyntaxError] if `other` is a number with units
|
244
238
|
def mod(other)
|
@@ -275,52 +275,50 @@ module Sass::Script
|
|
275
275
|
alias_method :opacity, :alpha
|
276
276
|
|
277
277
|
# Makes a color more opaque.
|
278
|
-
# Takes a color and an amount between
|
279
|
-
# and returns a color
|
278
|
+
# Takes a color and an amount between 0 and 1,
|
279
|
+
# and returns a color with the opacity increased by that value.
|
280
280
|
#
|
281
|
-
# For example
|
281
|
+
# For example:
|
282
282
|
#
|
283
|
-
# opacify(rgba(0, 0, 0, 0.5),
|
284
|
-
# opacify(rgba(0, 0,
|
285
|
-
# opacify(rgba(0, 0, 0, 0.2), 50%) => rgba(0, 0, 0, 0.8)
|
283
|
+
# opacify(rgba(0, 0, 0, 0.5), 0.1) => rgba(0, 0, 0, 0.6)
|
284
|
+
# opacify(rgba(0, 0, 17, 0.8), 0.2) => #001
|
286
285
|
#
|
287
|
-
#
|
288
|
-
#
|
286
|
+
# @param color [Color]
|
287
|
+
# @param amount [Number]
|
288
|
+
# @raise [ArgumentError] If `color` isn't a color,
|
289
|
+
# or `number` isn't a number between 0 and 1
|
289
290
|
def opacify(color, amount)
|
290
291
|
assert_type color, :Color
|
291
292
|
assert_type amount, :Number
|
292
|
-
unless (0..
|
293
|
-
raise ArgumentError.new("Amount #{amount} must be between 0
|
293
|
+
unless (0..1).include?(amount.value)
|
294
|
+
raise ArgumentError.new("Amount #{amount} must be between 0 and 1")
|
294
295
|
end
|
295
296
|
|
296
|
-
color
|
297
|
-
color.alpha += (1 - color.alpha) * (amount.value / 100.0)
|
298
|
-
color
|
297
|
+
color.with(:alpha => Haml::Util.restrict(color.alpha + amount.value, 0..1))
|
299
298
|
end
|
300
299
|
alias_method :fade_in, :opacify
|
301
300
|
|
302
301
|
# Makes a color more transparent.
|
303
|
-
# Takes a color and an amount between
|
304
|
-
# and returns a color
|
302
|
+
# Takes a color and an amount between 0 and 1,
|
303
|
+
# and returns a color with the opacity decreased by that value.
|
305
304
|
#
|
306
|
-
# For example
|
305
|
+
# For example:
|
307
306
|
#
|
308
|
-
#
|
309
|
-
#
|
310
|
-
# opacify(rgba(0, 0, 0, 0.2), 50%) => rgba(0, 0, 0, 0.1)
|
307
|
+
# transparentize(rgba(0, 0, 0, 0.5), 0.1) => rgba(0, 0, 0, 0.4)
|
308
|
+
# transparentize(rgba(0, 0, 0, 0.8), 0.2) => rgba(0, 0, 0, 0.6)
|
311
309
|
#
|
312
|
-
#
|
313
|
-
#
|
310
|
+
# @param color [Color]
|
311
|
+
# @param amount [Number]
|
312
|
+
# @raise [ArgumentError] If `color` isn't a color,
|
313
|
+
# or `number` isn't a number between 0 and 1
|
314
314
|
def transparentize(color, amount)
|
315
315
|
assert_type color, :Color
|
316
316
|
assert_type amount, :Number
|
317
|
-
unless (0..
|
318
|
-
raise ArgumentError.new("Amount #{amount} must be between 0
|
317
|
+
unless (0..1).include?(amount.value)
|
318
|
+
raise ArgumentError.new("Amount #{amount} must be between 0 and 1")
|
319
319
|
end
|
320
320
|
|
321
|
-
color
|
322
|
-
color.alpha *= 1 - (amount.value / 100.0)
|
323
|
-
color
|
321
|
+
color.with(:alpha => Haml::Util.restrict(color.alpha - amount.value, 0..1))
|
324
322
|
end
|
325
323
|
alias_method :fade_out, :transparentize
|
326
324
|
|