slim 0.6.0.beta.2 → 0.6.0.beta.3

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/Gemfile CHANGED
@@ -2,4 +2,7 @@ source :rubygems
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'slim', :path => File.dirname(__FILE__), :group => :development
5
+ group :development do
6
+ gem 'slim', :path => File.dirname(__FILE__)
7
+ gem 'minitest' if RUBY_VERSION < '1.9'
8
+ end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slim (0.6.0.beta.2)
4
+ slim (0.6.0.beta.3)
5
5
  escape_utils
6
6
 
7
7
  GEM
@@ -10,11 +10,11 @@ require 'slim/engine'
10
10
  module Slim
11
11
  class << self
12
12
  def version
13
- '0.6.0.beta.2'
13
+ '0.6.0.beta.3'
14
14
  end
15
15
 
16
16
  def escape_html(html)
17
- EscapeUtils.escape_html(html)
17
+ EscapeUtils.escape_html(html.to_s)
18
18
  end
19
19
  end
20
20
  end
@@ -13,9 +13,8 @@ module Slim
13
13
  REGEX_LINE_PARSER = /^(\s*)(!?`?\|?-?=?\/?\w*)((?:\s*(?:\w|-)*="[^=]+")+|(\S*[#.]\S+))?(.*)/
14
14
 
15
15
  REGEX_LINE_CONTAINS_OUTPUT_CODE = /^\s*=(.*)/
16
- REGEX_LINE_CONTAINS_ONLY_HTML_TAG = /^\s*\w+\S?$/
17
- REGEX_LINE_CONTAINS_METHOD_DETECTED = /^(\w+\(.*\))/
18
- REGEX_METHOD_HAS_NO_PARENTHESES = /^\w+\s/
16
+ REGEX_LINE_CONTAINS_METHOD_DETECTED = /^((?:(?!#{CONTROL_WORDS * '\b|'}\b).)*)/
17
+ REGEX_METHOD_HAS_NO_PARENTHESES = /^\w+\s+\S+/
19
18
  REGEX_CODE_BLOCK_DETECTED = / do ?.*$/
20
19
  REGEX_CODE_CONTROL_WORD_DETECTED = /(?:\s|(\())(#{CONTROL_WORDS * '|'})\b\s?(.*)$/
21
20
  REGEX_CODE_ELSE_CONTROL_WORD_DETECTED = /^#{ELSE_CONTROL_WORDS * '\b|'}\b/
@@ -55,9 +54,6 @@ module Slim
55
54
  # Remove the first space, but allow people to pad if they want.
56
55
  string.slice!(0) if string =~ /^\s/
57
56
 
58
- # prepends "div" to the shortcut form of attrs if no marker is given
59
- marker = 'div' if shortcut_attrs && marker.empty?
60
-
61
57
  line_type = case marker
62
58
  when '`', '|' then :text
63
59
  when '-' then :control_code
@@ -78,9 +74,8 @@ module Slim
78
74
  continue_closing = true
79
75
  ender, ender_indent = enders.pop
80
76
 
81
- unless ender_indent < indent || ender == 'end;' && line_type == :control_code &&
82
- ender_indent == indent && string =~ REGEX_CODE_ELSE_CONTROL_WORD_DETECTED
83
- @_buffer << ender
77
+ unless ender_indent < indent || ender_indent == indent && string =~ REGEX_CODE_ELSE_CONTROL_WORD_DETECTED
78
+ @_buffer << ender
84
79
  else
85
80
  enders << [ender, ender_indent]
86
81
  continue_closing = false
@@ -95,6 +90,9 @@ module Slim
95
90
  if AUTOCLOSED.include?(marker)
96
91
  @_buffer << "_buf << \"<#{marker}#{attrs}/>\";"
97
92
  else
93
+ # prepends "div" to the shortcut form of attrs if no marker is given
94
+ marker = 'div' if shortcut_attrs && marker.empty?
95
+
98
96
  enders << ["_buf << \"</#{marker}>\";", indent]
99
97
  @_buffer << "_buf << \"<#{marker}#{attrs}>\";"
100
98
  end
@@ -136,12 +134,13 @@ module Slim
136
134
  private
137
135
 
138
136
  def parse_string(string)
139
- string = string_skip_escape = $1.strip if string =~ REGEX_LINE_CONTAINS_OUTPUT_CODE
140
- string << ' ' if string =~ REGEX_LINE_CONTAINS_ONLY_HTML_TAG
141
- parenthesesify_method!(string) if string =~ REGEX_METHOD_HAS_NO_PARENTHESES
142
- wraps_with_slim_escape!(string) unless string =~ REGEX_CODE_BLOCK_DETECTED || string_skip_escape
143
-
144
- string.strip
137
+ if string =~ REGEX_LINE_CONTAINS_OUTPUT_CODE
138
+ $1.strip
139
+ else
140
+ parenthesesify_method!(string) if string =~ REGEX_METHOD_HAS_NO_PARENTHESES
141
+ wraps_with_slim_escape!(string) unless string =~ REGEX_CODE_BLOCK_DETECTED
142
+ string.strip
143
+ end
145
144
  end
146
145
 
147
146
  # adds a pair of parentheses to the method
@@ -157,8 +156,7 @@ module Slim
157
156
  # converts 'p#hello.world.mate' to 'p id="hello" class="world mate"'
158
157
  def normalize_attributes!(string)
159
158
  string.sub!(REGEX_FIND_HTML_ATTR_ID, ' id="\1"')
160
- string.sub!(REGEX_FIND_HTML_ATTR_CLASSES, ' class="\1"')
161
- string.gsub!('.', ' ')
159
+ string.sub!(REGEX_FIND_HTML_ATTR_CLASSES, ' class="\1"') && string.gsub!('.', ' ')
162
160
  end
163
161
  end
164
162
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{slim}
8
- s.version = "0.6.0.beta.2"
8
+ s.version = "0.6.0.beta.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrew Stone", "Fred Wu"]
12
- s.date = %q{2010-10-14}
12
+ s.date = %q{2010-10-16}
13
13
  s.description = %q{Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.}
