protos 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -5
  3. data/CHANGELOG.md +11 -0
  4. data/README.md +26 -7
  5. data/benchmarks/.keep +0 -0
  6. data/benchmarks/table.txt +12 -0
  7. data/examples/list.rb +2 -0
  8. data/lib/protos/accordion/item.rb +5 -6
  9. data/lib/protos/accordion.rb +6 -10
  10. data/lib/protos/alert/actions.rb +2 -2
  11. data/lib/protos/alert/icon.rb +2 -2
  12. data/lib/protos/alert.rb +4 -8
  13. data/lib/protos/attributes.rb +7 -8
  14. data/lib/protos/breadcrumbs/crumb.rb +2 -2
  15. data/lib/protos/breadcrumbs.rb +1 -3
  16. data/lib/protos/card/actions.rb +2 -2
  17. data/lib/protos/card/body.rb +2 -2
  18. data/lib/protos/card/image.rb +2 -2
  19. data/lib/protos/card/title.rb +2 -2
  20. data/lib/protos/card.rb +6 -14
  21. data/lib/protos/carousel/actions.rb +2 -2
  22. data/lib/protos/carousel/item.rb +2 -2
  23. data/lib/protos/carousel.rb +4 -8
  24. data/lib/protos/chat_bubble/content.rb +2 -2
  25. data/lib/protos/chat_bubble/footer.rb +2 -2
  26. data/lib/protos/chat_bubble/header.rb +2 -2
  27. data/lib/protos/chat_bubble/image.rb +2 -2
  28. data/lib/protos/chat_bubble.rb +6 -14
  29. data/lib/protos/collapse/content.rb +2 -2
  30. data/lib/protos/collapse/title.rb +3 -3
  31. data/lib/protos/collapse.rb +2 -6
  32. data/lib/protos/combobox.rb +8 -24
  33. data/lib/protos/command/empty.rb +2 -2
  34. data/lib/protos/command/item.rb +2 -2
  35. data/lib/protos/command/list.rb +2 -2
  36. data/lib/protos/command/title.rb +2 -2
  37. data/lib/protos/command/trigger.rb +2 -2
  38. data/lib/protos/command.rb +10 -26
  39. data/lib/protos/component.rb +21 -30
  40. data/lib/protos/drawer/content.rb +2 -2
  41. data/lib/protos/drawer/trigger.rb +2 -2
  42. data/lib/protos/drawer.rb +3 -9
  43. data/lib/protos/dropdown/item.rb +2 -2
  44. data/lib/protos/dropdown.rb +3 -9
  45. data/lib/protos/hero/content.rb +2 -2
  46. data/lib/protos/hero/overlay.rb +2 -2
  47. data/lib/protos/hero.rb +4 -8
  48. data/lib/protos/list/item.rb +2 -2
  49. data/lib/protos/list.rb +3 -5
  50. data/lib/protos/modal/trigger.rb +2 -2
  51. data/lib/protos/modal.rb +5 -11
  52. data/lib/protos/popover/content.rb +2 -0
  53. data/lib/protos/popover/trigger.rb +2 -2
  54. data/lib/protos/popover.rb +4 -8
  55. data/lib/protos/stats/actions.rb +2 -2
  56. data/lib/protos/stats/description.rb +2 -2
  57. data/lib/protos/stats/figure.rb +2 -2
  58. data/lib/protos/stats/stat.rb +2 -2
  59. data/lib/protos/stats/title.rb +2 -2
  60. data/lib/protos/stats/value.rb +2 -2
  61. data/lib/protos/stats.rb +8 -20
  62. data/lib/protos/swap/off.rb +2 -2
  63. data/lib/protos/swap/on.rb +2 -2
  64. data/lib/protos/swap.rb +2 -6
  65. data/lib/protos/table/body.rb +2 -2
  66. data/lib/protos/table/caption.rb +3 -3
  67. data/lib/protos/table/cell.rb +2 -2
  68. data/lib/protos/table/footer.rb +2 -2
  69. data/lib/protos/table/head.rb +2 -2
  70. data/lib/protos/table/header.rb +2 -2
  71. data/lib/protos/table/row.rb +2 -2
  72. data/lib/protos/table.rb +7 -21
  73. data/lib/protos/tabs/tab.rb +3 -3
  74. data/lib/protos/tabs.rb +3 -5
  75. data/lib/protos/theme.rb +38 -45
  76. data/lib/protos/timeline/center.rb +2 -2
  77. data/lib/protos/timeline/item.rb +2 -2
  78. data/lib/protos/timeline/left.rb +2 -2
  79. data/lib/protos/timeline/right.rb +2 -2
  80. data/lib/protos/timeline.rb +6 -14
  81. data/lib/protos/toast/close_button.rb +1 -0
  82. data/lib/protos/toast.rb +3 -5
  83. data/lib/protos/token_list.rb +18 -31
  84. data/lib/protos/typography/heading.rb +2 -2
  85. data/lib/protos/typography/inline_link.rb +3 -3
  86. data/lib/protos/typography/paragraph.rb +2 -2
  87. data/lib/protos/typography.rb +12 -12
  88. data/lib/protos/version.rb +1 -1
  89. data/protos.gemspec +14 -2
  90. metadata +6 -4
