brut 0.0.5 → 0.0.6

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: 7702194ca39391fce02e749d6050ff7ac0856739d4e635a562d01284eb8d2d95
4
- data.tar.gz: b7581e5a3ae897eae7acfb200e8a40c36092992305db27f25e319807d6986882
3
+ metadata.gz: 61b4016715aa0ca0ab347e21a91bf8e507665e900f20e505fb0100662fa09aa0
4
+ data.tar.gz: 7d6934311740a131a9f906d646d00cf3056bb860037cd218ce6c5cd35b84dfb9
5
5
  SHA512:
6
- metadata.gz: d8cb683694e8a4b1f1d35226d3cc0f60d3b4c6200c81f89a330f4efb74e359a8f31ebee40b2ad9b8264188b960bee505634092417b0e48fa8b71825d7bf01810
7
- data.tar.gz: d5ab249e7cdb783a9698af017c8c550910b39863c26842357c422e70716e5ce940ba6150d43e621faa60b9fdeffd578d765479ad2168403c5a2e863c427e8bfe
6
+ metadata.gz: 89aebab6c15c42835af1b1161d92cc923ba685c89aab1a848c9a8e7dc6c23b7b96691a2ba2fa219611f2440ea3b6860dcfa5d68fb167b1ada35c8a7cd8db3aee
7
+ data.tar.gz: fc14225d9512014d5b6e0a07a484407efb07913c86a4c0035adcbc7c4ca8ba477eb7347478e9e31053985fa9d35c4c2f4de097a5f52ff0517ca1b654cee39b67
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brut (0.0.5)
4
+ brut (0.0.6)
5
5
  concurrent-ruby
6
6
  i18n
7
7
  irb
@@ -81,15 +81,7 @@ class Brut::CLI::Apps::Test < Brut::CLI::App
81
81
  if options.build_assets?
82
82
  system!({ "RACK_ENV" => "test" }, "bin/build-assets")
83
83
  end
84
- begin
85
- system!({ "NODE_DISABLE_COLORS" => "1" },"npx mocha #{Brut.container.js_specs_dir} --no-color --extension 'spec.js' --recursive")
86
- rescue Brut::CLI::SystemExecError => ex
87
- if ex.exit_status == 1
88
- out.puts "mocha exited 1 - assuming this is because there are no test files and that this is intentional"
89
- else
90
- raise ex
91
- end
92
- end
84
+ system!({ "NODE_DISABLE_COLORS" => "1" },"npx mocha #{Brut.container.js_specs_dir} --no-color --extension 'spec.js' --recursive")
93
85
  0
94
86
  end
95
87
  end
@@ -60,7 +60,7 @@ class Brut::FrontEnd::Component
60
60
  if @yielded_block
61
61
  @yielded_block.().html_safe!
62
62
  else
63
- raise Brut::FrontEnd::Errors::Bug, "No block was yielded to #{self.class.name}"
63
+ raise Brut::Framework::Errors::Bug, "No block was yielded to #{self.class.name}"
64
64
  end
65
65
  end
66
66
 
@@ -167,27 +167,7 @@ class Brut::FrontEnd::Component
167
167
  # the same value, but with any content hashes that are part of the filename.
168
168
  def asset_path(path) = Brut.container.asset_path_resolver.resolve(path)
169
169
 
170
- # Creates the form surrounding the contents of the block yielded to it. If the form's action is a POST, it will include a CSRF token.
171
- # If the form's action is GET, it will not.
172
- #
173
- # @example Route without parameters
174
- # <%= form_tag(for: NewWidgetForm, class: "new-form") do %>
175
- # <input type="text" name="name">
176
- # <button>Create</button>
177
- # <% end %>
178
- #
179
- # @example Route with parameters
180
- # <%= form_tag(for: SaveWidgetWithIdForm, route_params: { id: widget.external_id }, class: "new-form") do %>
181
- # <input type="text" name="name">
182
- # <button>Save</button>
183
- # <% end %>
184
- #
185
- # @param route_params [Hash] if the form requires route parameters, their values must be passed here so that the HTML `action`
186
- # attribute can be constructed properly.
187
- # @param html_attributes [Hash] any additional attributes for the `<form>` tag
188
- # @option html_attributes [Class|Brut::FrontEnd::Form] :for the form object or class representing this HTML form. If you pass this, you may not pass the HTML attributes `:action` or `:method`. Both will be derived from this object.
189
- # @option html_attributes [String] «any-other-key» attributes to set on the `<form>` tag
190
- # @yield No parameters given. This is expected to return additional markup to appear inside the `<form>` element.
170
+ # (see Brut::FrontEnd::Components::FormTag)
191
171
  def form_tag(route_params: {}, **html_attributes,&contents)
192
172
  component(Brut::FrontEnd::Components::FormTag.new(route_params:, **html_attributes,&contents))
193
173
  end
@@ -1,7 +1,27 @@
1
1
  require "rexml"
2
2
  # Represents a `<form>` HTML element that includes a CSRF token as needed. You likely want to use this class via the {Brut::FrontEnd::Component::Helpers#form_tag} method.
3
3
  class Brut::FrontEnd::Components::FormTag < Brut::FrontEnd::Component
