Skip to content

Commit 9897611

Browse files
Merge pull request #227 from tae8838/add-pre-tag
add pre tag
2 parents 824a576 + f9db3e3 commit 9897611

File tree

4 files changed

+103
-0
lines changed

4 files changed

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

docs/components/pre.md

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

spec/usage/components/pre_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require_relative '../../support/utils'
2+
include Utils
3+
4+
describe 'Pre Component', type: :feature, js: true do
5+
it 'Example 1 - yield a given block' do
6+
class ExamplePage < Matestack::Ui::Page
7+
def response
8+
components {
9+
pre do
10+
plain 'This is preformatted text'
11+
end
12+
}
13+
end
14+
end
15+
16+
visit '/example'
17+
18+
static_output = page.html
19+
20+
expected_static_output = <<~HTML
21+
<pre>This is preformatted text</pre>
22+
HTML
23+
p stripped(static_output)
24+
expect(stripped(static_output)).to include(stripped(expected_static_output))
25+
end
26+
27+
it 'Example 2 - render options[:text] param' do
28+
class ExamplePage < Matestack::Ui::Page
29+
def response
30+
components {
31+
pre text: 'This is preformatted text'
32+
}
33+
end
34+
end
35+
36+
visit '/example'
37+
38+
static_output = page.html
39+
40+
expected_static_output = <<~HTML
41+
<pre>This is preformatted text</pre>
42+
HTML
43+
44+
expect(stripped(static_output)).to include(stripped(expected_static_output))
45+
end
46+
end

0 commit comments

Comments
 (0)