slim 1.1.0 → 1.1.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/.travis.yml +10 -2
- data/CHANGES +6 -1
- data/lib/slim/compiler.rb +1 -1
- data/lib/slim/engine.rb +6 -3
- data/lib/slim/parser.rb +8 -4
- data/lib/slim/version.rb +1 -1
- data/slim.gemspec +1 -1
- data/test/rails/test/test_slim.rb +2 -8
- data/test/slim/helper.rb +8 -2
- data/test/slim/test_chain_manipulation.rb +1 -1
- data/test/slim/test_code_output.rb +9 -0
- data/test/slim/test_html_structure.rb +9 -0
- data/test/slim/test_parser_errors.rb +17 -1
- metadata +20 -21
data/.travis.yml
CHANGED
@@ -1,16 +1,24 @@
|
|
1
1
|
rvm:
|
2
2
|
- 1.8.7
|
3
|
-
- 1.9.2
|
4
3
|
- 1.9.3
|
5
4
|
- ruby-head
|
6
5
|
- jruby
|
7
|
-
- rbx-
|
6
|
+
- rbx-18mode
|
8
7
|
env:
|
9
8
|
- "TASK=test"
|
10
9
|
- "TASK=test TEMPLE=master"
|
11
10
|
- "TASK=test:rails RAILS=master"
|
12
11
|
- "TASK=test:rails RAILS=3.0.11"
|
13
12
|
- "TASK=test:rails RAILS=3.1.3"
|
13
|
+
matrix:
|
14
|
+
exclude:
|
15
|
+
# Test Rails master only on 1.9.3+ Rubies
|
16
|
+
- rvm: 1.8.7
|
17
|
+
env: "TASK=test:rails RAILS=master"
|
18
|
+
- rvm: jruby
|
19
|
+
env: "TASK=test:rails RAILS=master"
|
20
|
+
- rvm: rbx-18mode
|
21
|
+
env: "TASK=test:rails RAILS=master"
|
14
22
|
script: "bundle exec rake test:ci"
|
15
23
|
notifications:
|
16
24
|
email: false
|
data/CHANGES
CHANGED
data/lib/slim/compiler.rb
CHANGED
data/lib/slim/engine.rb
CHANGED
@@ -33,7 +33,8 @@ module Slim
|
|
33
33
|
# Symbol | :format | :xhtml | HTML output format
|
34
34
|
# String | :attr_wrapper | '"' | Character to wrap attributes in html (can be ' or ")
|
35
35
|
# Hash | :attr_delimiter | {'class' => ' '} | Joining character used if multiple html attributes are supplied (e.g. id1_id2)
|
36
|
-
#
|
36
|
+
# Boolean | :sort_attrs | true | Sort attributes by name
|
37
|
+
# Boolean | :remove_empty_attrs| true | Remove attributes with empty value
|
37
38
|
# Boolean | :pretty | false | Pretty html indenting (This is slower!)
|
38
39
|
# String | :indent | ' ' | Indentation string
|
39
40
|
# Boolean | :streaming | false (true in Rails > 3.1) | Enable output streaming
|
@@ -61,8 +62,10 @@ module Slim
|
|
61
62
|
use Slim::Sections, :sections, :dictionary, :dictionary_access
|
62
63
|
use Slim::EndInserter
|
63
64
|
use Slim::Compiler, :disable_capture, :attr_delimiter
|
64
|
-
|
65
|
-
|
65
|
+
html :AttributeMerger, :attr_delimiter
|
66
|
+
html :AttributeSorter, :sort_attrs
|
67
|
+
html :AttributeRemover, :remove_empty_attrs
|
68
|
+
html :Pretty, :format, :attr_wrapper, :pretty, :indent
|
66
69
|
filter :Escapable, :use_html_safe, :disable_escape
|
67
70
|
filter :ControlFlow
|
68
71
|
filter :MultiFlattener
|
data/lib/slim/parser.rb
CHANGED
@@ -224,7 +224,7 @@ module Slim
|
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
227
|
-
def parse_text_block(first_line = nil, text_indent = nil)
|
227
|
+
def parse_text_block(first_line = nil, text_indent = nil, in_tag = false)
|
228
228
|
result = [:multi]
|
229
229
|
if !first_line || first_line.empty?
|
230
230
|
text_indent = nil
|
@@ -253,7 +253,11 @@ module Slim
|
|
253
253
|
# The text block lines must be at least indented
|
254
254
|
# as deep as the first line.
|
255
255
|
offset = text_indent ? indent - text_indent : 0
|
256
|
-
|
256
|
+
if offset < 0
|
257
|
+
syntax_error!("Text line not indented deep enough.\n" +
|
258
|
+
"The first text line defines the necessary text indentation." +
|
259
|
+
(in_tag ? "\nAre you trying to nest a child tag in a tag containing text? Use | for the text block!" : ''))
|
260
|
+
end
|
257
261
|
|
258
262
|
result << [:newline] << [:slim, :interpolate, (text_indent ? "\n" : '') + (' ' * offset) + @line]
|
259
263
|
|
@@ -267,7 +271,7 @@ module Slim
|
|
267
271
|
|
268
272
|
def parse_broken_line
|
269
273
|
broken_line = @line.strip
|
270
|
-
while broken_line[
|
274
|
+
while broken_line =~ /[,\\]\Z/
|
271
275
|
next_line || syntax_error!('Unexpected end of file')
|
272
276
|
broken_line << "\n" << @line.strip
|
273
277
|
end
|
@@ -312,7 +316,7 @@ module Slim
|
|
312
316
|
@stacks << content
|
313
317
|
when /\A( ?)(.*)\Z/
|
314
318
|
# Text content
|
315
|
-
tag << parse_text_block($2, @orig_line.size - @line.size + $1.size)
|
319
|
+
tag << parse_text_block($2, @orig_line.size - @line.size + $1.size, true)
|
316
320
|
end
|
317
321
|
end
|
318
322
|
|
data/lib/slim/version.rb
CHANGED
data/slim.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = %w(lib)
|
21
21
|
|
22
|
-
s.add_runtime_dependency('temple', ['~> 0.
|
22
|
+
s.add_runtime_dependency('temple', ['~> 0.4.0'])
|
23
23
|
s.add_runtime_dependency('tilt', ['~> 1.3.2'])
|
24
24
|
|
25
25
|
s.add_development_dependency('rake', ['>= 0.8.7'])
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path('../helper', __FILE__)
|
2
2
|
|
3
|
-
class TestSlim <
|
3
|
+
class TestSlim < ActionDispatch::IntegrationTest
|
4
4
|
test "normal view" do
|
5
5
|
get "slim/normal"
|
6
6
|
assert_response :success
|
@@ -59,13 +59,7 @@ class TestSlim < ActionController::IntegrationTest
|
|
59
59
|
post "parents", 'parent[name]' => "p1", 'parent[children_attributes][0][name]' => "c1"
|
60
60
|
get "parents/1/edit"
|
61
61
|
|
62
|
-
|
63
|
-
'<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" />'+
|
64
|
-
'</div><h1>Parent</h1><input id="parent_name" name="parent[name]" size="30" type="text" value="p1" />'+
|
65
|
-
'<h2>Children</h2>'+
|
66
|
-
'<ul><li><input id="parent_children_attributes_0_name" name="parent[children_attributes][0][name]" size="30" type="text" value="c1" /></li>'+
|
67
|
-
'<input id="parent_children_attributes_0_id" name="parent[children_attributes][0][id]" type="hidden" value="1" /></ul>'+
|
68
|
-
'</form>'
|
62
|
+
assert_match(%r{<form accept-charset="UTF-8" action="/parents/1" class="edit_parent" enctype="multipart/form-data" id="edit_parent_1" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="[^"]+" /></div><h1>Parent</h1><input id="parent_name" name="parent\[name\]" size="30" type="text" value="p1" /><h2>Children</h2><ul><li><input id="parent_children_attributes_0_name" name="parent\[children_attributes\]\[0\]\[name\]" size="30" type="text" value="c1" /></li><input id="parent_children_attributes_0_id" name="parent\[children_attributes\]\[0\]\[id\]" type="hidden" value="1" /></ul></form>}, @response.body)
|
69
63
|
end
|
70
64
|
|
71
65
|
protected
|
data/test/slim/helper.rb
CHANGED
@@ -9,7 +9,7 @@ MiniTest::Unit.autorun
|
|
9
9
|
|
10
10
|
Slim::Engine.after Slim::Parser, Temple::Filters::Validator, :grammar => Slim::Grammar
|
11
11
|
Slim::Engine.before Slim::Compiler, Temple::Filters::Validator, :grammar => Slim::Grammar
|
12
|
-
Slim::Engine.before
|
12
|
+
Slim::Engine.before :Pretty, Temple::Filters::Validator
|
13
13
|
|
14
14
|
class TestSlim < MiniTest::Unit::TestCase
|
15
15
|
def setup
|
@@ -72,7 +72,7 @@ class TestSlim < MiniTest::Unit::TestCase
|
|
72
72
|
end
|
73
73
|
|
74
74
|
class Env
|
75
|
-
attr_reader :var
|
75
|
+
attr_reader :var, :x
|
76
76
|
|
77
77
|
class ::HtmlSafeString < String
|
78
78
|
def html_safe?
|
@@ -88,6 +88,7 @@ class Env
|
|
88
88
|
|
89
89
|
def initialize
|
90
90
|
@var = 'instance'
|
91
|
+
@x = 0
|
91
92
|
end
|
92
93
|
|
93
94
|
def id_helper
|
@@ -144,6 +145,11 @@ class Env
|
|
144
145
|
def output_number
|
145
146
|
1337
|
146
147
|
end
|
148
|
+
|
149
|
+
def succ_x
|
150
|
+
@x = @x.succ
|
151
|
+
end
|
152
|
+
|
147
153
|
end
|
148
154
|
|
149
155
|
class ViewEnv
|
@@ -149,6 +149,15 @@ p = \
|
|
149
149
|
assert_html '<p>Hello Ruby!</p>7', source
|
150
150
|
end
|
151
151
|
|
152
|
+
def test_render_with_comma_end
|
153
|
+
source = %q{
|
154
|
+
p = message("Hello",
|
155
|
+
"Ruby!")
|
156
|
+
}
|
157
|
+
|
158
|
+
assert_html '<p>Hello Ruby!</p>', source
|
159
|
+
end
|
160
|
+
|
152
161
|
def test_render_with_no_trailing_character
|
153
162
|
source = %q{
|
154
163
|
p
|
@@ -459,4 +459,13 @@ html: body: .content
|
|
459
459
|
}
|
460
460
|
assert_html %{<html><body><div class=\"content\">Text</div></body></html>}, source
|
461
461
|
end
|
462
|
+
|
463
|
+
def test_eval_attributes_once
|
464
|
+
source = %q{
|
465
|
+
input[value=succ_x]
|
466
|
+
input[value=succ_x]
|
467
|
+
}
|
468
|
+
assert_html %{<input value="1" /><input value="2" />}, source
|
469
|
+
end
|
470
|
+
|
462
471
|
end
|
@@ -26,7 +26,23 @@ p
|
|
26
26
|
text
|
27
27
|
}
|
28
28
|
|
29
|
-
assert_syntax_error "
|
29
|
+
assert_syntax_error "Text line not indented deep enough.\nThe first text line defines the necessary text indentation.\n (__TEMPLATE__), Line 4\n text\n ^\n", source
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_unexpected_text_indentation_in_tag
|
33
|
+
source = %q{
|
34
|
+
ul
|
35
|
+
li List1
|
36
|
+
ul
|
37
|
+
li a
|
38
|
+
li b
|
39
|
+
li List2
|
40
|
+
ul
|
41
|
+
li a
|
42
|
+
li b
|
43
|
+
}
|
44
|
+
|
45
|
+
assert_syntax_error "Text line not indented deep enough.\nThe first text line defines the necessary text indentation.\nAre you trying to nest a child tag in a tag containing text? Use | for the text block!\n (__TEMPLATE__), Line 4\n ul\n ^\n", source
|
30
46
|
end
|
31
47
|
|
32
48
|
def test_malformed_indentation
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,22 +11,22 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-02-29 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: temple
|
18
|
-
requirement: &
|
18
|
+
requirement: &17637820 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 0.4.0
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *17637820
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: tilt
|
29
|
-
requirement: &
|
29
|
+
requirement: &17637240 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ~>
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: 1.3.2
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *17637240
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: rake
|
40
|
-
requirement: &
|
40
|
+
requirement: &17636740 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: 0.8.7
|
46
46
|
type: :development
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *17636740
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: sass
|
51
|
-
requirement: &
|
51
|
+
requirement: &17636160 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ! '>='
|
@@ -56,10 +56,10 @@ dependencies:
|
|
56
56
|
version: 3.1.0
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *17636160
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: minitest
|
62
|
-
requirement: &
|
62
|
+
requirement: &17652060 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ! '>='
|
@@ -67,10 +67,10 @@ dependencies:
|
|
67
67
|
version: '0'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
70
|
+
version_requirements: *17652060
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: kramdown
|
73
|
-
requirement: &
|
73
|
+
requirement: &17651560 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ! '>='
|
@@ -78,10 +78,10 @@ dependencies:
|
|
78
78
|
version: '0'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
|
-
version_requirements: *
|
81
|
+
version_requirements: *17651560
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: creole
|
84
|
-
requirement: &
|
84
|
+
requirement: &17650940 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
87
87
|
- - ! '>='
|
@@ -89,10 +89,10 @@ dependencies:
|
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
|
-
version_requirements: *
|
92
|
+
version_requirements: *17650940
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: builder
|
95
|
-
requirement: &
|
95
|
+
requirement: &17649640 !ruby/object:Gem::Requirement
|
96
96
|
none: false
|
97
97
|
requirements:
|
98
98
|
- - ! '>='
|
@@ -100,7 +100,7 @@ dependencies:
|
|
100
100
|
version: '0'
|
101
101
|
type: :development
|
102
102
|
prerelease: false
|
103
|
-
version_requirements: *
|
103
|
+
version_requirements: *17649640
|
104
104
|
description: Slim is a template language whose goal is reduce the syntax to the essential
|
105
105
|
parts without becoming cryptic.
|
106
106
|
email:
|
@@ -226,9 +226,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
226
|
version: '0'
|
227
227
|
requirements: []
|
228
228
|
rubyforge_project: slim
|
229
|
-
rubygems_version: 1.8.
|
229
|
+
rubygems_version: 1.8.15
|
230
230
|
signing_key:
|
231
231
|
specification_version: 3
|
232
232
|
summary: Slim is a template language.
|
233
233
|
test_files: []
|
234
|
-
has_rdoc:
|