From cecae312d626b9e6f8967f631825754fe03c29df Mon Sep 17 00:00:00 2001 From: Michael Evans Date: Sun, 4 Aug 2019 11:49:06 +0200 Subject: [PATCH] Add address tag, specs and documentation --- .../matestack/ui/core/address/address.haml | 5 ++ .../matestack/ui/core/address/address.rb | 5 ++ docs/components/address.md | 51 ++++++++++++++++ spec/usage/components/address_spec.rb | 58 +++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 app/concepts/matestack/ui/core/address/address.haml create mode 100644 app/concepts/matestack/ui/core/address/address.rb create mode 100644 docs/components/address.md create mode 100644 spec/usage/components/address_spec.rb diff --git a/app/concepts/matestack/ui/core/address/address.haml b/app/concepts/matestack/ui/core/address/address.haml new file mode 100644 index 000000000..8ae3ed0ca --- /dev/null +++ b/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] diff --git a/app/concepts/matestack/ui/core/address/address.rb b/app/concepts/matestack/ui/core/address/address.rb new file mode 100644 index 000000000..cb0c3a15a --- /dev/null +++ b/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 diff --git a/docs/components/address.md b/docs/components/address.md new file mode 100644 index 000000000..2b584fdad --- /dev/null +++ b/docs/components/address.md @@ -0,0 +1,51 @@ +# matestack core component: Address + +Show [specs](../../spec/usage/components/address_spec.rb) + +The HTML `
` 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 +
+ Codey McCodeface
+ 1 Developer Avenue
+ Techville +
+``` + +## Example 2 - render options[:text] param + +```ruby +address text: 'PO Box 12345' +``` + +returns + +```html +
+ PO Box 12345 +
+``` diff --git a/spec/usage/components/address_spec.rb b/spec/usage/components/address_spec.rb new file mode 100644 index 000000000..4b1700030 --- /dev/null +++ b/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 +
Codey McCodeface
1 Developer Avenue
Techville
+ 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 +
PO Box 12345
+ HTML + + expect(stripped(static_output)).to include(stripped(expected_static_output)) + end + + end