slim 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@ rvm:
8
8
  env:
9
9
  - "TASK=test"
10
10
  - "TASK=test TEMPLE=master"
11
- # - "TASK=test:rails RAILS=master"
11
+ - "TASK=test:rails RAILS=master"
12
12
  - "TASK=test:rails RAILS=3.0.10"
13
13
  - "TASK=test:rails RAILS=3.1.0"
14
14
  script: "bundle exec rake test:ci"
data/CHANGES CHANGED
@@ -1,5 +1,13 @@
1
1
  master
2
2
 
3
+
4
+ 1.0.4
5
+
6
+ * Pass options to embedded Tilt engine
7
+ Slim::EmbeddedEngine.set_default_options :markdown => {...}
8
+ * Add test case for precompiled embedded engine 'builder'
9
+ * Bug #204 fixed, tabs were not parsed correctly
10
+
3
11
  1.0.3
4
12
 
5
13
  * Fix rubinius test cases
data/Gemfile CHANGED
@@ -9,8 +9,17 @@ end
9
9
  if ENV['RAILS']
10
10
  if ENV['RAILS'] == 'master'
11
11
  gem 'rails', :git => 'git://github.com/rails/rails.git'
12
+ # FIXME: Rails Gemfile is invalid!
13
+ gem 'journey', :git => 'git://github.com/rails/journey.git'
12
14
  else
13
15
  gem 'rails', "= #{ENV['RAILS']}"
14
16
  end
15
- gem 'sqlite3-ruby'
17
+
18
+ if defined?(JRUBY_VERSION)
19
+ gem 'jdbc-sqlite3'
20
+ gem 'activerecord-jdbc-adapter'
21
+ gem 'activerecord-jdbcsqlite3-adapter'
22
+ else
23
+ gem 'sqlite3-ruby'
24
+ end
16
25
  end
data/README.md CHANGED
@@ -141,7 +141,7 @@ Here's a quick example to demonstrate what a Slim template looks like:
141
141
  #### If your ruby code needs to use multiple lines, append a `\` at the end of the lines, for example:
142
142
  = javascript_include_tag \
143
143
  "jquery", \