@@ -6,41 +6,25 @@ module Protos
6
6
  # filterable list of commands. Command modals are by default closable by
7
7
  # clicking the overlay rather than a specific close button.
8
8
 
9
- def view_template(&block)
10
- div(**attrs, &block)
9
+ def view_template(&)
10
+ div(**attrs, &)
11
11
  end
12
12
 
13
- def input(...)
14
- Input.new(...)
15
- end
13
+ def input(...) = render Input.new(...)
16
14
 
17
- def list(...)
18
- List.new(...)
19
- end
15
+ def list(...) = render List.new(...)
20
16
 
21
- def trigger(...)
22
- Trigger.new(...)
23
- end
17
+ def trigger(...) = render Trigger.new(...)
24
18
 
25
- def dialog(...)
26
- Dialog.new(...)
27
- end
19
+ def dialog(...) = render Dialog.new(...)
28
20
 
29
- def title(...)
30
- Title.new(...)
31
- end
21
+ def title(...) = render Title.new(...)
32
22
 
33
- def group(...)
34
- Group.new(...)
35
- end
23
+ def group(...) = render Group.new(...)
36
24
 
37
- def item(...)
38
- Item.new
39
- end
25
+ def item(...) = render Item.new(...)
40
26
 
41
- def empty(...)
42
- Empty.new(...)
43
- end
27
+ def empty(...) = render Empty.new(...)
44
28
 
45
29
  private
46
30
 
@@ -21,35 +21,24 @@ module Protos
21
21
  default_attrs_method :default_attrs
22
22
 
23
23
  # Theme can override the css hash and add additional styles
24
- option :theme, as: :theme_override, default: -> { {} }, reader: :private
24
+ option :theme, as: :theme_override, default: -> { {} }, reader: false
25
25
  # Class becomes the :container key in the css hash
26
- option :class, as: :container_class, default: -> { "" }, reader: :private
27
- option :html_options, default: -> { {} }, reader: :private
26
+ option :class, as: :container_class, default: -> { "" }, reader: false
27
+ option :html_options, default: -> { {} }, reader: false
28
28
 
29
29
  # Adds non-defined options to the html_options hash
30
- def initialize(*args, **kwargs, &block)
31
- raise_block_in_initializer_error if block
32
-
30
+ def initialize(*args, **kwargs, &)
33
31
  defined_keys = self.class.dry_initializer.definitions.keys
34
32
  defined, undefined =
35
33
  kwargs
36
34
  .partition { |key, _| defined_keys.include?(key) }
37
- .map(&:to_h)
35
+ .map!(&:to_h)
38
36
 
39
- super(*args, html_options: undefined, **defined)
37
+ super(*args, html_options: undefined, **defined, &)
40
38
  end
41
39
 
42
40
  private
43
41
 
44
- def raise_block_in_initializer_error
45
- raise(
46
- ArgumentError,
47
- "It is unexpected to pass a block to the initializer of a component. " \
48
- "You might have tried to render and passed a block but it went to " \
49
- "the component.new. Check your render call."
50
- )
51
- end
52
-
53
42
  def attrs
54
43
  @attrs ||= build_attrs
55
44
  end
@@ -59,33 +48,35 @@ module Protos
59
48
  end
60
49
 
61
50
  def build_attrs(...)
62
- defaults = if respond_to?(
63
- self.class.default_attrs_method,
64
- :include_private
65
- )
66
- send(self.class.default_attrs_method)
51
+ defaults = if respond_to?(default_attrs_method, :include_private)
52
+ send(default_attrs_method)
67
53
  end
68
54
 
69
55
  Attributes
70
56
  .new(...)
71
57
  .merge(defaults)
72
- .merge(html_options)
58
+ .merge(@html_options)
73
59
  .merge(class: css[:container])
74
60
  end
75
61
 
76
62
  def build_theme(...)
77
- component_style = if respond_to?(
78
- self.class.theme_method,
79
- :include_private
80
- )
81
- send(self.class.theme_method)
63
+ component_style = if respond_to?(theme_method, :include_private)
64
+ send(theme_method)
82
65
  end
