slim 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -53,12 +53,12 @@ So here's what I came up with:
53
53
  p No items found
54
54
 
55
55
  div id="footer"
56
- ` Copyright © 2010 Andrew Stone
56
+ | Copyright © 2010 Andrew Stone
57
57
 
58
58
  = render partial: 'tracking_code'
59
59
 
60
60
  script
61
- ` $(content).do_something();
61
+ | $(content).do_something();
62
62
 
63
63
 
64
64
  ### How do I?
@@ -70,11 +70,11 @@ So here's what I came up with:
70
70
  body
71
71
  h1 id="headline" Welcome to my site.
72
72
 
73
- # Or nest it. __Note:__ Must use backtick (with following space) to escape processing
73
+ # Or nest it. __Note:__ Must use a pipe or a backtick (followed by a space) to escape processing
74
74
 
75
75
  body
76
76
  h1 id="headline"
77
- ` Welcome to my site.
77
+ | Welcome to my site.
78
78
 
79
79
  #### Add content to a tag with code
80
80
 
@@ -86,8 +86,32 @@ So here's what I came up with:
86
86
  # Or nest it.
87
87
 
88
88
  body
89
- h1 id="headline"
89
+ h1 id="headline"
90
+ = page_headline
91
+
92
+ #### Shortcut form for `id` and `class` attributes
93
+
94
+ # Similarly to Haml, you can specify the `id` and `class`
95
+ # attributes in the following shortcut form
96
+ # Note: the shortcut form does not evaluate ruby code
97
+
98
+ body
99
+ h1#headline
90
100
  = page_headline
101
+ h2#tagline.small.tagline
102
+ = page_tagline
103
+ .content
104
+ = show_content
105
+
106
+ # this is the same as
107
+
108
+ body
109
+ h1 id="headline"
110
+ = page_headline
111
+ h2 id="tagline" class="small tagline"
112
+ = page_tagline
113
+ div class="content"
114
+ = show_content
91
115
 
92
116
  #### Set an attribute's value with a method?
93
117
 
@@ -106,7 +130,7 @@ So here's what I came up with:
106
130
 
107
131
  body
108
132
  p
109
- '
133
+ |
110
134
  This is a test of the text block.
111
135
 
112
136
  # The parsed result of the above:
@@ -118,7 +142,7 @@ So here's what I came up with:
118
142
 
119
143
  body
120
144
  p
121
- '
145
+ |
122
146
  This line is on the left margin.
123
147
  This line will have one space in front of it.
124
148
  This line will have two spaces in front of it.
@@ -128,9 +152,8 @@ So here's what I came up with:
128
152
 
129
153
  * Standard Ruby syntax after '-' and '='
130
154
  * __end__ is not required
131
- * If you're making a method call, wrap the arguments in parenthesis (__TODO:__ make this a non requirement)
132
155
  * Can put content on same line or nest it.
133
- * If you nest content (e.g. put it on the next line), start the line with a backtick ('`') or a pipe ('|')
156
+ * If you nest content (e.g. put it on the next line), start the line with a pipe ('|') a backtick ('`').
134
157
  * Indentation matters, but it's not as strict as Haml.
135
158
  * If you want to indent 2 spaces, then 5. It's your choice. To nest markup you only need to indent by one space, the rest is gravy.
136
159
 
@@ -138,10 +161,10 @@ So here's what I came up with:
138
161
  ### Line indicators:
139
162
  __Please note that all line indicators must be followed by a space__
140
163
 
