Skip to content

Commit c5c4380

Browse files
author
Nils Henning
committed
update unescaped, u, var, video, wbr, youtube components and specs
1 parent 282f454 commit c5c4380

File tree

9 files changed

+85
-113
lines changed

9 files changed

+85
-113
lines changed

.byebug_history

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ continue
22
static_output
33
continue
44
static_output
5+
continue
6+
static_output
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Matestack::Ui::Core::Unescaped
22
class Unescaped < Matestack::Ui::Core::Component::Static
33
def show
4-
@argument
4+
@argument.html_safe
55
end
66
end
77
end

lib/matestack/ui/core/components.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ def self.require_core_component(name)
108108
require_core_component "time"
109109
require_core_component "tr"
110110
require_core_component "transition"
111+
require_core_component "u"
111112
require_core_component "ul"
113+
require_core_component "unescaped"
114+
require_core_component "var"
115+
require_core_component "video"
116+
require_core_component "wbr"
117+
require_core_component "youtube"
112118
require_core_component "form"
113119
require_core_component "form/input"
114120
require_core_component "form/select"
@@ -201,7 +207,13 @@ def self.require_core_component(name)
201207
time: Matestack::Ui::Core::Time::Time,
202208
tr: Matestack::Ui::Core::Tr::Tr,
203209
transition: Matestack::Ui::Core::Transition::Transition,
210+
u: Matestack::Ui::Core::U::U,
204211
ul: Matestack::Ui::Core::Ul::Ul,
212+
unescaped: Matestack::Ui::Core::Unescaped::Unescaped,
213+
var: Matestack::Ui::Core::Var::Var,
214+
video: Matestack::Ui::Core::Video::Video,
215+
wbr: Matestack::Ui::Core::Wbr::Wbr,
216+
youtube: Matestack::Ui::Core::Youtube::Youtube,
205217
form: Matestack::Ui::Core::Form::Form,
206218
form_input: Matestack::Ui::Core::Form::Input::Input,
207219
form_select: Matestack::Ui::Core::Form::Select::Select,

spec/0.8/components/u.rb renamed to spec/0.8/components/u_spec.rb

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,45 @@
22
include Utils
33

44
describe 'u Component', type: :feature, js: true do
5-
65
it 'Example 1 - yield, no options[:text]' do
7-
86
class ExamplePage < Matestack::Ui::Page
9-
107
def response
11-
components {
12-
# simple u
13-
u do
14-
plain 'I am simple'
15-
end
16-
17-
# enhanced u
18-
u id: 'my-id', class: 'my-class' do
19-
plain 'I am enhanced'
20-
end
21-
}
8+
# simple u
9+
u do
10+
plain 'I am simple'
11+
end
12+
# enhanced u
13+
u id: 'my-id', class: 'my-class' do
14+
plain 'I am enhanced'
15+
end
2216
end
23-
2417
end
2518

2619
visit '/example'
27-
2820
static_output = page.html
29-
3021
expected_static_output = <<~HTML
31-
<u>I am simple</u>
32-
<u id="my-id" class="my-class">I am enhanced</u>
22+
<u>I am simple</u>
23+
<u id="my-id" class="my-class">I am enhanced</u>
3324
HTML
34-
3525
expect(stripped(static_output)).to include(stripped(expected_static_output))
3626
end
3727

3828
it 'Example 2 - render options[:text]' do
39-
4029
class ExamplePage < Matestack::Ui::Page
41-
4230
def response
43-
components {
44-
# simple u
45-
u text: 'I am simple'
46-
47-
# enhanced u
48-
u id: 'my-id', class: 'my-class', text: 'I am enhanced'
49-
}
31+
# simple u
32+
u text: 'I am simple'
33+
# enhanced u
34+
u id: 'my-id', class: 'my-class', text: 'I am enhanced'
5035
end
51-
5236
end
5337

