swage 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1eb99b2b002dccde7c9d242952b711e4d0fc2432b8c46c792e529b22d83e3486
4
- data.tar.gz: f4eabce375c4ffe258ee251297915ba55916eeafbac9e120b1929e5c87701ae4
3
+ metadata.gz: b26199e3851d0480633cf4b44108294d1b542561d5045322bc51e46415f42a35
4
+ data.tar.gz: f0061b0cba84f1a1b8ff166397b31aa99f773df14ac7d9bad81933c90a8ffb27
5
5
  SHA512:
6
- metadata.gz: d409d145064d845053c9a91db02fd017877c6d745918f95ce5d59627b4ec588ce6cc6ef6414aa66050169384a10add1f694a9b20c992ac3639e62c6dd44985bf
7
- data.tar.gz: 7f16fbe0f753870da630dfc455507bac3734204c0da4efc7fd420a170028ea7af8372227adf39962fdc0e2e0da8a0fbd655758c46834a72e14f3f23ced1cc24f
6
+ metadata.gz: 0ba5ec928eb9ba6858065ffeb8b2d97393b03ea1e9aa4f46985e0f1b8dd2388df292d8617c09e769f7fb1dca1777bb53d71adc27f50497c1d016e473e626019d
7
+ data.tar.gz: 66c2252090c03a29bb6cf6830ae1de84a1088e6f581e76920f5f4323ca5dd3ea426369e1ad93795eb5661b0b955c865e4877efc1a529a915e7d1225c80b90ed9
@@ -110,6 +110,10 @@ module Swage::Generators
110
110
  template "base_component.rb.tt", File.join(destination_root, "app/components/base.rb"), force: true if @override
111
111
  end
112
112
 
113
+ def create_flash_component
114
+ template "flash.rb.tt", File.join(destination_root, "app/components/flash.rb"), force: true if @override
115
+ end
116
+
113
117
  def create_base_view
114
118
  template "base_view.rb.tt", File.join(destination_root, "app/views/base.rb"), force: true if @override
115
119
  end
@@ -6,6 +6,8 @@ module Views
6
6
  include Phlex::Rails::Helpers::CSRFMetaTags
7
7
  include Phlex::Rails::Helpers::StyleSheetLinkTag
8
8
  include Phlex::Rails::Helpers::JavaScriptImportmapTags
9
+ include Phlex::Rails::Helpers::Notice
10
+ include Phlex::Rails::Helpers::Flash
9
11
 
10
12
  def initialize(view)
11
13
  @view = view
@@ -34,8 +36,19 @@ module Views
34
36
  stylesheet_link_tag "tailwind", "data-turbo-track": "reload"
35
37
  javascript_importmap_tags
36
38
  end
37
- body do
38
- div id: "body", &block
39
+ main do
40
+ div id: "notices" do
41
+ flash.each do |type, message|
42
+ var = convert_variants(type)
43
+ RubyUI::Alert(variant: var) do
44
+ RubyUI::AlertTitle { variant_title(var) }
45
+ RubyUI::AlertDescription() { message }
46
+ end
47
+ end
48
+ end
49
+ body do
50
+ div id: "body", &block
51
+ end
39
52
  end
40
53
  end
41
54
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Components
4
+ class Flash < Components::Base
5
+ def initialize(flash)
6
+ @flash = flash
7
+ end
8
+
9
+ # currently doesn't have a close button, but can add it later
10
+ def view_template(&)
11
+ div id: "notices" do
12
+ if block_given?
13
+ yield
14
+ else
15
+ @flash.each do |type, message|
16
+ var = convert_variants(type)
17
+ RubyUI::Alert(variant: var) do
18
+ RubyUI::AlertTitle { variant_title(var) }
19
+ RubyUI::AlertDescription() { message }
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+ def convert_variants(var)
28
+ var = var.to_sym
29
+ var = case var
30
+ when :danger, :error, :alert
31
+ :destructive
32
+ when :info
33
+ nil
34
+ when :notice
35
+ :success
36
+ else
37
+ var
38
+ end
39
+ end
40
+
41
+ def variant_title(var)
42
+ case var
43
+ when nil
44
+ "Notice"
45
+ when :destructive
46
+ "Error"
47
+ else
48
+ var.to_s.capitalize
49
+ end
50
+ end
51
+ end
52
+ end
@@ -22,24 +22,59 @@ module Components
22
22
  RubyUI::Textarea.new(**attributes) { attributes[:value] }
23
23
  end
24
24
 
25
- def select(*options, multiple: false, **attributes, &)
25
+ # options is an array of [ label, value ] pairs
26
+ def select(options, preselect: nil, **attributes)
26
27
  attributes.merge! dom_hash(field.dom)
27
- if mutliple
28
- CheckboxGroup do
29
- options.each do |opt|
30
- div class: "flex flex-col gap-2" do
31
- div class: "flex flex-row items-center gap-2" do
32
- RubyUI::Checkbox(*attributes, id: "select_#{opt}")
33
- FormFieldLabel(for: "select_#{opt}") { opt.capitalize }
34
- end
28
+ attributes[:value] = preselect[1] if preselect
29
+ RubyUI::Select() do
30
+ RubyUI::SelectInput(**attributes)
31
+
32
+ disabled = {
33
+ disabled: true,
34
+ aria: { disabled: "true" }
35
+ } if attributes[:disabled]
36
+ RubyUI::SelectTrigger(**disabled) do
37
+ RubyUI::SelectValue(placeholder: attributes[:placeholder], id: attributes[:id]) { preselect&.at(0) }
38
+ end
39
+
40
+ RubyUI::SelectContent(outlet_id: attributes[:id]) do
41
+ RubyUI::SelectGroup() do
42
+ options.each do |opt|
43
+ RubyUI::SelectItem(value: opt[1]) { opt[0] }
35
44
  end
