slim 0.6.1 → 0.7.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,98 @@
1
+ require 'helper'
2
+
3
+ class TestParserErrors < TestSlim
4
+ def test_unexpected_indentation
5
+ source = %q{
6
+ p Indent 0
7
+ div Invalid
8
+ }
9
+
10
+ assert_syntax_error "Unexpected indentation\n Line 3\n div Invalid\n ^\n ", source
11
+ end
12
+
13
+ def test_unexpected_text_indentation
14
+ source = %q{
15
+ p
16
+ | text block
17
+ text
18
+ }
19
+
20
+ assert_syntax_error "Unexpected text indentation\n Line 4\n text\n ^\n ", source
21
+ end
22
+
23
+ def test_malformed_indentation
24
+ source = %q{
25
+ p
26
+ div Valid
27
+ div Invalid
28
+ }
29
+
30
+ assert_syntax_error "Malformed indentation\n Line 4\n div Invalid\n ^\n ", source
31
+ end
32
+
33
+ def test_unknown_line_indicator
34
+ source = %q{
35
+ p
36
+ div Valid
37
+ .valid
38
+ #valid
39
+ ?invalid
40
+ }
41
+
42
+ assert_syntax_error "Unknown line indicator\n Line 6\n ?invalid\n ^\n ", source
43
+ end
44
+
45
+ def test_expected_closing_delimiter
46
+ source = %q{
47
+ p
48
+ img(src="img.jpg" title={title}
49
+ }
50
+
51
+ assert_syntax_error "Expected closing attribute delimiter )\n Line 3\n img(src=\"img.jpg\" title={title}\n ^\n ", source
52
+ end
53
+
54
+ def test_expected_closing_delimiter
55
+ source = %q{
56
+ p
57
+ img src=[hash[1] + hash[2]
58
+ }
59
+
60
+ assert_syntax_error "Expected closing attribute delimiter ]\n Line 3\n img src=[hash[1] + hash[2]\n ^\n ", source
61
+ end
62
+
63
+ def test_unexpected_closing
64
+ source = %q{
65
+ p
66
+ img src=(1+1)]
67
+ }
68
+
69
+ assert_syntax_error "Unexpected closing ]\n Line 3\n img src=(1+1)]\n ^\n ", source
70
+ end
71
+
72
+ def test_invalid_empty_attribute
73
+ source = %q{
74
+ p
75
+ img{src= }
76
+ }
77
+
78
+ assert_syntax_error "Invalid empty attribute\n Line 3\n img{src= }\n ^\n ", source
79
+ end
80
+
81
+ def test_invalid_empty_attribute2
82
+ source = %q{
83
+ p
84
+ img{src=}
85
+ }
86
+
87
+ assert_syntax_error "Invalid empty attribute\n Line 3\n img{src=}\n ^\n ", source
88
+ end
89
+
90
+ def test_invalid_empty_attribute3
91
+ source = %q{
92
+ p
93
+ img src=
94
+ }
95
+
96
+ assert_syntax_error "Invalid empty attribute\n Line 3\n img src=\n ^\n ", source
97
+ end
98
+ end
@@ -0,0 +1,128 @@
1
+ require 'helper'
2
+
3
+ class ::MockError < NameError
4
+ end
5
+
6
+ class TestSlimTemplate < MiniTest::Unit::TestCase
7
+ class Scope
8
+ include Tilt::CompileSite
9
+ end
10
+
11
+ def test_registered_extension
12
+ assert_equal Slim::Template, Tilt['test.slim']
13
+ end
14
+
15
+ def test_preparing_and_evaluating
16
+ template = Slim::Template.new { |t| "p Hello World!\n" }
17
+ assert_equal "<p>Hello World!</p>", template.render
18
+ end
19
+
20
+ def test_passing_locals
21
+ template = Slim::Template.new { "p = 'Hey ' + name + '!'\n" }
22
+ assert_equal "<p>Hey Joe!</p>", template.render(Object.new, :name => 'Joe')
23
+ end
24
+
25
+ def test_evaluating_in_an_object_scope
26
+ template = Slim::Template.new { "p = 'Hey ' + @name + '!'\n" }
27
+ scope = Object.new
28
+ scope.instance_variable_set :@name, 'Joe'
29
+ assert_equal "<p>Hey Joe!</p>", template.render(scope)
30
+ end
31
+
32
+ def test_passing_a_block_for_yield
33
+ template = Slim::Template.new { "p = 'Hey ' + yield + '!'\n" }
34
+ assert_equal "<p>Hey Joe!</p>", template.render { 'Joe' }
35
+ end
36
+
37
+ def test_backtrace_file_and_line_reporting_without_locals
38
+ data = File.read(__FILE__).split("\n__END__\n").last
39
+ fail unless data[0] == ?h
40
+ template = Slim::Template.new('test.slim', 10) { data }
41
+ begin
42
+ template.render
43
+ fail 'should have raised an exception'
44
+ rescue => boom
45
+ assert_kind_of NameError, boom
46
+ line = boom.backtrace.first
47
+ assert_equal 'test.slim', line.split(":").first
48
+ end
49
+ end
50
+
51
+ def test_backtrace_file_and_line_reporting_with_locals
52
+ data = File.read(__FILE__).split("\n__END__\n").last
53
+ fail unless data[0] == ?h
54
+ template = Slim::Template.new('test.slim') { data }
55
+ begin
56
+ res = template.render(Object.new, :name => 'Joe', :foo => 'bar')
57
+ rescue => boom
58
+ assert_kind_of MockError, boom
59
+ line = boom.backtrace.first
60
+ assert_equal 'test.slim', line.split(":").first
61
+ end
62
+ end
63
+
64
+ def test_compiling_template_source_to_a_method
65
+ template = Slim::Template.new { |t| "Hello World!" }
66
+ template.render(Scope.new)
67
+ method_name = template.send(:compiled_method_name, [])
68
+ method_name = method_name.to_sym if Symbol === Kernel.methods.first
69
+ assert Tilt::CompileSite.instance_methods.include?(method_name),
70
+ "CompileSite.instance_methods.include?(#{method_name.inspect})"
71
+ assert Scope.new.respond_to?(method_name),
72
+ "scope.respond_to?(#{method_name.inspect})"
73
+ end
74
+
75
+
76
+ def test_passing_locals
77
+ template = Slim::Template.new { "p = 'Hey ' + name + '!'\n" }
78
+ assert_equal "<p>Hey Joe!</p>", template.render(Scope.new, :name => 'Joe')
79
+ end
80
+
81
+ def test_evaluating_in_an_object_scope
82
+ template = Slim::Template.new { "p = 'Hey ' + @name + '!'\n" }
83
+ scope = Scope.new
84
+ scope.instance_variable_set :@name, 'Joe'
85
+ assert_equal "<p>Hey Joe!</p>", template.render(scope)
86
+ end
87
+
88
+ def test_passing_a_block_for_yield
89
+ template = Slim::Template.new { "p = 'Hey ' + yield + '!'\n" }
90
+ assert_equal "<p>Hey Joe!</p>", template.render(Scope.new) { 'Joe' }
91
+ end
92
+
93
+ def backtrace_file_and_line_reporting_without_locals
94
+ data = File.read(__FILE__).split("\n__END__\n").last
95
+ fail unless data[0] == ?h
96
+ template = Slim::Template.new('test.slim', 10) { data }
97
+ begin
98
+ template.render(Scope.new)
99
+ fail 'should have raised an exception'
100
+ rescue => boom
101
+ assert_kind_of NameError, boom
102
+ line = boom.backtrace.first
103
+ assert_equal 'test.slim', line.split(":").first
104
+ end
105
+ end
106
+
107
+ def test_backtrace_file_and_line_reporting_with_locals
108
+ data = File.read(__FILE__).split("\n__END__\n").last
109
+ fail unless data[0] == ?h
110
+ template = Slim::Template.new('test.slim') { data }
111
+ begin
112
+ res = template.render(Scope.new, :name => 'Joe', :foo => 'bar')
113
+ rescue => boom
114
+ assert_kind_of MockError, boom
115
+ line = boom.backtrace.first
116
+ assert_equal 'test.slim', line.split(":").first
117
+ end
118
+ end
119
+ end
120
+
121
+ __END__
122
+ html
123
+ body
124
+ h1 = "Hey #{name}"
125
+
126
+ = raise MockError
127
+
128
+ p we never get here
data/vim/slim.vim ADDED
@@ -0,0 +1,33 @@
1
+ " Vim syntax file
2
+ " Language: Slim
3
+ " Maintainer: Andrew Stone <andy@stonean.com>
4
+ " Version: 1
5
+ " Last Change: 2010 Sep 25
6
+ " TODO: Feedback is welcomed.
7
+
8
+ " Quit when a syntax file is already loaded.
9
+ if exists("b:current_syntax")
10
+ finish
11
+ endif
12
+
13
+ if !exists("main_syntax")
14
+ let main_syntax = 'slim'
15
+ endif
16
+
17
+ " Allows a per line syntax evaluation.
18
+ let b:ruby_no_expensive = 1
19
+
20
+ " Include Ruby syntax highlighting
21
+ syn include @slimRuby syntax/ruby.vim
22
+
23
+ " Include HTML
24
+ runtime! syntax/html.vim
25
+ unlet! b:current_syntax
26
+
27
+ syntax region slimHtml start="^\s*[^-=]\w" end="$" contains=htmlTagName, htmlArg, htmlString
28
+
29
+ syntax region slimControl start="-" end="$" contains=@slimRuby keepend
30
+ syntax region slimOutput start=".*=\s" end="$" contains=@slimRuby keepend
31
+
32
+
33
+ let b:current_syntax = "slim"
data/vim/test.slim ADDED
@@ -0,0 +1,27 @@
1
+ ! doctype html
2
+ head
3
+ title Slim Vim Test
4
+ meta name="keywords" content="slim, vim, syntax"
5
+ body
6
+ h1 = @page_title
7
+ p id="notice"
8
+ '
9
+ Welcome to the the syntax test. This file is to excercise the various markup.
10
+
11
+ - unless @users.empty?
12
+ table
13
+ - for user in users do
14
+ tr
15
+ td = user.name
16
+ - else
17
+ p There are no users.
18
+
19
+ script type="text/javascript"
20
+ '
21
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
22
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
23
+
24
+ script type="text/javascript"
25
+ '
26
+ var pageTracker = _gat._getTracker("UA-12345678-9");
27
+ pageTracker._trackPageview();
metadata CHANGED
@@ -1,12 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
6
  - 0
7
- - 6
8
- - 1
9
- version: 0.6.1
7
+ - 7
8
+ - 0
9
+ - beta
10
+ - 2
11
+ version: 0.7.0.beta.2
10
12
  platform: ruby
11
13
  authors:
12
14
  - Andrew Stone
@@ -15,11 +17,12 @@ autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2010-10-17 00:00:00 -04:00
20
+ date: 2010-10-22 00:00:00 -04:00
19
21
  default_executable:
20
22
  dependencies:
21
23
  - !ruby/object:Gem::Dependency
22
24
  name: escape_utils
25
+ prerelease: false
23
26
  requirement: &id001 !ruby/object:Gem::Requirement
24
27
  none: false
25
28
  requirements:
@@ -27,26 +30,59 @@ dependencies:
27
30
  - !ruby/object:Gem::Version
28
31
  segments:
29
32
  - 0
30
- version: "0"
33
+ - 1
34
+ - 9
35
+ version: 0.1.9
31
36
  type: :runtime
32
- prerelease: false
33
37
  version_requirements: *id001
34
38
  - !ruby/object:Gem::Dependency
35
- name: rake
39
+ name: temple
40
+ prerelease: false
36
41
  requirement: &id002 !ruby/object:Gem::Requirement
37
42
  none: false
38
43
  requirements:
39
- - - ">="
44
+ - - ~>
40
45
  - !ruby/object:Gem::Version
41
46
  segments:
42
47
  - 0
43
- version: "0"
44
- type: :development
45
- prerelease: false
48
+ - 1
49
+ - 2
50
+ version: 0.1.2
51
+ type: :runtime
46
52
  version_requirements: *id002
47
53
  - !ruby/object:Gem::Dependency
48
- name: jeweler
54
+ name: tilt
55
+ prerelease: false
49
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 1
63
+ - 1
64
+ version: "1.1"
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ - 8
78
+ - 7
79
+ version: 0.8.7
80
+ type: :development
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ name: haml
84
+ prerelease: false
85
+ requirement: &id005 !ruby/object:Gem::Requirement
50
86
  none: false
51
87
  requirements:
52
88
  - - ">="
@@ -55,11 +91,24 @@ dependencies:
55
91
  - 0
56
92
  version: "0"
57
93
  type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: erubis
58
97
  prerelease: false
59
- version_requirements: *id003
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ type: :development
107
+ version_requirements: *id006
60
108
  - !ruby/object:Gem::Dependency
61
- name: haml
62
- requirement: &id004 !ruby/object:Gem::Requirement
109
+ name: minitest
110
+ prerelease: false
111
+ requirement: &id007 !ruby/object:Gem::Requirement
63
112
  none: false
64
113
  requirements:
65
114
  - - ">="
@@ -68,11 +117,24 @@ dependencies:
68
117
  - 0
69
118
  version: "0"
70
119
  type: :development
120
+ version_requirements: *id007
121
+ - !ruby/object:Gem::Dependency
122
+ name: rcov
71
123
  prerelease: false
72
- version_requirements: *id004
124
+ requirement: &id008 !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ type: :development
133
+ version_requirements: *id008
73
134
  - !ruby/object:Gem::Dependency
74
- name: erubis
75
- requirement: &id005 !ruby/object:Gem::Requirement
135
+ name: rdiscount
136
+ prerelease: false
137
+ requirement: &id009 !ruby/object:Gem::Requirement
76
138
  none: false
77
139
  requirements:
78
140
  - - ">="
@@ -81,8 +143,20 @@ dependencies:
81
143
  - 0
82
144
  version: "0"
83
145
  type: :development
146
+ version_requirements: *id009
147
+ - !ruby/object:Gem::Dependency
148
+ name: liquid
84
149
  prerelease: false
85
- version_requirements: *id005
150
+ requirement: &id010 !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ type: :development
159
+ version_requirements: *id010
86
160
  description: Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.
87
161
  email:
88
162
  - andy@stonean.com
@@ -94,21 +168,42 @@ extensions: []
94
168
  extra_rdoc_files:
95
169
  - README.md
96
170
  files:
171
+ - .gitignore
97
172
  - Gemfile
98
173
  - Gemfile.lock
99
174
  - README.md
100
175
  - Rakefile
176
+ - benchmarks/run.rb
177
+ - benchmarks/src/complex.erb
178
+ - benchmarks/src/complex.haml
179
+ - benchmarks/src/complex.slim
180
+ - benchmarks/src/complex_view.rb
101
181
  - lib/slim.rb
102
182
  - lib/slim/compiler.rb
183
+ - lib/slim/embedded_engine.rb
184
+ - lib/slim/end_inserter.rb
103
185
  - lib/slim/engine.rb
104
- - lib/slim/optimizer.rb
186
+ - lib/slim/filter.rb
187
+ - lib/slim/helpers.rb
188
+ - lib/slim/parser.rb
105
189
  - lib/slim/rails.rb
106
- - readme.html
190
+ - lib/slim/template.rb
191
+ - lib/slim/version.rb
107
192
  - slim.gemspec
108
193
  - test/helper.rb
109
- - test/slim/test_compiler.rb
110
- - test/slim/test_engine.rb
111
- - test/test_slim.rb
194
+ - test/slim/test_code_blocks.rb
195
+ - test/slim/test_code_escaping.rb
196
+ - test/slim/test_code_evaluation.rb
197
+ - test/slim/test_code_helpers.rb
198
+ - test/slim/test_code_output.rb
199
+ - test/slim/test_code_structure.rb
200
+ - test/slim/test_embedded_engines.rb
201
+ - test/slim/test_html_escaping.rb
202
+ - test/slim/test_html_structure.rb
203
+ - test/slim/test_parser_errors.rb
204
+ - test/slim/test_slim_template.rb
205
+ - vim/slim.vim
206
+ - vim/test.slim
112
207
  has_rdoc: true
113
208
  homepage: http://github.com/stonean/slim
114
209
  licenses: []
@@ -123,18 +218,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
218
  requirements:
124
219
  - - ">="
125
220
  - !ruby/object:Gem::Version
126
- hash: -160104932492896005
127
221
  segments:
128
222
  - 0
129
223
  version: "0"
130
224
  required_rubygems_version: !ruby/object:Gem::Requirement
131
225
  none: false
132
226
  requirements:
133
- - - ">="
227
+ - - ">"
134
228
  - !ruby/object:Gem::Version
135
229
  segments:
136
- - 0
137
- version: "0"
230
+ - 1
231
+ - 3
232
+ - 1
233
+ version: 1.3.1
138
234
  requirements: []
139
235
 
140
236
  rubyforge_project: slim
@@ -142,8 +238,5 @@ rubygems_version: 1.3.7
142
238
  signing_key:
143
239
  specification_version: 3
144
240
  summary: Slim is a template language.
145
- test_files:
146
- - test/helper.rb
147
- - test/test_slim.rb
148
- - test/slim/test_engine.rb
149
- - test/slim/test_compiler.rb
241
+ test_files: []
242
+