5438
visit '/example'
55-
5639
static_output = page.html
57-
5840
expected_static_output = <<~HTML
59-
<u>I am simple</u>
60-
<u id="my-id" class="my-class">I am enhanced</u>
41+
<u>I am simple</u>
42+
<u id="my-id" class="my-class">I am enhanced</u>
6143
HTML
62-
6344
expect(stripped(static_output)).to include(stripped(expected_static_output))
6445
end
6546

spec/0.8/components/unescaped_spec.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
describe "Unescaped Component", type: :feature, js: true do
22

33
it "allows the insertion of pure HTML: Example 1" do
4-
54
class ExamplePage < Matestack::Ui::Page
65
def response
7-
components {
8-
unescaped <<~HTML
6+
unescaped <<~HTML
97
<h1>Hello World</h1>
108
<script>alert('Really Hello!')</script>
11-
HTML
12-
}
9+
HTML
1310
end
1411
end
1512

1613
accept_alert do
1714
visit "/example"
1815
end
19-
2016
static_output = page.html
21-
2217
expect(static_output).to include("<h1>Hello World</h1>")
2318
end
2419

spec/0.8/components/var_spec.rb

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,23 @@
44
describe 'Var Component', type: :feature, js: true do
55

66
it 'Example 1' do
7-
87
class ExamplePage < Matestack::Ui::Page
9-
108
def response
11-
components {
12-
# example 1
13-
var id: "foo", class: "bar" do
14-
plain 'I get yielded'
15-
end
16-
# example 2
17-
var id: "foo", class: "bar", text: 'I am text'
18-
}
9+
# example 1
10+
var id: "foo", class: "bar" do
11+
plain 'I get yielded'
12+
end
13+
# example 2
14+
var id: "foo", class: "bar", text: 'I am text'
1915
end
20-
2116
end
2217

2318
visit '/example'
24-
2519
static_output = page.html
26-
2720
expected_static_output = <<~HTML
28-
<var id="foo" class="bar">I get yielded</var>
29-
<var id="foo" class="bar">I am text</var>
21+
<var id="foo" class="bar">I get yielded</var>
22+
<var id="foo" class="bar">I am text</var>
3023
HTML
31-
3224
expect(stripped(static_output)).to include(stripped(expected_static_output))
3325
end
3426

spec/0.8/components/video_spec.rb

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,36 @@
44
describe 'Video Component', type: :feature, js: true do
55

66
it 'Renders a simple video tag on the page' do
7-
class ExamplePage < Matestack::Ui::Page
8-
def response
9-
components {
10-
video path: 'corgi.mp4', type: "mp4", width: 500, height: 300
11-
}
12-
end
13-
end
7+
class ExamplePage < Matestack::Ui::Page
8+
def response
9+
video path: 'corgi.mp4', type: "mp4", width: 500, height: 300
10+
end
11+
end
1412

15-
visit '/example'
16-
17-
expect(page).to have_xpath("//video[@width='500' and @height='300']")
18-
expect(page).to have_content('Your browser does not support the video tag.')
13+
visit '/example'
14+
expected_html_output = <<~HTML
15+
<video height="300" width="500">
16+
<source src="#{ActionController::Base.helpers.asset_path('corgi.mp4')}" type="video/mp4" />
17+
Your browser does not support the video tag.
18+
</video>
19+
HTML
1920
end
2021

2122
it 'Renders a video tag with more attributes on the page' do
22-
class ExamplePage < Matestack::Ui::Page
23-
def response
24-
components {
25-
video path: 'corgi.mp4', type: "mp4", width: 500, height: 300, autoplay: true, controls: true, loop: true, muted: true, playsinline: false, preload: 'auto'
26-
}
27-
end
28-
end
29-
30-
visit '/example'
23+
class ExamplePage < Matestack::Ui::Page
24+
def response
25+
video path: 'corgi.mp4', type: "mp4", width: 500, height: 300, autoplay: true, controls: true, loop: true, muted: true, playsinline: false, preload: 'auto'
26+
end
27+
end
3128