141
- * `
142
- * The backtick tells Slim to just copy the line. It essentially escapes any processing.
143
164
  * |
144
- * *Same as `\``.*
165
+ * The pipe tells Slim to just copy the line. It essentially escapes any processing.
166
+ * `
167
+ * _Same as the pipe ('|')._
145
168
  * -
146
169
  * The dash denotes control code (similar to Haml). Examples of control code are loops and conditionals.
147
170
  * =
data/lib/slim.rb CHANGED
@@ -8,7 +8,7 @@ require 'slim/engine'
8
8
  module Slim
9
9
  class << self
10
10
  def version
11
- '0.4.1'
11
+ '0.5.0'
12
12
  end
13
13
  end
14
14
  end
data/lib/slim/compiler.rb CHANGED
@@ -7,11 +7,18 @@ module Slim
7
7
  include Optimizer
8
8
  AUTOCLOSED = %w(meta img link br hr input area param col base)
9
9
 
10
- REGEX = /^(\s*)(!?`?\|?-?=?\w*)(\s*\w*=".+")?(.*)/
10
+ CONTROL_WORDS = %w{if unless else elsif do}
11
+
12
+ REGEX_LINE_PARSER = /^(\s*)(!?`?\|?-?=?\w*)((?:\s*(?:\w|-)*="[^=]+")+|(\s*[#.]\S+))?(.*)/
13
+ REGEX_LINE_CONTAINS_OUTPUT_CODE = /^=(.*)/
14
+ REGEX_METHOD_HAS_NO_PARENTHESES = /^\w+( )/
15
+ REGEX_CODE_BLOCK_DETECTED = / do ?(.*)$/
16
+ REGEX_CODE_CONTROL_WORD_DETECTED = /(?:( )|(\())(#{CONTROL_WORDS * '|'})\b ?(.*)$/
17
+ REGEX_FIND_ATTR_ID = /#([^.\s]+)/
18
+ REGEX_FIND_ATTR_CLASS = /\.([^#\s]+)/
11
19
 
12
20
  def compile
13
21
  @_buffer = ["_buf = [];"]
14
-
15
22
  @in_text = false
16
23
 
17
24
  text_indent = last_indent = -1; enders = []
@@ -24,9 +31,9 @@ module Slim
24
31
  next
25
32
  end
26
33
 
27
- line =~ REGEX
34
+ line =~ REGEX_LINE_PARSER
28
35
 
29
- indent = $1.to_s.length
36
+ indent = $1.to_s.length
30
37
 
31
38
  if @in_text && indent > text_indent
32
39
  spaces = indent - text_indent
@@ -34,17 +41,23 @@ module Slim
34
41
  next
35
42
  end
36
43
 
37
- marker = $2
38
- attrs = $3
39
- string = $4
44
+ marker = $2
45
+ attrs = $3
46
+ shortcut_attrs = $4
47
+ string = $5
48
+
49
+ # prepends "div" to the shortcut form of attrs if no marker is given
50
+ if shortcut_attrs && marker.empty?
51
+ marker = "div"
52
+ end
40
53
 
41
- line_type = case marker
42
- when '`', '|' then :text
43
- when '-' then :control_code
44
- when '=' then :output_code
45
- when '!' then :declaration
46
- else :markup
47
- end
54
+ line_type = case marker
55
+ when '`', '|' then :text
56
+ when '-' then :control_code
57
+ when '=' then :output_code
58
+ when '!' then :declaration
59
+ else :markup
60
+ end
48
61
 
49
62
  if line_type != :text
50
63
  @in_text = false
@@ -52,12 +65,13 @@ module Slim
52
65
  end
53
66
 
54
67
  if attrs
55
- attrs.gsub!('"', '\"')
68
+ attrs = normalize_attributes(attrs) if shortcut_attrs
69
+ attrs.gsub!('"', '\"')
56
70
  end
57
71
 
58
72
  if string
59
73
  string.strip!
60
- string = nil unless string.strip.length > 0
74
+ string = nil if string.empty?
61
75
  end
62
76
 
63
77
  unless indent > last_indent
@@ -84,30 +98,28 @@ module Slim
84
98
  if AUTOCLOSED.include?(marker)
85
99
  @_buffer << "_buf << \"<#{marker}#{attrs || ''}/>\";"
86
100
  else
87
- enders << ["_buf << \"</#{marker}>\";", indent]
101
+ enders << ["_buf << \"</#{marker}>\";", indent]
88
102
  @_buffer << "_buf << \"<#{marker}#{attrs || ''}>\";"
89
103
  end
90
104
 
91
105
  if string
92
106
  string.lstrip!
93
- if string =~ /^=(.*)/
94
- @_buffer << "_buf << #{$1.strip};"
107
+ if string =~ REGEX_LINE_CONTAINS_OUTPUT_CODE
108
+ @_buffer << "_buf << #{parenthesesify_method($1.strip)};"
95
109
  else
96
110
  @_buffer << "_buf << \"#{string}\";"
97
111
  end
98
112
  end
99
113
  when :text
100
- @in_text = true
114
+ @in_text = true
101
115
  text_indent = indent
102
-
103
116
  @_buffer << "_buf << \"#{string}\";" if string.to_s.length > 0
104
117
  when :control_code
105
- unless enders.detect{|e| e[0] == 'end;' && e[1] == indent}
106
- enders << ['end;', indent]
107
- end
118
+ enders << ['end;', indent] unless enders.detect{|e| e[0] == 'end;' && e[1] == indent}
108
119
  @_buffer << "#{string};"
109
120
  when :output_code
110
- @_buffer << "_buf << #{string};"
121
+ enders << ['end;', indent] if string =~ REGEX_CODE_BLOCK_DETECTED
122
+ @_buffer << "_buf << #{parenthesesify_method(string)};"
111
123
  when :declaration
112
124
  @_buffer << "_buf << \"<!#{string}>\";"
113
125
  else
@@ -127,5 +139,23 @@ module Slim
127
139
 
128
140
  return nil
129
141
  end
142
+
143
+ private
144
+
145
+ # adds a pair of parentheses to the method
146
+ def parenthesesify_method(string)
147
+ if string =~ REGEX_METHOD_HAS_NO_PARENTHESES
148
+ string.sub!(' ', '(') && string.sub!(REGEX_CODE_CONTROL_WORD_DETECTED, '\2) \3 \4') || string << ')'
149
+ end
150
+ string
151
+ end
152
+
153
+ # converts 'p#hello.world' to 'p id="hello" class="world"'
154
+ def normalize_attributes(string)
155
+ string.sub!(REGEX_FIND_ATTR_ID, ' id="\1"')
156
+ string.sub!(REGEX_FIND_ATTR_CLASS, ' class="\1"')
157
+ string.gsub!('.', ' ')
158
+ string
159
+ end
130
160
  end
131
161
  end
@@ -51,7 +51,8 @@ module Slim
51
51
  module Optimizer
52
52
  def optimize
53
53
  @optimized = ""
54
- string = nil
54
+ string = nil
55
+
55
56
  @_buffer.each do |line|
56
57
  if line =~ /^_buf << "(.+)"/
57
58
  string ||= ""
data/slim.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{slim}
8
- s.version = "0.4.1"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrew Stone"]
12
- s.date = %q{2010-10-03}
12
+ s.date = %q{2010-10-07}
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 = %q{andy@stonean.com}
15
15
  s.extra_rdoc_files = [
data/test/helper.rb CHANGED
@@ -8,17 +8,22 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
8
 
9
9
  require 'slim'
10
10
 
11
-
12
11
  class Env
13
12
  def id_helper
14
13
  "notice"
15
14
  end
16
15
 
17
- def show_first?
18
- false
16
+ def show_first?(show = false)
17
+ show
18
+ end
19
+
20
+ def hello_world(text = "Hello World from @env", opts = {})
21
+ text << opts.to_a * " " if opts.any?
22
+ yield if block_given?
23
+ text
19
24
  end
20
25
 
21
- def hello_world
22
- "Hello World from @env"
26
+ def in_keyword
27
+ "starts with keyword"
23
28
  end
24
29
  end
@@ -26,26 +26,19 @@ HTML
26
26
 
27
27
  expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
28
28
 
29
- output = TestEngine.new(string).compiled
30
-
31
- assert_equal expected, output
29
+ assert_equal expected, TestEngine.new(string).compiled
32
30
  end
33
31
 
34
32
  def test_simple_html_with_empty_lines
35
33
  string = <<HTML
36
- html
37
- head
38
- title Simple Test Title
39
- body
34
+ body
40
35
 
41
- p Hello World, meet Slim.
36
+ p Hello World, meet Slim.
42
37
  HTML
43
38
 
44
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
45
-
46
- output = TestEngine.new(string).compiled
39
+ expected = %q|_buf = [];_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf.join;|
47
40
 
48
- assert_equal expected, output
41
+ assert_equal expected, TestEngine.new(string).compiled
49
42
  end
50
43
 
51
44
  def test_simple_html_with_wraparound_text
@@ -59,9 +52,7 @@ HTML
59
52
 
60
53
  expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<p>";_buf << "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean gravida porta neque eu tincidunt. Aenean auctor blandit est sed consectetur. Quisque feugiat massa quis diam vestibulum accumsan. Morbi pharetra accumsan augue, in imperdiet sapien viverra non. Suspendisse molestie metus in sapien hendrerit dictum sit amet et leo. Donec accumsan, justo id porttitor luctus, velit erat tincidunt lorem, eu euismod enim nisl quis justo. Aliquam orci odio, ultricies sed ultrices nec, ultrices at mi. Vestibulum vel lacus eu massa mattis venenatis. In porta, quam ut dignissim varius, neque lectus laoreet felis, eget scelerisque odio lacus sed massa. Donec fringilla laoreet mi in dignissim. Curabitur porttitor ullamcorper ultrices. Quisque hendrerit odio ut ipsum blandit quis molestie diam vehicula. Suspendisse diam nibh, sollicitudin id faucibus et, pharetra sit amet massa. Mauris molestie elit id nulla euismod tempus.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
61
54
 
62
- output = TestEngine.new(string).compiled
63
-
64
- assert_equal expected, output
55
+ assert_equal expected, TestEngine.new(string).compiled
65
56
  end
66
57
 
67
58
 
@@ -69,248 +60,236 @@ HTML
69
60
  string = <<HTML
70
61
  ! doctype html5
71
62
  html
72
- head
73
- title Simple Test Title
74
63
  body
75
64
  p Hello World, meet Slim.
76
65
  HTML
77
66
 
78
- expected = %q|_buf = [];_buf << "<!doctype html5>";_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
79
-
80
- output = TestEngine.new(string).compiled
67
+ expected = %q|_buf = [];_buf << "<!doctype html5>";_buf << "<html>";_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
81
68
 
82
- assert_equal expected, output
69
+ assert_equal expected, TestEngine.new(string).compiled
83
70
  end
84
71
 
85
72
 
86
73
  def test_simple_html_with_params
87
74
  string = <<HTML
88
- html
75
+ html
89
76
  head
90
77
  title Simple Test Title
91
78
  meta name="description" content="This is a Slim Test, that's all"
92
- body
93
- p Hello World, meet Slim.
94
79
  HTML
95
80
 
96
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "</head>";_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
81
+ expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "</head>";_buf << "</html>";_buf.join;|
97
82
 
98
- output = TestEngine.new(string).compiled
99
-
100
- assert_equal expected, output
83
+ assert_equal expected, TestEngine.new(string).compiled
101
84
  end
102
85
 
103
86
  def test_simple_html_with_params_meta_first
104
87
  string = <<HTML
105
- html
88
+ html
106
89
  head
107
90
  meta name="description" content="This is a Slim Test, that's all"
108
91
  title Simple Test Title
109
- body
110
- p Hello World, meet Slim.
111
92
  HTML
112
93
 
113
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
94
+ expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "</html>";_buf.join;|
114
95
 
115
- output = TestEngine.new(string).compiled
116
-
117
- assert_equal expected, output
96
+ assert_equal expected, TestEngine.new(string).compiled
118
97
  end
119
98
 
120
99
  def test_nested_content
121
100
  string = <<HTML
122
- html
123
- head
124
- meta name="description" content="This is a Slim Test, that's all"
125
- title Simple Test Title
126
- body
127
- p
128
- ` Hello World, meet Slim.
129
- p
130
- | Hello World, meet Slim again.
101
+ body
102
+ p
103
+ ` Hello World, meet Slim.
104
+ p
105
+ | Hello World, meet Slim again.
131
106
  HTML
132
107
 
133
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "<p>";_buf << "Hello World, meet Slim again.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
134
-
135
- output = TestEngine.new(string).compiled
108
+ expected = %q|_buf = [];_buf << "<body>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "<p>";_buf << "Hello World, meet Slim again.";_buf << "</p>";_buf << "</body>";_buf.join;|
136
109
 
137
- assert_equal expected, output
110
+ assert_equal expected, TestEngine.new(string).compiled
138
111
  end
139
112
 
140
113
  def test_closing_tag_without_content_or_attributes
141
114
  string = <<HTML
142
- html
143
- head
144
- meta name="description" content="This is a Slim Test, that's all"
145
- title Simple Test Title
146
- body
147
- hr
148
- p
149
- ` Hello World, meet Slim.
115
+ hr
116
+ p
117
+ ` Hello World, meet Slim.
150
118
  HTML
151
119
 
152
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<hr/>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
120
+ expected = %q|_buf = [];_buf << "<hr/>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf.join;|
153
121
 
154
- output = TestEngine.new(string).compiled
155
-
156
- assert_equal expected, output
122
+ assert_equal expected, TestEngine.new(string).compiled
157
123
  end
158
124
 
159
125
 
160
126
  def test_closing_tag_without_content
161
127
  string = <<HTML
162
- html
163
- head
164
- meta name="description" content="This is a Slim Test, that's all"
165
- title Simple Test Title
166
- body
167
- img width="100" height="50" src="/images/test.jpg"
168
- p
169
- ` Hello World, meet Slim.
128
+ img width="100" height="50" src="/images/test.jpg"
129
+ p
130
+ ` Hello World, meet Slim.
170
131
  HTML
171
132
 
172
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<img width=\"100\" height=\"50\" src=\"/images/test.jpg\"/>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
133
+ expected = %q|_buf = [];_buf << "<img width=\"100\" height=\"50\" src=\"/images/test.jpg\"/>";_buf << "<p>";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf.join;|
173
134
 
174
- output = TestEngine.new(string).compiled
175
-
176
- assert_equal expected, output
135
+ assert_equal expected, TestEngine.new(string).compiled
177
136
  end
178
137
 
179
138
 
180
139
  def test_text_that_starts_with_tag_name
181
140
  string = <<HTML
182
- html
183
- head
184
- meta name="description" content="This is a Slim Test, that's all"
185
- title Simple Test Title
186
- body
187
- img width="100" height="50" src="/images/test.jpg"
188
- p
189
- ` another one bites the dust
190
- p
191
- ` i am iron man
141
+ p
142
+ ` another one bites the dust
143
+ p
144
+ ` i am iron man
192
145
  HTML
193
146
 
194
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<img width=\"100\" height=\"50\" src=\"/images/test.jpg\"/>";_buf << "<p>";_buf << "another one bites the dust";_buf << "</p>";_buf << "<p>";_buf << "i am iron man";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
195
-
196
- output = TestEngine.new(string).compiled
147
+ expected = %q|_buf = [];_buf << "<p>";_buf << "another one bites the dust";_buf << "</p>";_buf << "<p>";_buf << "i am iron man";_buf << "</p>";_buf.join;|
197
148
 
198
- assert_equal expected, output
149
+ assert_equal expected, TestEngine.new(string).compiled
199
150
  end
200
151
 
201
152
 
202
153
  def test_simple_if_code_block
203
154
  string = <<HTML
204
- html
205
- head
206
- meta name="description" content="This is a Slim Test, that's all"
207
- title Simple Test Title
208
- body
209
- - if something
210
- p
211
- ` another one bites the dust
212
- - else
213
- p
214
- ` i am iron man
155
+ body
156
+ - if something
157
+ p
158
+ ` another one bites the dust
159
+ - else
160
+ p
161
+ ` i am iron man
215
162
  HTML
216
163
 
217
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";if something;_buf << "<p>";_buf << "another one bites the dust";_buf << "</p>";else;_buf << "<p>";_buf << "i am iron man";_buf << "</p>";end;_buf << "</body>";_buf << "</html>";_buf.join;|
218
-
219
- output = TestEngine.new(string).compiled
164
+ expected = %q|_buf = [];_buf << "<body>";if something;_buf << "<p>";_buf << "another one bites the dust";_buf << "</p>";else;_buf << "<p>";_buf << "i am iron man";_buf << "</p>";end;_buf << "</body>";_buf.join;|
220
165
 
221
- assert_equal expected, output
166
+ assert_equal expected, TestEngine.new(string).compiled
222
167
  end
223
168
 
224
169
  def test_simple_output_code
225
170
  string = <<HTML
226
- html
227
- head
228
- title Simple Test Title
229
- body
230
- p
231
- = hello_world
171
+ p
172
+ = hello_world
232
173
  HTML
233
174
 
234
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<p>";_buf << hello_world;_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
175
+ expected = %q|_buf = [];_buf << "<p>";_buf << hello_world;_buf << "</p>";_buf.join;|
235
176
 
236
- output = TestEngine.new(string).compiled
237
-
238
- assert_equal expected, output
177
+ assert_equal expected, TestEngine.new(string).compiled
239
178
  end
240
179
 
241
180
  def test_simple_output_code_with_params
242
181
  string = <<HTML
243
- html
244
- head
245
- title Simple Test Title
246
- body
247
- p
248
- = hello_world(params[:key])
182
+ p
183
+ = hello_world(params[:key])
249
184
  HTML
250
185
 
251
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<p>";_buf << hello_world(params[:key]);_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
186
+ expected = %q|_buf = [];_buf << "<p>";_buf << hello_world(params[:key]);_buf << "</p>";_buf.join;|
252
187
 
253
- output = TestEngine.new(string).compiled
254
-
255
- assert_equal expected, output
188
+ assert_equal expected, TestEngine.new(string).compiled
256
189
  end
257
190
 
258
191
  def test_simple_html_with_params_and_content_on_same_line
259
192
  string = <<TEMPLATE
260
- html
261
- head
262
- title Simple Test Title
263
- meta name="description" content="This is a Slim Test, that's all"
264
- body
265
- p id="first" Hello World, meet Slim.
193
+ body
194
+ p id="first" class="hello world" Hello World, meet Slim.
266
195
  TEMPLATE
267
196
 
268
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "</head>";_buf << "<body>";_buf << "<p id=\"first\">";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
197
+ expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\" class=\"hello world\">";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf.join;|
269
198
 
270
- output = TestEngine.new(string).compiled
271
-
272
- assert_equal expected, output
199
+ assert_equal expected, TestEngine.new(string).compiled
273
200
  end
274
201
 
275
202
  def test_simple_html_with_params_and_code_call
276
203
  string = <<TEMPLATE
277
- html
278
- head
279
- title Simple Test Title
280
- meta name="description" content="This is a Slim Test, that's all"
281
- body
282
- p id="first" = hello_world
204
+ body
205
+ p id="first" = hello_world
283
206
  TEMPLATE
284
207
 
285
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "</head>";_buf << "<body>";_buf << "<p id=\"first\">";_buf << hello_world;_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
208
+ expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\">";_buf << hello_world;_buf << "</p>";_buf << "</body>";_buf.join;|
286
209
 
287
- output = TestEngine.new(string).compiled
210
+ assert_equal expected, TestEngine.new(string).compiled
211
+ end
288
212
 
289
- assert_equal expected, output
213
+ def test_simple_html_with_params_and_parameterized_code_call
214
+ string = <<TEMPLATE
215
+ body
216
+ p id="first" = hello_world("Hello Ruby!")
217
+ TEMPLATE
218
+
219
+ expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\">";_buf << hello_world("Hello Ruby!");_buf << "</p>";_buf << "</body>";_buf.join;|
220
+
221
+ assert_equal expected, TestEngine.new(string).compiled
290
222
  end
291
223
 
292
- def test_text_that_starts_with_tag_name
224
+ def test_simple_html_with_params_and_spaced_parameterized_code_call
225
+ string = <<TEMPLATE
226
+ body
227
+ p id="first" = hello_world "Hello Ruby!"
228
+ TEMPLATE
229
+
230
+ expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\">";_buf << hello_world("Hello Ruby!");_buf << "</p>";_buf << "</body>";_buf.join;|
231
+
232
+ assert_equal expected, TestEngine.new(string).compiled
233
+ end
234
+
235
+ def test_simple_html_with_params_and_spaced_parameterized_code_call_2
236
+ string = <<TEMPLATE
237
+ body
238
+ p id="first" = hello_world "Hello Ruby!", :dummy => "value"
239
+ TEMPLATE
240
+
241
+ expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\">";_buf << hello_world("Hello Ruby!", :dummy => "value");_buf << "</p>";_buf << "</body>";_buf.join;|
242
+
243
+ assert_equal expected, TestEngine.new(string).compiled
244
+ end
245
+
246
+ def test_simple_html_with_multiple_wraparound_text
293
247
  string = <<HTML
294
- html
295
- head
296
- meta name="description" content="This is a Slim Test, that's all"
297
- title Simple Test Title
298
- body
299
- img width="100" height="50" src="/images/test.jpg"
300
- p
301
- `
302
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam malesuada, dui at condimentum dapibus, purus sapien fringilla est, vel eleifend massa purus ut lectus. Praesent aliquam, ipsum eu ornare porta, tellus lacus viverra diam, nec scelerisque ipsum nunc et lacus. Nam adipiscing velit eget dolor ultricies in dignissim augue ultricies. Sed sed leo in sapien pretium dictum. Fusce sem quam, tincidunt vel lobortis sed, tincidunt vulputate est. Phasellus et ipsum quam, ac fringilla orci. In facilisis est et ante tempus suscipit. Morbi elementum quam ut urna laoreet vel malesuada justo adipiscing. Suspendisse eu lorem id lacus molestie dapibus fringilla ut orci. Cras pellentesque auctor leo, nec bibendum est suscipit id. Mauris dignissim aliquet libero vitae vulputate. Maecenas viverra sodales suscipit. Aenean eu nisi velit.
248
+ p
249
+ `
250
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam malesuada, dui at condimentum dapibus, purus sapien fringilla est, vel eleifend massa purus ut lectus. Praesent aliquam, ipsum eu ornare porta, tellus lacus viverra diam, nec scelerisque ipsum nunc et lacus. Nam adipiscing velit eget dolor ultricies in dignissim augue ultricies. Sed sed leo in sapien pretium dictum. Fusce sem quam, tincidunt vel lobortis sed, tincidunt vulputate est. Phasellus et ipsum quam, ac fringilla orci. In facilisis est et ante tempus suscipit. Morbi elementum quam ut urna laoreet vel malesuada justo adipiscing. Suspendisse eu lorem id lacus molestie dapibus fringilla ut orci. Cras pellentesque auctor leo, nec bibendum est suscipit id. Mauris dignissim aliquet libero vitae vulputate. Maecenas viverra sodales suscipit. Aenean eu nisi velit.
303
251
 
304
- Phasellus ultricies vulputate lacus, eget pretium orci tincidunt tristique. Duis vitae luctus risus. Aliquam turpis massa, adipiscing in adipiscing ut, congue sed justo. Sed egestas ullamcorper nisl placerat dictum. Sed a leo lectus, sit amet vehicula nisl. Duis adipiscing congue tortor ut vulputate. Phasellus ligula lectus, congue non lobortis sed, dictum sed tellus. Vestibulum viverra vestibulum felis convallis pharetra. Phasellus a dignissim tellus. Proin dapibus malesuada lorem, et porttitor diam bibendum a. Donec et dui mauris, et tempus metus. Etiam pharetra varius dignissim. Maecenas lacinia, ligula ut tincidunt porttitor, sapien nisi pulvinar magna, nec sollicitudin libero odio bibendum nisi. Aenean ipsum eros, convallis id consequat nec, commodo eget diam. Integer malesuada, libero non dignissim varius, velit metus malesuada lectus, a consequat turpis purus ut elit.
252
+ Phasellus ultricies vulputate lacus, eget pretium orci tincidunt tristique. Duis vitae luctus risus. Aliquam turpis massa, adipiscing in adipiscing ut, congue sed justo. Sed egestas ullamcorper nisl placerat dictum. Sed a leo lectus, sit amet vehicula nisl. Duis adipiscing congue tortor ut vulputate. Phasellus ligula lectus, congue non lobortis sed, dictum sed tellus. Vestibulum viverra vestibulum felis convallis pharetra. Phasellus a dignissim tellus. Proin dapibus malesuada lorem, et porttitor diam bibendum a. Donec et dui mauris, et tempus metus. Etiam pharetra varius dignissim. Maecenas lacinia, ligula ut tincidunt porttitor, sapien nisi pulvinar magna, nec sollicitudin libero odio bibendum nisi. Aenean ipsum eros, convallis id consequat nec, commodo eget diam. Integer malesuada, libero non dignissim varius, velit metus malesuada lectus, a consequat turpis purus ut elit.
305
253
  HTML
306
254
 
307
- expected = %q|_buf = [];_buf << "<html>";_buf << "<head>";_buf << "<meta name=\"description\" content=\"This is a Slim Test, that's all\"/>";_buf << "<title>";_buf << "Simple Test Title";_buf << "</title>";_buf << "</head>";_buf << "<body>";_buf << "<img width=\"100\" height=\"50\" src=\"/images/test.jpg\"/>";_buf << "<p>";_buf << " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam malesuada, dui at condimentum dapibus, purus sapien fringilla est, vel eleifend massa purus ut lectus. Praesent aliquam, ipsum eu ornare porta, tellus lacus viverra diam, nec scelerisque ipsum nunc et lacus. Nam adipiscing velit eget dolor ultricies in dignissim augue ultricies. Sed sed leo in sapien pretium dictum. Fusce sem quam, tincidunt vel lobortis sed, tincidunt vulputate est. Phasellus et ipsum quam, ac fringilla orci. In facilisis est et ante tempus suscipit. Morbi elementum quam ut urna laoreet vel malesuada justo adipiscing. Suspendisse eu lorem id lacus molestie dapibus fringilla ut orci. Cras pellentesque auctor leo, nec bibendum est suscipit id. Mauris dignissim aliquet libero vitae vulputate. Maecenas viverra sodales suscipit. Aenean eu nisi velit.";_buf << "<br/>";_buf << "Phasellus ultricies vulputate lacus, eget pretium orci tincidunt tristique. Duis vitae luctus risus. Aliquam turpis massa, adipiscing in adipiscing ut, congue sed justo. Sed egestas ullamcorper nisl placerat dictum. Sed a leo lectus, sit amet vehicula nisl. Duis adipiscing congue tortor ut vulputate. Phasellus ligula lectus, congue non lobortis sed, dictum sed tellus. Vestibulum viverra vestibulum felis convallis pharetra. Phasellus a dignissim tellus. Proin dapibus malesuada lorem, et porttitor diam bibendum a. Donec et dui mauris, et tempus metus. Etiam pharetra varius dignissim. Maecenas lacinia, ligula ut tincidunt porttitor, sapien nisi pulvinar magna, nec sollicitudin libero odio bibendum nisi. Aenean ipsum eros, convallis id consequat nec, commodo eget diam. Integer malesuada, libero non dignissim varius, velit metus malesuada lectus, a consequat turpis purus ut elit.";_buf << "</p>";_buf << "</body>";_buf << "</html>";_buf.join;|
255
+ expected = %q|_buf = [];_buf << "<p>";_buf << " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam malesuada, dui at condimentum dapibus, purus sapien fringilla est, vel eleifend massa purus ut lectus. Praesent aliquam, ipsum eu ornare porta, tellus lacus viverra diam, nec scelerisque ipsum nunc et lacus. Nam adipiscing velit eget dolor ultricies in dignissim augue ultricies. Sed sed leo in sapien pretium dictum. Fusce sem quam, tincidunt vel lobortis sed, tincidunt vulputate est. Phasellus et ipsum quam, ac fringilla orci. In facilisis est et ante tempus suscipit. Morbi elementum quam ut urna laoreet vel malesuada justo adipiscing. Suspendisse eu lorem id lacus molestie dapibus fringilla ut orci. Cras pellentesque auctor leo, nec bibendum est suscipit id. Mauris dignissim aliquet libero vitae vulputate. Maecenas viverra sodales suscipit. Aenean eu nisi velit.";_buf << "<br/>";_buf << "Phasellus ultricies vulputate lacus, eget pretium orci tincidunt tristique. Duis vitae luctus risus. Aliquam turpis massa, adipiscing in adipiscing ut, congue sed justo. Sed egestas ullamcorper nisl placerat dictum. Sed a leo lectus, sit amet vehicula nisl. Duis adipiscing congue tortor ut vulputate. Phasellus ligula lectus, congue non lobortis sed, dictum sed tellus. Vestibulum viverra vestibulum felis convallis pharetra. Phasellus a dignissim tellus. Proin dapibus malesuada lorem, et porttitor diam bibendum a. Donec et dui mauris, et tempus metus. Etiam pharetra varius dignissim. Maecenas lacinia, ligula ut tincidunt porttitor, sapien nisi pulvinar magna, nec sollicitudin libero odio bibendum nisi. Aenean ipsum eros, convallis id consequat nec, commodo eget diam. Integer malesuada, libero non dignissim varius, velit metus malesuada lectus, a consequat turpis purus ut elit.";_buf << "</p>";_buf.join;|
256
+
257
+ iterate_it expected, TestEngine.new(string).compiled
258
+ end
259
+
260
+ def test_shortcut_html_with_params
261
+ string = <<TEMPLATE
262
+ body
263
+ p#first.hello.world Hello World, meet Slim.
264
+ TEMPLATE
308
265
 
309
- output = TestEngine.new(string).compiled
266
+ expected = %q|_buf = [];_buf << "<body>";_buf << "<p id=\"first\" class=\"hello world\">";_buf << "Hello World, meet Slim.";_buf << "</p>";_buf << "</body>";_buf.join;|
310
267
 
311
- iterate_it expected, output
268
+ assert_equal expected, TestEngine.new(string).compiled
312
269
  end
313
270
 
271
+ def test_shortcut_div_tag_with_params
272
+ string = <<TEMPLATE
273
+ body
274
+ #first.hello.world Hello World, meet Slim.
275
+ TEMPLATE
276
+
277
+ expected = %q|_buf = [];_buf << "<body>";_buf << "<div id=\"first\" class=\"hello world\">";_buf << "Hello World, meet Slim.";_buf << "</div>";_buf << "</body>";_buf.join;|
278
+
279
+ assert_equal expected, TestEngine.new(string).compiled
280
+ end
281
+
282
+ def test_control_code_loop
283
+ string = <<TEMPLATE
284
+ p
285
+ - 3.times do
286
+ | Hey!
287
+ TEMPLATE
288
+
289
+ expected = %q|_buf = [];_buf << "<p>";3.times do;_buf << "Hey!";end;_buf << "</p>";_buf.join;|
290
+
291
+ assert_equal expected, TestEngine.new(string).compiled
292
+ end
314
293
 
315
294
  # Use this to do a line by line check. Much easier to see where the problem is.
316
295
  def iterate_it(expected, output)
@@ -15,141 +15,258 @@ html
15
15
  p Hello World, meet Slim.
16
16
  HTML
17
17
 
18
- engine = Slim::Engine.new(string)
19
-
20
18
  expected = "<html><head><title>Simple Test Title</title></head><body><p>Hello World, meet Slim.</p></body></html>"
21
19
 
22
- assert_equal expected, engine.render
20
+ assert_equal expected, Slim::Engine.new(string).render
23
21
  end
24
22
 
25
23
  def test_render_with_conditional
26
24
  string = <<HTML
27
- html
28
- head
29
- title Simple Test Title
30
- body
31
- - if show_first?
32
- p The first paragraph
33
- - else
34
- p The second paragraph
25
+ div
26
+ - if show_first?
27
+ p The first paragraph
28
+ - else
29
+ p The second paragraph
35
30
  HTML
36
31
 
37
- engine = Slim::Engine.new(string)
32
+ expected = "<div><p>The second paragraph</p></div>"
33
+
34
+ assert_equal expected, Slim::Engine.new(string).render(@env)
35
+ end
36
+
37
+ def test_render_with_parameterized_conditional
38
+ string = <<HTML
39
+ div
40
+ - if show_first? false
41
+ p The first paragraph
42
+ - else
43
+ p The second paragraph
44
+ HTML
38
45
 
39
- expected = "<html><head><title>Simple Test Title</title></head><body><p>The second paragraph</p></body></html>"
46
+ expected = "<div><p>The second paragraph</p></div>"
40
47
 
41
- assert_equal expected, engine.render(@env)
48
+ assert_equal expected, Slim::Engine.new(string).render(@env)
42
49
  end
43
50
 
44
51
  def test_render_with_call
45
52
  string = <<HTML
46
- html
47
- head
48
- title Simple Test Title
49
- body
50
- p
51
- = hello_world
53
+ p
54
+ = hello_world
55
+ HTML
56
+
57
+ expected = "<p>Hello World from @env</p>"
58
+
59
+ assert_equal expected, Slim::Engine.new(string).render(@env)
60
+ end
61
+
62
+ def test_render_with_conditional_call
63
+ string = <<HTML
64
+ p
65
+ = hello_world if true
66
+ HTML
67
+
68
+ expected = "<p>Hello World from @env</p>"
69
+
70
+ assert_equal expected, Slim::Engine.new(string).render(@env)
71
+ end
72
+
73
+ def test_render_with_parameterized_call
74
+ string = <<HTML
75
+ p
76
+ = hello_world("Hello Ruby!")
77
+ HTML
78
+
79
+ expected = "<p>Hello Ruby!</p>"
80
+
81
+ assert_equal expected, Slim::Engine.new(string).render(@env)
82
+ end
83
+
84
+ def test_render_with_spaced_parameterized_call
85
+ string = <<HTML
86
+ p
87
+ = hello_world "Hello Ruby!"
52
88
  HTML
53
89
 
54
- engine = Slim::Engine.new(string)
90
+ expected = "<p>Hello Ruby!</p>"
91
+
92
+ assert_equal expected, Slim::Engine.new(string).render(@env)
93
+ end
94
+
95
+ def test_render_with_spaced_parameterized_call_2
96
+ string = <<HTML
97
+ p
98
+ = hello_world "Hello Ruby!", :dummy => "value"
99
+ HTML
55
100
 
56
- expected = "<html><head><title>Simple Test Title</title></head><body><p>Hello World from @env</p></body></html>"
101
+ expected = "<p>Hello Ruby!dummy value</p>"
57
102
 
58
- assert_equal expected, engine.render(@env)
103
+ assert_equal expected, Slim::Engine.new(string).render(@env)
59
104
  end
60
105
 
61
106
  def test_render_with_call_and_inline_text
62
107
  string = <<HTML
63
- html
64
- head
65
- title Simple Test Title
66
- body
67
- h1 This is my title
68
- p
69
- = hello_world
108
+ h1 This is my title
109
+ p
110
+ = hello_world
70
111
  HTML
71
112
 
72
- engine = Slim::Engine.new(string)
113
+ expected = "<h1>This is my title</h1><p>Hello World from @env</p>"
114
+
115
+ assert_equal expected, Slim::Engine.new(string).render(@env)
116
+ end
117
+
118
+ def test_render_with_call_to_set_attributes
119
+ string = <<HTML
120
+ p id="#\{id_helper}" class="hello world"
121
+ = hello_world
122
+ HTML
73
123
 
74
- expected = "<html><head><title>Simple Test Title</title></head><body><h1>This is my title</h1><p>Hello World from @env</p></body></html>"
124
+ expected = "<p id=\"notice\" class=\"hello world\">Hello World from @env</p>"
75
125
 
76
- assert_equal expected, engine.render(@env)
126
+ assert_equal expected, Slim::Engine.new(string).render(@env)
77
127
  end
78
128
 
79
- def test_render_with_call_to_set_attribute
129
+ def test_render_with_call_to_set_custom_attributes
80
130
  string = <<HTML
81
- html
82
- head
83
- title Simple Test Title
84
- body
85
- h1 This is my title
86
- p id="#\{id_helper}"
87
- = hello_world
131
+ p data-id="#\{id_helper}" data-class="hello world"
132
+ = hello_world
88
133
  HTML
89
134
 
90
- engine = Slim::Engine.new(string)
135
+ expected = "<p data-id=\"notice\" data-class=\"hello world\">Hello World from @env</p>"
91
136
 
92
- expected = "<html><head><title>Simple Test Title</title></head><body><h1>This is my title</h1><p id=\"notice\">Hello World from @env</p></body></html>"
137
+ assert_equal expected, Slim::Engine.new(string).render(@env)
138
+ end
93
139
 
94
- assert_equal expected, engine.render(@env)
140
+ def test_render_with_shortcut_attributes
141
+ string = <<HTML
142
+ h1#title This is my title
143
+ #notice.hello.world
144
+ = hello_world
145
+ HTML
146
+
147
+ expected = "<h1 id=\"title\">This is my title</h1><div id=\"notice\" class=\"hello world\">Hello World from @env</div>"
148
+
149
+ assert_equal expected, Slim::Engine.new(string).render(@env)
95
150
  end
96
151
 
97
- def test_render_with_call_to_set_attribute_and_call_to_set_content
152
+ def test_render_with_call_to_set_attributes_and_call_to_set_content
98
153
  string = <<HTML
99
- html
100
- head
101
- title Simple Test Title
102
- body
103
- h1 This is my title
104
- p id="#\{id_helper}" = hello_world
154
+ p id="#\{id_helper}" class="hello world" = hello_world
105
155
  HTML
106
156
 
107
- engine = Slim::Engine.new(string)
157
+ expected = "<p id=\"notice\" class=\"hello world\">Hello World from @env</p>"
158
+
159
+ assert_equal expected, Slim::Engine.new(string).render(@env)
160
+ end
161
+
162
+ def test_render_with_parameterized_call_to_set_attributes_and_call_to_set_content
163
+ string = <<HTML
164
+ p id="#\{id_helper}" class="hello world" = hello_world("Hello Ruby!")
165
+ HTML
108
166
 
109
- expected = "<html><head><title>Simple Test Title</title></head><body><h1>This is my title</h1><p id=\"notice\">Hello World from @env</p></body></html>"
167
+ expected = "<p id=\"notice\" class=\"hello world\">Hello Ruby!</p>"
110
168
 
111
- assert_equal expected, engine.render(@env)
169
+ assert_equal expected, Slim::Engine.new(string).render(@env)
112
170
  end
113
171
 
114
- def test_render_with_text_block
172
+ def test_render_with_spaced_parameterized_call_to_set_attributes_and_call_to_set_content
115
173
  string = <<HTML
116
- html
117
- head
118
- title Simple Test Title
119
- body
120
- h1 This is my title
121
- p id="#\{id_helper}"
122
- `
123
- Phasellus ultricies vulputate lacus, eget pretium orci tincidunt tristique. Duis vitae luctus risus. Aliquam turpis massa, adipiscing in adipiscing ut, congue sed justo. Sed egestas ullamcorper nisl placerat dictum. Sed a leo lectus, sit amet vehicula nisl. Duis adipiscing congue tortor ut vulputate. Phasellus ligula lectus, congue non lobortis sed, dictum sed tellus. Vestibulum viverra vestibulum felis convallis pharetra. Phasellus a dignissim tellus. Proin dapibus malesuada lorem, et porttitor diam bibendum a. Donec et dui mauris, et tempus metus. Etiam pharetra varius dignissim. Maecenas lacinia, ligula ut tincidunt porttitor, sapien nisi pulvinar magna, nec sollicitudin libero odio bibendum nisi. Aenean ipsum eros, convallis id consequat nec, commodo eget diam. Integer malesuada, libero non dignissim varius, velit metus malesuada lectus, a consequat turpis purus ut elit.
174
+ p id="#\{id_helper}" class="hello world" = hello_world "Hello Ruby!"
124
175
  HTML
125
176
 
126
- engine = Slim::Engine.new(string)
177
+ expected = "<p id=\"notice\" class=\"hello world\">Hello Ruby!</p>"
178
+
179
+ assert_equal expected, Slim::Engine.new(string).render(@env)
180
+ end
181
+
182
+ def test_render_with_spaced_parameterized_call_to_set_attributes_and_call_to_set_content_2
183
+ string = <<HTML
184
+ p id="#\{id_helper}" class="hello world" = hello_world "Hello Ruby!", :dummy => "value"
185
+ HTML
127
186
 
128
- expected = "<html><head><title>Simple Test Title</title></head><body><h1>This is my title</h1><p id=\"notice\">Phasellus ultricies vulputate lacus, eget pretium orci tincidunt tristique. Duis vitae luctus risus. Aliquam turpis massa, adipiscing in adipiscing ut, congue sed justo. Sed egestas ullamcorper nisl placerat dictum. Sed a leo lectus, sit amet vehicula nisl. Duis adipiscing congue tortor ut vulputate. Phasellus ligula lectus, congue non lobortis sed, dictum sed tellus. Vestibulum viverra vestibulum felis convallis pharetra. Phasellus a dignissim tellus. Proin dapibus malesuada lorem, et porttitor diam bibendum a. Donec et dui mauris, et tempus metus. Etiam pharetra varius dignissim. Maecenas lacinia, ligula ut tincidunt porttitor, sapien nisi pulvinar magna, nec sollicitudin libero odio bibendum nisi. Aenean ipsum eros, convallis id consequat nec, commodo eget diam. Integer malesuada, libero non dignissim varius, velit metus malesuada lectus, a consequat turpis purus ut elit.</p></body></html>"
187
+ expected = "<p id=\"notice\" class=\"hello world\">Hello Ruby!dummy value</p>"
129
188
 
130
- assert_equal expected, engine.render(@env)
189
+ assert_equal expected, Slim::Engine.new(string).render(@env)
131
190
  end
132
191
 
192
+ def test_render_with_text_block
193
+ string = <<HTML
194
+ p
195
+ `
196
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
197
+ HTML
198
+
199
+ expected = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>"
200
+
201
+ assert_equal expected, Slim::Engine.new(string).render(@env)
202
+ end
133
203
 
134
204
  def test_render_with_text_block_with_subsequent_markup
135
205
  string = <<HTML
136
- html
137
- head
138
- title Simple Test Title
139
- body
140
- h1 This is my title
141
- p id="#\{id_helper}"
142
- `
143
- Phasellus ultricies vulputate lacus, eget pretium orci tincidunt tristique. Duis vitae luctus risus. Aliquam turpis massa, adipiscing in adipiscing ut, congue sed justo. Sed egestas ullamcorper nisl placerat dictum. Sed a leo lectus, sit amet vehicula nisl. Duis adipiscing congue tortor ut vulputate. Phasellus ligula lectus, congue non lobortis sed, dictum sed tellus. Vestibulum viverra vestibulum felis convallis pharetra. Phasellus a dignissim tellus. Proin dapibus malesuada lorem, et porttitor diam bibendum a. Donec et dui mauris, et tempus metus. Etiam pharetra varius dignissim. Maecenas lacinia, ligula ut tincidunt porttitor, sapien nisi pulvinar magna, nec sollicitudin libero odio bibendum nisi. Aenean ipsum eros, convallis id consequat nec, commodo eget diam. Integer malesuada, libero non dignissim varius, velit metus malesuada lectus, a consequat turpis purus ut elit.
144
- p Some more markup
206
+ p
207
+ `
208
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
209
+ p Some more markup
145
210
  HTML
146
211
 
147
- engine = Slim::Engine.new(string)
212
+ expected = "<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p><p>Some more markup</p>"
148
213
 
149
- expected = "<html><head><title>Simple Test Title</title></head><body><h1>This is my title</h1><p id=\"notice\"> Phasellus ultricies vulputate lacus, eget pretium orci tincidunt tristique. Duis vitae luctus risus. Aliquam turpis massa, adipiscing in adipiscing ut, congue sed justo. Sed egestas ullamcorper nisl placerat dictum. Sed a leo lectus, sit amet vehicula nisl. Duis adipiscing congue tortor ut vulputate. Phasellus ligula lectus, congue non lobortis sed, dictum sed tellus. Vestibulum viverra vestibulum felis convallis pharetra. Phasellus a dignissim tellus. Proin dapibus malesuada lorem, et porttitor diam bibendum a. Donec et dui mauris, et tempus metus. Etiam pharetra varius dignissim. Maecenas lacinia, ligula ut tincidunt porttitor, sapien nisi pulvinar magna, nec sollicitudin libero odio bibendum nisi. Aenean ipsum eros, convallis id consequat nec, commodo eget diam. Integer malesuada, libero non dignissim varius, velit metus malesuada lectus, a consequat turpis purus ut elit.</p><p>Some more markup</p></body></html>"
214
+ assert_equal expected, Slim::Engine.new(string).render(@env)
215
+ end
216
+
217
+ def test_render_with_output_code_block
218
+ string = <<HTML
219
+ p
220
+ = hello_world "Hello Ruby!" do
221
+ | Hello from within a block!
222
+ HTML
223
+
224
+ expected = "<p>Hello from within a block!Hello Ruby!</p>"
225
+
226
+ assert_equal expected, Slim::Engine.new(string).render(@env)
227
+ end
150
228
 
151
- assert_equal expected, engine.render(@env)
229
+ def test_render_with_output_code_within_block
230
+ string = <<HTML
231
+ p
232
+ = hello_world "Hello Ruby!" do
233
+ = hello_world "Hello from within a block! "
234
+ HTML
235
+
236
+ expected = "<p>Hello from within a block! Hello Ruby!</p>"
237
+
238
+ assert_equal expected, Slim::Engine.new(string).render(@env)
152
239
  end
153
240
 
241
+ def test_render_with_control_code_loop
242
+ string = <<HTML
243
+ p
244
+ - 3.times do
245
+ | Hey!
246
+ HTML
247
+
248
+ expected = "<p>Hey!Hey!Hey!</p>"
154
249
 
250
+ assert_equal expected, Slim::Engine.new(string).render(@env)
251
+ end
252
+
253
+ def test_render_with_inline_condition
254
+ string = <<HTML
255
+ p = hello_world if true
256
+ HTML
257
+
258
+ expected = "<p>Hello World from @env</p>"
259
+
260
+ assert_equal expected, Slim::Engine.new(string).render(@env)
261
+ end
262
+
263
+ def test_render_with_attribute_starts_with_keyword
264
+ string = <<HTML
265
+ p = hello_world in_keyword
266
+ HTML
267
+
268
+ expected = "<p>starts with keyword</p>"
269
+
270
+ assert_equal expected, Slim::Engine.new(string).render(@env)
271
+ end
155
272
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 4
8
- - 1
9
- version: 0.4.1
7
+ - 5
8
+ - 0
9
+ version: 0.5.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andrew Stone
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-03 00:00:00 -04:00
17
+ date: 2010-10-07 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20