144
- "application"`
144
+ "application"
145
145
 
146
146
  ### Wrap attributes with delimiters
147
147
 
@@ -348,12 +348,14 @@ with 'rake test' and the rails integration tests with 'rake test:rails'.
348
348
 
349
349
  Travis-CI is used for continous integration testing: http://travis-ci.org/#!/stonean/slim
350
350
 
351
- Slim is working well on the following ruby implementations:
351
+ Slim is working well on all major Ruby implementations:
352
352
 
353
353
  * Ruby 1.8.7
354
354
  * Ruby 1.9.2
355
+ * Ruby 1.9.3
355
356
  * Ruby EE
356
357
  * JRuby
358
+ * Rubinius 2.0
357
359
 
358
360
  ## License
359
361
 
@@ -19,7 +19,7 @@ module Slim
19
19
  # @param [Array] content Temple expression
20
20
  # @return [Array] Compiled temple expression
21
21
  def on_slim_condcomment(condition, content)
22
- [:multi, [:static, "<!--[#{condition}]>"], compile(content), [:static, '<![endif]-->']]
22
+ [:html, :comment, [:multi, [:static, "[#{condition}]>"], compile(content), [:static, '<![endif]']]]
23
23
  end
24
24
 
25
25
  # Handle output expression `[:slim, :output, escape, code, content]`
@@ -79,25 +79,20 @@ module Slim
79
79
  end
80
80
 
81
81
  def on_slim_embedded(name, body)
82
- new_engine(name).on_slim_embedded(name, body)
83
- end
84
-
85
- protected
86
-
87
- def new_engine(name)
88
82
  name = name.to_s
89
83
  raise "Embedded engine #{name} is disabled" if (options[:enable_engines] && !options[:enable_engines].include?(name)) ||
90
84
  (options[:disable_engines] && options[:disable_engines].include?(name))
91
85
  engine, option_filter, local_options = self.class.engines[name] || raise("Embedded engine #{name} not found")
92
86
  filtered_options = Hash[*option_filter.select {|k| options.include?(k) }.map {|k| [k, options[k]] }.flatten]
93
- engine.new(Temple::ImmutableHash.new(local_options, filtered_options))
87
+ engine.new(Temple::ImmutableHash.new(local_options, filtered_options)).on_slim_embedded(name, body)
94
88
  end
95
89
 
96
90
  # Basic tilt engine
97
- class TiltEngine < Filter
91
+ class TiltEngine < EmbeddedEngine
98
92
  def on_slim_embedded(engine, body)
99
- engine = Tilt[engine] || raise("Tilt engine #{engine} is not available.")
100
- [:multi, render(engine, collect_text(body)), CollectNewlines.new.call(body)]
93
+ tilt_engine = Tilt[engine] || raise("Tilt engine #{engine} is not available.")
94
+ tilt_options = options[engine.to_sym] || {}
95
+ [:multi, tilt_render(tilt_engine, tilt_options, collect_text(body)), CollectNewlines.new.call(body)]
101
96
  end
102
97
 
103
98
  protected
@@ -111,8 +106,8 @@ module Slim
111
106
  class StaticTiltEngine < TiltEngine
112
107
  protected
113
108
 
114
- def render(engine, text)
115
- [:static, engine.new { text }.render]
109
+ def tilt_render(tilt_engine, tilt_options, text)
110
+ [:static, tilt_engine.new(tilt_options) { text }.render]
116
111
  end
117
112
  end
118
113
 
@@ -120,8 +115,9 @@ module Slim
120
115
  class SassEngine < TiltEngine
121
116
  protected
122
117
 
123
- def render(engine, text)
124
- text = engine.new(:style => (options[:pretty] ? :expanded : :compressed), :cache => false) { text }.render
118
+ def tilt_render(tilt_engine, tilt_options, text)
119
+ text = tilt_engine.new(tilt_options.merge(
120
+ :style => (options[:pretty] ? :expanded : :compressed), :cache => false)) { text }.render
125
121
  text.chomp!
126
122
  [:static, options[:pretty] ? "\n#{text}\n" : text]
127
123
  end
@@ -131,9 +127,9 @@ module Slim
131
127
  class PrecompiledTiltEngine < TiltEngine
132
128
  protected
133
129
 
134
- def render(engine, text)
130
+ def tilt_render(tilt_engine, tilt_options, text)
135
131
  # WARNING: This is a bit of a hack. Tilt::Engine#precompiled is protected
136
- [:dynamic, engine.new { text }.send(:precompiled, {}).first]
132
+ [:dynamic, tilt_engine.new(tilt_options) { text }.send(:precompiled, {}).first]
137
133
  end
138
134
  end
139
135
 
@@ -149,13 +145,13 @@ module Slim
149
145
  @protect.call(text)
150
146
  end
151
147
 
152
- def render(engine, text)
153
- @protect.unprotect(engine.new { text }.render)
148
+ def tilt_render(tilt_engine, tilt_options, text)
149
+ @protect.unprotect(tilt_engine.new(tilt_options) { text }.render)
154
150
  end
155
151
  end
156
152
 
157
153
  # ERB engine (uses the Temple ERB implementation)
158
- class ERBEngine < Filter
154
+ class ERBEngine < EmbeddedEngine
159
155
  def on_slim_embedded(engine, body)
160
156
  Temple::ERB::Parser.new.call(CollectText.new.call(body))
161
157
  end
@@ -163,7 +159,7 @@ module Slim
163
159
 
164
160
  # Tag wrapper engine
165
161
  # Generates a html tag and wraps another engine (specified via :engine option)
166
- class TagEngine < Filter
162
+ class TagEngine < EmbeddedEngine
167
163
  def on_slim_embedded(engine, body)
168
164
  content = options[:engine] ? options[:engine].new(options).on_slim_embedded(engine, body) : body
169
165
  [:html, :tag, options[:tag], [:html, :attrs, *options[:attributes].map {|k, v| [:html, :attr, k, [:static, v]] }], content]
@@ -171,7 +167,7 @@ module Slim
171
167
  end
172
168
 
173
169
  # Embeds ruby code
174
- class RubyEngine < Filter
170
+ class RubyEngine < EmbeddedEngine
175
171
  def on_slim_embedded(engine, body)
176
172
  [:code, CollectText.new.call(body) + "\n"]
177
173
  end
@@ -254,16 +254,14 @@ module Slim
254
254
  end
255
255
 
256
256
  next_line
257
+ @line.lstrip!
257
258
 
258
259
  # The text block lines must be at least indented
259
260
  # as deep as the first line.
260
- if text_indent && indent < text_indent
261
- @line.lstrip!
262
- syntax_error!('Unexpected text indentation')
263
- end
261
+ offset = text_indent ? indent - text_indent : 0
262
+ syntax_error!('Unexpected text indentation') if offset < 0
264
263
 
265
- @line.slice!(0, text_indent || indent)
266
- @stacks.last << [:slim, :interpolate, (text_indent ? "\n" : '') + @line] << [:newline]
264
+ @stacks.last << [:slim, :interpolate, (text_indent ? "\n" : '') + (' ' * offset) + @line] << [:newline]
267
265
 
268
266
  # The indentation of first line of the text block
269
267
  # determines the text base indentation.
@@ -1,5 +1,5 @@
1
1
  module Slim
2
2
  # Slim version string
3
3
  # @api public
4
- VERSION = '1.0.3'
4
+ VERSION = '1.0.4'
5
5
  end
@@ -28,8 +28,6 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency('kramdown', ['>= 0'])
29
29
  s.add_development_dependency('yard', ['>= 0'])
30
30
  s.add_development_dependency('creole', ['>= 0'])
31
-
32
- unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
33
- s.add_development_dependency('rcov', ['>= 0'])
34
- end
31
+ s.add_development_dependency('builder', ['>= 0'])
32
+ #s.add_development_dependency('rcov', ['>= 0'])
35
33
  end
@@ -27,6 +27,12 @@ markdown:
27
27
  * two
28
28
  }
29
29
  assert_html "<h1 id=\"header\">Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
30
+
31
+ Slim::EmbeddedEngine.default_options[:markdown] = {:auto_ids => false}
32
+ assert_html "<h1>Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
33
+ Slim::EmbeddedEngine.default_options[:markdown] = nil
34
+
35
+ assert_html "<h1 id=\"header\">Header</h1>\n<p>Hello from Markdown!</p>\n\n<p>3</p>\n\n<ul>\n <li>one</li>\n <li>two</li>\n</ul>\n", source
30
36
  end
31
37
 
32
38
  def test_render_with_creole
@@ -38,6 +44,16 @@ creole:
38
44
  assert_html "<h1>head1</h1><h2>head2</h2>", source
39
45
  end
40
46
 
47
+ def test_render_with_builder
48
+ source = %q{
49
+ builder:
50
+ xml.p(:id => 'test') {
51
+ xml.text!('Hello')
52
+ }
53
+ }
54
+ assert_html "<p id=\"test\">\nHello</p>\n", source
55
+ end
56
+
41
57
  def test_render_with_wiki
42
58
  source = %q{
43
59
  wiki:
@@ -60,6 +76,12 @@ p Hi
60
76
  assert_html %{<script type="text/javascript">$(function() {});\n\n\nalert('hello')</script><p>Hi</p>}, source
61
77
  end
62
78
 
79
+ def test_render_with_javascript_with_tabs
80
+ # Keep the trailing space behind "javascript: "!
81
+ source = "javascript:\n\t$(function() {});\n\talert('hello')\np Hi"
82
+ assert_html "<script type=\"text/javascript\">$(function() {});\nalert('hello')</script><p>Hi</p>", source
83
+ end
84
+
63
85
  def test_render_with_javascript_including_variable
64
86
  # Keep the trailing space behind "javascript: "!
65
87
  source = %q{
@@ -25,6 +25,9 @@ html
25
25
  /! Javascripts
26
26
  script src="jquery.js"
27
27
  script src="jquery.ui.js"
28
+ /[if lt IE 9]
29
+ script src="old-ie1.js"
30
+ script src="old-ie2.js"
28
31
  sass:
29
32
  body
30
33
  background-color: red
@@ -49,6 +52,8 @@ html
49
52
  <!--Javascripts-->
50
53
  <script src="jquery.js"></script>
51
54
  <script src="jquery.ui.js"></script>
55
+ <!--[if lt IE 9]><script src="old-ie1.js"></script>
56
+ <script src="old-ie2.js"></script><![endif]-->
52
57
  <style type="text/css">
53
58
  body {
54
59
  background-color: red;
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.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,12 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-10-08 00:00:00.000000000 -04:00
15
- default_executable:
14
+ date: 2011-11-03 00:00:00.000000000 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: temple
19
- requirement: &2153286200 !ruby/object:Gem::Requirement
18
+ requirement: &2160332500 !ruby/object:Gem::Requirement
20
19
  none: false
21
20
  requirements:
22
21
  - - ~>
@@ -24,10 +23,10 @@ dependencies:
24
23
  version: 0.3.4
25
24
  type: :runtime
26
25
  prerelease: false
27
- version_requirements: *2153286200
26
+ version_requirements: *2160332500
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: tilt
30
- requirement: &2153285680 !ruby/object:Gem::Requirement
29
+ requirement: &2160331940 !ruby/object:Gem::Requirement
31
30
  none: false
32
31
  requirements:
33
32
  - - ~>
@@ -35,10 +34,10 @@ dependencies:
35
34
  version: 1.3.2
36
35
  type: :runtime
37
36
  prerelease: false
38
- version_requirements: *2153285680
37
+ version_requirements: *2160331940
39
38
  - !ruby/object:Gem::Dependency
40
39
  name: rake
41
- requirement: &2153285200 !ruby/object:Gem::Requirement
40
+ requirement: &2160331240 !ruby/object:Gem::Requirement
42
41
  none: false
43
42
  requirements:
44
43
  - - ! '>='
@@ -46,10 +45,10 @@ dependencies:
46
45
  version: 0.8.7
47
46
  type: :development
48
47
  prerelease: false
49
- version_requirements: *2153285200
48
+ version_requirements: *2160331240
50
49
  - !ruby/object:Gem::Dependency
51
50
  name: sass
52
- requirement: &2153284720 !ruby/object:Gem::Requirement
51
+ requirement: &2160330540 !ruby/object:Gem::Requirement
53
52
  none: false
54
53
  requirements:
55
54
  - - ! '>='
@@ -57,10 +56,10 @@ dependencies:
57
56
  version: 3.1.0
58
57
  type: :development
59
58
  prerelease: false
60
- version_requirements: *2153284720
59
+ version_requirements: *2160330540
61
60
  - !ruby/object:Gem::Dependency
62
61
  name: minitest
63
- requirement: &2153284240 !ruby/object:Gem::Requirement
62
+ requirement: &2160329940 !ruby/object:Gem::Requirement
64
63
  none: false
65
64
  requirements:
66
65
  - - ! '>='
@@ -68,10 +67,10 @@ dependencies:
68
67
  version: '0'
69
68
  type: :development
70
69
  prerelease: false
71
- version_requirements: *2153284240
70
+ version_requirements: *2160329940
72
71
  - !ruby/object:Gem::Dependency
73
72
  name: kramdown
74
- requirement: &2153283760 !ruby/object:Gem::Requirement
73
+ requirement: &2160329440 !ruby/object:Gem::Requirement
75
74
  none: false
76
75
  requirements:
77
76
  - - ! '>='
@@ -79,10 +78,10 @@ dependencies:
79
78
  version: '0'
80
79
  type: :development
81
80
  prerelease: false
82
- version_requirements: *2153283760
81
+ version_requirements: *2160329440
83
82
  - !ruby/object:Gem::Dependency
84
83
  name: yard
85
- requirement: &2153283280 !ruby/object:Gem::Requirement
84
+ requirement: &2160328920 !ruby/object:Gem::Requirement
86
85
  none: false
87
86
  requirements:
88
87
  - - ! '>='
@@ -90,10 +89,10 @@ dependencies:
90
89
  version: '0'
91
90
  type: :development
92
91
  prerelease: false
93
- version_requirements: *2153283280
92
+ version_requirements: *2160328920
94
93
  - !ruby/object:Gem::Dependency
95
94
  name: creole
96
- requirement: &2153282800 !ruby/object:Gem::Requirement
95
+ requirement: &2160328340 !ruby/object:Gem::Requirement
97
96
  none: false
98
97
  requirements:
99
98
  - - ! '>='
@@ -101,10 +100,10 @@ dependencies:
101
100
  version: '0'
102
101
  type: :development
103
102
  prerelease: false
104
- version_requirements: *2153282800
103
+ version_requirements: *2160328340
105
104
  - !ruby/object:Gem::Dependency
106
- name: rcov
107
- requirement: &2153282280 !ruby/object:Gem::Requirement
105
+ name: builder
106
+ requirement: &2160327860 !ruby/object:Gem::Requirement
108
107
  none: false
109
108
  requirements:
110
109
  - - ! '>='
@@ -112,7 +111,7 @@ dependencies:
112
111
  version: '0'
113
112
  type: :development
114
113
  prerelease: false
115
- version_requirements: *2153282280
114
+ version_requirements: *2160327860
116
115
  description: Slim is a template language whose goal is reduce the syntax to the essential
117
116
  parts without becoming cryptic.
118
117
  email:
@@ -214,7 +213,6 @@ files:
214
213
  - test/slim/test_slim_template.rb
215
214
  - test/slim/test_text_interpolation.rb
216
215
  - test/slim/test_wrapper.rb
217
- has_rdoc: true
218
216
  homepage: http://github.com/stonean/slim
219
217
  licenses: []
220
218
  post_install_message:
@@ -236,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
234
  version: '0'
237
235
  requirements: []
238
236
  rubyforge_project: slim
239
- rubygems_version: 1.6.2
237
+ rubygems_version: 1.8.10
240
238
  signing_key:
241
239
  specification_version: 3
242
240
  summary: Slim is a template language.