organism-ui 0.2.15 → 0.2.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f27836996619577882186d159e7ca50cc282dddcfd8090832f901965cce8828c
4
- data.tar.gz: abb2ae83b2f31627e6df9ea53b2f5fbe9a240ea1a7ec1f6e089c97ae265789a8
3
+ metadata.gz: 45abc828f8e47547304444edd15b9ffb4ec4377feb286c5559fe4c60d6e23dfd
4
+ data.tar.gz: 411a58b849148a4f9c1635a8a318784bc25421a4b146a4911ce0bc4c1cec4dfb
5
5
  SHA512:
6
- metadata.gz: 5a4e588f073083ac3d9dc3cb735567c4e5fd7d9b899de3c33e040c0af948e68700ceba48d76d893f7ad2e2ab6ba60df8b6514749aa16d14821c5e6f787acf916
7
- data.tar.gz: ae0d450685712bc9d35669299de10c8ba0f132ec56ff03865d78004d1b7917105ffc59a041a4d70768f84c1cb4731cf96bfdb9c6c294be73b5a12bd7950e2fdd
6
+ metadata.gz: db0d57b58f82cd7cf96aa9afad5f6862f7ce8b11652e383ca1ac13b5b38c4c1d360b4c6ad9bdbb66d28926f8c9cc66f657efc16ccab365ed5df8bbd3b6ce6649
7
+ data.tar.gz: d75702678ac862483be221af7bd4a3a19fc60e502767214a14688ca2710814b893a33c1a7907857d9b6631596f13dd24425e051148249bf569656a0c57f9fb1b
@@ -674,11 +674,10 @@
674
674
  ).()
675
675
  }
676
676
  ],
677
- renderable: ->(item) {
677
+ item_renderer: ->(item) {
678
678
  content_tag(
679
679
  :div,
680
- render_group([
681
- content_tag(:p, item),
680
+ content_tag(:p, item) +
682
681
  content_tag(
683
682
  :nav,
684
683
  cell(
@@ -687,8 +686,7 @@
687
686
  path: '#',
688
687
  size: :small
689
688
  ).call(:edit)
690
- )
691
- ]),
689
+ ),
692
690
  class: 'flex flex-row justify-between items-center p-4'
693
691
  )
694
692
  }
data/lib/ui.rb CHANGED
@@ -4,6 +4,8 @@ require "cells-erb"
4
4
  require "cells-rails"
5
5
  require 'dry-struct'
6
6
 
7
+ require "ui/errors/base"
8
+
7
9
  require "ui/types"
8
10
  require "ui/value"
9
11
 
data/lib/ui/actionable.rb CHANGED
@@ -2,18 +2,25 @@ module Ui
2
2
  module Actionable
3
3
  Actions = Types::Array.default([].freeze).of(Types::Callable)
4
4
 
5
- def actions
5
+ def actions(object = model)
6
6
  content_tag(:nav, class: 'ui-actions', role: 'navigation') do
7
7
  render_group(
8
- Actions[actions_list].map do |action|
9
- action.call(model)
8
+ actions_list.map do |action|
9
+ action.call(object)
10
10
  end
11
11
  )
12
12
  end
13
13
  end
14
14
 
15
15
  def actions_list
16
- options.fetch(:actions, Array.new) || Array.new
16
+ begin
17
+ Actions[options.fetch(:actions, Array.new)]
18
+ rescue Dry::Types::ConstraintError
19
+ raise Ui::Errors::InvalidActions.new(
20
+ "Actions for #{self.class.to_s} are invalid. Ensure you are passing " \
21
+ "an array of callable objects that will be passed a model"
22
+ )
23
+ end
17
24
  end
18
25
 
19
26
  def actions_length
@@ -1,9 +1,9 @@
1
1
  module Ui
2
2
  class Breadcrumbs < Component
3
+ include Stylable
4
+
3
5
  def show
4
- content_tag(:nav, class: 'ui-breadcrumbs') do
5
- breadcrumb_links
6
- end
6
+ content_tag(:nav, render_group(breadcrumb_links.flatten), class: style)
7
7
  end
8
8
 
9
9
  private
@@ -13,13 +13,11 @@ module Ui
13
13
  end
14
14
 
15
15
  def breadcrumb_links
