slim 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +5 -0
- data/Gemfile +6 -3
- data/README.md +2 -1
- data/Rakefile +15 -28
- data/lib/slim/filter.rb +2 -2
- data/lib/slim/version.rb +1 -1
- data/test/core/test_html_attributes.rb +0 -25
- data/test/literate/TESTS.md +6 -31
- data/test/sinatra/contest.rb +91 -0
- data/test/sinatra/helper.rb +145 -0
- data/test/sinatra/test_core.rb +91 -0
- data/test/sinatra/test_include.rb +16 -0
- data/test/sinatra/views/embed_include_js.slim +8 -0
- data/test/sinatra/views/embed_js.slim +11 -0
- data/test/sinatra/views/footer.slim +1 -0
- data/test/sinatra/views/hello.slim +1 -0
- data/test/sinatra/views/layout2.slim +3 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69d6aa964ff22bb2b6cfc10cfbf3073e2f3c4256a47607f49500d4c54010bf60
|
4
|
+
data.tar.gz: fe1d48dd358b5e44f3f639e55284e2c81d7859d62a7feb10e51985675394ba95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1410081c98ad63fdbae03019edd862177b19ad675f0f3aa151dc2cdbbe4275ea17751b69eded1ebf0ddeed773d5f44b3325f74b5fa15f7ee67575df62a3f173d
|
7
|
+
data.tar.gz: af294f677929992cd72f76db74e99e111096379a924daf83a7c54515321bcca5ff92e45a40a50c839a88c5ab515458c87f64cd56ea3bab116a9e26804538fa0f
|
data/CHANGES
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
+
4.0.1 (2018-09-02)
|
2
|
+
|
3
|
+
* Fix incompatibility issue with Slim Include plugin and new ability to specifiy attributes for embedded engines #819
|
4
|
+
|
1
5
|
4.0.0 (2018-08-26)
|
6
|
+
|
2
7
|
* Add ability to specify attributes for embedded engines using TagEngine - #653
|
3
8
|
* Set Tilt's default encoding to utf-8 - #800
|
4
9
|
* Prevent generation of invalid Ruby code in heredoc - #770
|
data/Gemfile
CHANGED
@@ -2,6 +2,11 @@ source 'https://rubygems.org/'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
+
group :test do
|
6
|
+
gem 'sinatra'
|
7
|
+
gem 'rack-test'
|
8
|
+
end
|
9
|
+
|
5
10
|
if ENV['TRAVIS']
|
6
11
|
gem 'rails-controller-testing'
|
7
12
|
end
|
@@ -44,12 +49,10 @@ if RUBY_ENGINE == 'rbx' && !ENV['TRAVIS']
|
|
44
49
|
end
|
45
50
|
|
46
51
|
if ENV['SINATRA']
|
47
|
-
gem 'rack-test'
|
48
52
|
if ENV['SINATRA'] == 'master'
|
49
53
|
gem 'sinatra', :github => 'sinatra/sinatra'
|
50
54
|
else
|
51
|
-
|
52
|
-
gem 'sinatra', :github => 'sinatra/sinatra', :tag => "v#{ENV['SINATRA']}"
|
55
|
+
gem 'sinatra', :tag => "v#{ENV['SINATRA']}"
|
53
56
|
end
|
54
57
|
end
|
55
58
|
|
data/README.md
CHANGED
@@ -1120,7 +1120,7 @@ Usage: slimrb [options]
|
|
1120
1120
|
-e, --erb Convert to ERB
|
1121
1121
|
--rails Generate rails compatible code (Implies --compile)
|
1122
1122
|
-r, --require library Load library or plugin with -r slim/plugin
|
1123
|
-
-p, --pretty Produce pretty html
|
1123
|
+
-p, --pretty Produce pretty html for debugging purposes
|
1124
1124
|
-o, --option name=code Set slim option
|
1125
1125
|
-l, --locals Hash|YAML|JSON Set local variables
|
1126
1126
|
-h, --help Show this message
|
@@ -1266,6 +1266,7 @@ Static code analysis:
|
|
1266
1266
|
|
1267
1267
|
Template Converters (HAML, ERB, ...):
|
1268
1268
|
|
1269
|
+
* [ERB 2 Slim](http://erb2slim.com/)
|
1269
1270
|
* [Haml2Slim converter](https://github.com/slim-template/haml2slim)
|
1270
1271
|
* [ERB2Slim, HTML2Slim converter](https://github.com/slim-template/html2slim)
|
1271
1272
|
|
data/Rakefile
CHANGED
@@ -19,67 +19,54 @@ namespace 'test' do
|
|
19
19
|
Rake::TestTask.new('core') do |t|
|
20
20
|
t.libs << 'lib' << 'test/core'
|
21
21
|
t.test_files = FileList['test/core/test_*.rb']
|
22
|
-
t.
|
22
|
+
t.warning = true
|
23
23
|
#t.ruby_opts << '-w' << '-v'
|
24
24
|
end
|
25
25
|
|
26
26
|
Rake::TestTask.new('literate') do |t|
|
27
27
|
t.libs << 'lib' << 'test/literate'
|
28
28
|
t.test_files = FileList['test/literate/run.rb']
|
29
|
-
t.
|
29
|
+
t.warning = true
|
30
30
|
end
|
31
31
|
|
32
32
|
Rake::TestTask.new('logic_less') do |t|
|
33
33
|
t.libs << 'lib' << 'test/core'
|
34
34
|
t.test_files = FileList['test/logic_less/test_*.rb']
|
35
|
-
t.
|
35
|
+
t.warning = true
|
36
36
|
end
|
37
37
|
|
38
38
|
Rake::TestTask.new('translator') do |t|
|
39
39
|
t.libs << 'lib' << 'test/core'
|
40
40
|
t.test_files = FileList['test/translator/test_*.rb']
|
41
|
-
t.
|
41
|
+
t.warning = true
|
42
42
|
end
|
43
43
|
|
44
44
|
Rake::TestTask.new('smart') do |t|
|
45
45
|
t.libs << 'lib' << 'test/core'
|
46
46
|
t.test_files = FileList['test/smart/test_*.rb']
|
47
|
-
t.
|
47
|
+
t.warning = true
|
48
48
|
end
|
49
49
|
|
50
50
|
Rake::TestTask.new('include') do |t|
|
51
51
|
t.libs << 'lib' << 'test/core'
|
52
52
|
t.test_files = FileList['test/include/test_*.rb']
|
53
|
-
t.
|
53
|
+
t.warning = true
|
54
54
|
end
|
55
55
|
|
56
56
|
Rake::TestTask.new('rails') do |t|
|
57
57
|
t.libs << 'lib'
|
58
58
|
t.test_files = FileList['test/rails/test/test_*.rb']
|
59
|
-
t.
|
59
|
+
t.warning = true
|
60
60
|
end
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
code = File.read(file)
|
71
|
-
code.gsub!('attr_wrapper', 'attr_quote')
|
72
|
-
File.open(file, 'w') {|out| out.write(code) }
|
73
|
-
end
|
74
|
-
|
75
|
-
# Run Slim integration test in Sinatra
|
76
|
-
t.test_files = FileList[file]
|
77
|
-
t.verbose = true
|
78
|
-
end
|
79
|
-
rescue LoadError
|
80
|
-
task :sinatra do
|
81
|
-
abort 'Sinatra is not available'
|
82
|
-
end
|
62
|
+
Rake::TestTask.new('sinatra') do |t|
|
63
|
+
t.libs << 'lib'
|
64
|
+
t.test_files = FileList['test/sinatra/test_*.rb']
|
65
|
+
|
66
|
+
# Copied from test task in Sinatra project to mimic their approach
|
67
|
+
t.ruby_opts = ['-r rubygems'] if defined? Gem
|
68
|
+
t.ruby_opts << '-I.'
|
69
|
+
t.warning = true
|
83
70
|
end
|
84
71
|
end
|
85
72
|
|
data/lib/slim/filter.rb
CHANGED
@@ -13,8 +13,8 @@ module Slim
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# Pass-through handler
|
16
|
-
def on_slim_embedded(type, content)
|
17
|
-
[:slim, :embedded, type, compile(content)]
|
16
|
+
def on_slim_embedded(type, content, attrs)
|
17
|
+
[:slim, :embedded, type, compile(content), attrs]
|
18
18
|
end
|
19
19
|
|
20
20
|
# Pass-through handler
|
data/lib/slim/version.rb
CHANGED
@@ -265,29 +265,4 @@ p
|
|
265
265
|
}
|
266
266
|
assert_html '<p><img src="img.png" whatsthis?!="" /><img src="img.png" whatsthis?!="wtf" /></p>', source
|
267
267
|
end
|
268
|
-
|
269
|
-
def test_multiline_attribute_with_space
|
270
|
-
source = %q{
|
271
|
-
a data-title="help" data-content="extremely long help text that goes on\
|
272
|
-
and one and one and then starts over...." Link
|
273
|
-
}
|
274
|
-
assert_html '<a data-content="extremely long help text that goes on and one and one and then starts over...." data-title="help">Link</a>', source
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_multiline_attribute_without_space
|
278
|
-
source= %q{
|
279
|
-
link rel="stylesheet" type="text/css" href="https://stylesheet-cdn.com/\
|
280
|
-
this/is/a/quite/long/url/that/would/be/nice/to/split/up"
|
281
|
-
}
|
282
|
-
assert_html '<link rel="stylesheet" type="text/css" href="https://stylesheet-cdn.com/this/is/a/quite/long/url/that/would/be/nice/to/split/up" />', source
|
283
|
-
end
|
284
|
-
|
285
|
-
def test_eme
|
286
|
-
source = %q{
|
287
|
-
script#template[type="text/x-template"]
|
288
|
-
div[v-bind:class="{'some-class': boolean_var}"]
|
289
|
-
span contents
|
290
|
-
}
|
291
|
-
assert_html '<script></script>', source
|
292
|
-
end
|
293
268
|
end
|
data/test/literate/TESTS.md
CHANGED
@@ -420,18 +420,6 @@ renders as
|
|
420
420
|
49
|
421
421
|
~~~
|
422
422
|
|
423
|
-
The legacy syntax `='` is also supported.
|
424
|
-
|
425
|
-
~~~ slim
|
426
|
-
=' 7*7
|
427
|
-
~~~
|
428
|
-
|
429
|
-
renders as
|
430
|
-
|
431
|
-
~~~ html
|
432
|
-
49
|
433
|
-
~~~
|
434
|
-
|
435
423
|
The equal sign with modifier `=<` produces dynamic output with a leading white space.
|
436
424
|
|
437
425
|
~~~ slim
|
@@ -500,18 +488,6 @@ renders as
|
|
500
488
|
<script>evil();</script>
|
501
489
|
~~~
|
502
490
|
|
503
|
-
The legacy syntax `=='` is also supported.
|
504
|
-
|
505
|
-
~~~ slim
|
506
|
-
==' '<script>evil();</script>'
|
507
|
-
~~~
|
508
|
-
|
509
|
-
renders as
|
510
|
-
|
511
|
-
~~~ html
|
512
|
-
<script>evil();</script>
|
513
|
-
~~~
|
514
|
-
|
515
491
|
The option option
|
516
492
|
|
517
493
|
~~~ options
|
@@ -521,7 +497,7 @@ The option option
|
|
521
497
|
doesn't affect the output of `==`.
|
522
498
|
|
523
499
|
~~~ slim
|
524
|
-
|
500
|
+
==> '<script>evil();</script>'
|
525
501
|
~~~
|
526
502
|
|
527
503
|
renders as
|
@@ -709,27 +685,26 @@ renders as
|
|
709
685
|
|
710
686
|
### Trailing and leading whitespace
|
711
687
|
|
712
|
-
You can force a trailing whitespace behind a tag by adding `>`.
|
688
|
+
You can force a trailing whitespace behind a tag by adding `>`.
|
713
689
|
|
714
690
|
~~~ slim
|
715
691
|
a#closed> class="test" /
|
716
692
|
a#closed> class="test"/
|
717
693
|
a> href='url1' Link1
|
718
694
|
a< href='url1' Link1
|
719
|
-
a' href='url2' Link2
|
720
695
|
~~~
|
721
696
|
|
722
697
|
renders as
|
723
698
|
|
724
699
|
~~~ html
|
725
|
-
<a class="test" id="closed" /> <a class="test" id="closed" /> <a href="url1">Link1</a> <a href="url1">Link1</a
|
700
|
+
<a class="test" id="closed" /> <a class="test" id="closed" /> <a href="url1">Link1</a> <a href="url1">Link1</a>
|
726
701
|
~~~
|
727
702
|
|
728
|
-
If you combine > and
|
703
|
+
If you combine > and => only one trailing whitespace is added.
|
729
704
|
|
730
705
|
~~~ slim
|
731
|
-
a>
|
732
|
-
a
|
706
|
+
a> => 'Text1'
|
707
|
+
a => 'Text2'
|
733
708
|
a> = 'Text3'
|
734
709
|
a>= 'Text4'
|
735
710
|
a=> 'Text5'
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# Copyright (c) 2009 Damian Janowski and Michel Martens for Citrusbyte
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
require "rubygems"
|
21
|
+
require "minitest/autorun"
|
22
|
+
|
23
|
+
# Contest adds +teardown+, +test+ and +context+ as class methods, and the
|
24
|
+
# instance methods +setup+ and +teardown+ now iterate on the corresponding
|
25
|
+
# blocks. Note that all setup and teardown blocks must be defined with the
|
26
|
+
# block syntax. Adding setup or teardown instance methods defeats the purpose
|
27
|
+
# of this library.
|
28
|
+
class Minitest::Test
|
29
|
+
def self.setup(&block) setup_blocks << block end
|
30
|
+
def self.teardown(&block) teardown_blocks << block end
|
31
|
+
def self.setup_blocks() @setup_blocks ||= [] end
|
32
|
+
def self.teardown_blocks() @teardown_blocks ||= [] end
|
33
|
+
|
34
|
+
def setup_blocks(base = self.class)
|
35
|
+
setup_blocks base.superclass if base.superclass.respond_to? :setup_blocks
|
36
|
+
base.setup_blocks.each do |block|
|
37
|
+
instance_eval(&block)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def teardown_blocks(base = self.class)
|
42
|
+
teardown_blocks base.superclass if base.superclass.respond_to? :teardown_blocks
|
43
|
+
base.teardown_blocks.each do |block|
|
44
|
+
instance_eval(&block)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
alias setup setup_blocks
|
49
|
+
alias teardown teardown_blocks
|
50
|
+
|
51
|
+
def self.context(*name, &block)
|
52
|
+
subclass = Class.new(self)
|
53
|
+
remove_tests(subclass)
|
54
|
+
subclass.class_eval(&block) if block_given?
|
55
|
+
const_set(context_name(name.join(" ")), subclass)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.test(name, &block)
|
59
|
+
define_method(test_name(name), &block)
|
60
|
+
end
|
61
|
+
|
62
|
+
class << self
|
63
|
+
alias_method :should, :test
|
64
|
+
alias_method :describe, :context
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def self.context_name(name)
|
70
|
+
# "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
|
71
|
+
name = "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}"
|
72
|
+
name.tr(" ", "_").to_sym
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.test_name(name)
|
76
|
+
name = "test_#{sanitize_name(name).gsub(/\s+/,'_')}_0"
|
77
|
+
name = name.succ while method_defined? name
|
78
|
+
name.to_sym
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.sanitize_name(name)
|
82
|
+
# name.gsub(/\W+/, ' ').strip
|
83
|
+
name.gsub(/\W+/, ' ')
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.remove_tests(subclass)
|
87
|
+
subclass.public_instance_methods.grep(/^test_/).each do |meth|
|
88
|
+
subclass.send(:undef_method, meth.to_sym)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
if ENV['COVERAGE']
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter '/test/'
|
5
|
+
add_group 'sinatra-contrib', 'sinatra-contrib'
|
6
|
+
add_group 'rack-protection', 'rack-protection'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
ENV['APP_ENV'] = 'test'
|
11
|
+
Encoding.default_external = "UTF-8" if defined? Encoding
|
12
|
+
|
13
|
+
RUBY_ENGINE = 'ruby' unless defined? RUBY_ENGINE
|
14
|
+
|
15
|
+
require 'rack'
|
16
|
+
|
17
|
+
testdir = File.dirname(__FILE__)
|
18
|
+
$LOAD_PATH.unshift testdir unless $LOAD_PATH.include?(testdir)
|
19
|
+
|
20
|
+
libdir = File.dirname(File.dirname(__FILE__)) + '/lib'
|
21
|
+
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
|
22
|
+
|
23
|
+
require 'minitest'
|
24
|
+
require 'contest'
|
25
|
+
require 'rack/test'
|
26
|
+
require 'sinatra'
|
27
|
+
require 'sinatra/base'
|
28
|
+
|
29
|
+
class Sinatra::Base
|
30
|
+
include Minitest::Assertions
|
31
|
+
# Allow assertions in request context
|
32
|
+
def assertions
|
33
|
+
@assertions ||= 0
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_writer :assertions
|
37
|
+
end
|
38
|
+
|
39
|
+
class Rack::Builder
|
40
|
+
def include?(middleware)
|
41
|
+
@ins.any? { |m| middleware === m }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Sinatra::Base.set :environment, :test
|
46
|
+
|
47
|
+
class Minitest::Test
|
48
|
+
include Rack::Test::Methods
|
49
|
+
|
50
|
+
class << self
|
51
|
+
alias_method :it, :test
|
52
|
+
alias_method :section, :context
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.example(desc = nil, &block)
|
56
|
+
@example_count = 0 unless instance_variable_defined? :@example_count
|
57
|
+
@example_count += 1
|
58
|
+
it(desc || "Example #{@example_count}", &block)
|
59
|
+
end
|
60
|
+
|
61
|
+
alias_method :response, :last_response
|
62
|
+
|
63
|
+
setup do
|
64
|
+
Sinatra::Base.set :environment, :test
|
65
|
+
end
|
66
|
+
|
67
|
+
# Sets up a Sinatra::Base subclass defined with the block
|
68
|
+
# given. Used in setup or individual spec methods to establish
|
69
|
+
# the application.
|
70
|
+
def mock_app(base=Sinatra::Base, &block)
|
71
|
+
@app = Sinatra.new(base, &block)
|
72
|
+
end
|
73
|
+
|
74
|
+
def app
|
75
|
+
Rack::Lint.new(@app)
|
76
|
+
end
|
77
|
+
|
78
|
+
def slim_app(&block)
|
79
|
+
mock_app do
|
80
|
+
set :views, File.dirname(__FILE__) + '/views'
|
81
|
+
get('/', &block)
|
82
|
+
end
|
83
|
+
get '/'
|
84
|
+
end
|
85
|
+
|
86
|
+
def body
|
87
|
+
response.body.to_s
|
88
|
+
end
|
89
|
+
|
90
|
+
def assert_body(value)
|
91
|
+
if value.respond_to? :to_str
|
92
|
+
assert_equal value.lstrip.gsub(/\s*\n\s*/, ""), body.lstrip.gsub(/\s*\n\s*/, "")
|
93
|
+
else
|
94
|
+
assert_match value, body
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def assert_status(expected)
|
99
|
+
assert_equal Integer(expected), Integer(status)
|
100
|
+
end
|
101
|
+
|
102
|
+
def assert_like(a,b)
|
103
|
+
pattern = /id=['"][^"']*["']|\s+/
|
104
|
+
assert_equal a.strip.gsub(pattern, ""), b.strip.gsub(pattern, "")
|
105
|
+
end
|
106
|
+
|
107
|
+
def assert_include(str, substr)
|
108
|
+
assert str.include?(substr), "expected #{str.inspect} to include #{substr.inspect}"
|
109
|
+
end
|
110
|
+
|
111
|
+
def options(uri, params = {}, env = {}, &block)
|
112
|
+
request(uri, env.merge(:method => "OPTIONS", :params => params), &block)
|
113
|
+
end
|
114
|
+
|
115
|
+
def patch(uri, params = {}, env = {}, &block)
|
116
|
+
request(uri, env.merge(:method => "PATCH", :params => params), &block)
|
117
|
+
end
|
118
|
+
|
119
|
+
def link(uri, params = {}, env = {}, &block)
|
120
|
+
request(uri, env.merge(:method => "LINK", :params => params), &block)
|
121
|
+
end
|
122
|
+
|
123
|
+
def unlink(uri, params = {}, env = {}, &block)
|
124
|
+
request(uri, env.merge(:method => "UNLINK", :params => params), &block)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Delegate other missing methods to response.
|
128
|
+
def method_missing(name, *args, &block)
|
129
|
+
if response && response.respond_to?(name)
|
130
|
+
response.send(name, *args, &block)
|
131
|
+
else
|
132
|
+
super
|
133
|
+
end
|
134
|
+
rescue Rack::Test::Error
|
135
|
+
super
|
136
|
+
end
|
137
|
+
|
138
|
+
# Do not output warnings for the duration of the block.
|
139
|
+
def silence_warnings
|
140
|
+
$VERBOSE, v = nil, $VERBOSE
|
141
|
+
yield
|
142
|
+
ensure
|
143
|
+
$VERBOSE = v
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative 'helper.rb'
|
2
|
+
|
3
|
+
begin
|
4
|
+
class SlimTest < Minitest::Test
|
5
|
+
it 'renders inline slim strings' do
|
6
|
+
slim_app { slim "h1 Hiya\n" }
|
7
|
+
assert ok?
|
8
|
+
assert_equal "<h1>Hiya</h1>", body
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'renders .slim files in views path' do
|
12
|
+
slim_app { slim :hello }
|
13
|
+
assert ok?
|
14
|
+
assert_equal "<h1>Hello From Slim</h1>", body
|
15
|
+
end
|
16
|
+
|
17
|
+
it "renders with inline layouts" do
|
18
|
+
mock_app do
|
19
|
+
layout { %(h1\n | THIS. IS. \n == yield.upcase ) }
|
20
|
+
get('/') { slim 'em Sparta' }
|
21
|
+
end
|
22
|
+
get '/'
|
23
|
+
assert ok?
|
24
|
+
assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>", body
|
25
|
+
end
|
26
|
+
|
27
|
+
it "renders with file layouts" do
|
28
|
+
slim_app { slim('| Hello World', :layout => :layout2) }
|
29
|
+
assert ok?
|
30
|
+
assert_equal "<h1>Slim Layout!</h1><p>Hello World</p>", body
|
31
|
+
end
|
32
|
+
|
33
|
+
it "raises error if template not found" do
|
34
|
+
mock_app { get('/') { slim(:no_such_template) } }
|
35
|
+
assert_raises(Errno::ENOENT) { get('/') }
|
36
|
+
end
|
37
|
+
|
38
|
+
HTML4_DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
|
39
|
+
|
40
|
+
it "passes slim options to the slim engine" do
|
41
|
+
mock_app { get('/') { slim("x foo='bar'", :attr_quote => "'") }}
|
42
|
+
get '/'
|
43
|
+
assert ok?
|
44
|
+
assert_body "<x foo='bar'></x>"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "passes default slim options to the slim engine" do
|
48
|
+
mock_app do
|
49
|
+
set :slim, :attr_quote => "'"
|
50
|
+
get('/') { slim("x foo='bar'") }
|
51
|
+
end
|
52
|
+
get '/'
|
53
|
+
assert ok?
|
54
|
+
assert_body "<x foo='bar'></x>"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "merges the default slim options with the overrides and passes them to the slim engine" do
|
58
|
+
mock_app do
|
59
|
+
set :slim, :attr_quote => "'"
|
60
|
+
get('/') { slim("x foo='bar'") }
|
61
|
+
get('/other') { slim("x foo='bar'", :attr_quote => '"') }
|
62
|
+
end
|
63
|
+
get '/'
|
64
|
+
assert ok?
|
65
|
+
assert_body "<x foo='bar'></x>"
|
66
|
+
get '/other'
|
67
|
+
assert ok?
|
68
|
+
assert_body '<x foo="bar"></x>'
|
69
|
+
end
|
70
|
+
|
71
|
+
it "can render truly nested layouts by accepting a layout and a block with the contents" do
|
72
|
+
mock_app do
|
73
|
+
template(:main_outer_layout) { "h1 Title\n== yield" }
|
74
|
+
template(:an_inner_layout) { "h2 Subtitle\n== yield" }
|
75
|
+
template(:a_page) { "p Contents." }
|
76
|
+
get('/') do
|
77
|
+
slim :main_outer_layout, :layout => false do
|
78
|
+
slim :an_inner_layout do
|
79
|
+
slim :a_page
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
get '/'
|
85
|
+
assert ok?
|
86
|
+
assert_body "<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Contents.</p>\n"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
rescue LoadError
|
90
|
+
warn "#{$!}: skipping slim tests"
|
91
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'slim/include'
|
2
|
+
|
3
|
+
require_relative 'helper.rb'
|
4
|
+
|
5
|
+
begin
|
6
|
+
class SlimTest < Minitest::Test
|
7
|
+
it 'renders .slim files includes with js embed' do
|
8
|
+
slim_app { slim :embed_include_js }
|
9
|
+
assert ok?
|
10
|
+
assert_equal "<!DOCTYPE html><html><head><title>Slim Examples</title><script>alert('Slim supports embedded javascript!')</script></head><body><footer>Slim</footer></body></html>", body
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
warn "#{$!}: skipping slim tests"
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
footer Slim
|
@@ -0,0 +1 @@
|
|
1
|
+
h1 Hello From Slim
|
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: 4.0.
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Mendler
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-
|
13
|
+
date: 2018-09-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: temple
|
@@ -183,6 +183,15 @@ files:
|
|
183
183
|
- test/rails/script/rails
|
184
184
|
- test/rails/test/helper.rb
|
185
185
|
- test/rails/test/test_slim.rb
|
186
|
+
- test/sinatra/contest.rb
|
187
|
+
- test/sinatra/helper.rb
|
188
|
+
- test/sinatra/test_core.rb
|
189
|
+
- test/sinatra/test_include.rb
|
190
|
+
- test/sinatra/views/embed_include_js.slim
|
191
|
+
- test/sinatra/views/embed_js.slim
|
192
|
+
- test/sinatra/views/footer.slim
|
193
|
+
- test/sinatra/views/hello.slim
|
194
|
+
- test/sinatra/views/layout2.slim
|
186
195
|
- test/smart/test_smart_text.rb
|
187
196
|
- test/translator/test_translator.rb
|
188
197
|
homepage: http://slim-lang.com/
|