curtain 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/README.md +311 -17
- data/TODO.md +7 -0
- data/curtain.gemspec +2 -3
- data/erubs_example.rb +103 -0
- data/example.erb +4 -0
- data/example.slim +2 -0
- data/lib/curtain/caching.rb +9 -0
- data/lib/curtain/erubis.rb +33 -0
- data/lib/curtain/erubis_template.rb +23 -0
- data/lib/curtain/form_builder.rb +218 -0
- data/lib/curtain/form_helpers.rb +23 -0
- data/lib/curtain/html_helpers.rb +180 -0
- data/lib/curtain/output_buffer.rb +10 -0
- data/lib/curtain/rendering.rb +9 -30
- data/lib/curtain/templating.rb +5 -1
- data/lib/curtain/version.rb +1 -1
- data/lib/curtain.rb +18 -1
- data/test/basic_test.rb +66 -0
- data/test/cache_test.rb +17 -0
- data/test/examples/{body.erb → basic/erb/body.erb} +0 -0
- data/test/examples/basic/erb/index.erb +1 -0
- data/test/examples/basic/erb/layout.erb +3 -0
- data/test/examples/{subdir → basic/erb/subdir}/index.erb +0 -0
- data/test/examples/{test.erb → basic/erb/test.erb} +0 -0
- data/test/examples/basic/slim/body.slim +5 -0
- data/test/examples/basic/slim/index.slim +1 -0
- data/test/examples/basic/slim/layout.slim +2 -0
- data/test/examples/basic/slim/subdir/index.slim +1 -0
- data/test/examples/basic/slim/test.slim +3 -0
- data/test/examples/cache/erb/cache.erb +3 -0
- data/test/examples/cache/slim/cache.slim +2 -0
- data/test/examples/form/Rakefile +56 -0
- data/test/examples/form/account.html +101 -0
- data/test/examples/form/account.rb +11 -0
- data/test/examples/form/account.yml +11 -0
- data/test/examples/form/account_view.rb +3 -0
- data/test/examples/form/account_with_data.html +100 -0
- data/test/examples/form/erb/account.erb +84 -0
- data/test/examples/form/erb/account_with_fields.erb +0 -0
- data/test/examples/form/erb/bootstrap.erb +15 -0
- data/test/examples/form/slim/account.slim +65 -0
- data/test/examples/form/slim/bootstrap.slim +11 -0
- data/test/examples/html/erb/content_tag.erb +1 -0
- data/test/examples/html/erb/content_tag_with_content.erb +1 -0
- data/test/examples/html/erb/content_tag_with_content_and_attributes.erb +1 -0
- data/test/examples/html/erb/content_tag_with_content_block_and_attributes.erb +3 -0
- data/test/examples/html/erb/content_tag_with_content_block_with_nested_tags.erb +3 -0
- data/test/examples/html/erb/empty_content_tag.erb +1 -0
- data/test/examples/html/erb/void_tag.erb +1 -0
- data/test/examples/html/erb/void_tag_with_attributes.erb +1 -0
- data/test/examples/html/slim/content_tag.slim +1 -0
- data/test/examples/html/slim/content_tag_with_content.slim +1 -0
- data/test/examples/html/slim/content_tag_with_content_and_attributes.slim +1 -0
- data/test/examples/html/slim/content_tag_with_content_block_and_attributes.slim +2 -0
- data/test/examples/html/slim/content_tag_with_content_block_with_nested_tags.slim +2 -0
- data/test/examples/html/slim/empty_content_tag.slim +1 -0
- data/test/examples/html/slim/void_tag.slim +1 -0
- data/test/examples/html/slim/void_tag_with_attributes.slim +1 -0
- data/test/form_test.rb +44 -0
- data/test/html_test.rb +32 -0
- data/test/test_helper.rb +31 -2
- metadata +101 -34
- data/test/curtain_test.rb +0 -119
- data/test/examples/index.erb +0 -1
- data/test/examples/layout.erb +0 -1
- data/test/examples/registration.mustache +0 -48
- data/test/examples/simple.erb +0 -1
@@ -0,0 +1,56 @@
|
|
1
|
+
$root = File.expand_path("../../../..", __FILE__)
|
2
|
+
puts $root
|
3
|
+
$:.unshift(File.expand_path("lib", $root))
|
4
|
+
require 'curtain'
|
5
|
+
require 'curtain/erubis'
|
6
|
+
require_relative 'account'
|
7
|
+
require_relative 'account_view'
|
8
|
+
require 'yaml'
|
9
|
+
require 'glam'
|
10
|
+
|
11
|
+
def write_file(file, contents)
|
12
|
+
out_file = File.join(Dir.pwd, file)
|
13
|
+
out_dir = File.dirname(out_file)
|
14
|
+
unless Dir.exists?(out_dir)
|
15
|
+
mkdir_p out_dir
|
16
|
+
end
|
17
|
+
puts out_file
|
18
|
+
open(out_file, 'w') {|f| f << Glam(contents) }
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Build account page using ERB and no data"
|
22
|
+
task :erb do
|
23
|
+
AccountView.template_directories = File.join(File.dirname(__FILE__), 'erb')
|
24
|
+
view = AccountView.new
|
25
|
+
write_file 'account.html', view.render("bootstrap", main: "account")
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Build the account page using ERB with data"
|
29
|
+
task :erb_with_data do
|
30
|
+
AccountView.template_directories = File.join(File.dirname(__FILE__), 'erb')
|
31
|
+
view = AccountView.new
|
32
|
+
view.account = Account.new(YAML.load_file(File.expand_path('account.yml')))
|
33
|
+
write_file 'account_with_data.html', view.render("bootstrap", main: "account")
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Watch this directory for changes and run the default task when there are some"
|
37
|
+
task :watch do
|
38
|
+
begin
|
39
|
+
require 'listen'
|
40
|
+
rescue LoadError
|
41
|
+
puts "You must install the listen gem in order to use this task"
|
42
|
+
exit 1
|
43
|
+
end
|
44
|
+
|
45
|
+
listener = Listen.to(File.join($root, 'lib'), File.join($root, 'test')) do |directories|
|
46
|
+
puts "Detected change in #{directories.inspect}"
|
47
|
+
system 'rake'
|
48
|
+
end
|
49
|
+
puts "Watching for changes..."
|
50
|
+
listener.start
|
51
|
+
trap("SIGINT") { exit! }
|
52
|
+
sleep
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "Build all examples"
|
56
|
+
task :default => [:erb, :erb_with_data]
|
@@ -0,0 +1,101 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Account</title>
|
5
|
+
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7
|
+
|
8
|
+
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<div class="container">
|
12
|
+
<h1>Account</h1>
|
13
|
+
<form role="form">
|
14
|
+
<div class="form-group">
|
15
|
+
<label for="email" class="control-label">Email</label>
|
16
|
+
|
17
|
+
<input name="email" type="email" class="form-control" id="email">
|
18
|
+
</div>
|
19
|
+
<div class="form-group">
|
20
|
+
<label for="password" class="control-label">Password</label>
|
21
|
+
|
22
|
+
<input name="password" type="password" class="form-control" id="password">
|
23
|
+
</div>
|
24
|
+
<div class="form-group">
|
25
|
+
<label for="first_name" class="control-label">First Name</label>
|
26
|
+
|
27
|
+
<input name="first_name" type="text" class="form-control" id="first_name">
|
28
|
+
</div>
|
29
|
+
<div class="form-group">
|
30
|
+
<label for="last_name" class="control-label">Last Name</label>
|
31
|
+
|
32
|
+
<input name="last_name" type="text" class="form-control" id="last_name">
|
33
|
+
</div>
|
34
|
+
<div class="form-group">
|
35
|
+
<label for="website" class="control-label">Website</label>
|
36
|
+
|
37
|
+
<input name="website" type="url" class="form-control" id="website">
|
38
|
+
</div>
|
39
|
+
<div class="form-group">
|
40
|
+
<label for="phone" class="control-label">Phone</label>
|
41
|
+
|
42
|
+
<input name="phone" type="tel" class="form-control" id="phone">
|
43
|
+
</div>
|
44
|
+
<div class="form-group">
|
45
|
+
<label class="control-label">Gender</label>
|
46
|
+
<div>
|
47
|
+
<label class="radio-inline">
|
48
|
+
|
49
|
+
<input name="radio" type="radio" value="m" id="radio">
|
50
|
+
Male
|
51
|
+
</label>
|
52
|
+
<label class="radio-inline">
|
53
|
+
|
54
|
+
<input name="radio" type="radio" value="f" id="radio">
|
55
|
+
Female
|
56
|
+
</label>
|
57
|
+
</div>
|
58
|
+
</div>
|
59
|
+
<div class="form-group">
|
60
|
+
<label for="photo" class="control-label">Photo</label>
|
61
|
+
|
62
|
+
<input name="photo" type="file" class="form-control" id="photo">
|
63
|
+
</div>
|
64
|
+
<div class="form-group">
|
65
|
+
<label for="favorite_color" class="control-label">Favorite Color</label>
|
66
|
+
|
67
|
+
<input name="favorite_color" type="color" class="form-control" id="favorite_color">
|
68
|
+
</div>
|
69
|
+
<div class="form-group">
|
70
|
+
<label for="language">Language</label>
|
71
|
+
<select name="language" class="form-control" id="language">
|
72
|
+
<option value="en">English</option>
|
73
|
+
<option value="es">Spanish</option>
|
74
|
+
</select>
|
75
|
+
</div>
|
76
|
+
<div class="form-group">
|
77
|
+
<label for="date_of_birth">Date Of Birth</label>
|
78
|
+
|
79
|
+
<input name="date_of_birth" type="date" class="form-control" id="date_of_birth">
|
80
|
+
</div>
|
81
|
+
<div class="form-group">
|
82
|
+
<label for="bio">Bio</label>
|
83
|
+
<textarea class="form-control">
|
84
|
+
</textarea>
|
85
|
+
</div>
|
86
|
+
<div class="form-group">
|
87
|
+
<label>
|
88
|
+
|
89
|
+
<input name="checkbox" type="checkbox" value="true" id="checkbox">
|
90
|
+
Send Me Monthly Updates
|
91
|
+
</label>
|
92
|
+
</div>
|
93
|
+
<button type="submit" class="btn btn-default">Save</button>
|
94
|
+
</form>
|
95
|
+
</div>
|
96
|
+
<script src="http://code.jquery.com/jquery.js">
|
97
|
+
</script>
|
98
|
+
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js">
|
99
|
+
</script>
|
100
|
+
</body>
|
101
|
+
</html>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Account
|
2
|
+
attr_accessor :email, :password, :first_name, :last_name, :website, :phone, :photo, :gender, :favorite_color, :language, :date_of_birth, :bio, :notifications
|
3
|
+
|
4
|
+
def initialize(attrs={})
|
5
|
+
if attrs
|
6
|
+
attrs.each do |attr, value|
|
7
|
+
send("#{attr}=", value)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
email: mail@paulbarry.com
|
2
|
+
password: secret
|
3
|
+
first_name: Paul
|
4
|
+
last_name: Barry
|
5
|
+
website: http://paulbarry.com
|
6
|
+
phone: 555-123-4567
|
7
|
+
gender: m
|
8
|
+
favorite_color: "#00cc00"
|
9
|
+
date_of_birth: '1970-01-01'
|
10
|
+
bio: This is my bio & it needs to be HTML escaped
|
11
|
+
notifications: true
|
@@ -0,0 +1,100 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Account</title>
|
5
|
+
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7
|
+
|
8
|
+
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<div class="container">
|
12
|
+
<h1>Account</h1>
|
13
|
+
<form role="form">
|
14
|
+
<div class="form-group">
|
15
|
+
<label for="email" class="control-label">Email</label>
|
16
|
+
|
17
|
+
<input name="email" value="mail@paulbarry.com" type="email" class="form-control" id="email">
|
18
|
+
</div>
|
19
|
+
<div class="form-group">
|
20
|
+
<label for="password" class="control-label">Password</label>
|
21
|
+
|
22
|
+
<input name="password" type="password" class="form-control" id="password">
|
23
|
+
</div>
|
24
|
+
<div class="form-group">
|
25
|
+
<label for="first_name" class="control-label">First Name</label>
|
26
|
+
|
27
|
+
<input name="first_name" value="Paul" type="text" class="form-control" id="first_name">
|
28
|
+
</div>
|
29
|
+
<div class="form-group">
|
30
|
+
<label for="last_name" class="control-label">Last Name</label>
|
31
|
+
|
32
|
+
<input name="last_name" value="Barry" type="text" class="form-control" id="last_name">
|
33
|
+
</div>
|
34
|
+
<div class="form-group">
|
35
|
+
<label for="website" class="control-label">Website</label>
|
36
|
+
|
37
|
+
<input name="website" value="http://paulbarry.com" type="url" class="form-control" id="website">
|
38
|
+
</div>
|
39
|
+
<div class="form-group">
|
40
|
+
<label for="phone" class="control-label">Phone</label>
|
41
|
+
|
42
|
+
<input name="phone" value="555-123-4567" type="tel" class="form-control" id="phone">
|
43
|
+
</div>
|
44
|
+
<div class="form-group">
|
45
|
+
<label class="control-label">Gender</label>
|
46
|
+
<div>
|
47
|
+
<label class="radio-inline">
|
48
|
+
|
49
|
+
<input name="radio" type="radio" checked="checked" value="m" id="radio">
|
50
|
+
Male
|
51
|
+
</label>
|
52
|
+
<label class="radio-inline">
|
53
|
+
|
54
|
+
<input name="radio" type="radio" value="f" id="radio">
|
55
|
+
Female
|
56
|
+
</label>
|
57
|
+
</div>
|
58
|
+
</div>
|
59
|
+
<div class="form-group">
|
60
|
+
<label for="photo" class="control-label">Photo</label>
|
61
|
+
|
62
|
+
<input name="photo" type="file" class="form-control" id="photo">
|
63
|
+
</div>
|
64
|
+
<div class="form-group">
|
65
|
+
<label for="favorite_color" class="control-label">Favorite Color</label>
|
66
|
+
|
67
|
+
<input name="favorite_color" value="#00cc00" type="color" class="form-control" id="favorite_color">
|
68
|
+
</div>
|
69
|
+
<div class="form-group">
|
70
|
+
<label for="language">Language</label>
|
71
|
+
<select name="language" class="form-control" id="language">
|
72
|
+
<option value="en">English</option>
|
73
|
+
<option value="es">Spanish</option>
|
74
|
+
</select>
|
75
|
+
</div>
|
76
|
+
<div class="form-group">
|
77
|
+
<label for="date_of_birth">Date Of Birth</label>
|
78
|
+
|
79
|
+
<input name="date_of_birth" value="1970-01-01" type="date" class="form-control" id="date_of_birth">
|
80
|
+
</div>
|
81
|
+
<div class="form-group">
|
82
|
+
<label for="bio">Bio</label>
|
83
|
+
<textarea class="form-control">This is my bio & it needs to be HTML escaped</textarea>
|
84
|
+
</div>
|
85
|
+
<div class="form-group">
|
86
|
+
<label>
|
87
|
+
|
88
|
+
<input name="checkbox" type="checkbox" value="true" checked="checked" id="checkbox">
|
89
|
+
Send Me Monthly Updates
|
90
|
+
</label>
|
91
|
+
</div>
|
92
|
+
<button type="submit" class="btn btn-default">Save</button>
|
93
|
+
</form>
|
94
|
+
</div>
|
95
|
+
<script src="http://code.jquery.com/jquery.js">
|
96
|
+
</script>
|
97
|
+
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js">
|
98
|
+
</script>
|
99
|
+
</body>
|
100
|
+
</html>
|
@@ -0,0 +1,84 @@
|
|
1
|
+
<h1>Account</h1>
|
2
|
+
|
3
|
+
<%= form for: @account, role: 'form' do %>
|
4
|
+
<div class="form-group">
|
5
|
+
<%= label :email, class: 'control-label' %>
|
6
|
+
<%= email :email, class: 'form-control' %>
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<%# I don't recommend using the div method if it's just static HTML %>
|
10
|
+
<%# but I want to test to make sure that it does work %>
|
11
|
+
<%= div class: 'form-group' do %>
|
12
|
+
<%= label :password, class: 'control-label' %>
|
13
|
+
<%= password :password, class: 'form-control' %>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
<div class="form-group">
|
17
|
+
<%= label :first_name, class: 'control-label' %>
|
18
|
+
<%= text :first_name, class: 'form-control' %>
|
19
|
+
</div>
|
20
|
+
|
21
|
+
<div class="form-group">
|
22
|
+
<%= label :last_name, class: 'control-label' %>
|
23
|
+
<%= text :last_name, class: 'form-control' %>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<div class="form-group">
|
27
|
+
<%= label :website, class: 'control-label' %>
|
28
|
+
<%= url :website, class: 'form-control' %>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
<div class="form-group">
|
32
|
+
<%= label :phone, class: 'control-label' %>
|
33
|
+
<%= tel :phone, class: 'form-control' %>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div class="form-group">
|
37
|
+
<label class="control-label">Gender</label>
|
38
|
+
<div>
|
39
|
+
<label class="radio-inline">
|
40
|
+
<%= radio :gender, value: 'm' %>
|
41
|
+
Male
|
42
|
+
</label>
|
43
|
+
|
44
|
+
<label class="radio-inline">
|
45
|
+
<%= radio :gender, value: 'f' %>
|
46
|
+
Female
|
47
|
+
</label>
|
48
|
+
</div>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<div class="form-group">
|
52
|
+
<%= label :photo, class: 'control-label' %>
|
53
|
+
<%= file :photo, class: 'form-control' %>
|
54
|
+
</div>
|
55
|
+
|
56
|
+
<div class="form-group">
|
57
|
+
<%= label :favorite_color, class: 'control-label' %>
|
58
|
+
<%= color :favorite_color, class: 'form-control' %>
|
59
|
+
</div>
|
60
|
+
|
61
|
+
<div class="form-group">
|
62
|
+
<%= label :language %>
|
63
|
+
<%= select :language, options: [["English", "en"], ["Spanish", "es"]], class: 'form-control' %>
|
64
|
+
</div>
|
65
|
+
|
66
|
+
<div class="form-group">
|
67
|
+
<%= label :date_of_birth %>
|
68
|
+
<%= date :date_of_birth, class: 'form-control' %>
|
69
|
+
</div>
|
70
|
+
|
71
|
+
<div class="form-group">
|
72
|
+
<%= label :bio %>
|
73
|
+
<%= textarea :bio, class: 'form-control' %>
|
74
|
+
</div>
|
75
|
+
|
76
|
+
<div class="form-group">
|
77
|
+
<label>
|
78
|
+
<%= checkbox :notifications %>
|
79
|
+
Send Me Monthly Updates
|
80
|
+
</label>
|
81
|
+
</div>
|
82
|
+
|
83
|
+
<%= submit "Save", class: 'btn btn-default' %>
|
84
|
+
<% end %>
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Account</title>
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<div class="container">
|
10
|
+
<%= render main %>
|
11
|
+
</div>
|
12
|
+
<script src="http://code.jquery.com/jquery.js"></script>
|
13
|
+
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1,65 @@
|
|
1
|
+
h1 Account
|
2
|
+
|
3
|
+
= form for: @account, role: 'form' do
|
4
|
+
.form-group
|
5
|
+
= label :email, class: 'control-label'
|
6
|
+
= email :email, class: 'form-control'
|
7
|
+
|
8
|
+
- # I don't recommend using the div method if it's just static HTML
|
9
|
+
- # but I want to test to make sure that it does work
|
10
|
+
= div class: 'form-group' do
|
11
|
+
= label :password, class: 'control-label'
|
12
|
+
= password :password, class: 'form-control'
|
13
|
+
|
14
|
+
.form-group
|
15
|
+
= label :first_name, class: 'control-label'
|
16
|
+
= text :first_name, class: 'form-control'
|
17
|
+
|
18
|
+
.form-group
|
19
|
+
= label :last_name, class: 'control-label'
|
20
|
+
= text :last_name, class: 'form-control'
|
21
|
+
|
22
|
+
.form-group
|
23
|
+
= label :website, class: 'control-label'
|
24
|
+
= url :website, class: 'form-control'
|
25
|
+
|
26
|
+
.form-group
|
27
|
+
= label :phone, class: 'control-label'
|
28
|
+
= tel :phone, class: 'form-control'
|
29
|
+
|
30
|
+
.form-group
|
31
|
+
label.control-label Gender
|
32
|
+
div
|
33
|
+
label.radio-inline
|
34
|
+
= radio :gender, value: 'm'
|
35
|
+
| Male
|
36
|
+
label.radio-inline
|
37
|
+
= radio :gender, value: 'f'
|
38
|
+
| Female
|
39
|
+
|
40
|
+
.form-group
|
41
|
+
= label :photo, class: 'control-label'
|
42
|
+
= file :photo, class: 'form-control'
|
43
|
+
|
44
|
+
.form-group
|
45
|
+
= label :favorite_color, class: 'control-label'
|
46
|
+
= color :favorite_color, class: 'form-control'
|
47
|
+
|
48
|
+
.form-group
|
49
|
+
= label :language
|
50
|
+
= select :language, options: [["English", "en"], ["Spanish", "es"]], class: 'form-control'
|
51
|
+
|
52
|
+
.form-group
|
53
|
+
= label :date_of_birth
|
54
|
+
= date :date_of_birth, class: 'form-control'
|
55
|
+
|
56
|
+
.form-group
|
57
|
+
= label :bio
|
58
|
+
= textarea :bio, class: 'form-control'
|
59
|
+
|
60
|
+
.form-group
|
61
|
+
label
|
62
|
+
= checkbox :notifications
|
63
|
+
| Send Me Monthly Updates
|
64
|
+
|
65
|
+
= submit "Save", class: 'btn btn-default'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
doctype html
|
2
|
+
html
|
3
|
+
head
|
4
|
+
title Account
|
5
|
+
meta name="viewport" content="width=device-width, initial-scale=1.0"
|
6
|
+
link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"
|
7
|
+
body
|
8
|
+
.container
|
9
|
+
= render main
|
10
|
+
script src="http://code.jquery.com/jquery.js"
|
11
|
+
script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= p %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= p "Hello" %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= a "Log In", href: "/log_in" %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= script src: '/js/jquery.js' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= br %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= img src: '/logo.png', alt: 'Logo' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
= p
|
@@ -0,0 +1 @@
|
|
1
|
+
= p "Hello"
|
@@ -0,0 +1 @@
|
|
1
|
+
= a "Log In", href: "/log_in"
|
@@ -0,0 +1 @@
|
|
1
|
+
= script src: '/js/jquery.js'
|
@@ -0,0 +1 @@
|
|
1
|
+
= br
|
@@ -0,0 +1 @@
|
|
1
|
+
= img src: '/logo.png', alt: 'Logo'
|
data/test/form_test.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FormTest < Curtain::TestCase
|
4
|
+
class Account
|
5
|
+
attr_accessor :email, :password, :first_name, :last_name, :website, :phone, :photo, :gender, :favorite_color, :language, :date_of_birth, :bio, :notifications
|
6
|
+
|
7
|
+
def initialize(attrs={})
|
8
|
+
if attrs
|
9
|
+
attrs.each do |attr, value|
|
10
|
+
send("#{attr}=", value)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class ::AccountView < Curtain::View
|
17
|
+
attr_accessor :account
|
18
|
+
end
|
19
|
+
|
20
|
+
def use(lang)
|
21
|
+
AccountView.template_directories File.join(File.dirname(__FILE__), "examples", "form", lang)
|
22
|
+
end
|
23
|
+
|
24
|
+
%w[erb slim].each do |lang|
|
25
|
+
test "form with #{lang}" do
|
26
|
+
use lang
|
27
|
+
expected = File.read(File.expand_path("examples/form/account.html", File.dirname(__FILE__)))
|
28
|
+
|
29
|
+
assert_equal expected, Glam(AccountView.render("bootstrap", main: 'account'))
|
30
|
+
end
|
31
|
+
|
32
|
+
test "form with data with #{lang}" do
|
33
|
+
use lang
|
34
|
+
expected = File.read(File.expand_path("examples/form/account_with_data.html", File.dirname(__FILE__)))
|
35
|
+
|
36
|
+
account_data = YAML.load_file(File.expand_path("examples/form/account.yml", File.dirname(__FILE__)))
|
37
|
+
account = Account.new(account_data)
|
38
|
+
view = AccountView.new(account: account)
|
39
|
+
assert_equal "mail@paulbarry.com", view.account.email
|
40
|
+
assert_equal expected, Glam(view.render("bootstrap", main: 'account'))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/test/html_test.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class HTMLTest < Curtain::TestCase
|
4
|
+
class ::HTMLView < Curtain::View
|
5
|
+
end
|
6
|
+
|
7
|
+
def use(lang)
|
8
|
+
HTMLView.template_directories File.join(File.dirname(__FILE__), "examples", "html", lang)
|
9
|
+
end
|
10
|
+
|
11
|
+
%w[erb slim].each do |lang|
|
12
|
+
test "void tag with #{lang}" do
|
13
|
+
use lang
|
14
|
+
assert_equal '<br>', render(:void_tag)
|
15
|
+
end
|
16
|
+
|
17
|
+
test "void tag with attributes with #{lang}" do
|
18
|
+
use lang
|
19
|
+
assert_equal %{<img src="/logo.png" alt="Logo">}, render(:void_tag_with_attributes)
|
20
|
+
end
|
21
|
+
|
22
|
+
test "content tag with #{lang}" do
|
23
|
+
use lang
|
24
|
+
assert_equal %{<p></p>}, render(:content_tag)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
def render(*args)
|
30
|
+
strip_lines(HTMLView.new.render(*args))
|
31
|
+
end
|
32
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,4 +1,33 @@
|
|
1
|
-
require '
|
2
|
-
require 'mustache'
|
1
|
+
require 'minitest/autorun'
|
3
2
|
require 'slim'
|
4
3
|
require 'curtain'
|
4
|
+
require 'curtain/erubis'
|
5
|
+
require 'glam'
|
6
|
+
|
7
|
+
Slim::Engine.set_default_options pretty: true, sort_attrs: false, format: :html5
|
8
|
+
|
9
|
+
class Curtain::TestCase < MiniTest::Unit::TestCase
|
10
|
+
|
11
|
+
def initialize(name=nil)
|
12
|
+
@test_name = name
|
13
|
+
super(name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.test(name, &block)
|
17
|
+
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
18
|
+
defined = instance_method(test_name) rescue false
|
19
|
+
raise "#{test_name} is already defined in #{self}" if defined
|
20
|
+
if block_given?
|
21
|
+
define_method(test_name, &block)
|
22
|
+
else
|
23
|
+
define_method(test_name) do
|
24
|
+
flunk "No implementation provided for #{name}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def strip_lines(s)
|
31
|
+
s.to_s.split("\n").map(&:strip).reject(&:blank?).join
|
32
|
+
end
|
33
|
+
end
|