mab-cj 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +19 -0
- data/Gemfile +14 -0
- data/README.md +224 -0
- data/Rakefile +16 -0
- data/lib/mab.rb +6 -0
- data/lib/mab/builder.rb +45 -0
- data/lib/mab/indentation.rb +33 -0
- data/lib/mab/kernel_method.rb +6 -0
- data/lib/mab/mixin.rb +262 -0
- data/lib/mab/rails.rb +20 -0
- data/lib/mab/tilt.rb +42 -0
- data/lib/mab/version.rb +4 -0
- data/mab.gemspec +20 -0
- data/test/helper.rb +4 -0
- data/test/rails/Rakefile +7 -0
- data/test/rails/app/assets/images/rails.png +0 -0
- data/test/rails/app/assets/javascripts/application.js +15 -0
- data/test/rails/app/assets/stylesheets/application.css +13 -0
- data/test/rails/app/controllers/application_controller.rb +17 -0
- data/test/rails/app/helpers/application_helper.rb +2 -0
- data/test/rails/app/views/application/content_for.html.mab +6 -0
- data/test/rails/app/views/application/normal.html.mab +2 -0
- data/test/rails/app/views/application/variables.html.mab +2 -0
- data/test/rails/app/views/layouts/application.html.mab +15 -0
- data/test/rails/config.ru +4 -0
- data/test/rails/config/application.rb +54 -0
- data/test/rails/config/boot.rb +6 -0
- data/test/rails/config/environment.rb +5 -0
- data/test/rails/config/environments/development.rb +27 -0
- data/test/rails/config/environments/production.rb +67 -0
- data/test/rails/config/environments/test.rb +29 -0
- data/test/rails/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails/config/initializers/inflections.rb +15 -0
- data/test/rails/config/initializers/mime_types.rb +5 -0
- data/test/rails/config/initializers/secret_token.rb +7 -0
- data/test/rails/config/initializers/session_store.rb +8 -0
- data/test/rails/config/initializers/wrap_parameters.rb +14 -0
- data/test/rails/config/locales/en.yml +5 -0
- data/test/rails/config/routes.rb +3 -0
- data/test/rails/script/rails +6 -0
- data/test/rails/test/helper.rb +7 -0
- data/test/rails/test/test_mab.rb +40 -0
- data/test/test_mab_builder.rb +56 -0
- data/test/test_mab_indentation.rb +66 -0
- data/test/test_mab_kernel_method.rb +10 -0
- data/test/test_mab_mixin.rb +250 -0
- metadata +118 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
#
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters :format => [:json]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Disable root element in JSON by default.
|
12
|
+
ActiveSupport.on_load(:active_record) do
|
13
|
+
self.include_root_in_json = false
|
14
|
+
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,40 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
|
3
|
+
class TestMab < ActionDispatch::IntegrationTest
|
4
|
+
test "normal view" do
|
5
|
+
get "application/normal"
|
6
|
+
assert_response :success
|
7
|
+
assert_template "application/normal"
|
8
|
+
assert_template "layouts/application"
|
9
|
+
assert_html "<h1>Hello Mab!</h1>"
|
10
|
+
end
|
11
|
+
|
12
|
+
test "no layout" do
|
13
|
+
get "application/no_layout"
|
14
|
+
assert_response :success
|
15
|
+
assert_template "application/normal"
|
16
|
+
assert_equal "<h1>Hello Mab!</h1>", @response.body
|
17
|
+
end
|
18
|
+
|
19
|
+
test "variables" do
|
20
|
+
get "application/variables"
|
21
|
+
assert_response :success
|
22
|
+
assert_template "application/variables"
|
23
|
+
assert_template "layouts/application"
|
24
|
+
assert_html "<h1>Hello world!</h1>"
|
25
|
+
end
|
26
|
+
|
27
|
+
test "content for" do
|
28
|
+
get "application/content_for"
|
29
|
+
assert_response :success
|
30
|
+
assert_template "application/content_for"
|
31
|
+
assert_template "layouts/application"
|
32
|
+
assert_html "<h2>Sub</h2>", :heading => "<h1>Heading</h1>"
|
33
|
+
end
|
34
|
+
|
35
|
+
def assert_html(expected, options = {})
|
36
|
+
expected = "<!DOCTYPE html><html><head><title>Dummy</title></head><body>#{options[:heading]}<div class=\"content\">#{expected}</div></body></html>" unless options[:skip_layout]
|
37
|
+
assert_equal expected, @response.body
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMabBuilder < MiniTest::Unit::TestCase
|
4
|
+
def test_assigns
|
5
|
+
b = Mab::Builder.new(:title => 'Mab') do
|
6
|
+
title @title
|
7
|
+
end
|
8
|
+
|
9
|
+
assert_equal '<title>Mab</title>', b.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_capture
|
13
|
+
b = Mab::Builder.new do
|
14
|
+
%w[name address].map do |key|
|
15
|
+
mab do
|
16
|
+
p key
|
17
|
+
end
|
18
|
+
end.join('<br>')
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_equal "<p>name</p><br><p>address</p>", b.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_helper
|
25
|
+
obj = Class.new {
|
26
|
+
def initialize
|
27
|
+
@a = 1
|
28
|
+
@b = 2
|
29
|
+
end
|
30
|
+
|
31
|
+
def c; @a + @b end
|
32
|
+
}.new
|
33
|
+
|
34
|
+
b = Mab::Builder.new({}, obj) do
|
35
|
+
p @a
|
36
|
+
p @b
|
37
|
+
p c
|
38
|
+
end
|
39
|
+
|
40
|
+
assert_equal '<p>1</p><p>2</p><p>3</p>', b.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_pretty
|
44
|
+
b = Mab::PrettyBuilder.new do
|
45
|
+
doctype!
|
46
|
+
html do
|
47
|
+
body do
|
48
|
+
h1 "Nice"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
assert_equal "<!DOCTYPE html>\n<html>\n <body>\n <h1>Nice</h1>\n </body>\n</html>", b.to_s
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMabIndentation < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@obj = Object.new
|
7
|
+
@obj.extend Mab::Mixin
|
8
|
+
@obj.extend Mab::Indentation
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_simple
|
12
|
+
assert_equal "<p>Hello</p>", @obj.mab { tag! :p, 'Hello' }
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_block
|
16
|
+
assert_equal "<p>\n Hello\n</p>", @obj.mab { tag!(:p) { text 'Hello' } }
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_chaining
|
20
|
+
res = <<HTML.strip
|
21
|
+
<p class="hello">
|
22
|
+
<br>
|
23
|
+
</p>
|
24
|
+
HTML
|
25
|
+
|
26
|
+
assert_equal res, @obj.mab {
|
27
|
+
tag!(:p).hello do
|
28
|
+
tag! :br
|
29
|
+
end
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_reindent
|
34
|
+
res = <<HTML.strip
|
35
|
+
<p>
|
36
|
+
Hello
|
37
|
+
World
|
38
|
+
</p>
|
39
|
+
HTML
|
40
|
+
|
41
|
+
assert_equal res, @obj.mab {
|
42
|
+
tag! :p do
|
43
|
+
reindent! "Hello\nWorld"
|
44
|
+
end
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_stringification
|
49
|
+
res = <<HTML.strip
|
50
|
+
<h1>
|
51
|
+
<div><span>Hello</span> | <span>Hello</span></div>
|
52
|
+
</h1>
|
53
|
+
HTML
|
54
|
+
|
55
|
+
assert_equal res, @obj.mab {
|
56
|
+
tag!(:h1) do
|
57
|
+
s = tag!(:span, 'Hello')
|
58
|
+
tag!(:div) do
|
59
|
+
[s, s].join(' | ')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,250 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMabMixin < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@obj = Object.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_tag
|
10
|
+
@obj.extend Mab::Mixin
|
11
|
+
|
12
|
+
assert_equal '<br>', @obj.mab {
|
13
|
+
tag! :br
|
14
|
+
}
|
15
|
+
|
16
|
+
assert_equal '<br></br>', @obj.mab {
|
17
|
+
tag! :br, nil
|
18
|
+
}
|
19
|
+
|
20
|
+
assert_equal '<p>Hello</p>', @obj.mab {
|
21
|
+
tag! :p, 'Hello'
|
22
|
+
}
|
23
|
+
|
24
|
+
assert_equal '<p class="intro">Hello</p>', @obj.mab {
|
25
|
+
tag! :p, 'Hello', :class => "intro"
|
26
|
+
}
|
27
|
+
|
28
|
+
assert_equal '<p><br></p>', @obj.mab {
|
29
|
+
tag! :p do
|
30
|
+
tag! :br
|
31
|
+
end
|
32
|
+
}
|
33
|
+
|
34
|
+
assert_equal '<br class="intro">', @obj.mab {
|
35
|
+
tag! :br, :class => 'intro'
|
36
|
+
}
|
37
|
+
|
38
|
+
assert_equal '<br>', @obj.mab {
|
39
|
+
tag! :br, :class => nil
|
40
|
+
}
|
41
|
+
|
42
|
+
assert_raises Mab::Mixin::Error do
|
43
|
+
@obj.mab do
|
44
|
+
tag! :p, "content" do
|
45
|
+
"and block"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_multile_attrs
|
52
|
+
@obj.extend Mab::Mixin
|
53
|
+
|
54
|
+
assert_equal '<br class="intro" id="yay">', @obj.mab {
|
55
|
+
tag! :br, { :class => "intro" }, { :id => "yay" }
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_escaping
|
60
|
+
@obj.extend Mab::Mixin
|
61
|
+
|
62
|
+
assert_equal '<p>&</p>', @obj.mab {
|
63
|
+
tag! :p, '&'
|
64
|
+
}
|
65
|
+
|
66
|
+
assert_equal '<p>&</p>', @obj.mab {
|
67
|
+
tag! :p do '&' end
|
68
|
+
}
|
69
|
+
|
70
|
+
assert_equal '&', @obj.mab { text '&' }
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_chaining
|
74
|
+
@obj.extend Mab::Mixin
|
75
|
+
|
76
|
+
assert_equal '<p class="intro" id="first">Hello</p>', @obj.mab {
|
77
|
+
tag!(:p).intro.first!('Hello')
|
78
|
+
}
|
79
|
+
|
80
|
+
assert_equal '<div class="content">Hello</div>', @obj.mab {
|
81
|
+
tag!(:div).content("Hello")
|
82
|
+
}
|
83
|
+
|
84
|
+
assert_raises(Mab::Mixin::Error) do
|
85
|
+
@obj.mab do
|
86
|
+
tag!(:p).intro('Hello').first!('Hello')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
assert_raises(Mab::Mixin::Error) do
|
91
|
+
@obj.mab do
|
92
|
+
tag!(:p).intro(:class => 'bar').first!('Hello')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_html5_chaining
|
98
|
+
@obj.extend Mab::Mixin::HTML5
|
99
|
+
|
100
|
+
assert_equal '<p class="intro" id="first">Hello</p>', @obj.mab {
|
101
|
+
p.intro.first!('Hello')
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_mab_done
|
106
|
+
@obj.extend Mab::Mixin
|
107
|
+
def @obj.mab_done(tag)
|
108
|
+
tag._attributes = { :nope => 123 }
|
109
|
+
end
|
110
|
+
|
111
|
+
assert_equal '<p nope="123"><br nope="123"></p>', @obj.mab {
|
112
|
+
tag! :p, :hello => :world do
|
113
|
+
tag!(:br).klass(:hello => :world)
|
114
|
+
end
|
115
|
+
}
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_mab_done_ignore_block
|
119
|
+
@obj.extend Mab::Mixin
|
120
|
+
def @obj.mab_done(tag)
|
121
|
+
tag._block = nil
|
122
|
+
tag._content = ''
|
123
|
+
end
|
124
|
+
|
125
|
+
assert_equal '<p></p>', @obj.mab {
|
126
|
+
tag! :p do
|
127
|
+
tag!(:br).klass(:hello => :world)
|
128
|
+
end
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_mab_done_wrap_block
|
133
|
+
@obj.extend Mab::Mixin
|
134
|
+
def @obj.mab_done(tag)
|
135
|
+
tag._block do |blk|
|
136
|
+
tag! :p, 'nice'
|
137
|
+
blk.call
|
138
|
+
end if tag._name == :body
|
139
|
+
end
|
140
|
+
|
141
|
+
assert_equal "<body><p>nice</p><br></body>", @obj.mab {
|
142
|
+
tag! :body do
|
143
|
+
tag! :br
|
144
|
+
end
|
145
|
+
}
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_mab_insert
|
149
|
+
@obj.extend Mab::Mixin
|
150
|
+
def @obj.mab_insert(tag)
|
151
|
+
tag._name = :nope if tag.respond_to?(:_name=)
|
152
|
+
super
|
153
|
+
end
|
154
|
+
|
155
|
+
assert_equal '<nope>', @obj.mab {
|
156
|
+
tag! :br
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_stringification
|
161
|
+
@obj.extend Mab::Mixin
|
162
|
+
|
163
|
+
assert_equal '<h1>My name is: <span>Bob</span></h1>', @obj.mab {
|
164
|
+
tag!(:h1) do
|
165
|
+
"My name is: #{tag!(:span, 'Bob')}"
|
166
|
+
end
|
167
|
+
}
|
168
|
+
|
169
|
+
assert_equal '<h1><div><span>Hello</span> | <span>Hello</span></div></h1>', @obj.mab {
|
170
|
+
tag!(:h1) do
|
171
|
+
s = tag!(:span, 'Hello')
|
172
|
+
tag!(:div) do
|
173
|
+
[s, s].join(' | ')
|
174
|
+
end
|
175
|
+
end
|
176
|
+
}
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_xml
|
180
|
+
@obj.extend Mab::Mixin
|
181
|
+
@obj.mab_options[:xml] = true
|
182
|
+
|
183
|
+
assert_equal '<br /><br></br><br>hello</br>', @obj.mab {
|
184
|
+
tag! :br
|
185
|
+
tag! :br, ''
|
186
|
+
tag! :br, 'hello'
|
187
|
+
}
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_html5
|
191
|
+
@obj.extend Mab::Mixin::HTML5
|
192
|
+
assert_equal '<!DOCTYPE html><html><body><p></p><br></body></html>', @obj.mab {
|
193
|
+
doctype!
|
194
|
+
html do
|
195
|
+
body do
|
196
|
+
p
|
197
|
+
br
|
198
|
+
end
|
199
|
+
end
|
200
|
+
}
|
201
|
+
|
202
|
+
assert_raises Mab::Mixin::Error do
|
203
|
+
@obj.mab { br { } }
|
204
|
+
end
|
205
|
+
|
206
|
+
assert_raises Mab::Mixin::Error do
|
207
|
+
@obj.mab { br "hello" }
|
208
|
+
end
|
209
|
+
|
210
|
+
assert_raises Mab::Mixin::Error do
|
211
|
+
@obj.mab { br.klass "hello" }
|
212
|
+
end
|
213
|
+
|
214
|
+
assert_includes [
|
215
|
+
'<input class="text" value="name">',
|
216
|
+
'<input value="name" class="text">',
|
217
|
+
], @obj.mab {
|
218
|
+
input.text :value => 'name'
|
219
|
+
}
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_xhtml5
|
223
|
+
@obj.extend Mab::Mixin::XHTML5
|
224
|
+
assert_equal '<!DOCTYPE html><html><body><p></p><br /></body></html>', @obj.mab {
|
225
|
+
doctype!
|
226
|
+
html do
|
227
|
+
body do
|
228
|
+
p
|
229
|
+
br
|
230
|
+
end
|
231
|
+
end
|
232
|
+
}
|
233
|
+
|
234
|
+
assert_raises Mab::Mixin::Error do
|
235
|
+
@obj.mab { br { } }
|
236
|
+
end
|
237
|
+
|
238
|
+
assert_raises Mab::Mixin::Error do
|
239
|
+
@obj.mab { br "hello" }
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_core_xml
|
244
|
+
@obj.extend Mab::Mixin::XML
|
245
|
+
assert_equal '<br />', @obj.mab {
|
246
|
+
tag! :br
|
247
|
+
}
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|