83
66
 
84
67
  Theme
85
68
  .new(...)
86
69
  .merge(component_style)
87
- .merge(theme_override)
88
- .merge(container: container_class)
70
+ .merge(@theme_override)
71
+ .merge(container: @container_class)
72
+ end
73
+
74
+ def theme_method
75
+ self.class.theme_method
76
+ end
77
+
78
+ def default_attrs_method
79
+ self.class.default_attrs_method
89
80
  end
90
81
  end
91
82
  end
@@ -6,8 +6,8 @@ module Protos
6
6
  # DOCS: The content of a drawer. This would be visible at all times and
7
7
  # represents the main content of your page.
8
8
 
9
- def view_template(&block)
10
- div(**attrs, &block)
9
+ def view_template(&)
10
+ div(**attrs, &)
11
11
  end
12
12
 
13
13
  private
@@ -8,8 +8,8 @@ module Protos
8
8
 
9
9
  option :id, type: Types::Coercible::String
10
10
 
11
- def view_template(&block)
12
- label(for: id, **attrs, &block)
11
+ def view_template(&)
12
+ label(for: id, **attrs, &)
13
13
  end
14
14
 
15
15
  private
data/lib/protos/drawer.rb CHANGED
@@ -16,17 +16,11 @@ module Protos
16
16
  end
17
17
  end
18
18
 
19
- def content(...)
20
- Content.new(...)
21
- end
19
+ def content(...) = render Content.new(...)
22
20
 
23
- def side(*args, **kwargs, &block)
24
- Side.new(*args, id:, **kwargs, &block)
25
- end
21
+ def side(*, **, &) = render Side.new(*, id:, **, &)
26
22
 
27
- def trigger(*args, **kwargs, &block)
28
- Trigger.new(*args, id:, **kwargs, &block)
29
- end
23
+ def trigger(*, **, &) = render Trigger.new(*, id:, **, &)
30
24
 
31
25
  private
32
26
 
@@ -5,8 +5,8 @@ module Protos
5
5
  class Item < Component
6
6
  # DOCS: A single item within a dropdown
7
7
 
8
- def view_template(&block)
9
- li(**attrs, &block)
8
+ def view_template(&)
9
+ li(**attrs, &)
10
10
  end
11
11
  end
12
12
  end
@@ -19,16 +19,10 @@ module Protos
19
19
  reader: false,
20
20
  type: TriggerTypes | Types::Array.of(TriggerTypes)
21
21
 
22
- def item(...)
23
- Item.new(...)
24
- end
22
+ def item(...) = render Item.new(...)
25
23
 
26
- def menu(...)
27
- Menu.new(...)
28
- end
24
+ def menu(...) = render Menu.new(...)
29
25
 
30
- def trigger(...)
31
- Trigger.new(...)
32
- end
26
+ def trigger(...) = render Trigger.new(...)
33
27
  end
34
28
  end
@@ -6,8 +6,8 @@ module Protos
6
6
  # DOCS: The content of a hero. This would be centered within the main
7
7
  # component container.
8
8
 
9
- def view_template(&block)
10
- div(**attrs, &block)
9
+ def view_template(&)
10
+ div(**attrs, &)
11
11
  end
12
12
 
13
13
  private
@@ -7,8 +7,8 @@ module Protos
7
7
  # their opacity through the opacity of the overlay. This can be useful to
8
8
  # make text readable on noisy images.
9
9
 
10
- def view_template(&block)
11
- div(**attrs, &block)
10
+ def view_template(&)
11
+ div(**attrs, &)
12
12
  end
13
13
 
14
14
  private
data/lib/protos/hero.rb CHANGED
@@ -6,17 +6,13 @@ module Protos
6
6
  # optionally layout an image for a responsive layout.
7
7
  # https://daisyui.com/components/hero/
8
8
 
9
- def view_template(&block)
10
- div(**attrs, &block)
9
+ def view_template(&)
10
+ div(**attrs, &)
11
11
  end
12
12
 
13
- def content(...)
14
- Content.new(...)
15
- end
13
+ def content(...) = render Content.new(...)
16
14
 
17
- def overlay(...)
18
- Overlay.new(...)
19
- end
15
+ def overlay(...) = render Overlay.new(...)
20
16
 
21
17
  private
22
18
 
@@ -7,8 +7,8 @@ module Protos
7
7
  # work for list items, including border radius. E.g. only the first and
8
8
  # last items will have border radius on the top and bottom.
9
9
 
10
- def view_template(&block)
11
- li(**attrs, &block)
10
+ def view_template(&)
11
+ li(**attrs, &)
12
12
  end
