slim 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eeabe6b2a2349dba5997fc11b9f8308b8c059b64
4
- data.tar.gz: bf7ecd8073af2e89a0ee3cf413ac8db8bdf2392f
3
+ metadata.gz: 40ec0b5a06448c8dd50ccf5b2113fce5b14c2ce2
4
+ data.tar.gz: 9b34f912436340d0e603eeb342ac5f3cd93c188c
5
5
  SHA512:
6
- metadata.gz: e84616653fbc224fbff5e4ce111a38d38afaa75a20a70f6f7c0428e65a225ca23228a4b0bf9c26d01784b3ee919d476cd369aaffdfe602d13a2cc2c8aa04cb1e
7
- data.tar.gz: 122cfa59ce81ad34e11d67b9988768b69fa7a9cdb18bacd02a0a4d1f722631b7cfa5a22985dcde14c743fa99cb8726dda8a8a8b9d264c47066d55b8eb3fef289
6
+ metadata.gz: 5405f3254bfa3edba989203f191a8f8069fdf075ca4428ed173fbbdc40ca83061739c065e3a45c3fc765e1979015ad2969ac84eab93ba8075cf7aecf00fe4530
7
+ data.tar.gz: 66231d7ee04b5c03dae4f1497045d3345bbff266b5176f593f91f38fe83d8789fd956d93e9a3dea639d17e20dcd967ed8c661d754ad173173eaf9e880dfff287
data/.gitignore CHANGED
@@ -9,3 +9,5 @@ coverage
9
9
  pkg
10
10
  test/rails/log
11
11
  test/rails/tmp
12
+ /.ruby-gemset
13
+ /.ruby-version
data/.travis.yml CHANGED
@@ -1,12 +1,14 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.0
7
4
  - ruby-head
8
- - jruby-19mode
5
+ - 2.2.0
6
+ - 2.1.5
7
+ - 2.0.0
9
8
  - rbx-2
9
+ - 1.9.3
10
+ - jruby-head
11
+ - jruby-19mode
10
12
 
11
13
  sudo: false
12
14
 
@@ -33,7 +35,16 @@ matrix:
33
35
  exclude:
34
36
  - rvm: rbx-2
35
37
  env: "TASK=test:rails RAILS=master"
38
+ - rvm: 1.9.3
39
+ env: "TASK=test:rails RAILS=master"
40
+ - rvm: 2.0.0
41
+ env: "TASK=test:rails RAILS=master"
36
42
  allow_failures:
37
43
  - env: "TASK=test:core_and_plugins TILT=master"
38
44
  - env: "TASK=test:rails RAILS=master"
45
+ - env: "TASK=test:sinatra SINATRA=master"
39
46
  - rvm: ruby-head
