slim 0.9.0 → 0.9.1.alpha.1
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/Rakefile +53 -0
- data/lib/slim/version.rb +1 -1
- data/test/helper.rb +177 -0
- data/test/integration/rails/dummy/Rakefile +7 -0
- data/test/integration/rails/dummy/app/controllers/application_controller.rb +3 -0
- data/test/integration/rails/dummy/app/controllers/parents_controller.rb +84 -0
- data/test/integration/rails/dummy/app/controllers/slim_controller.rb +25 -0
- data/test/integration/rails/dummy/app/helpers/application_helper.rb +2 -0
- data/test/integration/rails/dummy/app/models/child.rb +5 -0
- data/test/integration/rails/dummy/app/models/parent.rb +6 -0
- data/test/integration/rails/dummy/app/views/layouts/application.html.slim +10 -0
- data/test/integration/rails/dummy/app/views/parents/_form.html.slim +8 -0
- data/test/integration/rails/dummy/app/views/parents/edit.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/parents/new.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/parents/show.html.slim +5 -0
- data/test/integration/rails/dummy/app/views/slim/_partial.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/slim/content_for.html.slim +7 -0
- data/test/integration/rails/dummy/app/views/slim/erb.html.erb +1 -0
- data/test/integration/rails/dummy/app/views/slim/integers.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/slim/nil.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/slim/no_layout.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/slim/normal.html.slim +1 -0
- data/test/integration/rails/dummy/app/views/slim/partial.html.slim +2 -0
- data/test/integration/rails/dummy/app/views/slim/variables.html.slim +1 -0
- data/test/integration/rails/dummy/config/application.rb +44 -0
- data/test/integration/rails/dummy/config/boot.rb +10 -0
- data/test/integration/rails/dummy/config/database.yml +22 -0
- data/test/integration/rails/dummy/config/environment.rb +5 -0
- data/test/integration/rails/dummy/config/environments/development.rb +26 -0
- data/test/integration/rails/dummy/config/environments/production.rb +49 -0
- data/test/integration/rails/dummy/config/environments/test.rb +35 -0
- data/test/integration/rails/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/integration/rails/dummy/config/initializers/inflections.rb +10 -0
- data/test/integration/rails/dummy/config/initializers/mime_types.rb +5 -0
- data/test/integration/rails/dummy/config/initializers/secret_token.rb +7 -0
- data/test/integration/rails/dummy/config/initializers/session_store.rb +8 -0
- data/test/integration/rails/dummy/config/locales/en.yml +5 -0
- data/test/integration/rails/dummy/config/routes.rb +60 -0
- data/test/integration/rails/dummy/config.ru +4 -0
- data/test/integration/rails/dummy/db/migrate/20101220223037_parents_and_children.rb +17 -0
- data/test/integration/rails/dummy/script/rails +6 -0
- data/test/integration/rails/test_helper.rb +10 -0
- data/test/integration/rails/test_slim_rails.rb +66 -0
- data/test/slim/test_code_blocks.rb +68 -0
- data/test/slim/test_code_escaping.rb +53 -0
- data/test/slim/test_code_evaluation.rb +201 -0
- data/test/slim/test_code_output.rb +124 -0
- data/test/slim/test_code_structure.rb +95 -0
- data/test/slim/test_embedded_engines.rb +98 -0
- data/test/slim/test_html_escaping.rb +32 -0
- data/test/slim/test_html_structure.rb +307 -0
- data/test/slim/test_parser_errors.rb +107 -0
- data/test/slim/test_ruby_errors.rb +144 -0
- data/test/slim/test_sections.rb +90 -0
- data/test/slim/test_slim_template.rb +123 -0
- data/test/slim/test_text_interpolation.rb +56 -0
- data/test/slim/test_validator.rb +47 -0
- data/test/slim/test_wrapper.rb +32 -0
- metadata +68 -7
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Dummy::Application.config.secret_token = '123a9119fb14a410f485f9390286b33f2743b9d348246cf3e4434522078f77c202d7a1fb7e42666dd0844bcb10d0ff3d8b4ee087796269d4c574837948512dbf'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,60 @@
|
|
1
|
+
Dummy::Application.routes.draw do
|
2
|
+
# The priority is based upon order of creation:
|
3
|
+
# first created -> highest priority.
|
4
|
+
|
5
|
+
resources :parents
|
6
|
+
|
7
|
+
# Sample of regular route:
|
8
|
+
# match 'products/:id' => 'catalog#view'
|
9
|
+
# Keep in mind you can assign values other than :controller and :action
|
10
|
+
|
11
|
+
# Sample of named route:
|
12
|
+
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
13
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
14
|
+
|
15
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
16
|
+
# resources :products
|
17
|
+
|
18
|
+
# Sample resource route with options:
|
19
|
+
# resources :products do
|
20
|
+
# member do
|
21
|
+
# get 'short'
|
22
|
+
# post 'toggle'
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# collection do
|
26
|
+
# get 'sold'
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
|
30
|
+
# Sample resource route with sub-resources:
|
31
|
+
# resources :products do
|
32
|
+
# resources :comments, :sales
|
33
|
+
# resource :seller
|
34
|
+
# end
|
35
|
+
|
36
|
+
# Sample resource route with more complex sub-resources
|
37
|
+
# resources :products do
|
38
|
+
# resources :comments
|
39
|
+
# resources :sales do
|
40
|
+
# get 'recent', :on => :collection
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
|
44
|
+
# Sample resource route within a namespace:
|
45
|
+
# namespace :admin do
|
46
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
47
|
+
# # (app/controllers/admin/products_controller.rb)
|
48
|
+
# resources :products
|
49
|
+
# end
|
50
|
+
|
51
|
+
# You can have the root of your site routed with "root"
|
52
|
+
# just remember to delete public/index.html.
|
53
|
+
# root :to => "welcome#index"
|
54
|
+
|
55
|
+
# See how all your routes lay out with "rake routes"
|
56
|
+
|
57
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
58
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
59
|
+
match ':controller(/:action(/:id(.:format)))'
|
60
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class ParentsAndChildren < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :parents do |t|
|
4
|
+
t.string :name
|
5
|
+
end
|
6
|
+
create_table :children do |t|
|
7
|
+
t.string :name
|
8
|
+
t.integer :parent_id
|
9
|
+
end
|
10
|
+
add_index :children, :parent_id
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :children
|
15
|
+
drop_table :parents
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Configure Rails Envinronment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Run any available migration
|
10
|
+
ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class TestSlimRails < ActionController::IntegrationTest
|
4
|
+
test "normal view" do
|
5
|
+
get "slim/normal"
|
6
|
+
assert_response :success
|
7
|
+
assert_template ["slim/normal", "layouts/application"]
|
8
|
+
assert_html "<h1>Hello Slim!</h1>"
|
9
|
+
end
|
10
|
+
|
11
|
+
test "normal erb view" do
|
12
|
+
get "slim/erb"
|
13
|
+
assert_html "<h1>Hello Erb!</h1>"
|
14
|
+
end
|
15
|
+
|
16
|
+
test "view without a layout" do
|
17
|
+
get "slim/no_layout"
|
18
|
+
assert_template "slim/no_layout"
|
19
|
+
assert_html "<h1>Hello Slim without a layout!</h1>", :skip_layout => true
|
20
|
+
end
|
21
|
+
|
22
|
+
test "view with variables" do
|
23
|
+
get "slim/variables"
|
24
|
+
assert_html "<h1>Hello Slim with variables!</h1>"
|
25
|
+
end
|
26
|
+
|
27
|
+
test "partial view" do
|
28
|
+
get "slim/partial"
|
29
|
+
assert_html "<h1>Hello Slim!</h1><p>With a partial!</p>"
|
30
|
+
end
|
31
|
+
|
32
|
+
test "render integers" do
|
33
|
+
get "slim/integers"
|
34
|
+
assert_html "<p>1337</p>"
|
35
|
+
end
|
36
|
+
|
37
|
+
test "render nil" do
|
38
|
+
get "slim/nil"
|
39
|
+
assert_html "<p></p>"
|
40
|
+
end
|
41
|
+
|
42
|
+
test "content_for" do
|
43
|
+
get "slim/content_for"
|
44
|
+
assert_html "Heading set from a view<p>Page content</p><h1><p>Hello Slim!</p></h1><h2><p>Hello Slim!</p></h2>"
|
45
|
+
end
|
46
|
+
|
47
|
+
test "nested_attributes_form" do
|
48
|
+
post "parents", 'parent[name]' => "p1", 'parent[children_attributes][0][name]' => "c1"
|
49
|
+
get "parents/1/edit"
|
50
|
+
|
51
|
+
assert_html '<form accept-charset="UTF-8" action="/parents/1" class="edit_parent" enctype="multipart/form-data" id="edit_parent_1" method="post">'+
|
52
|
+
'<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="put" />'+
|
53
|
+
'</div><h1>Parent</h1><input id="parent_name" name="parent[name]" size="30" type="text" value="p1" />'+
|
54
|
+
'<h2>Children</h2>'+
|
55
|
+
'<ul><li><input id="parent_children_attributes_0_name" name="parent[children_attributes][0][name]" size="30" type="text" value="c1" /></li>'+
|
56
|
+
'<input id="parent_children_attributes_0_id" name="parent[children_attributes][0][id]" type="hidden" value="1" /></ul>'+
|
57
|
+
'<input id="parent_submit" name="commit" type="submit" value="Update Parent" /></form>'
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
|
62
|
+
def assert_html(expected, options = {})
|
63
|
+
expected = "<!DOCTYPE html><html><head><title>Dummy</title></head><body>#{expected}</body></html>" unless options[:skip_layout]
|
64
|
+
assert_equal expected, @response.body
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimCodeBlocks < TestSlim
|
4
|
+
def test_render_with_output_code_block
|
5
|
+
source = %q{
|
6
|
+
p
|
7
|
+
= hello_world "Hello Ruby!" do
|
8
|
+
| Hello from within a block!
|
9
|
+
}
|
10
|
+
|
11
|
+
assert_html '<p>Hello Ruby! Hello from within a block! Hello Ruby!</p>', source
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_render_with_output_code_within_block
|
15
|
+
source = %q{
|
16
|
+
p
|
17
|
+
= hello_world "Hello Ruby!" do
|
18
|
+
= hello_world "Hello from within a block!"
|
19
|
+
}
|
20
|
+
|
21
|
+
assert_html '<p>Hello Ruby! Hello from within a block! Hello Ruby!</p>', source
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_render_with_output_code_within_block_2
|
25
|
+
source = %q{
|
26
|
+
p
|
27
|
+
= hello_world "Hello Ruby!" do
|
28
|
+
= hello_world "Hello from within a block!" do
|
29
|
+
= hello_world "And another one!"
|
30
|
+
}
|
31
|
+
|
32
|
+
assert_html '<p>Hello Ruby! Hello from within a block! And another one! Hello from within a block! Hello Ruby!</p>', source
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_output_block_with_arguments
|
36
|
+
source = %q{
|
37
|
+
p
|
38
|
+
= define_macro :person do |first_name, last_name|
|
39
|
+
.first_name = first_name
|
40
|
+
.last_name = last_name
|
41
|
+
== call_macro :person, 'John', 'Doe'
|
42
|
+
== call_macro :person, 'Max', 'Mustermann'
|
43
|
+
}
|
44
|
+
|
45
|
+
assert_html '<p><div class="first_name">John</div><div class="last_name">Doe</div><div class="first_name">Max</div><div class="last_name">Mustermann</div></p>', source
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def test_render_with_control_code_loop
|
50
|
+
source = %q{
|
51
|
+
p
|
52
|
+
- 3.times do
|
53
|
+
| Hey!
|
54
|
+
}
|
55
|
+
|
56
|
+
assert_html '<p>Hey!Hey!Hey!</p>', source
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_captured_code_block_with_conditional
|
60
|
+
source = %q{
|
61
|
+
= hello_world "Hello Ruby!" do
|
62
|
+
- if true
|
63
|
+
| Hello from within a block!
|
64
|
+
}
|
65
|
+
|
66
|
+
assert_html 'Hello Ruby! Hello from within a block! Hello Ruby!', source
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimCodeEscaping < TestSlim
|
4
|
+
def test_escaping_evil_method
|
5
|
+
source = %q{
|
6
|
+
p = evil_method
|
7
|
+
}
|
8
|
+
|
9
|
+
assert_html '<p><script>do_something_evil();</script></p>', source
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_render_without_html_safe
|
13
|
+
source = %q{
|
14
|
+
p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>."
|
15
|
+
}
|
16
|
+
|
17
|
+
assert_html "<p><strong>Hello World\n, meet \"Slim\"</strong>.</p>", source
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_render_with_html_safe_false
|
21
|
+
source = %q{
|
22
|
+
p = HtmlUnsafeString.new("<strong>Hello World\\n, meet \\"Slim\\"</strong>.")
|
23
|
+
}
|
24
|
+
|
25
|
+
assert_html "<p><strong>Hello World\n, meet \"Slim\"</strong>.</p>", source, :use_html_safe => true
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_render_with_html_safe_true
|
29
|
+
source = %q{
|
30
|
+
p = HtmlSafeString.new("<strong>Hello World\\n, meet \\"Slim\\"</strong>.")
|
31
|
+
}
|
32
|
+
|
33
|
+
assert_html "<p><strong>Hello World\n, meet \"Slim\"</strong>.</p>", source, :use_html_safe => true
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_render_with_auto_escape_true
|
37
|
+
source = %q{
|
38
|
+
= "<p>Hello</p>"
|
39
|
+
== "<p>World</p>"
|
40
|
+
}
|
41
|
+
|
42
|
+
assert_html "<p>Hello</p><p>World</p>", source
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_render_with_auto_escape_false
|
46
|
+
source = %q{
|
47
|
+
= "<p>Hello</p>"
|
48
|
+
== "<p>World</p>"
|
49
|
+
}
|
50
|
+
|
51
|
+
assert_html "<p>Hello</p><p>World</p>", source, :auto_escape => false
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimCodeEvaluation < TestSlim
|
4
|
+
def test_render_with_call_to_set_attributes
|
5
|
+
source = %q{
|
6
|
+
p id="#{id_helper}" class="hello world" = hello_world
|
7
|
+
}
|
8
|
+
|
9
|
+
assert_html '<p class="hello world" id="notice">Hello World from @env</p>', source
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_render_with_call_to_set_custom_attributes
|
13
|
+
source = %q{
|
14
|
+
p data-id="#{id_helper}" data-class="hello world"
|
15
|
+
= hello_world
|
16
|
+
}
|
17
|
+
|
18
|
+
assert_html '<p data-class="hello world" data-id="notice">Hello World from @env</p>', source
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_render_with_call_to_set_attributes_and_call_to_set_content
|
22
|
+
source = %q{
|
23
|
+
p id="#{id_helper}" class="hello world" = hello_world
|
24
|
+
}
|
25
|
+
|
26
|
+
assert_html '<p class="hello world" id="notice">Hello World from @env</p>', source
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_render_with_parameterized_call_to_set_attributes_and_call_to_set_content
|
30
|
+
source = %q{
|
31
|
+
p id="#{id_helper}" class="hello world" = hello_world("Hello Ruby!")
|
32
|
+
}
|
33
|
+
|
34
|
+
assert_html '<p class="hello world" id="notice">Hello Ruby!</p>', source
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_render_with_spaced_parameterized_call_to_set_attributes_and_call_to_set_content
|
38
|
+
source = %q{
|
39
|
+
p id="#{id_helper}" class="hello world" = hello_world "Hello Ruby!"
|
40
|
+
}
|
41
|
+
|
42
|
+
assert_html '<p class="hello world" id="notice">Hello Ruby!</p>', source
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_render_with_spaced_parameterized_call_to_set_attributes_and_call_to_set_content_2
|
46
|
+
source = %q{
|
47
|
+
p id="#{id_helper}" class="hello world" = hello_world "Hello Ruby!", :dummy => "value"
|
48
|
+
}
|
49
|
+
|
50
|
+
assert_html '<p class="hello world" id="notice">Hello Ruby!dummy value</p>', source
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_hash_call_in_attribute
|
54
|
+
source = %q{
|
55
|
+
p id="#{hash[:a]}" Test it
|
56
|
+
}
|
57
|
+
|
58
|
+
assert_html '<p id="The letter a">Test it</p>', source
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_instance_variable_in_attribute_without_quotes
|
62
|
+
source = %q{
|
63
|
+
p id=@var
|
64
|
+
}
|
65
|
+
|
66
|
+
assert_html '<p id="instance"></p>', source
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_method_call_in_attribute_without_quotes
|
70
|
+
source = %q{
|
71
|
+
form action=action_path(:page, :save) method='post'
|
72
|
+
}
|
73
|
+
|
74
|
+
assert_html '<form action="/action-page-save" method="post"></form>', source
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_method_call_in_delimited_attribute_without_quotes
|
78
|
+
source = %q{
|
79
|
+
form(action=action_path(:page, :save) method='post')
|
80
|
+
}
|
81
|
+
|
82
|
+
assert_html '<form action="/action-page-save" method="post"></form>', source
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_method_call_in_delimited_attribute_without_quotes2
|
86
|
+
source = %q{
|
87
|
+
form(method='post' action=action_path(:page, :save))
|
88
|
+
}
|
89
|
+
|
90
|
+
assert_html '<form action="/action-page-save" method="post"></form>', source
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_hash_call_in_attribute_without_quotes
|
94
|
+
source = %q{
|
95
|
+
p id=hash[:a] Test it
|
96
|
+
}
|
97
|
+
|
98
|
+
assert_html '<p id="The letter a">Test it</p>', source
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_hash_call_in_delimited_attribute
|
102
|
+
source = %q{
|
103
|
+
p(id=hash[:a]) Test it
|
104
|
+
}
|
105
|
+
|
106
|
+
assert_html '<p id="The letter a">Test it</p>', source
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_hash_call_in_attribute_with_ruby_evaluation
|
110
|
+
source = %q{
|
111
|
+
p id={hash[:a] + hash[:a]} Test it
|
112
|
+
}
|
113
|
+
|
114
|
+
assert_html '<p id="The letter aThe letter a">Test it</p>', source
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_hash_call_in_delimited_attribute_with_ruby_evaluation
|
118
|
+
source = %q{
|
119
|
+
p(id=(hash[:a] + hash[:a])) Test it
|
120
|
+
}
|
121
|
+
|
122
|
+
assert_html '<p id="The letter aThe letter a">Test it</p>', source
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_hash_call_in_delimited_attribute_with_ruby_evaluation_2
|
126
|
+
source = %q{
|
127
|
+
p[id=(hash[:a] + hash[:a])] Test it
|
128
|
+
}
|
129
|
+
|
130
|
+
assert_html '<p id="The letter aThe letter a">Test it</p>', source
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_hash_call_in_delimited_attribute_with_ruby_evaluation_3
|
134
|
+
source = %q{
|
135
|
+
p(id=[hash[:a] + hash[:a]]) Test it
|
136
|
+
}
|
137
|
+
|
138
|
+
assert_html '<p id="The letter aThe letter a">Test it</p>', source
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_hash_call_in_delimited_attribute_with_ruby_evaluation_4
|
142
|
+
source = %q{
|
143
|
+
p(id=[hash[:a] + hash[:a]] class=[hash[:a]]) Test it
|
144
|
+
}
|
145
|
+
|
146
|
+
assert_html '<p class="The letter a" id="The letter aThe letter a">Test it</p>', source
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_hash_call_in_delimited_attribute_with_ruby_evaluation_5
|
150
|
+
source = %q{
|
151
|
+
p(id=hash[:a] class=[hash[:a]]) Test it
|
152
|
+
}
|
153
|
+
|
154
|
+
assert_html '<p class="The letter a" id="The letter a">Test it</p>', source
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_computation_in_attribute
|
158
|
+
source = %q{
|
159
|
+
p id=(1 + 1)*5 Test it
|
160
|
+
}
|
161
|
+
|
162
|
+
assert_html '<p id="10">Test it</p>', source
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_number_type_interpolation
|
166
|
+
source = %q{
|
167
|
+
p = output_number
|
168
|
+
}
|
169
|
+
|
170
|
+
assert_html '<p>1337</p>', source
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_ternary_operation_in_attribute
|
174
|
+
source = %q{
|
175
|
+
p id="#{(false ? 'notshown' : 'shown')}" = output_number
|
176
|
+
}
|
177
|
+
|
178
|
+
assert_html '<p id="shown">1337</p>', source
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_class_attribute_merging
|
182
|
+
source = %{
|
183
|
+
.alpha class="beta" Test it
|
184
|
+
}
|
185
|
+
assert_html '<div class="alpha beta">Test it</div>', source
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_id_attribute_merging
|
189
|
+
source = %{
|
190
|
+
#alpha id="beta" Test it
|
191
|
+
}
|
192
|
+
assert_html '<div id="alpha_beta">Test it</div>', source, :id_delimiter => '_'
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_id_attribute_merging2
|
196
|
+
source = %{
|
197
|
+
#alpha id="beta" Test it
|
198
|
+
}
|
199
|
+
assert_html '<div id="alpha-beta">Test it</div>', source, :id_delimiter => '-'
|
200
|
+
end
|
201
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSlimCodeOutput < TestSlim
|
4
|
+
def test_render_with_call
|
5
|
+
source = %q{
|
6
|
+
p
|
7
|
+
= hello_world
|
8
|
+
}
|
9
|
+
|
10
|
+
assert_html '<p>Hello World from @env</p>', source #, :debug => true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_render_with_conditional_call
|
14
|
+
source = %q{
|
15
|
+
p
|
16
|
+
= hello_world if true
|
17
|
+
}
|
18
|
+
|
19
|
+
assert_html '<p>Hello World from @env</p>', source
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_render_with_parameterized_call
|
23
|
+
source = %q{
|
24
|
+
p
|
25
|
+
= hello_world("Hello Ruby!")
|
26
|
+
}
|
27
|
+
|
28
|
+
assert_html '<p>Hello Ruby!</p>', source
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_render_with_spaced_parameterized_call
|
32
|
+
source = %q{
|
33
|
+
p
|
34
|
+
= hello_world "Hello Ruby!"
|
35
|
+
}
|
36
|
+
|
37
|
+
assert_html '<p>Hello Ruby!</p>', source
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_render_with_spaced_parameterized_call_2
|
41
|
+
source = %q{
|
42
|
+
p
|
43
|
+
= hello_world "Hello Ruby!", :dummy => "value"
|
44
|
+
}
|
45
|
+
|
46
|
+
assert_html '<p>Hello Ruby!dummy value</p>', source
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_render_with_call_and_inline_text
|
50
|
+
source = %q{
|
51
|
+
h1 This is my title
|
52
|
+
p
|
53
|
+
= hello_world
|
54
|
+
}
|
55
|
+
|
56
|
+
assert_html '<h1>This is my title</h1><p>Hello World from @env</p>', source
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_render_with_attribute_starts_with_keyword
|
60
|
+
source = %q{
|
61
|
+
p = hello_world in_keyword
|
62
|
+
}
|
63
|
+
|
64
|
+
assert_html '<p>starts with keyword</p>', source
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_hash_call
|
68
|
+
source = %q{
|
69
|
+
p = hash[:a]
|
70
|
+
}
|
71
|
+
|
72
|
+
assert_html '<p>The letter a</p>', source
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_tag_output_without_space
|
76
|
+
source = %q{
|
77
|
+
p= hello_world
|
78
|
+
p=hello_world
|
79
|
+
}
|
80
|
+
|
81
|
+
assert_html '<p>Hello World from @env</p><p>Hello World from @env</p>', source
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_class_output_without_space
|
85
|
+
source = %q{
|
86
|
+
.test=hello_world
|
87
|
+
#test==hello_world
|
88
|
+
}
|
89
|
+
|
90
|
+
assert_html '<div class="test">Hello World from @env</div><div id="test">Hello World from @env</div>', source
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_attribute_output_without_space
|
94
|
+
source = %q{
|
95
|
+
p id="test"=hello_world
|
96
|
+
p(id="test")==hello_world
|
97
|
+
}
|
98
|
+
|
99
|
+
assert_html '<p id="test">Hello World from @env</p><p id="test">Hello World from @env</p>', source
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_render_with_backslash_end
|
103
|
+
source = %q{
|
104
|
+
p = \
|
105
|
+
"Hello" + \
|
106
|
+
" Ruby!"
|
107
|
+
- variable = 1 + \
|
108
|
+
2 + \
|
109
|
+
3
|
110
|
+
= variable + \
|
111
|
+
1
|
112
|
+
}
|
113
|
+
|
114
|
+
assert_html '<p>Hello Ruby!</p>7', source
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_render_with_no_trailing_character
|
118
|
+
source = %q{
|
119
|
+
p
|
120
|
+
= hello_world}
|
121
|
+
|
122
|
+
assert_html '<p>Hello World from @env</p>', source
|
123
|
+
end
|
124
|
+
end
|