36
45
  end
37
46
  end
38
- else
39
- RubyUI::Select(**attributes) do
40
- SelectGroup do
41
- options.each do |opt|
42
- SelectItem(value: opt) { opt.capitalize }
47
+ end
48
+ end
49
+
50
+ # options is an array of [ label, value ] pairs
51
+ # alternatively, supply a block for customization
52
+ def combobox(options = [], multiple: false, **attributes, &block)
53
+ RubyUI::Combobox(data: attributes[:data]) do
54
+ RubyUI::ComboboxTrigger(placeholder: attributes[:placeholder])
55
+ RubyUI::ComboboxPopover() do
56
+ RubyUI::ComboboxSearchInput(placeholder: attributes[:placeholder])
57
+ RubyUI::ComboboxList() do
58
+ RubyUI::ComboboxEmptyState { "No results" }
59
+ if multiple
60
+ RubyUI::ComboboxItem() do
61
+ RubyUI::ComboboxToggleAllCheckbox(name: "all", value: "all")
62
+ span { "Select all" }
63
+ end
64
+ end
65
+ if block_given?
66
+ yield block
67
+ else
68
+ options.each do |opt|
69
+ RubyUI::ComboBoxItem() do
70
+ if multiple
71
+ RubyUI::ComboboxCheckbox(name: attributes[:name, value: opt[1]])
72
+ else
73
+ RubyUI::ComboboxRadio(name: attributes[:name], value: opt[1])
74
+ end
75
+ span { opt[0] }
76
+ end
77
+ end
43
78
  end
44
79
  end
45
80
  end
@@ -26,3 +26,15 @@ module Phlexible::Rails::ButtonToConcerns
26
26
  end
27
27
  end
28
28
  end
29
+
30
+ module Superform::Rails::StrongParameters
31
+ protected
32
+ # don't change passwords if they're blank
33
+ def permit(form)
34
+ form_params = params.require(form.key).delete_if do
35
+ (_1.to_s == "password" || _1.to_s == "password_confirmation") && (_2.nil? || _2.empty?)
36
+ end
37
+ assign(form_params, to: form).model
38
+ end
39
+ end
40
+
@@ -2,7 +2,6 @@ module Views
2
2
  module <%= controller_class_name %>
3
3
  class Index < Views::Base
4
4
  include Phlexible::Rails::AutoLayout
5
- include Phlex::Rails::Helpers::Notice
6
5
 
7
6
  def initialize(<%= plural_table_name %>: nil)
8
7
  @<%= plural_table_name %> = <%= plural_table_name %>
@@ -12,10 +11,6 @@ module Views
12
11
 
13
12
  def view_template
14
13
  div(class: "w-full px-8") do
15
- if notice.present?
16
- Text(id: "notice") { notice }
17
- end
18
-
19
14
  div(class: "flex justify-between items-center mb-10") do
20
15
  Heading(level: 1) { "<%= human_name.pluralize %>" }
21
16
  Link(href: new_<%= singular_table_name %>_path) { "New <%= human_name.downcase %>" }
@@ -2,7 +2,6 @@ module Views
2
2
  module <%= controller_class_name %>
3
3
  class Show < Views::Base
4
4
  include Phlexible::Rails::AutoLayout
5
- include Phlex::Rails::Helpers::Notice
6
5
 
7
6
  def initialize(<%= singular_table_name %>: nil)
8
7
  @<%= singular_table_name %> = <%= singular_table_name %>
@@ -12,10 +11,6 @@ module Views
12
11
 
13
12
  def view_template
14
13
  div(class: "mx-auto md:w-2/3 w-full px-8") do
15
- if notice.present?
16
- Text(id: "notice") { notice }
17
- end
18
-
19
14
  render Partial.new(<%= singular_table_name %>: @<%= singular_table_name %>)
20
15
 
21
16
  div(class: "mt-8 flex gap-4 border-t pt-6") do
data/lib/swage.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Swage
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Wobschall
@@ -112,6 +112,7 @@ files:
112
112
  - lib/generators/swage/install/templates/base_component.rb.tt
113
113
  - lib/generators/swage/install/templates/base_view.rb.tt
114
114
  - lib/generators/swage/install/templates/engine.rb.tt
115
+ - lib/generators/swage/install/templates/flash.rb.tt
115
116
  - lib/generators/swage/install/templates/form.rb.tt
116
117
  - lib/generators/swage/install/templates/swage.rb.tt
117
118
  - lib/generators/swage/install/templates/tw-animate-css.js.tt
@@ -144,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
145
  - !ruby/object:Gem::Version
145
146
  version: '0'
146
147
  requirements: []
147
- rubygems_version: 4.0.3
148
+ rubygems_version: 4.0.17
148
149
  specification_version: 4
149
150
  summary: A Phlex UI library for Rails
150
151
  test_files: []