Skip to content

Commit 3ae4dac

Browse files
Merge pull request #225 from basemate/issue-183
ISSUE #183 Adds del component
2 parents 444f59e + 395bd17 commit 3ae4dac

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%del{@tag_attributes.merge({:cite => options[:cite], :datetime => options[:datetime]})}
2+
- if options[:text].nil? && block_given?
3+
= yield
4+
- else
5+
= options[:text]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Matestack::Ui::Core::Del
2+
class Del < Matestack::Ui::Core::Component::Static
3+
end
4+
end

docs/components/del.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# matestack core component: Del
2+
3+
Show [specs](/spec/usage/components/del_spec.rb)
4+
5+
The HTML del 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 del should have.
13+
14+
#### # class (optional)
15+
Expects a string with all classes the del should have.
16+
17+
#### # cite (optional)
18+
Expects a string with a URL to a document that explains the reason why the text was deleted.
19+
20+
#### # datetime (optional)
21+
Expects a string which specifies the date and time of when the text was deleted.
22+
23+
## Example 1: Yield a given block
24+
25+
```ruby
26+
del id: "foo", class: "bar" do
27+
plain 'Hello World' # optional content
28+
end
29+
```
30+
31+
returns
32+
33+
```html
34+
<del id="foo" class="bar">
35+
Hello World
36+
</del>
37+
```
38+
39+
## Example 2: Render options[:text] param
40+
41+
```ruby
42+
del id: "foo", class: "bar", text: 'Hello World'
43+
```
44+
45+
returns
46+
47+
```html
48+
<del id="foo" class="bar">
49+
Hello World
50+
</del>
51+
```

spec/usage/components/del_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+
RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = 10_000
4+
describe 'Del 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 del
13+
del cite: 'http://citeurl.com', datetime: '2019-01-01T00:00:00Z' do
14+
plain 'I am simple'
15+
end
16+
17+
# enhanced del
18+
del id: 'my-id', class: 'my-class', cite: 'http://citeurl.com', datetime: '2019-01-01T00:00:00Z' 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+
<del cite=\"http://citeurl.com\" datetime=\"2019-01-01T00:00:00Z\">I am simple</del>
32+
<del cite=\"http://citeurl.com\" datetime=\"2019-01-01T00:00:00Z\" id=\"my-id\" class=\"my-class\">I am enhanced</del>
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 del
45+
del cite: 'http://citeurl.com', datetime: '2019-01-01T00:00:00Z', text: 'I am simple'
46+
47+
# enhanced del
48+
del id: 'my-id', class: 'my-class', cite: 'http://citeurl.com', datetime: '2019-01-01T00:00:00Z', 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+
<del cite=\"http://citeurl.com\" datetime=\"2019-01-01T00:00:00Z\">I am simple</del>
60+
<del cite=\"http://citeurl.com\" datetime=\"2019-01-01T00:00:00Z\" id=\"my-id\" class=\"my-class\">I am enhanced</del>
61+
HTML
62+
63+
expect(stripped(static_output)).to include(stripped(expected_static_output))
64+
end
65+
66+
end

0 commit comments

Comments
 (0)