slim 0.6.0.beta.1 → 0.6.0.beta.2

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
@@ -1,3 +1,5 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec
4
+
5
+ gem 'slim', :path => File.dirname(__FILE__), :group => :development
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slim (0.5.1)
4
+ slim (0.6.0.beta.2)
5
5
  escape_utils
6
6
 
7
7
  GEM
@@ -10,11 +10,13 @@ GEM
10
10
  escape_utils (0.1.8)
11
11
  gemcutter (0.6.1)
12
12
  git (1.2.5)
13
+ haml (3.0.21)
13
14
  jeweler (1.4.0)
14
15
  gemcutter (>= 0.1.0)
15
16
  git (>= 1.2.5)
16
17
  rubyforge (>= 2.0.0)
17
18
  json_pure (1.4.6)
19
+ mustache (0.11.2)
18
20
  rake (0.8.7)
19
21
  rubyforge (2.0.4)
20
22
  json_pure (>= 1.1.7)
@@ -24,6 +26,8 @@ PLATFORMS
24
26
 
25
27
  DEPENDENCIES
26
28
  escape_utils
29
+ haml
27
30
  jeweler
31
+ mustache
28
32
  rake
29
33
  slim!
data/README.md CHANGED
@@ -115,16 +115,28 @@ So here's what I came up with:
115
115
 
116
116
  #### Set an attribute's value with a method?
117
117
 
118
- # Just use standard Ruby interpolation.
118
+ # Use standard Ruby interpolation.
119
119
 
120
120
  body
121
121
  table
122
122
  - for user in users do
123
123
  tr id="user_#{user.id}"
124
124
 
125
+ #### Call a method in content
126
+
127
+ # Use standard Ruby interpolation.
128
+
129
+ body
130
+ h1 Welcome #{current_user.name} to the show.
131
+
132
+ # To escape the interpolation (i.e. render as is)
133
+
134
+ body
135
+ h1 Welcome \#{current_user.name} to the show.
136
+
125
137
  #### Escape the escaping?
126
138
 
127
- # Just use a double equal sign
139
+ # Use a double equal sign
128
140
 
129
141
  body
130
142
  h1 id="headline"
@@ -132,8 +144,9 @@ So here's what I came up with:
132
144
 
133
145
  #### Treat multiple lines of code as text that should bypass parsing.
134
146
 
135
- # Use a backtick to start the escape. Each following line that is
136
- # indented greater than the backtick is copied over.
147
+ # Use a pipe ('|') or backtick ('`') to start the escape.
148
+ # Each following line that is indented greater than
149
+ # the backtick is copied over.
137
150
 
138
151
  body
139
152
  p
@@ -151,9 +164,9 @@ So here's what I came up with:
151
164
  p
152
165
  |
153
166
  This line is on the left margin.
154
- This line will have one space in front of it.
155
- This line will have two spaces in front of it.
156
- And so on...
167
+ This line will have one space in front of it.
168
+ This line will have two spaces in front of it.
169
+ And so on...
157
170
 
158
171
  #### Add ruby code comments?
159
172
 
@@ -173,7 +186,7 @@ So here's what I came up with:
173
186
  * Standard Ruby syntax after '-' and '='
174
187
  * __end__ is not required
175
188
  * Can put content on same line or nest it.
176
- * If you nest content (e.g. put it on the next line), start the line with a pipe ('|') a backtick ('`').
189
+ * If you nest content (e.g. put it on the next line), start the line with a pipe ('|') or a backtick ('`').
177
190
  * Indentation matters, but it's not as strict as Haml.
178
191
  * 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.
179
192
 
data/Rakefile CHANGED
@@ -8,19 +8,22 @@ begin
8
8
  Jeweler::Tasks.new do |gem|
9
9
  gem.name = "slim"
10
10
  gem.version = Slim.version
11
- gem.rubyforge_project = "slim"
11
+ gem.rubyforge_project = gem.name
12
12
  gem.summary = "Slim is a template language."
13
13
  gem.description = "Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic."
14
- gem.email = "andy@stonean.com"
15
14
  gem.homepage = "http://github.com/stonean/slim"
16
- gem.authors = ["Andrew Stone"]
15
+ gem.authors = ["Andrew Stone", "Fred Wu"]
16
+ gem.email = ["andy@stonean.com", "ifredwu@gmail.com"]
17
+ gem.files = ['*', 'lib/**/*', 'test/**/*']
17
18
  gem.add_dependency 'escape_utils'