47
+ - rvm: jruby-19mode
48
+ - rvm: jruby-head
49
+ - rvm: rbx-2
50
+ env: "TASK=test:rails RAILS=4.1.8"
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ 3.0.2
2
+
3
+ * slimrb: Add option --locals
4
+ * Fix issues in the test suite (#576), thanks @dmke!
5
+
1
6
  3.0.1
2
7
 
3
8
  * Allow more special characters in html attribute names (See https://html.spec.whatwg.org/multipage/syntax.html#attributes-2), #567
data/Gemfile CHANGED
@@ -8,7 +8,6 @@ end
8
8
 
9
9
  if ENV['TILT']
10
10
  if ENV['TILT'] == 'master'
11
- gem 'opal', github: 'opal/opal' if RUBY_VERSION > '1.9'
12
11
  gem 'tilt', github: 'rtomayko/tilt'
13
12
  else
14
13
  gem 'tilt', "= #{ENV['TILT']}"
@@ -16,6 +15,9 @@ if ENV['TILT']
16
15
  end
17
16
 
18
17
  if ENV['RAILS']
18
+ # we need some smarter test logic for the different Rails versions
19
+ gem 'nokogiri'
20
+
19
21
  if ENV['RAILS'] == 'master'
20
22
  gem 'rails', github: 'rails/rails'
21
23
  else
@@ -24,12 +26,21 @@ if ENV['RAILS']
24
26
  end
25
27
 
26
28
  #Choose minitest 4.7.x for sinatra or rails 3 and 4.0 otherwise go for newer version
27
- if ENV['SINATRA'] || (ENV['RAILS'] && !ENV['RAILS'].match(/4\.([1-9])(\..*)?/))
29
+ if (ENV['SINATRA'] && ENV['sinatra'] != 'master') || (ENV['RAILS'] && ENV['RAILS'].match(/^(3|4\.0)/))
28
30
  gem 'minitest', '~> 4.7.4'
29
31
  else
30
32
  gem 'minitest', '~> 5.1'
31
33
  end
32
34
 
35
+ #Ruby >= 2.2.0 has removed test/unit from Stdlib
36
+ if RUBY_VERSION >= '2.2.0'
37
+ gem 'test-unit', platforms: :mri
38
+ end
39
+
40
+ if RUBY_ENGINE == 'rbx' && !ENV.key?('TRAVIS')
41
+ gem 'psych'
42
+ end
43
+
33
44
  if ENV['SINATRA']
34
45
  gem 'rack-test'
35
46
  if ENV['SINATRA'] == 'master'
data/README.jp.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Slim
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/slim.png)](http://rubygems.org/gems/slim) [![Build Status](https://secure.travis-ci.org/slim-template/slim.png?branch=master)](http://travis-ci.org/slim-template/slim) [![Dependency Status](https://gemnasium.com/slim-template/slim.png?travis)](https://gemnasium.com/slim-template/slim) [![Code Climate](https://codeclimate.com/github/slim-template/slim.png)](https://codeclimate.com/github/slim-template/slim) [![Gittip donate button](http://img.shields.io/gittip/bevry.png)](https://www.gittip.com/min4d/ "Donate weekly to this project using Gittip")
3
+ [![Gem Version](https://img.shields.io/gem/v/slim.svg)](http://rubygems.org/gems/slim) [![Build Status](https://img.shields.io/travis/slim-template/slim.svg?branch=master)](http://travis-ci.org/slim-template/slim) [![Dependency Status](https://img.shields.io/gemnasium/slim-template/slim.svg?travis)](https://gemnasium.com/slim-template/slim) [![Code Climate](https://img.shields.io/codeclimate/github/slim-template/slim.svg)](https://codeclimate.com/github/slim-template/slim) [![Gittip donate button](https://img.shields.io/gratipay/bevry.svg)](https://www.gittip.com/min4d/ "Donate weekly to this project using Gittip")
4
4
  [![Flattr donate button](https://raw.github.com/balupton/flattr-buttons/master/badge-89x18.gif)](https://flattr.com/submit/auto?user_id=min4d&url=http%3A%2F%2Fslim-lang.org%2F "Donate monthly to this project using Flattr")
5
5
 
6
6
  Slim は 不可解にならないように view の構文を本質的な部品まで減らすことを目指したテンプレート言語です。標準的な HTML テンプレートからどれだけのものが削除できるか確かめるところから始まりました。(<, >, 閉じタグなど) 多くの人が Slim に興味を持ったことで, 機能性は発展し, 柔軟な構文をもたらしました。
@@ -1041,6 +1041,7 @@ Usage: slimrb [options]
1041
1041
  -r library Load library or plugin with -r slim/plugin
1042
1042
  -p, --pretty Produce pretty html
1043
1043
  -o, --option name=code Set slim option
1044
+ -l, --locals Hash|YAML|JSON Set local variables
1044
1045
  -h, --help Show this message
1045
1046
  -v, --version Print version
1046
1047
  </pre>
@@ -1166,6 +1167,7 @@ Slim は [MIT license](http://www.opensource.org/licenses/MIT) に基づいて
1166
1167
  フレームワークサポート:
1167
1168
 
1168
1169
  * [Rails generators (slim-rails)](https://github.com/slim-template/slim-rails)
1170
+ * [slimkeyfy - Translation string extraction](https://github.com/phrase/slimkeyfy)
1169
1171
 
1170
1172
  構文ハイライト:
1171
1173
 
data/README.md CHANGED
@@ -62,7 +62,7 @@ ___Yes, Slim is speedy!___ Slim was developed right from the start with performa
62
62
  Benchmarks are done for every commit at <http://travis-ci.org/slim-template/slim>.
63
63
  Don't trust the numbers? That's as it should be. Please try the benchmark rake task yourself!
64
64
 
65
- However in our opionion you should use Slim because of its features and syntax. We just ensure that Slim doesn't have a negative impact on the performance of your application.
65
+ However in our opinion you should use Slim because of its features and syntax. We just ensure that Slim doesn't have a negative impact on the performance of your application.
66
66
 
67
67
  ### How to start?
68
68
 
@@ -1041,6 +1041,7 @@ Usage: slimrb [options]
1041
1041
  -r library Load library or plugin with -r slim/plugin
1042
1042
  -p, --pretty Produce pretty html
1043
1043
  -o, --option name=code Set slim option
1044
+ -l, --locals Hash|YAML|JSON Set local variables
1044
1045
  -h, --help Show this message
1045
1046
  -v, --version Print version
1046
1047
  </pre>
@@ -1166,6 +1167,7 @@ Template compilation framework:
1166
1167
  Framework support:
1167
1168
 
1168
1169
  * [Rails generators (slim-rails)](https://github.com/slim-template/slim-rails)
1170
+ * [slimkeyfy - Translation string extraction](https://github.com/phrase/slimkeyfy)
1169
1171
 
1170
1172
  Syntax highlighting:
1171
1173
 
data/lib/slim/command.rb CHANGED
@@ -45,7 +45,7 @@ module Slim
45
45
  end
46
46
 
47
47
  opts.on('-r library', "Load library or plugin with -r slim/plugin") do |lib|
48
- require lib
48
+ require lib.strip
49
49
  end
50
50
 
51
51
  opts.on('-p', '--pretty', 'Produce pretty html') do
@@ -57,6 +57,23 @@ module Slim
57
57
  Engine.options[parts.first.gsub(/\A:/, '').to_sym] = eval(parts.last)
58
58
  end
59
59
 
60
+ opts.on('-l', '--locals Hash|YAML|JSON', String, 'Set local variables') do |locals|
61
+ @options[:locals] =
62
+ if locals =~ /\A\s*\{\s*\p{Word}+:/
63
+ eval(locals)
64
+ else
65
+ require 'yaml'
66
+ if RUBY_ENGINE == 'rbx'
67
+ begin
68
+ require 'psych'
69
+ rescue LoadError
70
+ $stderr.puts 'Please install psych gem as Rubunius ships with an old YAML engine.'
71
+ end
72
+ end
73
+ YAML.load(locals)
74
+ end
75
+ end
76
+
60
77
  opts.on_tail('-h', '--help', 'Show this message') do
61
78
  puts opts
62
79
  exit
@@ -82,6 +99,7 @@ module Slim
82
99
  end
83
100
  end
84
101
 
102
+ locals = @options.delete(:locals) || {}
85
103
  result =
86
104
  if @options[:erb]
87
105
  require 'slim/erb_converter'
@@ -89,7 +107,7 @@ module Slim
89
107
  elsif @options[:compile]
90
108
  Engine.new(file: @options[:file]).call(@options[:input].read)
91
109
  else
92
- Template.new(@options[:file]) { @options[:input].read }.render
110
+ Template.new(@options[:file]) { @options[:input].read }.render(nil, locals)
93
111
  end
94
112
 
95
113
  rescue Exception => ex
data/lib/slim/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Slim
2
2
  # Slim version string
3
3
  # @api public
4
- VERSION = '3.0.1'
4
+ VERSION = '3.0.2'
5
5
  end
data/test/core/helper.rb CHANGED
@@ -7,7 +7,7 @@ require 'slim/grammar'
7
7
  Slim::Engine.after Slim::Parser, Temple::Filters::Validator, grammar: Slim::Grammar
8
8
  Slim::Engine.before :Pretty, Temple::Filters::Validator
9
9
 
10
- class TestSlim < MiniTest::Unit::TestCase
10
+ class TestSlim < Minitest::Test
11
11
  def setup
12
12
  @env = Env.new
13
13
  end
@@ -0,0 +1,223 @@
1
+ require 'helper'
2
+ require 'slim/command'
3
+ require 'open3'
4
+ require 'tempfile'
5
+
6
+ class TestSlimCommands < Minitest::Test
7
+ # nothing complex
8
+ STATIC_TEMPLATE = "p Hello World!\n"
9
+
10
+ # requires a `name` variable to exist at render time
11
+ DYNAMIC_TEMPLATE = "p Hello \#{name}!\n"
12
+
13
+ # a more complex example
14
+ LONG_TEMPLATE = "h1 Hello\np\n | World!\n small Tiny text"
15
+
16
+ # exception raising example
17
+ EXCEPTION_TEMPLATE = '- raise NotImplementedError'
18
+
19
+ # Temple has this feature...
20
+ STRING_FREEZER = RUBY_VERSION >= '2.1' ? '.freeze' : ''
21
+
22
+ def test_option_help
23
+ out, err = exec_slimrb '--help'
24
+
25
+ assert err.empty?
26
+ assert_match /Show this message/, out
27
+ end
28
+
29
+ def test_option_version
30
+ out, err = exec_slimrb '--version'
31
+
32
+ assert err.empty?
33
+ assert_match /\ASlim #{Regexp.escape Slim::VERSION}$/, out
34
+ end
35
+
36
+ def test_render
37
+ prepare_common_test STATIC_TEMPLATE do |out, err|
38
+ assert err.empty?
39
+ assert_equal "<p>Hello World!</p>\n", out
40
+ end
41
+ end
42
+
43
+ # superficial test, we don't want to test Tilt/Temple
44
+ def test_compile
45
+ prepare_common_test STATIC_TEMPLATE, '--compile' do |out, err|
46
+ assert err.empty?
47
+ assert_match %r{\"<p>Hello World!<\/p>\"#{STRING_FREEZER}}, out
48
+ end
49
+ end
50
+
51
+ def test_erb
52
+ prepare_common_test DYNAMIC_TEMPLATE, '--erb' do |out, err|
53
+ assert err.empty?
54
+ assert_equal "<p>Hello <%= ::Temple::Utils.escape_html((name)) %>!</p>\n", out
55
+ end
56
+ end
57
+
58
+ def test_rails
59
+ prepare_common_test DYNAMIC_TEMPLATE, '--rails' do |out, err|
60
+ assert err.empty?
61
+
62
+ assert out.include? %Q{@output_buffer = ActiveSupport::SafeBuffer.new;}
63
+ assert out.include? %Q{@output_buffer.safe_concat(("<p>Hello "#{STRING_FREEZER}));}
64
+ assert out.include? %Q{@output_buffer.safe_concat(((::Temple::Utils.escape_html((name))).to_s));}
65
+ assert out.include? %Q{@output_buffer.safe_concat(("!</p>"#{STRING_FREEZER}));}
66
+ end
67
+ end
68
+
69
+ def test_pretty
70
+ prepare_common_test LONG_TEMPLATE, '--pretty' do |out, err|
71
+ assert err.empty?
72
+ assert_equal "<h1>\n Hello\n</h1>\n<p>\n World!<small>Tiny text</small>\n</p>\n", out
73
+ end
74
+ end
75
+
76
+ # We cannot run these two on Travis, because we can't install libyaml.
77
+ # See https://github.com/slim-template/slim/issues/576
78
+ if ENV['TRAVIS'] && RUBY_ENGINE != 'rbx'
79
+ def test_locals_json
80
+ data = '{"name":"from slim"}'
81
+ prepare_common_test DYNAMIC_TEMPLATE, '--locals', data do |out, err|
82
+ assert err.empty?
83
+ assert_equal "<p>Hello from slim!</p>\n", out
84
+ end
85
+ end
86
+
87
+ def test_locals_yaml
88
+ data = "name: from slim"
89
+ prepare_common_test DYNAMIC_TEMPLATE, '--locals', data do |out, err|
90
+ assert err.empty?
91
+ assert_equal "<p>Hello from slim!</p>\n", out
92
+ end
93
+ end
94
+ end
95
+
96
+ def test_locals_hash
97
+ data = '{name:"from slim"}'
98
+ prepare_common_test DYNAMIC_TEMPLATE, '--locals', data do |out, err|
99
+ assert err.empty?
100
+ assert_equal "<p>Hello from slim!</p>\n", out
101
+ end
102
+ end
103
+
104
+ def test_require
105
+ with_tempfile 'puts "Not in slim"', 'rb' do |lib|
106
+ prepare_common_test STATIC_TEMPLATE, '-r', lib, stdin_file: false, file_file: false do |out, err|
107
+ assert err.empty?
108
+ assert_equal "Not in slim\n<p>Hello World!</p>\n", out
109
+ end
110
+ end
111
+ end
112
+
113
+ def test_error
114
+ prepare_common_test EXCEPTION_TEMPLATE, stdin_file: false do |out, err|
115
+ assert out.empty?
116
+ assert_match /NotImplementedError: NotImplementedError/, err
117
+ assert_match /Use --trace for backtrace/, err
118
+ end
119
+ end
120
+
121
+ def test_trace_error
122
+ prepare_common_test EXCEPTION_TEMPLATE, '--trace', stdin_file: false do |out, err|
123
+ assert out.empty?
124
+ assert_match /bin\/slimrb/, err
125
+ end
126
+ end
127
+
128
+ private
129
+
130
+ # Whether you call slimrb with a file argument or pass the slim content
131
+ # via $stdin; whether you want the output written to $stdout or into
132
+ # another file given as argument, the output is the same.
133
+ #
134
+ # This method prepares a test with this exact behaviour:
135
+ #
136
+ # It yields the tupel (out, err) once after the `content` was passed
137
+ # in via $stdin and once it was passed as a (temporary) file argument.
138
+ #
139
+ # In effect, this method executes a test (given as block) 4 times:
140
+ #
141
+ # 1. read from $stdin, write to $stdout
142
+ # 2. read from file, write to $stdout
143
+ # 3. read from $stdin, write to file
144
+ # 4. read from file, write to file
145
+ def prepare_common_test(content, *args)
146
+ options = Hash === args.last ? args.pop : {}
147
+
148
+ # case 1. $stdin → $stdout
149
+ unless options[:stdin_stdout] == false
150
+ out, err = exec_slimrb *args, '--stdin' do |i|
151
+ i.write content
152
+ end
153
+ yield out, err
154
+ end
155
+
156
+ # case 2. file → $stdout
157
+ unless options[:file_stdout] == false
158
+ with_tempfile content do |in_file|
159
+ out, err = exec_slimrb *args, in_file
160
+ yield out, err
161
+ end
162
+ end
163
+
164
+ # case 3. $stdin → file
165
+ unless options[:stdin_file] == false
166
+ with_tempfile content do |out_file|
167
+ _, err = exec_slimrb *args, '--stdin', out_file do |i|
168
+ i.write content
169
+ end
170
+ yield File.read(out_file), err
171
+ end
172
+ end
173
+
174
+ # case 3. file → file
175
+ unless options[:file_file] == false
176
+ with_tempfile '' do |out_file|
177
+ with_tempfile content do |in_file|
178
+ _, err = exec_slimrb *args, in_file, out_file do |i|
179
+ i.write content
180
+ end
181
+ yield File.read(out_file), err
182
+ end
183
+ end
184
+ end
185
+ end
186
+
187
+ # Calls bin/slimrb as a subprocess.
188
+ #
189
+ # Yields $stdin to the caller and returns a tupel (out,err) with the
190
+ # contents of $stdout and $stderr.
191
+ #
192
+ # (I'd like to use Minitest::Assertions#capture_subprecess_io here,
193
+ # but then there's no way to insert data via $stdin.)
194
+ def exec_slimrb(*args)
195
+ out, err = nil, nil
196
+
197
+ Open3.popen3 'ruby', 'bin/slimrb', *args do |i,o,e,t|
198
+ yield i if block_given?
199
+ i.close
200
+ out, err = o.read, e.read
201
+ end
202
+
203
+ return out, err
204
+ end
205
+
206
+ # Creates a temporary file with the given content and yield the path
207
+ # to this file. The file itself is only available inside the block and
208
+ # will be deleted afterwards.
209
+ def with_tempfile(content=nil, extname='slim')
210
+ f = Tempfile.new ['slim', ".#{extname}"]
211
+ if content
212
+ f.write content
213
+ f.flush # ensure content is actually saved to disk
214
+ f.rewind
215
+ end
216
+
217
+ yield f.path
218
+ ensure
219
+ f.close
220
+ f.unlink
221
+ end
222
+
223
+ end
@@ -2,6 +2,7 @@ require 'helper'
2
2
 
3
3
  class TestSlimPretty < TestSlim
4
4
  def setup
5
+ super
5
6
  Slim::Engine.set_options pretty: true
6
7
  end
7
8
 
@@ -113,4 +114,53 @@ html
113
114
 
114
115
  assert_ruby_error NameError,"(__TEMPLATE__):9", source
115
116
  end
117
+
118
+ def test_unindenting
119
+ source = %q{
120
+ span before
121
+ span = " middle "
122
+ span after
123
+ }
124
+
125
+ result = %q{<span>before</span><span> middle </span><span>after</span>}
126
+
127
+ assert_html result, source
128
+
129
+ source = %q{
130
+ html
131
+ body == " <div>\n <a>link</a>\n </div>"
132
+ }
133
+
134
+ result = %q{<html>
135
+ <body>
136
+ <div>
137
+ <a>link</a>
138
+ </div>
139
+ </body>
140
+ </html>}
141
+ assert_html result, source
142
+ end
143
+
144
+ def test_helper_unindent
145
+ source = %q{
146
+ = define_macro :content
147
+ div
148
+ a link
149
+ html
150
+ body
151
+ == call_macro :content
152
+ }
153
+
154
+ result = %q{
155
+
156
+ <html>
157
+ <body>
158
+ <div>
159
+ <a>link</a>
160
+ </div>
161
+ </body>
162
+ </html>}
163
+
164
+ assert_html result, source
165
+ end
116
166
  end
@@ -3,5 +3,29 @@ ENV["RAILS_ENV"] = "test"
3
3
 
4
4
  require File.expand_path("../../config/environment.rb", __FILE__)
5
5
  require "rails/test_help"
6
+ require "nokogiri"
6
7
 
7
8
  Rails.backtrace_cleaner.remove_silencers!
9
+
10
+ class ActionDispatch::IntegrationTest
11
+
12
+ protected
13
+
14
+ def assert_xpath(xpath, message="Unable to find '#{xpath}' in response body.")
15
+ assert_response :success, "Response type is not :success (code 200..299)."
16
+
17
+ body = @response.body
18
+ assert !body.empty?, "No response body found."
19
+
20
+ doc = Nokogiri::HTML(body) rescue nil
21
+ assert_not_nil doc, "Cannot parse response body."
22
+
23
+ assert doc.xpath(xpath).size >= 1, message
24
+ end
25
+
26
+ def assert_html(expected, options = {})
27
+ expected = "<!DOCTYPE html><html><head><title>Dummy</title></head><body>#{options[:heading]}<div class=\"content\">#{expected}</div></body></html>" unless options[:skip_layout]
28
+ assert_equal expected, @response.body
29
+ end
30
+
31
+ end
@@ -2,7 +2,7 @@ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  class TestSlim < ActionDispatch::IntegrationTest
4
4
  test "normal view" do
5
- get "slim/normal"
5
+ get "/slim/normal"
6
6
  assert_response :success
7
7
  assert_template "slim/normal"
8
8
  assert_template "layouts/application"
@@ -10,7 +10,7 @@ class TestSlim < ActionDispatch::IntegrationTest
10
10
  end
11
11
 
12
12
  test "xml view" do
13
- get "slim/xml"
13
+ get "/slim/xml"
14
14
  assert_response :success
15
15
  assert_template "slim/xml"
16
16
  assert_template "layouts/application"
@@ -18,7 +18,7 @@ class TestSlim < ActionDispatch::IntegrationTest
18
18
  end
19
19
 
20
20
  test "helper" do
21
- get "slim/helper"
21
+ get "/slim/helper"
22
22
  assert_response :success
23
23
  assert_template "slim/helper"
24
24
  assert_template "layouts/application"
@@ -26,61 +26,60 @@ class TestSlim < ActionDispatch::IntegrationTest
26
26
  end
27
27
 
28
28
  test "normal erb view" do
29
- get "slim/erb"
29
+ get "/slim/erb"
30
30
  assert_html "<h1>Hello Erb!</h1>"
31
31
  end
32
32
 
33
33
  test "view without a layout" do
34
- get "slim/no_layout"
34
+ get "/slim/no_layout"
35
35
  assert_template "slim/no_layout"
36
36
  assert_html "<h1>Hello Slim without a layout!</h1>", skip_layout: true
37
37
  end
38
38
 
39
39
  test "view with variables" do
40
- get "slim/variables"
40
+ get "/slim/variables"
41
41
  assert_html "<h1>Hello Slim with variables!</h1>"
42
42
  end
43
43
 
44
44
  test "partial view" do
45
- get "slim/partial"
45
+ get "/slim/partial"
46
46
  assert_html "<h1>Hello Slim!</h1><p>With a partial!</p>"
47
47
  end
48
48
 
49
- puts 'Streaming test enabled'
50
- test "streaming" do
51
- get "slim/streaming"
52
- output = "2f\r\n<!DOCTYPE html><html><head><title>Dummy</title>\r\nd\r\n</head><body>\r\n17\r\nHeading set from a view\r\n15\r\n<div class=\"content\">\r\n53\r\n<p>Page content</p><h1><p>Hello Streaming!</p></h1><h2><p>Hello Streaming!</p></h2>\r\n14\r\n</div></body></html>\r\n0\r\n\r\n"
53
- assert_equal output, @response.body
49
+ if RUBY_ENGINE == 'jruby' && RUBY_ENGINE < '2.2.0'
50
+ puts 'Streaming test disabled for JRuby < 9000.',
51
+ 'See https://github.com/jruby/jruby/issues/1243',
52
+ 'and https://github.com/jruby/jruby/issues/1789'
53
+ else
54
+ puts 'Streaming test enabled.'
55
+ test "streaming" do
56
+ get "/slim/streaming"
57
+ output = "2f\r\n<!DOCTYPE html><html><head><title>Dummy</title>\r\nd\r\n</head><body>\r\n17\r\nHeading set from a view\r\n15\r\n<div class=\"content\">\r\n53\r\n<p>Page content</p><h1><p>Hello Streaming!</p></h1><h2><p>Hello Streaming!</p></h2>\r\n14\r\n</div></body></html>\r\n0\r\n\r\n"
58
+ assert_equal output, @response.body
59
+ end
54
60
  end
55
61
 
56
62
  test "render integers" do
57
- get "slim/integers"
63
+ get "/slim/integers"
58
64
  assert_html "<p>1337</p>"
59
65
  end
60
66
 
61
67
  test "render thread_options" do
62
- get "slim/thread_options", attr: 'role'
68
+ get "/slim/thread_options", attr: 'role'
63
69
  assert_html '<p role="empty">Test</p>'
64
- get "slim/thread_options", attr: 'id' # Overwriting doesn't work because of caching
70
+ get "/slim/thread_options", attr: 'id' # Overwriting doesn't work because of caching
65
71
  assert_html '<p role="empty">Test</p>'
66
72
  end
67
73
 
68
74
  test "content_for" do
69
- get "slim/content_for"
75
+ get "/slim/content_for"
70
76
  assert_html "<p>Page content</p><h1><p>Hello Slim!</p></h1><h2><p>Hello Slim!</p></h2>", heading: 'Heading set from a view'
71
77
  end
72
78
 
73
79
  test "form_for" do
74
- get "entries/edit/1"
80
+ get "/entries/edit/1"
75
81
  assert_match %r{action="/entries"}, @response.body
76
82
  assert_match %r{<label><b>Name</b></label>}, @response.body
77
- assert_match %r{<input id="entry_name" name="entry\[name\]"}, @response.body
78
- end
79
-
80
- protected
81
-
82
- def assert_html(expected, options = {})
83
- expected = "<!DOCTYPE html><html><head><title>Dummy</title></head><body>#{options[:heading]}<div class=\"content\">#{expected}</div></body></html>" unless options[:skip_layout]
84
- assert_equal expected, @response.body
83
+ assert_xpath '//input[@id="entry_name" and @name="entry[name]" and @type="text"]'
85
84
  end
86
85
  end
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: 3.0.1
4
+ version: 3.0.2
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: 2014-12-22 00:00:00.000000000 Z
13
+ date: 2015-02-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: temple
@@ -116,6 +116,7 @@ files:
116
116
  - test/core/test_code_evaluation.rb
117
117
  - test/core/test_code_output.rb
118
118
  - test/core/test_code_structure.rb
119
+ - test/core/test_commands.rb
119
120
  - test/core/test_embedded_engines.rb
120
121
  - test/core/test_encoding.rb
121
122
  - test/core/test_erb_converter.rb