Skip to content

Commit b811cb3

Browse files
authored
Merge pull request #74 from basemate/update_span_component
Update span component in 0.7.0
2 parents 6d406f9 + 7b7a52d commit b811cb3

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
matestack-ui-core (0.6.0)
4+
matestack-ui-core (0.7.0)
55
cells-haml
66
cells-rails
77
haml
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
%span{@tag_attributes}
2-
- if block_given?
2+
- if options[:text].nil? && block_given?
33
= yield
4+
- else
5+
= options[:text]

docs/components/span.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ The HTML span tag implemented in ruby.
66

77
## Parameters
88

9-
This component can take 2 optional configuration params and optional content.
9+
This component can take 2 optional configuration params and either yield content or display what gets passed to the `text` configuration param.
1010

1111
#### # id (optional)
1212
Expects a string with all ids the span should have.
1313

1414
#### # class (optional)
1515
Expects a string with all classes the span should have.
1616

17-
## Example
17+
## Example 1: Yield a given block
1818

1919
```ruby
2020
span id: "foo", class: "bar" do
@@ -29,3 +29,16 @@ returns
2929
Hello World
3030
</span>
3131
```
32+
33+
## Example 2: Render options[:text] param
34+
35+
```ruby
36+
span id: "foo", class: "bar", text: 'Hello World'
37+
```
38+
39+
returns
40+
41+
```html
42+
<span id="foo" class="bar">
43+
Hello World
44+
</span>

spec/usage/components/span_spec.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
describe 'Span Component', type: :feature, js: true do
55

6-
it 'Example 1' do
6+
it 'Example 1 - yield, no options[:text]' do
77

88
class ExamplePage < Matestack::Ui::Page
99

@@ -35,4 +35,32 @@ def response
3535
expect(stripped(static_output)).to include(stripped(expected_static_output))
3636
end
3737

38+
it 'Example 2 - render options[:text]' do
39+
40+
class ExamplePage < Matestack::Ui::Page
41+
42+
def response
43+
components {
44+
# simple span
45+
span text: 'I am simple'
46+
47+
# enhanced span
48+
span 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+
<span>I am simple</span>
60+
<span id="my-id" class="my-class">I am enhanced</span>
61+
HTML
62+
63+
expect(stripped(static_output)).to include(stripped(expected_static_output))
64+
end
65+
3866
end

0 commit comments

Comments
 (0)