18
19
  gem.add_development_dependency 'rake'
19
20
  gem.add_development_dependency 'jeweler'
21
+ gem.add_development_dependency 'haml'
22
+ gem.add_development_dependency 'mustache'
20
23
  end
21
24
  Jeweler::GemcutterTasks.new
22
25
  rescue LoadError
23
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
26
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
24
27
  end
25
28
 
26
29
  begin
@@ -31,7 +34,7 @@ begin
31
34
  end
32
35
  rescue LoadError
33
36
  task :yard do
34
- abort "YARD is not available. In order to run yard, you must: sudo gem install yard"
37
+ abort "YARD is not available. In order to run yard, you must: gem install yard"
35
38
  end
36
39
  end
37
40
 
@@ -51,7 +54,7 @@ begin
51
54
  end
52
55
  rescue LoadError
53
56
  task :rcov do
54
- abort "RCov is not available. In order to run rcov, you must: sudo gem install rcov"
57
+ abort "RCov is not available. In order to run rcov, you must: gem install rcov"
55
58
  end
56
59
  end
57
60
 
@@ -10,7 +10,7 @@ require 'slim/engine'
10
10
  module Slim
11
11
  class << self
12
12
  def version
13
- '0.6.0.beta.1'
13
+ '0.6.0.beta.2'
14
14
  end
15
15
 
16
16
  def escape_html(html)
@@ -10,10 +10,11 @@ module Slim
10
10
  CONTROL_WORDS = %w{if unless do}
11
11
  ELSE_CONTROL_WORDS = %w{else elsif}
12
12
 