16
- render_group(
17
- breadcrumbs.map.with_index do |crumb, index|
18
- [item_renderer.call(crumb)].tap do |renderable|
19
- renderable.unshift(delimiter) unless index == 0
20
- end
21
- end.flatten
22
- )
16
+ breadcrumbs.map.with_index do |crumb, index|
17
+ [item_renderer.call(crumb)].tap do |array|
18
+ array.unshift(delimiter) unless index == 0
19
+ end
20
+ end
23
21
  end
24
22
 
25
23
  def delimiter
@@ -27,7 +25,20 @@ module Ui
27
25
  end
28
26
 
29
27
  def item_renderer
30
- options[:item_renderer] || Ui::Breadcrumbs::Breadcrumb
28
+ options[:item_renderer] || default_item_renderer
29
+ end
30
+
31
+ def default_item_renderer
32
+ ->(item) {
33
+ cell(
34
+ Ui::Breadcrumbs::Breadcrumb,
35
+ item
36
+ ).()
37
+ }
38
+ end
39
+
40
+ def component_style
41
+ 'ui-breadcrumbs'
31
42
  end
32
43
  end
33
44
  end
@@ -1,6 +1,8 @@
1
1
  module Ui
2
2
  class Breadcrumbs < Component
3
3
  class Breadcrumb < Component
4
+ include Stylable
5
+
4
6
  property :name
5
7
  property :path
6
8
  property :current?
@@ -9,7 +11,7 @@ module Ui
9
11
  def show
10
12
  content_tag(
11
13
  :span,
12
- link_to(path, title),
14
+ link_to(render_group(title), path),
13
15
  class: style
14
16
  )
15
17
  end
@@ -17,17 +19,19 @@ module Ui
17
19
  private
18
20
 
19
21
  def title
20
- [name].tap do |array|
21
- array.unshift(content_tag(:i, nil, class: icon)) if model.try(:icon)
22
- end.join(' ')
22
+ [content_tag(:span, name)].tap do |array|
23
+ array.unshift(content_tag(:i, nil, class: icon)) if has_icon?
24
+ end
23
25
  end
24
26
 
25
- def style
26
- [
27
- 'breadcrumb'
28
- ].tap do |array|
29
- array << 'breadcrumb--current' if current?
30
- end
27
+ def has_icon?
28
+ model.try(:icon)
29
+ end
30
+
31
+ def component_style
32
+ ['ui-breadcrumb'].tap do |array|
33
+ array << 'ui-breadcrumb--current' if current?
34
+ end.join(' ')
31
35
  end
32
36
  end
33
37
  end
data/lib/ui/card.rb CHANGED
@@ -16,9 +16,7 @@ module Ui
16
16
  end
17
17
 
18
18
  def card_actions
19
- content_tag(:nav, class: "ui-card__controls") do
20
- actions
21
- end if has_actions?
19
+ actions if has_actions?
22
20
  end
23
21
 
24
22
  def title
@@ -5,19 +5,33 @@ module Ui
5
5
  content_tag(
6
6
  :div,
7
7
  render_group([
8
- content_tag(:dt, title),
8
+ content_tag(:dt, item_title),
9
9
  content_tag(:dd, value)
10
10
  ]),
11
11
  class: 'ui-descriptive-list__item'
12
12
  )
13
13
  end
14
14
 
15
- def title
15
+ def value
16
+ render_group([
17
+ display(item_value)
18
+ ])
19
+ end
20
+
21
+ def display(value)
22
+ if value.is_a?(Proc)
23
+ value.call
24
+ else
25
+ value
26
+ end
27
+ end
28
+
29
+ def item_title
16
30
  model[0]
17
31
  end
18
32
 
19
- def value
20
- model[1].try(:call) || model[1]
33
+ def item_value
34
+ model[1]
21
35
  end
22
36
  end
23
37
  end
data/lib/ui/dropdown.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Ui
2
2
  class Dropdown < Component
