Skip to content

Commit

Permalink
Add address tag, specs and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrevans committed Aug 5, 2019
1 parent cf82a65 commit cecae31
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/concepts/matestack/ui/core/address/address.haml
@@ -0,0 +1,5 @@
%address{@tag_attributes}
- if options[:text].nil? && block_given?
= yield
- else
= options[:text]
5 changes: 5 additions & 0 deletions app/concepts/matestack/ui/core/address/address.rb
@@ -0,0 +1,5 @@
module Matestack::Ui::Core::Address
class Address < Matestack::Ui::Core::Component::Static

end
end
51 changes: 51 additions & 0 deletions docs/components/address.md
@@ -0,0 +1,51 @@
# matestack core component: Address

Show [specs](../../spec/usage/components/address_spec.rb)

The HTML `<address>` tag implemented in ruby.

## Parameters

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

#### # id (optional)
Expects a string with all ids the address should have.

#### # class (optional)
Expects a string with all classes the address should have.

## Example 1 - yield a given block

```ruby
address do
plain 'Codey McCodeface'
br
plain '1 Developer Avenue'
br
plain 'Techville'
end
```

returns

```html
<address>
Codey McCodeface<br>
1 Developer Avenue<br>
Techville
</address>
```

## Example 2 - render options[:text] param

```ruby
address text: 'PO Box 12345'
```

returns

```html
<address>
PO Box 12345
</address>
```
58 changes: 58 additions & 0 deletions spec/usage/components/address_spec.rb
@@ -0,0 +1,58 @@
require_relative '../../support/utils'
include Utils

describe 'Address Component', type: :feature, js: true do

it 'Example 1 - yield a given block' do

class ExamplePage < Matestack::Ui::Page

def response
components {
address do
plain 'Codey McCodeface'
br
plain '1 Developer Avenue'
br
plain 'Techville'
end
}
end

end

visit '/example'

static_output = page.html

expected_static_output = <<~HTML
<address>Codey McCodeface<br>1 Developer Avenue<br>Techville</address>
HTML

expect(stripped(static_output)).to include(stripped(expected_static_output))
end

it 'Example 2 - render options[:text] param' do

class ExamplePage < Matestack::Ui::Page

def response
components {
address text: 'PO Box 12345'
}
end

end

visit '/example'

static_output = page.html

expected_static_output = <<~HTML
<address>PO Box 12345</address>
HTML

expect(stripped(static_output)).to include(stripped(expected_static_output))
end

end

0 comments on commit cecae31

Please sign in to comment.