Skip to content

Commit 0af512d

Browse files
committed
Add iframe component with doc and spec.
1 parent 7b13968 commit 0af512d

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%iframe{@tag_attributes}
2+
- if options[:text].nil? && block_given?
3+
= yield
4+
- else
5+
= options[:text]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Matestack::Ui::Core::Iframe
2+
class Iframe < Matestack::Ui::Core::Component::Static
3+
4+
end
5+
end

docs/components/iframe.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# matestack core component: Iframe
2+
3+
Show [specs](/spec/usage/components/iframe_spec.rb)
4+
5+
The HTML iframe tag implemented in ruby.
6+
7+
## Parameters
8+
9+
This component can take 3 configuration params and either yield content or display what gets passed to the `text` configuration param.
10+
11+
#### # id (optional)
12+
Expects a string with all ids the `iframe` should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the `iframe` should have for styling purpose.
16+
17+
18+
#### # src
19+
Specifies the address of the document to embed in the `iframe` tag.
20+
21+
## Example 1: Yield a given block
22+
23+
```ruby
24+
iframe id: "foo", class: "bar", src="https://www.demopage.com" do
25+
plain 'The browser does not support iframe.'
26+
end
27+
```
28+
29+
returns
30+
31+
```html
32+
<iframe id="foo" class="bar" src="https://www.demopage.com">
33+
The browser does not support iframe.
34+
</iframe>
35+
```
36+
37+
## Example 2: Render options[:text] param
38+
39+
```ruby
40+
iframe id: "foo", class: "bar", src="https://www.demopage.com", text: 'The browser does not support iframe.'
41+
```
42+
43+
returns
44+
45+
```html
46+
<iframe id="foo" class="bar" src="https://www.demopage.com">
47+
The browser does not support iframe.
48+
</iframe>
49+
```
50+

spec/usage/components/iframe_spec.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
require_relative "../../support/utils"
2+
include Utils
3+
4+
describe 'Iframe Component', type: :feature, js: true do
5+
6+
it 'Example 1 - yield, no options[:text]' do
7+
8+
class ExamplePage < Matestack::Ui::Page
9+
10+
def response
11+
components {
12+
# simple iframe tag
13+
iframe src="https://www.demopage.com" do
14+
plain 'The browser does not support iframe.'
15+
end
16+
17+
# enhanced iframe tag
18+
iframe id: 'my-id', class: 'my-class', src="https://www.demopage.com" do
19+
plain 'The browser does not support iframe.'
20+
end
21+
}
22+
end
23+
24+
end
25+
26+
visit '/example'
27+
static_output = page.html
28+
29+
expected_static_output = <<~HTML
30+
<iframe src="https://www.demopage.com">The browser does not support iframe.</iframe>
31+
<iframe id="my-id" class="my-class" src="https://www.demopage.com">The browser does not support iframe.</iframe>
32+
HTML
33+
expect(stripped(static_output)).to include(stripped(expected_static_output))
34+
end
35+
36+
it 'Example 2 - render options[:text]' do
37+
38+
class ExamplePage < Matestack::Ui::Page
39+
40+
def response
41+
components {
42+
# simple iframe tag
43+
iframe src="https://www.demopage.com", text: 'The browser does not support iframe.'
44+
45+
# enhanced iframe tag
46+
iframe id: 'my-id', class: 'my-class', src="https://www.demopage.com", text: 'The browser does not support iframe.'
47+
}
48+
end
49+
50+
end
51+
52+
visit '/example'
53+
54+
static_output = page.html
55+
56+
expected_static_output = <<~HTML
57+
<iframe src="https://www.demopage.com">The browser does not support iframe.</iframe>
58+
<iframe id="my-id" class="my-class" src="https://www.demopage.com">The browser does not support iframe.</iframe>
59+
HTML
60+
61+
expect(stripped(static_output)).to include(stripped(expected_static_output))
62+
end
63+
64+
end

0 commit comments

Comments
 (0)