Skip to content

Commit d35e7aa

Browse files
Merge pull request #233 from mayanktap/add-iframe-tag
Add iframe component.
2 parents e91105e + 94c2a9c commit d35e7aa

File tree

4 files changed

+142
-0
lines changed

4 files changed

+142
-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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Matestack::Ui::Core::Iframe
2+
class Iframe < Matestack::Ui::Core::Component::Static
3+
4+
def setup
5+
@tag_attributes.merge!({
6+
src: options[:src],
7+
height: options[:height],
8+
width: options[:width],
9+
srcdoc: options[:srcdoc]
10+
})
11+
end
12+
13+
end
14+
end

docs/components/iframe.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
#### # height (optional)
18+
Specifies the height of an `iframe`.
19+
20+
#### # width (optional)
21+
Specifies the width of an `iframe`.
22+
23+
#### # src
24+
Specifies the address of the document to embed in the `iframe` tag.
25+
26+
#### # srcdoc
27+
Specifies the HTML content of the page to show in the inline frame.
28+
29+
## Example 1: Yield a given block
30+
31+
```ruby
32+
iframe id: "foo", class: "bar", src="https://www.demopage.com" do
33+
plain 'The browser does not support iframe.'
34+
end
35+
```
36+
37+
returns
38+
39+
```html
40+
<iframe id="foo" class="bar" src="https://www.demopage.com">
41+
The browser does not support iframe.
42+
</iframe>
43+
```
44+
45+
## Example 2: Render options[:text] param
46+
47+
```ruby
48+
iframe id: "foo", class: "bar", src="https://www.demopage.com", text: 'The browser does not support iframe.'
49+
```
50+
51+
returns
52+
53+
```html
54+
<iframe id="foo" class="bar" src="https://www.demopage.com">
55+
The browser does not support iframe.
56+
</iframe>
57+
```
58+

spec/usage/components/iframe_spec.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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", srcdoc="<p>Mate Stack UI!</p>" 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" srcdoc="<p>Mate Stack UI!</p>">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",
47+
srcdoc="<p>Mate Stack UI!</p>", text: 'The browser does not support iframe.'
48+
}
49+
end
50+
51+
end
52+
53+
visit '/example'
54+
55+
static_output = page.html
56+
57+
expected_static_output = <<~HTML
58+
<iframe src="https://www.demopage.com">The browser does not support iframe.</iframe>
59+
<iframe id="my-id" class="my-class" src="https://www.demopage.com" srcdoc="<p>Mate Stack UI!</p>">The browser does not support iframe.</iframe>
60+
HTML
61+
62+
expect(stripped(static_output)).to include(stripped(expected_static_output))
63+
end
64+
65+
end

0 commit comments

Comments
 (0)