13
13
 
14
14
  private
data/lib/protos/list.rb CHANGED
@@ -7,13 +7,11 @@ module Protos
7
7
 
8
8
  option :ordered, Types::Bool, default: -> { false }, reader: false
9
9
 
10
- def view_template(&block)
11
- send(element, **attrs, &block)
10
+ def view_template(&)
11
+ send(element, **attrs, &)
12
12
  end
13
13
 
14
- def item(...)
15
- Item.new(...)
16
- end
14
+ def item(...) = render Item.new(...)
17
15
 
18
16
  private
19
17
 
@@ -5,8 +5,8 @@ module Protos
5
5
  class Trigger < Component
6
6
  # DOCS: A trigger is a button that opens a modal
7
7
 
8
- def view_template(&block)
9
- button(**attrs, &block)
8
+ def view_template(&)
9
+ button(**attrs, &)
10
10
  end
11
11
 
12
12
  private
data/lib/protos/modal.rb CHANGED
@@ -5,21 +5,15 @@ module Protos
5
5
  # DOCS: A modal component that can be triggered by a button or a link and
6
6
  # will open a fullscreen modal, usually with a close button.
7
7
 
8
- def view_template(&block)
9
- div(**attrs, class: css[:container], &block)
8
+ def view_template(&)
9
+ div(**attrs, class: css[:container], &)
10
10
  end
11
11
 
12
- def close_button(...)
13
- CloseButton.new(...)
14
- end
12
+ def close_button(...) = render CloseButton.new(...)
15
13
 
16
- def dialog(...)
17
- Dialog.new(...)
18
- end
14
+ def dialog(...) = render Dialog.new(...)
19
15
 
20
- def trigger(...)
21
- Trigger.new(...)
22
- end
16
+ def trigger(...) = render Trigger.new(...)
23
17
 
24
18
  private
25
19
 
@@ -7,6 +7,8 @@ module Protos
7
7
  # added to the DOM by tippy.js to handle the position of the content.
8
8
  # This means content in here will not be available in system tests that
9
9
  # use rack_test.
10
+ #
11
+ # TODO: Move away from using template
10
12
 
11
13
  def view_template(&block)
12
14
  template_tag(**template_attrs) do
@@ -6,8 +6,8 @@ module Protos
6
6
  # DOCS: The trigger of a popover. This is the element that you would hover
7
7
  # or click on to show the popover.
8
8
 
9
- def view_template(&block)
10
- div(**attrs, &block)
9
+ def view_template(&)
10
+ div(**attrs, &)
11
11
  end
12
12
 
13
13
  private
@@ -80,17 +80,13 @@ module Protos
80
80
  reader: false,
81
81
  type: TriggerTypes | Types::Array.of(TriggerTypes)
82
82
 
83
- def view_template(&block)
84
- div(**attrs, &block)
83
+ def view_template(&)
84
+ div(**attrs, &)
85
85
  end
86
86
 
87
- def content(...)
88
- Content.new(...)
89
- end
87
+ def content(...) = render Content.new(...)
90
88
 
91
- def trigger(...)
92
- Trigger.new(...)
93
- end
89
+ def trigger(...) = render Trigger.new(...)
94
90
 
95
91
  private
96
92
 
@@ -5,8 +5,8 @@ module Protos
5
5
  class Actions < Component
6
6
  # DOCS: A container for the actions (e.g. buttons) for a group of stats
7
7
 
8
- def view_template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class Description < Component
6
6
  # DOCS: A description for a group of stats
7
7
 
8
- def view_template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class Figure < Component
6
6
  # DOCS: A figure for a single stat
7
7
 
8
- def view_template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class Stat < Component
6
6
  # DOCS: A single stat container
7
7
 
8
- def view_template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class Title < Component
6
6
  # DOCS: A title for a group of stats
7
7
 
8
- def view_template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class Value < Component
6
6
  # DOCS: A value for a single stat
7
7
 
8
- def view_template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
data/lib/protos/stats.rb CHANGED
@@ -5,33 +5,21 @@ module Protos
5
5
  # DOCS: Stats component that contains a collection of stats
6
6
  # https://daisyui.com/components/stat/
7
7
 
8
- def view_template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
- def actions(...)
13
- Actions.new(...)
14
- end
12
+ def actions(...) = render Actions.new(...)
15
13
 
16
- def description(...)
17
- Description.new(...)
18
- end
14
+ def description(...) = render Description.new(...)
19
15
 
20
- def figure(...)
21
- Figure.new(...)
22
- end
16
+ def figure(...) = render Figure.new(...)
23
17
 