13
- REGEX_LINE_PARSER = /^(\s*)(!?`?\|?-?=?\/?\w*)((?:\s*(?:\w|-)*="[^=]+")+|(\s*[#.]\S+))?(.*)/
14
- REGEX_LINE_CONTAINS_OUTPUT_CODE = /^=(.*)/
13
+ REGEX_LINE_PARSER = /^(\s*)(!?`?\|?-?=?\/?\w*)((?:\s*(?:\w|-)*="[^=]+")+|(\S*[#.]\S+))?(.*)/
14
+
15
+ REGEX_LINE_CONTAINS_OUTPUT_CODE = /^\s*=(.*)/
15
16
  REGEX_LINE_CONTAINS_ONLY_HTML_TAG = /^\s*\w+\S?$/
16
- REGEX_LINE_CONTAINS_METHOD_DETECTED = /^(\w+\(.*\))(.*)/
17
+ REGEX_LINE_CONTAINS_METHOD_DETECTED = /^(\w+\(.*\))/
17
18
  REGEX_METHOD_HAS_NO_PARENTHESES = /^\w+\s/
18
19
  REGEX_CODE_BLOCK_DETECTED = / do ?.*$/
19
20
  REGEX_CODE_CONTROL_WORD_DETECTED = /(?:\s|(\())(#{CONTROL_WORDS * '|'})\b\s?(.*)$/
@@ -49,7 +50,10 @@ module Slim
49
50
  marker = $2
50
51
  attrs = $3
51
52
  shortcut_attrs = $4
52
- string = $5.strip
53
+ string = $5
54
+
55
+ # Remove the first space, but allow people to pad if they want.
56
+ string.slice!(0) if string =~ /^\s/
53
57
 
54
58
  # prepends "div" to the shortcut form of attrs if no marker is given
55
59
  marker = 'div' if shortcut_attrs && marker.empty?
@@ -89,14 +93,13 @@ module Slim
89
93
  case line_type
90
94
  when :markup
91
95
  if AUTOCLOSED.include?(marker)
92
- @_buffer << "_buf << \"<#{marker}#{attrs || ''}/>\";"
96
+ @_buffer << "_buf << \"<#{marker}#{attrs}/>\";"
93
97
  else
94
98
  enders << ["_buf << \"</#{marker}>\";", indent]
95
- @_buffer << "_buf << \"<#{marker}#{attrs || ''}>\";"
99
+ @_buffer << "_buf << \"<#{marker}#{attrs}>\";"
96
100
  end
97
101
 
98
102
  unless string.empty?
99
- string.lstrip!
100
103
  if string =~ REGEX_LINE_CONTAINS_OUTPUT_CODE
101
104
  @_buffer << "_buf << #{parse_string($1.strip)};"
102
105
  else
@@ -106,7 +109,7 @@ module Slim
106
109
  when :text
107
110
  in_text = true
108
111
  text_indent = indent
109
- @_buffer << "_buf << \"#{string}\";" if string.to_s.length > 0
112
+ @_buffer << "_buf << \"#{string}\";" unless string.empty?
110
113
  when :control_code
111
114
  enders << ['end;', indent] unless enders.detect{|e| e[0] == 'end;' && e[1] == indent}
112
115
  @_buffer << "#{string};"
@@ -148,7 +151,7 @@ module Slim
148
151
 
149
152
  # escapes the string
150
153
  def wraps_with_slim_escape!(string)
151
- string.sub!(REGEX_LINE_CONTAINS_METHOD_DETECTED, 'Slim.escape_html(\1) \2')
154
+ string.sub!(REGEX_LINE_CONTAINS_METHOD_DETECTED, 'Slim.escape_html(\1)')
152
155
  end
153
156
 
154
157
  # converts 'p#hello.world.mate' to 'p id="hello" class="world mate"'
@@ -5,19 +5,18 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{slim}
8
- s.version = "0.6.0.beta.1"
8
+ s.version = "0.6.0.beta.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Andrew Stone"]
11
+ s.authors = ["Andrew Stone", "Fred Wu"]
12
12
  s.date = %q{2010-10-14}
13
13
  s.description = %q{Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.}
14
- s.email = %q{andy@stonean.com}
14
+ s.email = ["andy@stonean.com", "ifredwu@gmail.com"]
15
15
  s.extra_rdoc_files = [
16
16
  "README.md"
17
17
  ]
18
18
  s.files = [
19
- ".gitignore",
20
- "Gemfile",
19
+ "Gemfile",
21
20
  "Gemfile.lock",
22
21
  "README.md",
23
22
  "Rakefile",
@@ -30,9 +29,7 @@ Gem::Specification.new do |s|
30
29
  "test/helper.rb",
31
30
  "test/slim/test_compiler.rb",
32
31
  "test/slim/test_engine.rb",
33
- "test/test_slim.rb",
34
- "vim/slim.vim",
35
- "vim/test.slim"
32
+ "test/test_slim.rb"
36
33
  ]
37
34
  s.homepage = %q{http://github.com/stonean/slim}
38
35
  s.rdoc_options = ["--charset=UTF-8"]
@@ -55,15 +52,21 @@ Gem::Specification.new do |s|
55
52
  s.add_runtime_dependency(%q<escape_utils>, [">= 0"])
56
53
  s.add_development_dependency(%q<rake>, [">= 0"])
57
54
  s.add_development_dependency(%q<jeweler>, [">= 0"])
55
+ s.add_development_dependency(%q<haml>, [">= 0"])
56
+ s.add_development_dependency(%q<mustache>, [">= 0"])
58
57
  else
59
58
  s.add_dependency(%q<escape_utils>, [">= 0"])
60
59
  s.add_dependency(%q<rake>, [">= 0"])
61
60
  s.add_dependency(%q<jeweler>, [">= 0"])
61
+ s.add_dependency(%q<haml>, [">= 0"])
62
+ s.add_dependency(%q<mustache>, [">= 0"])
62
63
  end
63
64
  else
64
65
  s.add_dependency(%q<escape_utils>, [">= 0"])
65
66
  s.add_dependency(%q<rake>, [">= 0"])
66
67
  s.add_dependency(%q<jeweler>, [">= 0"])
68
+ s.add_dependency(%q<haml>, [">= 0"])
69
+ s.add_dependency(%q<mustache>, [">= 0"])
67
70
  end
68
71
  end
69
72
 
@@ -340,7 +340,7 @@ TEMPLATE
340
340
  assert_equal expected, TestEngine.new(string).compiled
341
341
  end
342
342
 
343
- def test_irregular_spaces
343
+ def test_irregular_indentions
344
344
  string = <<TEMPLATE
345
345
  body
346
346
  p
@@ -303,4 +303,96 @@ HTML
303
303
 
304
304
  assert_equal expected, Slim::Engine.new(string).render(@env)
305
305
  end
306
+
307
+
308
+ def test_nested_text
309
+ string = <<HTML
310
+ p
311
+ |
312
+ This is line one.
313
+ This is line two.
314
+ This is line three.
315
+ This is line four.
316
+ p This is a new paragraph.
317
+ HTML
318
+
319
+ expected = "<p>This is line one. This is line two. This is line three. This is line four.</p><p>This is a new paragraph.</p>"
320
+
321
+ assert_equal expected, Slim::Engine.new(string).render(@env)
322
+ end
323
+
324
+ def test_nested_text_with_nested_html
325
+ string = <<HTML
326
+ p
327
+ |
328
+ This is line one.
329
+ This is line two.
330
+ This is line three.
331
+ This is line four.
332
+ span.bold This is a bold line in the paragraph.
333
+ | This is more content.
334
+ HTML
335
+
336
+ expected = "<p>This is line one. This is line two. This is line three. This is line four.<span class=\"bold\">This is a bold line in the paragraph.</span> This is more content.</p>"
337
+
338
+ assert_equal expected, Slim::Engine.new(string).render(@env)
339
+
340
+ end
341
+
342
+
343
+ def test_simple_paragraph_with_padding
344
+ string = <<HTML
345
+ p There will be 3 spaces in front of this line.
346
+ HTML
347
+
348
+ expected = "<p> There will be 3 spaces in front of this line.</p>"
349
+
350
+ assert_equal expected, Slim::Engine.new(string).render(@env)
351
+ end
352
+
353
+ def test_output_code_with_leading_spaces
354
+ string = <<HTML
355
+ p= hello_world
356
+ p = hello_world
357
+ p = hello_world
358
+ HTML
359
+
360
+ expected = "<p>Hello World from @env</p><p>Hello World from @env</p><p>Hello World from @env</p>"
361
+
362
+ assert_equal expected, Slim::Engine.new(string).render(@env)
363
+ end
364
+
365
+ def test_interpolation_in_text
366
+ string = <<HTML
367
+ p
368
+ | \#{hello_world}
369
+ p
370
+ |
371
+ A message from the compiler: \#{hello_world}
372
+ HTML
373
+
374
+ expected = "<p>Hello World from @env</p><p>A message from the compiler: Hello World from @env</p>"
375
+
376
+ assert_equal expected, Slim::Engine.new(string).render(@env)
377
+ end
378
+
379
+ def test_interpolation_in_tag
380
+ string = <<HTML
381
+ p \#{hello_world}
382
+ HTML
383
+
384
+ expected = "<p>Hello World from @env</p>"
385
+
386
+ assert_equal expected, Slim::Engine.new(string).render(@env)
387
+ end
388
+
389
+ def test_escape_interpolation
390
+ string = <<HTML
391
+ p \\\#{hello_world}
392
+ HTML
393
+
394
+ expected = "<p>\#{hello_world}</p>"
395
+
396
+ assert_equal expected, Slim::Engine.new(string).render(@env)
397
+ end
306
398
  end
metadata CHANGED
@@ -7,11 +7,12 @@ version: !ruby/object:Gem::Version
7
7
  - 6
8
8
  - 0
9
9
  - beta
10
- - 1
11
- version: 0.6.0.beta.1
10
+ - 2
11
+ version: 0.6.0.beta.2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Andrew Stone
15
+ - Fred Wu
15
16
  autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
@@ -58,8 +59,36 @@ dependencies:
58
59
  type: :development
59
60
  prerelease: false
60
61
  version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: haml
64
+ requirement: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: *id004
75
+ - !ruby/object:Gem::Dependency
76
+ name: mustache
77
+ requirement: &id005 !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: *id005
61
88
  description: Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.
62
- email: andy@stonean.com
89
+ email:
90
+ - andy@stonean.com
91
+ - ifredwu@gmail.com
63
92
  executables: []
64
93
 
65
94
  extensions: []
@@ -67,7 +96,6 @@ extensions: []
67
96
  extra_rdoc_files:
68
97
  - README.md
69
98
  files:
70
- - .gitignore
71
99
  - Gemfile
72
100
  - Gemfile.lock
73
101
  - README.md
@@ -82,8 +110,6 @@ files:
82
110
  - test/slim/test_compiler.rb
83
111
  - test/slim/test_engine.rb
84
112
  - test/test_slim.rb
85
- - vim/slim.vim
86
- - vim/test.slim
87
113
  has_rdoc: true
88
114
  homepage: http://github.com/stonean/slim
89
115
  licenses: []
@@ -98,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
124
  requirements:
99
125
  - - ">="
100
126
  - !ruby/object:Gem::Version
101
- hash: -4287789825889488572
127
+ hash: 3027777953181693052
102
128
  segments:
103
129
  - 0
104
130
  version: "0"
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- *.swp
2
- pkg
3
- readme.html
4
- .yardoc/
5
- doc/
6
- .bundle/
@@ -1,33 +0,0 @@
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"
@@ -1,27 +0,0 @@
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();