Skip to content

Commit 2976948

Browse files
Merge pull request #260 from lumisce/ins_tag
Add ins tag Thank you for contributing @lumisce && props to @borref and @bdlb77 for reviewing!
2 parents cfe888e + 12a57f1 commit 2976948

File tree

5 files changed

+138
-0
lines changed

5 files changed

+138
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%ins{@tag_attributes}
2+
- if options[:text].nil? && block_given?
3+
= yield
4+
- else
5+
= options[:text]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Matestack::Ui::Core::Ins
2+
class Ins < Matestack::Ui::Core::Component::Static
3+
def setup
4+
@tag_attributes.merge!({
5+
cite: options[:cite],
6+
datetime: options[:datetime]
7+
})
8+
end
9+
end

docs/components/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ You can build your [own components](/docs/extend/custom_components.md) as well,
1414
- [kbd](/docs/components/kbd.md)
1515
- [hr](/docs/components/hr.md)
1616
- [icon](/docs/components/icon.md)
17+
- [ins](/docs/components/ins.md)
1718
- [main](/docs/components/main.md)
1819
- [nav](/docs/components/nav.md)
1920
- [plain](/docs/components/plain.md)

docs/components/ins.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# matestack core component: Ins
2+
3+
Show [specs](/spec/usage/components/ins_spec.rb)
4+
5+
The HTML ins tag implemented in Ruby.
6+
7+
## Parameters
8+
9+
This component can take 4 optional 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 ins tag should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the ins tag should have.
16+
17+
#### # cite (optional)
18+
Expects a string with a URL to a document that explains the reason why the text was inserted/changed.
19+
20+
#### # datetime (optional)
21+
Expects a string which specifies the date and time of when the text was inserted/changed.
22+
23+
## Example 1: Yield a given block
24+
25+
```ruby
26+
ins id: "foo", class: "bar", cite: "example.html", datetime: "2008-05-25T17:25:00Z" do
27+
plain 'Inserted text' # optional content
28+
end
29+
```
30+
31+
returns
32+
33+
```html
34+
<ins id="foo" class="bar" cite="example.html" datetime="2008-05-25T17:25:00Z">Inserted text</ins>
35+
```
36+
37+
## Example 2: Render options[:text] param
38+
39+
```ruby
40+
ins id: "foo", class: "bar", cite: "example.html", datetime: "2008-05-25T17:25:00Z", text: 'Inserted text'
41+
```
42+
43+
returns
44+
45+
```html
46+
<ins id="foo" class="bar" cite="example.html" datetime="2008-05-25T17:25:00Z">Inserted text</ins>
47+
```

spec/usage/components/ins_spec.rb

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
require_relative "../../support/utils"
2+
include Utils
3+
4+
describe 'Ins 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 ins
13+
ins do
14+
plain 'I am simple'
15+
end
16+
17+
# enhanced ins
18+
ins id: 'my-id', class: 'my-class' do
19+
plain 'I am enhanced'
20+
end
21+
22+
# ins with cite and datetime
23+
ins cite: 'example.html', datetime: '2008-05-25T17:25:00Z' do
24+
plain 'I have cite and datetime'
25+
end
26+
}
27+
end
28+
29+
end
30+
31+
visit '/example'
32+
33+
static_output = page.html
34+
35+
expected_static_output = <<~HTML
36+
<ins>I am simple</ins>
37+
<ins id="my-id" class="my-class">I am enhanced</ins>
38+
<ins cite="example.html" datetime="2008-05-25T17:25:00Z">I have cite and datetime</ins>
39+
HTML
40+
41+
expect(stripped(static_output)).to include(stripped(expected_static_output))
42+
end
43+
44+
it 'Example 2 - render options[:text]' do
45+
46+
class ExamplePage < Matestack::Ui::Page
47+
48+
def response
49+
components {
50+
# simple ins
51+
ins text: 'I am simple'
52+
53+
# enhanced ins
54+
ins id: 'my-id', class: 'my-class', text: 'I am enhanced'
55+
56+
# ins with cite and datetime
57+
ins cite: 'example.html', datetime: '2008-05-25T17:25:00Z', text: 'I am enhanced'
58+
}
59+
end
60+
61+
end
62+
63+
visit '/example'
64+
65+
static_output = page.html
66+
67+
expected_static_output = <<~HTML
68+
<ins>I am simple</ins>
69+
<ins id="my-id" class="my-class">I am enhanced</ins>
70+
<ins cite="example.html" datetime="2008-05-25T17:25:00Z">I have cite and datetime</ins>
71+
HTML
72+
73+
expect(stripped(static_output)).to include(stripped(expected_static_output))
74+
end
75+
76+
end

0 commit comments

Comments
 (0)