Skip to content

Commit 0bfe250

Browse files
committed
fixed and documented link component #83
1 parent e3f5da2 commit 0bfe250

File tree

3 files changed

+131
-44
lines changed

3 files changed

+131
-44
lines changed
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
- if options[:text].nil?
2-
= link_to link_path, @tag_attributes do
3-
- if block_given?
4-
= yield
5-
- else
6-
= link_to options[:text], link_path, @tag_attributes
1+
%a{@tag_attributes}
2+
- if options[:text].nil? && block_given?
3+
= yield
4+
- else
5+
= options[:text]

app/concepts/matestack/ui/core/link/link.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module Matestack::Ui::Core::Link
22
class Link < Matestack::Ui::Core::Component::Static
33

4-
REQUIRED_KEYS = [:path]
5-
64
def setup
7-
@tag_attributes.merge!({ "class": options[:class],
5+
@tag_attributes.merge!({
6+
"class": options[:class],
87
"id": component_id,
98
"method": options[:method],
10-
"target": options[:target] ||= nil
9+
"target": options[:target] ||= nil,
10+
"href": link_path
1111
})
1212
end
1313

spec/usage/components/link_spec.rb

Lines changed: 122 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,127 @@
22
include Utils
33

44
describe 'Link Component', type: :feature, js: true do
5-
# does not work at all. Maybe a problem with the dummy application?
6-
# it 'Example 1' do
7-
#
8-
# class ExamplePage < Matestack::Ui::Page
9-
#
10-
# def response
11-
# components {
12-
# div id: "foo", class: "bar" do
13-
# link path: "https://matestack.org", text: 'here'
14-
# end
15-
# # div id: "foo", class: "bar" do
16-
# # link path: "https://matestack.org" do
17-
# # plain 'here'
18-
# # end
19-
# # end
20-
#
21-
# }
22-
# end
23-
#
24-
# end
25-
#
26-
# visit "/example"
27-
#
28-
# sleep 500
29-
# static_output = page.html
30-
#
31-
# expected_static_output = <<~HTML
32-
# <div id="foo" class="bar">
33-
# <a href="https://matestack.org">here</a>
34-
# </div>
35-
# HTML
36-
#
37-
# expect(stripped(static_output)).to ( include(stripped(expected_static_output)) )
38-
# end
5+
6+
it 'Example 1 - Text Option' do
7+
8+
class ExamplePage < Matestack::Ui::Page
9+
10+
def response
11+
components {
12+
div id: "foo", class: "bar" do
13+
link path: "https://matestack.org", text: 'here'
14+
end
15+
}
16+
end
17+
18+
end
19+
20+
visit "/example"
21+
22+
static_output = page.html
23+
24+
expected_static_output = <<~HTML
25+
<div id="foo" class="bar">
26+
<a href="https://matestack.org">here</a>
27+
</div>
28+
HTML
29+
30+
expect(stripped(static_output)).to ( include(stripped(expected_static_output)) )
31+
end
32+
33+
it 'Example 2 - Yield' do
34+
35+
class ExamplePage < Matestack::Ui::Page
36+
37+
def response
38+
components {
39+
div id: "foo", class: "bar" do
40+
link path: "https://matestack.org" do
41+
plain 'here'
42+
end
43+
end
44+
45+
}
46+
end
47+
48+
end
49+
50+
visit "/example"
51+
52+
static_output = page.html
53+
54+
expected_static_output = <<~HTML
55+
<div id="foo" class="bar">
56+
<a href="https://matestack.org">here</a>
57+
</div>
58+
HTML
59+
60+
expect(stripped(static_output)).to ( include(stripped(expected_static_output)) )
61+
end
62+
63+
it 'Example 3 - Target' do
64+
65+
class ExamplePage < Matestack::Ui::Page
66+
67+
def response
68+
components {
69+
div id: "foo", class: "bar" do
70+
link path: "https://matestack.org", target: "_blank" do
71+
plain 'here'
72+
end
73+
end
74+
75+
}
76+
end
77+
78+
end
79+
80+
visit "/example"
81+
82+
static_output = page.html
83+
84+
expected_static_output = <<~HTML
85+
<div id="foo" class="bar">
86+
<a href="https://matestack.org" target="_blank">here</a>
87+
</div>
88+
HTML
89+
90+
expect(stripped(static_output)).to ( include(stripped(expected_static_output)) )
91+
end
92+
93+
it 'Example 4 - Rails Routing' do
94+
95+
Rails.application.routes.append do
96+
get '/some_link_test_path', to: 'page_test#my_action', as: 'link_test'
97+
end
98+
Rails.application.reload_routes!
99+
100+
class ExamplePage < Matestack::Ui::Page
101+
102+
def response
103+
components {
104+
div id: "foo", class: "bar" do
105+
link path: :link_test_path do
106+
plain 'here'
107+
end
108+
end
109+
110+
}
111+
end
112+
113+
end
114+
115+
visit "/example"
116+
117+
static_output = page.html
118+
119+
expected_static_output = <<~HTML
120+
<div id="foo" class="bar">
121+
<a href="/some_link_test_path">here</a>
122+
</div>
123+
HTML
124+
125+
expect(stripped(static_output)).to ( include(stripped(expected_static_output)) )
126+
end
39127

40128
end

0 commit comments

Comments
 (0)