24
- def stat(...)
25
- Stat.new(...)
26
- end
18
+ def stat(...) = render Stat.new(...)
27
19
 
28
- def title(...)
29
- Title.new(...)
30
- end
20
+ def title(...) = render Title.new(...)
31
21
 
32
- def value(...)
33
- Value.new(...)
34
- end
22
+ def value(...) = render Value.new(...)
35
23
 
36
24
  private
37
25
 
@@ -5,8 +5,8 @@ module Protos
5
5
  class Off < Component
6
6
  # DOCS: The off state for a swap component. This is the default state.
7
7
 
8
- def view_template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class On < Component
6
6
  # DOCS: The on state for a swap component. This is the active state.
7
7
 
8
- def view_template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
data/lib/protos/swap.rb CHANGED
@@ -13,13 +13,9 @@ module Protos
13
13
  end
14
14
  end
15
15
 
16
- def on(...)
17
- On.new(...)
18
- end
16
+ def on(...) = render On.new(...)
19
17
 
20
- def off(...)
21
- Off.new(...)
22
- end
18
+ def off(...) = render Off.new(...)
23
19
 
24
20
  private
25
21
 
@@ -5,8 +5,8 @@ module Protos
5
5
  class Body < Component
6
6
  # DOCS: The body of a table
7
7
 
8
- def view_template(&block)
9
- tbody(**attrs, &block)
8
+ def view_template(&)
9
+ tbody(**attrs, &)
10
10
  end
11
11
  end
12
12
  end
@@ -5,15 +5,15 @@ module Protos
5
5
  class Caption < Component
6
6
  # DOCS: The caption of a table
7
7
 
8
- def view_template(&block)
9
- caption(**attrs, &block)
8
+ def view_template(&)
9
+ caption(**attrs, &)
10
10
  end
11
11
 
12
12
  private
13
13
 
14
14
  def theme
15
15
  {
16
- container: tokens("caption-bottom", "p-sm")
16
+ container: tokens("caption-bottom")
17
17
  }
18
18
  end
19
19
  end
@@ -11,8 +11,8 @@ module Protos
11
11
  :left
12
12
  }
13
13
 
14
- def view_template(&block)
15
- td(**attrs, &block)
14
+ def view_template(&)
15
+ td(**attrs, &)
16
16
  end
17
17
 
18
18
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class Footer < Component
6
6
  # DOCS: The footer of a table
7
7
 
8
- def view_template(&block)
9
- tfoot(**attrs, &block)
8
+ def view_template(&)
9
+ tfoot(**attrs, &)
10
10
  end
11
11
  end
12
12
  end
@@ -11,8 +11,8 @@ module Protos
11
11
  :left
12
12
  }
13
13
 
14
- def view_template(&block)
15
- th(**attrs, &block)
14
+ def view_template(&)
15
+ th(**attrs, &)
16
16
  end
17
17
 
18
18
  private
@@ -6,8 +6,8 @@ module Protos
6
6
  # DOCS: The header of a table that contains many Protos::Table::Head
7
7
  # components
8
8
 
9
- def view_template(&block)
10
- thead(**attrs, &block)
9
+ def view_template(&)
10
+ thead(**attrs, &)
11
11
  end
12
12
  end
13
13
  end
@@ -5,8 +5,8 @@ module Protos
5
5
  class Row < Component
6
6
  # DOCS: The row of a table
7
7
 
8
- def view_template(&block)
9
- tr(**attrs, &block)
8
+ def view_template(&)
9
+ tr(**attrs, &)
10
10
  end
11
11
  end
12
12
  end
data/lib/protos/table.rb CHANGED
@@ -24,33 +24,19 @@ module Protos
24
24
  end
25
25
  end
26
26
 
27
- def body(...)
28
- Body.new(...)
29
- end
27
+ def body(...) = render Body.new(...)
30
28
 
31
- def caption(...)
32
- Caption.new(...)
33
- end
29
+ def caption(...) = render Caption.new(...)
34
30
 
35
- def cell(...)
36
- Cell.new(...)
37
- end
31
+ def cell(...) = render Cell.new(...)
38
32
 
39
- def footer(...)
40
- Footer.new(...)
41
- end
33
+ def footer(...) = render Footer.new(...)
42
34
 
43
- def head(...)
44
- Head.new(...)
45
- end
35
+ def head(...) = render Head.new(...)
46
36
 
47
- def header(...)
48
- Header.new(...)
49
- end
37
+ def header(...) = render Header.new(...)
50
38
 
51
- def row(...)
52
- Row.new(...)
53
- end
39
+ def row(...) = render Row.new(...)
54
40
 
55
41
  private
56
42