haml 2.2.14 → 2.2.15
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of haml might be problematic. Click here for more details.
- data/README.md +1 -1
- data/Rakefile +17 -4
- data/VERSION +1 -1
- data/lib/haml/helpers.rb +1 -1
- data/lib/haml/precompiler.rb +28 -22
- data/lib/sass/engine.rb +3 -3
- data/lib/sass/files.rb +1 -0
- data/lib/sass/script/color.rb +32 -13
- data/lib/sass/script/lexer.rb +4 -4
- data/test/haml/engine_test.rb +10 -0
- metadata +4 -4
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
@@ -225,6 +225,17 @@ end
|
|
225
225
|
begin
|
226
226
|
require 'yard'
|
227
227
|
|
228
|
+
namespace :yard do
|
229
|
+
task :sass do
|
230
|
+
require File.dirname(__FILE__) + '/lib/sass'
|
231
|
+
Dir[File.dirname(__FILE__) + "/yard/default/**/*.sass"].each do |sass|
|
232
|
+
File.open(sass.gsub(/sass$/, 'css'), 'w') do |f|
|
233
|
+
f.write(Sass::Engine.new(File.read(sass)).render)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
228
239
|
YARD::Rake::YardocTask.new do |t|
|
229
240
|
t.files = FileList.new('lib/**/*.rb') do |list|
|
230
241
|
list.exclude('lib/haml/template/*.rb')
|
@@ -234,16 +245,18 @@ begin
|
|
234
245
|
t.options += FileList.new('yard/*.rb').to_a.map {|f| ['-e', f]}.flatten
|
235
246
|
files = FileList.new('doc-src/*').to_a.sort_by {|s| s.size} + %w[MIT-LICENSE VERSION]
|
236
247
|
t.options << '--files' << files.join(',')
|
248
|
+
t.options << '--template-path' << File.dirname(__FILE__) + '/yard'
|
237
249
|
end
|
238
|
-
Rake::Task['
|
250
|
+
Rake::Task['yard'].prerequisites.insert(0, 'yard:sass')
|
251
|
+
Rake::Task['yard'].instance_variable_set('@comment', nil)
|
239
252
|
|
240
253
|
desc "Generate Documentation"
|
241
|
-
task :doc => :
|
242
|
-
task :redoc => :
|
254
|
+
task :doc => :yard
|
255
|
+
task :redoc => :yard
|
243
256
|
rescue LoadError
|
244
257
|
desc "Generate Documentation"
|
245
258
|
task :doc => :rdoc
|
246
|
-
task :
|
259
|
+
task :yard => :rdoc
|
247
260
|
end
|
248
261
|
|
249
262
|
task :pages do
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2.
|
1
|
+
2.2.15
|
data/lib/haml/helpers.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
|
@@ -347,18 +353,18 @@ END
|
|
347
353
|
end
|
348
354
|
end
|
349
355
|
|
350
|
-
# Adds +text+ to
|
356
|
+
# Adds +text+ to `@buffer` while flattening text.
|
351
357
|
def push_flat(line)
|
352
358
|
text = line.full.dup
|
353
359
|
text = "" unless text.gsub!(/^#{@flat_spaces}/, '')
|
354
360
|
@filter_buffer << "#{text}\n"
|
355
361
|
end
|
356
362
|
|
357
|
-
# Causes
|
358
|
-
# the scope object and the result to be added to
|
363
|
+
# Causes `text` to be evaluated in the context of
|
364
|
+
# the scope object and the result to be added to `@buffer`.
|
359
365
|
#
|
360
|
-
# If
|
361
|
-
# the result before it is added to
|
366
|
+
# If `opts[:preserve_script]` is true, Haml::Helpers#find_and_flatten is run on
|
367
|
+
# the result before it is added to `@buffer`
|
362
368
|
def push_script(text, opts = {})
|
363
369
|
raise SyntaxError.new("There's no Ruby code for = to evaluate.") if text.empty?
|
364
370
|
return if options[:suppress_eval]
|
@@ -391,7 +397,7 @@ END
|
|
391
397
|
!(opts[:in_tag] || opts[:nuke_inner_whitespace] || @options[:ugly])])
|
392
398
|
end
|
393
399
|
|
394
|
-
# Causes
|
400
|
+
# Causes `text` to be evaluated, and Haml::Helpers#find_and_flatten
|
395
401
|
# to be run on it afterwards.
|
396
402
|
def push_flat_script(text, options = {})
|
397
403
|
flush_merged_text
|
@@ -407,13 +413,13 @@ END
|
|
407
413
|
push_and_tabulate([:haml_comment])
|
408
414
|
end
|
409
415
|
|
410
|
-
# Closes the most recent item in
|
416
|
+
# Closes the most recent item in `@to_close_stack`.
|
411
417
|
def close
|
412
418
|
tag, *rest = @to_close_stack.pop
|
413
419
|
send("close_#{tag}", *rest)
|
414
420
|
end
|
415
421
|
|
416
|
-
# Puts a line in
|
422
|
+
# Puts a line in `@precompiled` that will add the closing tag of
|
417
423
|
# the most recently opened tag.
|
418
424
|
def close_element(value)
|
419
425
|
tag, nuke_outer_whitespace, nuke_inner_whitespace = value
|
@@ -465,8 +471,8 @@ END
|
|
465
471
|
@template_tabs -= 1
|
466
472
|
end
|
467
473
|
|
468
|
-
# Iterates through the classes and ids supplied through
|
469
|
-
# and
|
474
|
+
# Iterates through the classes and ids supplied through `.`
|
475
|
+
# and `#` syntax, and returns a hash with them as attributes,
|
470
476
|
# that can then be merged with another attributes hash.
|
471
477
|
def parse_class_and_id(list)
|
472
478
|
attributes = {}
|
@@ -663,7 +669,7 @@ END
|
|
663
669
|
end
|
664
670
|
|
665
671
|
# Parses a line that will render as an XHTML tag, and adds the code that will
|
666
|
-
# render that tag to
|
672
|
+
# render that tag to `@precompiled`.
|
667
673
|
def render_tag(line)
|
668
674
|
tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace,
|
669
675
|
nuke_inner_whitespace, action, value, last_line = parse_tag(line)
|
@@ -794,7 +800,7 @@ END
|
|
794
800
|
end
|
795
801
|
|
796
802
|
# Renders a line that creates an XHTML tag and has an implicit div because of
|
797
|
-
#
|
803
|
+
# `.` or `#`.
|
798
804
|
def render_div(line)
|
799
805
|
render_tag('%div' + line)
|
800
806
|
end
|
@@ -982,8 +988,8 @@ END
|
|
982
988
|
!flat? && @next_line.tabs > @line.tabs
|
983
989
|
end
|
984
990
|
|
985
|
-
# Pushes value onto
|
986
|
-
#
|
991
|
+
# Pushes value onto `@to_close_stack` and increases
|
992
|
+
# `@template_tabs`.
|
987
993
|
def push_and_tabulate(value)
|
988
994
|
@to_close_stack.push(value)
|
989
995
|
@template_tabs += 1
|
data/lib/sass/engine.rb
CHANGED
@@ -106,15 +106,15 @@ module Sass
|
|
106
106
|
# Includes named mixin declared using MIXIN_DEFINITION_CHAR
|
107
107
|
MIXIN_INCLUDE_CHAR = ?+
|
108
108
|
|
109
|
-
# The regex that matches properties of the form
|
109
|
+
# The regex that matches properties of the form `name: prop`.
|
110
110
|
PROPERTY_NEW_MATCHER = /^[^\s:"\[]+\s*[=:](\s|$)/
|
111
111
|
|
112
112
|
# The regex that matches and extracts data from
|
113
|
-
# properties of the form
|
113
|
+
# properties of the form `name: prop`.
|
114
114
|
PROPERTY_NEW = /^([^\s=:"]+)(\s*=|:)(?:\s+|$)(.*)/
|
115
115
|
|
116
116
|
# The regex that matches and extracts data from
|
117
|
-
# properties of the form
|
117
|
+
# properties of the form `:name prop`.
|
118
118
|
PROPERTY_OLD = /^:([^\s=:"]+)\s*(=?)(?:\s+|$)(.*)/
|
119
119
|
|
120
120
|
# The default options for Sass::Engine.
|
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,16 +24,21 @@ 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
|
+
# Creates a new color from RGB components.
|
31
|
+
# *Note*: when modifying the components of an existing color,
|
32
|
+
# use \{#with} rather than creating a new color object.
|
33
|
+
# This preserves forwards-compatiblity for alpha channels and such.
|
34
|
+
#
|
30
35
|
# @param rgb [Array<Fixnum>] A three-element array of the red, green, and blue values (respectively)
|
31
36
|
# of the color
|
32
37
|
# @raise [Sass::SyntaxError] if any color value isn't between 0 and 255
|
33
38
|
def initialize(rgb)
|
34
39
|
rgb = rgb.map {|c| c.to_i}
|
35
40
|
raise Sass::SyntaxError.new("Color values must be between 0 and 255") if rgb.any? {|c| c < 0 || c > 255}
|
36
|
-
super(rgb)
|
41
|
+
super(rgb.freeze)
|
37
42
|
end
|
38
43
|
|
39
44
|
# @deprecated This will be removed in version 2.6.
|
@@ -49,12 +54,32 @@ END
|
|
49
54
|
|
50
55
|
# Returns the red, green, and blue components of the color.
|
51
56
|
#
|
52
|
-
# @return [Array<Fixnum>] A three-element array of the red, green, and blue
|
57
|
+
# @return [Array<Fixnum>] A frozen three-element array of the red, green, and blue
|
53
58
|
# values (respectively) of the color
|
54
59
|
def rgb
|
55
60
|
@value
|
56
61
|
end
|
57
62
|
|
63
|
+
# Returns a copy of this color with one or more channels changed.
|
64
|
+
#
|
65
|
+
# For example:
|
66
|
+
#
|
67
|
+
# Color.new([10, 20, 30]).with(:blue => 40)
|
68
|
+
# #=> rgb(10, 40, 30)
|
69
|
+
# Color.new([126, 126, 126]).with(:red => 0, :green => 255)
|
70
|
+
# #=> rgb(0, 255, 126)
|
71
|
+
#
|
72
|
+
# @param attrs [Hash<Symbol, Fixnum>]
|
73
|
+
# A map of channel names (`:red`, `:green`, or `:blue`) to values
|
74
|
+
# @return [Color] The new Color object
|
75
|
+
def with(attrs)
|
76
|
+
Color.new([
|
77
|
+
attrs[:red] || rgb[0],
|
78
|
+
attrs[:green] || rgb[1],
|
79
|
+
attrs[:blue] || rgb[2],
|
80
|
+
])
|
81
|
+
end
|
82
|
+
|
58
83
|
# The SassScript `+` operation.
|
59
84
|
# Its functionality depends on the type of its argument:
|
60
85
|
#
|
@@ -110,10 +135,7 @@ END
|
|
110
135
|
# {Color}
|
111
136
|
# : Multiplies each of the RGB color channels together.
|
112
137
|
#
|
113
|
-
#
|
114
|
-
# : See {Literal#times}.
|
115
|
-
#
|
116
|
-
# @param other [Literal] The right-hand side of the operator
|
138
|
+
# @param other [Number, Color] The right-hand side of the operator
|
117
139
|
# @return [Color] The resulting color
|
118
140
|
# @raise [Sass::SyntaxError] if `other` is a number with units
|
119
141
|
def times(other)
|
@@ -156,10 +178,7 @@ END
|
|
156
178
|
# {Color}
|
157
179
|
# : Takes each of this color's RGB color channels modulo the other color's.
|
158
180
|
#
|
159
|
-
#
|
160
|
-
# : See {Literal#mod}.
|
161
|
-
#
|
162
|
-
# @param other [Literal] The right-hand side of the operator
|
181
|
+
# @param other [Number, Color] The right-hand side of the operator
|
163
182
|
# @return [Color] The resulting color
|
164
183
|
# @raise [Sass::SyntaxError] if `other` is a number with units
|
165
184
|
def mod(other)
|
@@ -195,7 +214,7 @@ END
|
|
195
214
|
res = rgb[i].send(operation, other_num ? other.value : other.rgb[i])
|
196
215
|
result[i] = [ [res, 255].min, 0 ].max
|
197
216
|
end
|
198
|
-
|
217
|
+
with(:red => result[0], :green => result[1], :blue => result[2])
|
199
218
|
end
|
200
219
|
end
|
201
220
|
end
|
data/lib/sass/script/lexer.rb
CHANGED
@@ -8,16 +8,16 @@ module Sass
|
|
8
8
|
class Lexer
|
9
9
|
# A struct containing information about an individual token.
|
10
10
|
#
|
11
|
-
# `type`: [{Symbol}]
|
11
|
+
# `type`: \[{Symbol}\]
|
12
12
|
# : The type of token.
|
13
13
|
#
|
14
|
-
# `value`: [{Object}]
|
14
|
+
# `value`: \[{Object}\]
|
15
15
|
# : The Ruby object corresponding to the value of the token.
|
16
16
|
#
|
17
|
-
# `line`: [{Fixnum}]
|
17
|
+
# `line`: \[{Fixnum}\]
|
18
18
|
# : The line of the source file on which the token appears.
|
19
19
|
#
|
20
|
-
# `offset`: [{Fixnum}]
|
20
|
+
# `offset`: \[{Fixnum}\]
|
21
21
|
# : The number of bytes into the line the SassScript token appeared.
|
22
22
|
Token = Struct.new(:type, :value, :line, :offset)
|
23
23
|
|
data/test/haml/engine_test.rb
CHANGED
@@ -581,6 +581,16 @@ HTML
|
|
581
581
|
HAML
|
582
582
|
end
|
583
583
|
|
584
|
+
def test_if_without_content_and_else
|
585
|
+
assert_equal(<<HTML, render(<<HAML))
|
586
|
+
foo
|
587
|
+
HTML
|
588
|
+
- if false
|
589
|
+
- else
|
590
|
+
foo
|
591
|
+
HAML
|
592
|
+
end
|
593
|
+
|
584
594
|
# HTML escaping tests
|
585
595
|
|
586
596
|
def test_ampersand_equals_should_escape
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Weizenbaum
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-12-01 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
requirements:
|
22
22
|
- - ">="
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 0.
|
24
|
+
version: 0.4.0
|
25
25
|
version:
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: maruku
|
@@ -239,7 +239,7 @@ files:
|
|
239
239
|
- REVISION
|
240
240
|
- CONTRIBUTING
|
241
241
|
has_rdoc: true
|
242
|
-
homepage: http://haml.
|
242
|
+
homepage: http://haml-lang.com/
|
243
243
|
licenses: []
|
244
244
|
|
245
245
|
post_install_message:
|