Skip to content

Commit 14d48d5

Browse files
committed
Add article component with docs and specs
1 parent 3d0d618 commit 14d48d5

File tree

4 files changed

+105
-0
lines changed

4 files changed

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

docs/components/article.md

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

spec/usage/components/article_spec.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
require_relative "../../support/utils"
2+
include Utils
3+
4+
describe 'Article 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+
article do
13+
paragraph text: "Hello world"
14+
end
15+
}
16+
end
17+
18+
end
19+
20+
visit '/example'
21+
static_output = page.html
22+
23+
expected_static_output = <<~HTML
24+
<article><p>Hello world</p></article>
25+
HTML
26+
expect(stripped(static_output)).to include(stripped(expected_static_output))
27+
end
28+
29+
it 'Example 2 - render options[:text]' do
30+
31+
class ExamplePage < Matestack::Ui::Page
32+
33+
def response
34+
components {
35+
article text: "Hello world"
36+
}
37+
end
38+
39+
end
40+
41+
visit '/example'
42+
43+
static_output = page.html
44+
45+
expected_static_output = <<~HTML
46+
<article>Hello world</article>
47+
HTML
48+
49+
expect(stripped(static_output)).to include(stripped(expected_static_output))
50+
end
51+
52+
end

0 commit comments

Comments
 (0)