4
- # (see Brut::FrontEnd::Component::Helpers#form_tag)
4
+ # Creates the form surrounding the contents of the block yielded to it. If the form's action is a POST, it will include a CSRF token.
5
+ # If the form's action is GET, it will not.
6
+ #
7
+ # @example Route without parameters
8
+ # <%= form_tag(for: NewWidgetForm, class: "new-form") do %>
9
+ # <input type="text" name="name">
10
+ # <button>Create</button>
11
+ # <% end %>
12
+ #
13
+ # @example Route with parameters
14
+ # <%= form_tag(for: SaveWidgetWithIdForm, route_params: { id: widget.external_id }, class: "new-form") do %>
15
+ # <input type="text" name="name">
16
+ # <button>Save</button>
17
+ # <% end %>
18
+ #
19
+ # @param route_params [Hash] if the form requires route parameters, their values must be passed here so that the HTML `action`
20
+ # attribute can be constructed properly.
21
+ # @param html_attributes [Hash] any additional attributes for the `<form>` tag
22
+ # @option html_attributes [Class|Brut::FrontEnd::Form] :for the form object or class representing this HTML form *or* the class of a handler the form should submit to. If you pass this, you may not pass the HTML attributes `:action` or `:method`. Both will be derived from this object.
23
+ # @option html_attributes [String] «any-other-key» attributes to set on the `<form>` tag
24
+ # @yield No parameters given. This is expected to return additional markup to appear inside the `<form>` element.
5
25
  def initialize(route_params: {}, **html_attributes,&contents)
6
26
  form_class = html_attributes.delete(:for) # Cannot be a keyword arg, since for is a reserved word
7
27
  if !form_class.nil?
@@ -10,7 +10,6 @@ class Brut::FrontEnd::Components::Inputs::TextField < Brut::FrontEnd::Components
10
10
  def self.for_form_input(form:, input_name:, index: nil, html_attributes: {})
11
11
  default_html_attributes = {}
12
12
  html_attributes = html_attributes.map { |key,value| [ key.to_s, value ] }.to_h
13
- index ||= 0
14
13
  input = form.input(input_name, index:)
15
14
 
16
15
  default_html_attributes["required"] = input.required
@@ -40,8 +39,8 @@ class Brut::FrontEnd::Components::Inputs::TextField < Brut::FrontEnd::Components
40
39
  value = input.value
41
40
 
42
41
  if input.type == "checkbox"
43
- default_html_attributes["value"] = "true"
44
- default_html_attributes["checked"] = value == "true"
42
+ default_html_attributes["value"] = (index || true).to_s
43
+ default_html_attributes["checked"] = !!value
45
44
  else
46
45
  default_html_attributes["value"] = value
47
46
  end
@@ -37,7 +37,33 @@ class Brut::FrontEnd::Form
37
37
  if unknown_params.any?
38
38
  Brut.container.instrumentation.add_attributes(ignored_unknown_params: unknown_params)
39
39
  end
40
- @params = params.except(*unknown_params)
40
+ @params = params.except(*unknown_params).map { |name,value|
41
+ input_definition = begin
42
+ self.class.input_definitions[name] || self.class.input_definitions.fetch(name.to_s)
43
+ rescue KeyError
44
+ raise "cannot find input definition for '#{name}'. Have these: #{self.class.input_definitions.keys.inspect}"
45
+ end
46
+ if value.kind_of?(Array)
47
+ input_definition = begin
48
+ self.class.input_definitions[name] || self.class.input_definitions.fetch(name.to_s)
49
+ rescue KeyError
50
+ raise "cannot find input definition for '#{name}'. Have these: #{self.class.input_definitions.keys.inspect}"
51
+ end
52
+ if input_definition.respond_to?(:type) && input_definition.type == "checkbox"
53
+ if value.all? { it.to_s =~ /^\d+$/ }
54
+ # the values represent the indexes of which checkboxes were checked
55
+ new_values = []
56
+ value.each do |index_as_string|
57
+ index = Integer(index_as_string)
58
+ new_values[index] = true
59
+ end
60
+ value = new_values.map { !!it }
61
+ end
62
+ end
63
+ end
64
+ [ name, value ]
65
+ }.to_h
66
+
41
67
  @new = params_empty?(@params)
42
68
  @inputs = self.class.input_definitions.map { |name,input_definition|
43
69
  value = @params[name] || @params[name.to_sym]
@@ -31,8 +31,7 @@ module Brut::FrontEnd::Forms::InputDeclarations
31
31
  # {Brut::FrontEnd::Components::Inputs::RadioButton.for_form_input}.
32
32
  #
33
33
  # @param [String] name The name of the group (used in the `name` attribute)
34
- # @param [Hash] attributes Attributes to be used on the tag that represent its contraints. See
35
- # {Brut::FrontEnd::Forms::RadioButtonGroupInputDefinition}
34
+ # @param [Hash] attributes Attributes to be used on the tag that represent its contraints. See {Brut::FrontEnd::Forms::RadioButtonGroupInputDefinition}
36
35
  def radio_button_group(name,attributes={})
37
36
  self.add_input_definition(
38
37
  Brut::FrontEnd::Forms::RadioButtonGroupInputDefinition.new(**(attributes.merge(name: name)))
data/lib/brut/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Brut
2
2
  # @!visibility private
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Bryant Copeland
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-24 00:00:00.000000000 Z
10
+ date: 2025-02-27 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: irb