Skip to content

Commit 649901e

Browse files
Merge pull request #87 from basemate/add-small-tags
Add small tags
2 parents c54c38d + c84ace8 commit 649901e

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%small{@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::Small
2+
class Small < Matestack::Ui::Core::Component::Static
3+
4+
end
5+
end

docs/components/small.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# matestack core component: Small
2+
3+
Show [specs](../../spec/usage/components/small_spec.rb)
4+
5+
The HTML small 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+
Expects a string with all ids the small tag should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the small tag should have.
16+
17+
## Example 1: Yield a given block
18+
19+
```ruby
20+
small id: "foo", class: "bar" do
21+
plain 'Hello World' # optional content
22+
end
23+
```
24+
25+
returns
26+
27+
```html
28+
<small id="foo" class="bar">Hello World</small>
29+
```
30+
31+
## Example 2: Render options[:text] param
32+
33+
```ruby
34+
small id: "foo", class: "bar", text: 'Hello World'
35+
```
36+
37+
returns
38+
39+
```html
40+
<small id="foo" class="bar">Hello World</small>

spec/usage/components/small_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 'Small 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 small tag
13+
small do
14+
plain 'I am a simple small tag'
15+
end
16+
17+
# enhanced small tag
18+
small id: 'my-id', class: 'my-class' do
19+
plain 'I am a enhanced small tag'
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+
<small>I am a simple small tag</small>
32+
<small id="my-id" class="my-class">I am a enhanced small tag</small>
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 small
45+
small text: 'I am a simple small tag'
46+
47+
# enhanced small
48+
small id: 'my-id', class: 'my-class', text: 'I am enhanced small tag'
49+
}
50+
end
51+
52+
end
53+
54+
visit '/example'
55+
56+
static_output = page.html
57+
58+
expected_static_output = <<~HTML
59+
<small>I am a simple small tag</small>
60+
<small id="my-id" class="my-class">I am enhanced small tag</small>
61+
HTML
62+
63+
expect(stripped(static_output)).to include(stripped(expected_static_output))
64+
end
65+
66+
end

0 commit comments

Comments
 (0)