14
14
  s.email = ["andy@stonean.com", "ifredwu@gmail.com"]
15
15
  s.extra_rdoc_files = [
@@ -34,4 +34,8 @@ class Env
34
34
  def evil_method
35
35
  "<script>do_something_evil();</script>"
36
36
  end
37
+
38
+ def output_number
39
+ 1337
40
+ end
37
41
  end
@@ -188,7 +188,7 @@ p
188
188
  = hello_world
189
189
  HTML
190
190
 
191
- expected = %q|_buf = [];_buf << "<p>";_buf << Slim.escape_html(hello_world());_buf << "</p>";_buf.join;|
191
+ expected = %q|_buf = [];_buf << "<p>";_buf << Slim.escape_html(hello_world);_buf << "</p>";_buf.join;|
192
192
 
193
193
  assert_equal expected, TestEngine.new(string).compiled
194
194
  end
@@ -221,7 +221,7 @@ body
221
221
  p id="first" = hello_world
222
222
  TEMPLATE
223
223
 
224
- expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\">";_buf << Slim.escape_html(hello_world());_buf << "</p>";_buf << "</body>";_buf.join;|
224
+ expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\">";_buf << Slim.escape_html(hello_world);_buf << "</p>";_buf << "</body>";_buf.join;|
225
225
 
226
226
  assert_equal expected, TestEngine.new(string).compiled
227
227
  end
@@ -312,17 +312,27 @@ TEMPLATE
312
312
  p = session[:id]
313
313
  TEMPLATE
314
314
 
315
- expected = %q|_buf = [];_buf << "<p>";_buf << session[:id];_buf << "</p>";_buf.join;|
315
+ expected = %q|_buf = [];_buf << "<p>";_buf << Slim.escape_html(session[:id]);_buf << "</p>";_buf.join;|
316
316
 
317
317
  assert_equal expected, TestEngine.new(string).compiled
318
318
  end
319
319
 
320
320
  def test_escape_escaping
321
321
  string = <<TEMPLATE
322
+ p == session[:id]
323
+ TEMPLATE
324
+
325
+ expected = %q|_buf = [];_buf << "<p>";_buf << session[:id];_buf << "</p>";_buf.join;|
326
+
327
+ assert_equal expected, TestEngine.new(string).compiled
328
+ end
329
+
330
+ def test_escape_escaping2
331
+ string = <<TEMPLATE
322
332
  p == safe_method_call
323
333
  TEMPLATE
324
334
 
325
- expected = %q|_buf = [];_buf << "<p>";_buf << safe_method_call();_buf << "</p>";_buf.join;|
335
+ expected = %q|_buf = [];_buf << "<p>";_buf << safe_method_call;_buf << "</p>";_buf.join;|
326
336
 
327
337
  assert_equal expected, TestEngine.new(string).compiled
328
338
  end
@@ -348,7 +358,22 @@ TEMPLATE
348
358
  == hello
349
359
  TEMPLATE
350
360
 
351
- expected = %q|_buf = [];_buf << "<body>";_buf << "<p>";_buf << "hey";_buf << hello();_buf << "</p>";_buf << "</body>";_buf.join;|
361
+ expected = %q|_buf = [];_buf << "<body>";_buf << "<p>";_buf << "hey";_buf << hello;_buf << "</p>";_buf << "</body>";_buf.join;|
362
+
363
+ assert_equal expected, TestEngine.new(string).compiled
364
+ end
365
+
366
+ def test_code_block
367
+ string = <<TEMPLATE
368
+ - unless items.empty?
369
+ ul
370
+ - items.each do |item|
371
+ li = item
372
+ - else
373
+ p No items
374
+ TEMPLATE
375
+
376
+ expected = %q|_buf = [];unless items.empty?;_buf << "<ul>";items.each do \|item\|;_buf << "<li>";_buf << Slim.escape_html(item);_buf << "</li>";end;_buf << "</ul>";else;_buf << "<p>";_buf << "No items";_buf << "</p>";end;_buf.join;|
352
377
 
353
378
  assert_equal expected, TestEngine.new(string).compiled
354
379
  end
@@ -395,4 +395,14 @@ HTML
395
395
 
396
396
  assert_equal expected, Slim::Engine.new(string).render(@env)
397
397
  end
398
+
399
+ def test_number_type_interpolation
400
+ string = <<HTML
401
+ p = output_number
402
+ HTML
403
+
404
+ expected = "<p>1337</p>"
405
+
406
+ assert_equal expected, Slim::Engine.new(string).render(@env)
407
+ end
398
408
  end
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 6
8
8
  - 0
9
9
  - beta
10
- - 2
11
- version: 0.6.0.beta.2
10
+ - 3
11
+ version: 0.6.0.beta.3
12
12
  platform: ruby
13
13
  authors:
14
14
  - Andrew Stone
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-10-14 00:00:00 +11:00
20
+ date: 2010-10-16 00:00:00 +11:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - ">="
126
126
  - !ruby/object:Gem::Version
127
- hash: 3027777953181693052
127
+ hash: 2018264533147870573
128
128
  segments:
129
129
  - 0
130
130
  version: "0"