slim 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -1
- data/CHANGES +8 -0
- data/Gemfile +10 -1
- data/README.md +4 -2
- data/lib/slim/compiler.rb +1 -1
- data/lib/slim/embedded_engine.rb +17 -21
- data/lib/slim/parser.rb +4 -6
- data/lib/slim/version.rb +1 -1
- data/slim.gemspec +2 -4
- data/test/slim/test_embedded_engines.rb +22 -0
- data/test/slim/test_pretty.rb +5 -0
- metadata +22 -24
data/.travis.yml
CHANGED
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
|
-
|
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
|
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
|
|
data/lib/slim/compiler.rb
CHANGED
@@ -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, "
|
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]`
|
data/lib/slim/embedded_engine.rb
CHANGED
@@ -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 <
|
91
|
+
class TiltEngine < EmbeddedEngine
|
98
92
|
def on_slim_embedded(engine, body)
|
99
|
-
|
100
|
-
[
|
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
|
115
|
-
[:static,
|
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
|
124
|
-
text =
|
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
|
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,
|
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
|
153
|
-
@protect.unprotect(
|
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 <
|
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 <
|
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 <
|
170
|
+
class RubyEngine < EmbeddedEngine
|
175
171
|
def on_slim_embedded(engine, body)
|
176
172
|
[:code, CollectText.new.call(body) + "\n"]
|
177
173
|
end
|
data/lib/slim/parser.rb
CHANGED
@@ -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
|
-
|
261
|
-
|
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
|
-
@
|
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.
|
data/lib/slim/version.rb
CHANGED
data/slim.gemspec
CHANGED
@@ -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
|
-
|
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{
|
data/test/slim/test_pretty.rb
CHANGED
@@ -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.
|
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-
|
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: &
|
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: *
|
26
|
+
version_requirements: *2160332500
|
28
27
|
- !ruby/object:Gem::Dependency
|
29
28
|
name: tilt
|
30
|
-
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: *
|
37
|
+
version_requirements: *2160331940
|
39
38
|
- !ruby/object:Gem::Dependency
|
40
39
|
name: rake
|
41
|
-
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: *
|
48
|
+
version_requirements: *2160331240
|
50
49
|
- !ruby/object:Gem::Dependency
|
51
50
|
name: sass
|
52
|
-
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: *
|
59
|
+
version_requirements: *2160330540
|
61
60
|
- !ruby/object:Gem::Dependency
|
62
61
|
name: minitest
|
63
|
-
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: *
|
70
|
+
version_requirements: *2160329940
|
72
71
|
- !ruby/object:Gem::Dependency
|
73
72
|
name: kramdown
|
74
|
-
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: *
|
81
|
+
version_requirements: *2160329440
|
83
82
|
- !ruby/object:Gem::Dependency
|
84
83
|
name: yard
|
85
|
-
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: *
|
92
|
+
version_requirements: *2160328920
|
94
93
|
- !ruby/object:Gem::Dependency
|
95
94
|
name: creole
|
96
|
-
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: *
|
103
|
+
version_requirements: *2160328340
|
105
104
|
- !ruby/object:Gem::Dependency
|
106
|
-
name:
|
107
|
-
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: *
|
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.
|
237
|
+
rubygems_version: 1.8.10
|
240
238
|
signing_key:
|
241
239
|
specification_version: 3
|
242
240
|
summary: Slim is a template language.
|