Skip to content

Commit 7c31ffe

Browse files
Merge pull request #236 from basemate/add-sup-tag
Add <sup> tag
2 parents 21b533d + dcbe462 commit 7c31ffe

File tree

6 files changed

+131
-2
lines changed

6 files changed

+131
-2
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
matestack-ui-core (0.7.1)
4+
matestack-ui-core (0.7.2.1)
55
cells-haml
66
cells-rails
77
haml
@@ -123,7 +123,7 @@ GEM
123123
mini_mime (1.0.1)
124124
mini_portile2 (2.4.0)
125125
minitest (5.11.3)
126-
nio4r (2.4.0)
126+
nio4r (2.5.2)
127127
nokogiri (1.10.4)
128128
mini_portile2 (~> 2.4.0)
129129
pipetree (0.1.1)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%sup{@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::Sup
2+
class Sup < Matestack::Ui::Core::Component::Static
3+
4+
end
5+
end

docs/components/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ You can build your [own components](/docs/extend/custom_components.md) as well,
3838
- [rp](/docs/components/rt.md)
3939
- [legend](/docs/components/legend.md)
4040
- [noscript](/docs/components/noscript.md)
41+
- [sup](/docs/components/sup.md)
42+
- [sub](/docs/components/sub.md)
4143

4244
## Dynamic Core Components
4345

docs/components/sup.md

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

spec/usage/components/sup_spec.rb

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

0 commit comments

Comments
 (0)