32-
expect(page).to have_xpath("//video[@width='500' and @height='300' and @autoplay and @controls and @loop and @muted and @preload='auto']")
33-
expect(page).to have_content('Your browser does not support the video tag.')
29+
visit '/example'
30+
static_output = page.html
31+
expected_html_output = <<~HTML
32+
<video autoplay="autoplay" controls="controls" height="300" loop="loop" muted="muted" preload="auto" width="500">
33+
<source src="#{ActionController::Base.helpers.asset_path('corgi.mp4')}" type="video/mp4" />
34+
Your browser does not support the video tag.
35+
</video>
36+
HTML
37+
expect(stripped(static_output)).to include(stripped(expected_html_output))
3438
end
3539
end

spec/0.8/components/wbr_spec.rb

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,27 @@
55
it 'Renders a simple and enhanced wbr tag on a page' do
66
class ExamplePage < Matestack::Ui::Page
77
def response
8-
components {
9-
# Simple wbr
10-
paragraph do
11-
plain 'First part of text'
12-
wbr
13-
plain 'Second part of text'
14-
end
15-
16-
# Enhanced wbr
17-
paragraph do
18-
plain 'First part of second text'
19-
wbr id: 'special', class: 'nice-wbr'
20-
plain 'Second part of second text'
21-
end
22-
}
8+
# Simple wbr
9+
paragraph do
10+
plain 'First part of text'
11+
wbr
12+
plain 'Second part of text'
13+
end
14+
# Enhanced wbr
15+
paragraph do
16+
plain 'First part of second text'
17+
wbr id: 'special', class: 'nice-wbr'
18+
plain 'Second part of second text'
19+
end
2320
end
2421
end
2522

2623
visit '/example'
27-
2824
static_output = page.html
29-
3025
expected_static_output = <<~HTML
3126
<p>First part of text<wbr/>Second part of text</p>
3227
<p>First part of second text<wbr id="special" class="nice-wbr"/>Second part of second text</p>
3328
HTML
34-
3529
expect(stripped(static_output)).to include(stripped(expected_static_output))
3630
end
3731
end

spec/0.8/components/youtube_spec.rb

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,22 @@
44
describe 'Youtube Component', type: :feature, js: true do
55

66
it 'Example 1' do
7-
87
class ExamplePage < Matestack::Ui::Page
9-
108
def response
11-
components {
12-
# simple youtube video
13-
youtube height: 360, width: 360, yt_id: 'OY5AeGhgK7I', class: 'iframe'
14-
# youtube video with start_at and no_controls
15-
youtube height: 360, width: 360, yt_id: 'OY5AeGhgK7I', start_at: 30, no_controls: true
16-
# youtube video with start_at and privacy_mode
17-
youtube height: 360, width: 360, yt_id: 'OY5AeGhgK7I', start_at: 30, privacy_mode: true
18-
}
9+
# simple youtube video
10+
youtube height: 360, width: 360, yt_id: 'OY5AeGhgK7I', class: 'iframe'
11+
# youtube video with start_at and no_controls
12+
youtube height: 360, width: 360, yt_id: 'OY5AeGhgK7I', start_at: 30, no_controls: true
13+
# youtube video with start_at and privacy_mode
14+
youtube height: 360, width: 360, yt_id: 'OY5AeGhgK7I', start_at: 30, privacy_mode: true
1915
end
20-
2116
end
2217

2318
visit '/example'
24-
2519
static_output = page.html
26-
2720
expect(page).to have_selector("iframe[src='https://www.youtube.com/embed/OY5AeGhgK7I'][class='iframe']")
2821
expect(page).to have_selector("iframe[src='https://www.youtube.com/embed/OY5AeGhgK7I?controls=0&amp;start=30']")
2922
expect(page).to have_selector("iframe[src='https://www.youtube-nocookie.com/embed/OY5AeGhgK7I?start=30']")
30-
3123
end
3224

3325
end

0 commit comments

Comments
 (0)