3
+ include Stylable
4
+
3
5
  Modes = Types::String.enum(
4
6
  'click',
5
7
  'hover'
@@ -18,5 +20,9 @@ module Ui
18
20
  def mode
19
21
  Modes[options.fetch(:mode, 'click')]
20
22
  end
23
+
24
+ def component_style
25
+ "ui-dropdown"
26
+ end
21
27
  end
22
28
  end
@@ -4,7 +4,7 @@
4
4
  data-dropdown-expanded-value="false"
5
5
  data-dropdown-mode-value="<%= mode %>"
6
6
  data-action="click->dropdown#toggle"
7
- class="ui-dropdown">
7
+ class="<%= style %>">
8
8
  <%= yield %>
9
9
 
10
10
  <div data-dropdown-target="expandable" class="ui-dropdown__expandable">
@@ -4,8 +4,6 @@
4
4
 
5
5
  <figcaption>
6
6
  <%= caption %>
7
- <nav>
8
- <%= actions %>
9
- </nav>
7
+ <%= actions %>
10
8
  </figcaption>
11
9
  </figure>
@@ -0,0 +1,6 @@
1
+ module Ui
2
+ module Errors
3
+ class Base < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Ui
2
+ module Errors
3
+ class InvalidActions < Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Ui
2
+ module Errors
3
+ class InvalidListItems < Base
4
+ end
5
+ end
6
+ end
data/lib/ui/list.rb CHANGED
@@ -4,6 +4,7 @@ module Ui
4
4
  include Actionable
5
5
 
6
6
  Renderable = Types.Interface(:call)
7
+ ListItems = Types.Interface(:each, :map, :any?)
7
8
 
8
9
  def show
9
10
  render
@@ -11,21 +12,32 @@ module Ui
11
12
 
12
13
  private
13
14
 
15
+ def list_data
16
+ begin
17
+ ListItems[model]
18
+ rescue Dry::Types::ConstraintError
19
+ raise Ui::Errors::InvalidListItems.new(
20
+ "List items for #{self.class.to_s} are invalid. Ensure you are passing " \
21
+ "an empty array or array of items that will be passed to the item renderer"
22
+ )
23
+ end
24
+ end
25
+
14
26
  def list
15
27
  content_tag(:ul, list_items)
16
28
  end
17
29
 
18
30
  def list_items
19
- if list_data.any?
20
- render_group(list_data)
31
+ if rendered_items.any?
32
+ render_group(rendered_items)
21
33
  else
22
34
  render_empty
23
35
  end
24
36
  end
25
37
 
26
- def list_data
27
- model.map do |item|
28
- renderable.call(item)
38
+ def rendered_items
39
+ list_data.map do |item|
40
+ item_renderer.call(item)
29
41
  end
30
42
  end
31
43
 
@@ -46,8 +58,8 @@ module Ui
46
58
  ) if options[:footer]
47
59
  end
48
60
 
49
- def renderable
50
- Renderable[options.fetch(:renderable, default_renderable)]
61
+ def item_renderer
62
+ Renderable[options.fetch(:item_renderer, default_renderable)]
51
63
  end
52
64
 
53
65
  def default_renderable
@@ -60,7 +60,7 @@ module Ui
60
60
  def page_links
61
61
  render_group(
62
62
  pages.map do |page|
63
- content += content_tag(
63
+ content_tag(
64
64
  :li,
65
65
  cell(
66
66
  Ui::Pagination::PageLink,
data/lib/ui/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ui
2
- VERSION = '0.2.15'
2
+ VERSION = '0.2.16'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: organism-ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.15
4
+ version: 0.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nolan Tait
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-22 00:00:00.000000000 Z
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -215,6 +215,9 @@ files:
215
215
  - lib/ui/empty.rb
216
216
  - lib/ui/empty/show.erb
217
217
  - lib/ui/engine.rb
218
+ - lib/ui/errors/base.rb
219
+ - lib/ui/errors/invalid_actions.rb
220
+ - lib/ui/errors/invalid_list_items.rb
218
221
  - lib/ui/list.rb
219
222
  - lib/ui/list/item.rb
220
223
  - lib/ui/list/show.erb
@@ -260,7 +263,7 @@ homepage: https://github.com/nolantait/organism-ui
260
263
  licenses:
261
264
  - MIT
262
265
  metadata: {}
263
- post_install_message:
266
+ post_install_message:
264
267
  rdoc_options: []
265
268
  require_paths:
266
269
  - lib
@@ -276,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
276
279
  version: '0'
277
280
  requirements: []
278
281
  rubygems_version: 3.1.4
279
- signing_key:
282
+ signing_key:
280
283
  specification_version: 4
281
284
  summary: A collection of ui components implemented in cells.
282
285
  test_files: []