bulma-phlex-rails 0.2.1 → 0.4.0

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: 9ccde325abe028d8ab12fb8dfbcd754814274554029fffe1c443c21d0936c6e1
4
- data.tar.gz: 0e526e0539626fa8b17780e9ce1db8edc2d81b68c4808fa0fcb108dad44e1944
3
+ metadata.gz: 44794453fc2f23bad30359fbe4c2334a3f01f492e883d149752eb7855d22926e
4
+ data.tar.gz: 63fafad11cdb41bb3c26e768bb9042faea483befb1802c0741b9c054cd9262a9
5
5
  SHA512:
6
- metadata.gz: fca248f599cd3f0793a37864c791e451b8e9019639e093dea13b27dc5a5443dc21b85959201f14763a896edf8f094c22907fd45854b74c6302dce3f5712430e0
7
- data.tar.gz: 0e7e6196221edf59fb6c1303d4ef0e74d30522dfbb37e9c7c2ff8a15f3e90f33a6c3f65c142776ce1f9a53d155ab8e6860c909335bafe9ccd464e25c11b3d64e
6
+ metadata.gz: 88e3734a644ae73ccde892ddbae655a6e3f5e18ae1d3ec5ed951822d4ec3a1c4bd903f0f315e8811860929d4e473894e4dfd536da4c39b12bad59230459036d4
7
+ data.tar.gz: f36bcded467eacbc374f08b75a8033aa0e9089de882f2363c9d51f547803b7b9586478ddbdb2377ec4bb2f3091b967a6bd901f18a184b85cdeae3d170268b0d4
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BulmaPhlex
4
+ module Rails
5
+ # # Checkbox Component
6
+ #
7
+ # This component renders a Bulma-styled checkbox within a form. It integrates with Rails' form builder
8
+ # to ensure proper labeling and value handling.
9
+ #
10
+ # The label can be generated automatically based on the attribute name or customized using a block.
11
+ #
12
+ # Example usage:
13
+ #
14
+ # ```ruby
15
+ # form_with model: @user do |f|
16
+ # f.checkbox :subscribe_newsletter
17
+ # f.checkbox :terms_of_service do
18
+ # span { "I agree to " }
19
+ # a(href: "/terms") { "the terms and conditions" }
20
+ # end
21
+ # end
22
+ # ```
23
+ class Checkbox < BulmaPhlex::Base
24
+ def initialize(form_builder, method, options, delivered, label_block)
25
+ @form_builder = form_builder
26
+ @method = method
27
+ @options = options.dup
28
+ @delivered = delivered
29
+ @label_block = label_block
30
+
31
+ @options[:class] = Array.wrap(@options[:class]) << "mr-2"
32
+ @form_field_options = @options.extract!(:column, :grid)
33
+ .with_defaults(column: @form_builder.columns_flag,
34
+ grid: @form_builder.grid_flag)
35
+ end
36
+
37
+ def view_template
38
+ render FormField.new(**@form_field_options) do |f|
39
+ f.control do
40
+ @form_builder.label(@method, nil, class: "checkbox", skip_label_class: true) do |label_builder|
41
+ raw @delivered.call(@options)
42
+ render_label(label_builder)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def render_label(label_builder)
51
+ output = @label_block ? @label_block.call(label_builder) : label_builder.to_s
52
+
53
+ # ActiveSupport::SafeBuffer is html safe, strings are not
54
+ if output.html_safe?
55
+ raw output
56
+ else
57
+ plain output
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,139 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BulmaPhlex
4
+ module Rails
5
+ # # Form Builder
6
+ #
7
+ # This form builder wraps inputs with [Bulma Form Fields](https://bulma.io/documentation/form/general/#form-field).
8
+ #
9
+ # In addition to standard input options, it supports the following Bulma-specific options:
10
+ # - `suppress_label`: If true, the label will not be rendered.
11
+ # - `icon_left`: If set, the specified icon will be rendered on the left side of the input.
12
+ # - `icon_right`: If set, the specified icon will be rendered on the right side of the input.
13
+ # - `column`: If true, the input will be wrapped in a Bulma column (only within a `columns` block).
14
+ # - `grid`: If true, the input will be wrapped in a Bulma grid cell (only within a `grid` block).
15
+ class FormBuilder < ActionView::Helpers::FormBuilder
16
+ attr_reader :columns_flag, :grid_flag
17
+
18
+ def text_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
19
+ def password_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
20
+ def color_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
21
+ def search_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
22
+ def telephone_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
23
+ def phone_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
24
+ def date_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
25
+ def time_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
26
+ def datetime_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
27
+ def datetime_local_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
28
+ def month_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
29
+ def week_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
30
+ def url_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
31
+ def email_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
32
+ def number_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
33
+ def range_field(method, options = {}) = wrap_field(method, options) { |m, opts| super(m, opts) }
34
+
35
+ def textarea(method, options = {})
36
+ wrap_field(method, options, add_class: "textarea") do |m, opts|
37
+ super(m, opts)
38
+ end
39
+ end
40
+ alias text_area textarea
41
+
42
+ def checkbox(method, options = {}, checked_value = "1", unchecked_value = "0", &label_block)
43
+ delivered = ->(opts) { super(method, opts, checked_value, unchecked_value) }
44
+ Checkbox.new(self, method, options, delivered, label_block).render_in(@template)
45
+ end
46
+ alias check_box checkbox
47
+
48
+ # Override label to add Bulma's `label` class by default. Add `:skip_label_class` option
49
+ # to skip adding the class.
50
+ def label(method, text = nil, options = {}, &)
51
+ skip_label_class = options.delete(:skip_label_class)
52
+ options[:class] = Array.wrap(options[:class]) << :label unless skip_label_class
53
+ super
54
+ end
55
+
56
+ def select(method, choices = nil, options = {}, html_options = {}, &)
57
+ wrap_select_field(method, html_options) do |m, html_opts|
58
+ super(m, choices, options, html_opts, &)
59
+ end
60
+ end
61
+
62
+ # rubocop:disable Metrics/ParameterLists
63
+ def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
64
+ wrap_select_field(method, html_options) do |m, html_opts|
65
+ super(m, collection, value_method, text_method, options, html_opts)
66
+ end
67
+ end
68
+ # rubocop:enable Metrics/ParameterLists
69
+
70
+ def submit(value = nil, options = {})
71
+ options = options.dup
72
+ options[:class] = Array.wrap(options[:class]) << :button
73
+
74
+ FormField.new do |field|
75
+ field.control { super(value, options) }
76
+ end.render_in(@template)
77
+ end
78
+
79
+ # Fields declared in a column block will be wrapped in a Bulma column and carry
80
+ # the `column` class by default (fields can use the `column` option to set sizes).
81
+ def columns(min_breakpoint = nil, &)
82
+ @columns_flag = true
83
+ columns = @template.capture(&)
84
+ @columns_flag = false
85
+
86
+ @template.content_tag(:div, class: [:columns, min_breakpoint]) do
87
+ @template.concat(columns)
88
+ end
89
+ end
90
+
91
+ # Fields declared in a fixed_grid block will be wrapped in a Bulma fixed grid and
92
+ # carry the `grid` class by default (fields can use the `grid` option to set sizes).
93
+ def fixed_grid(&)
94
+ # TODO: Use BulmaPhlex::FixedGrid for more options
95
+ @template.content_tag(:div, class: "fixed-grid") do
96
+ grid(&)
97
+ end
98
+ end
99
+
100
+ # Fields declared in a grid block will be wrapped in a Bulma fixed grid and carry
101
+ # the `grid` class by default (fields can use the `grid` option to set sizes).
102
+ def grid(&)
103
+ @grid_flag = true
104
+ cells = @template.capture(&)
105
+ @grid_flag = false
106
+
107
+ # TODO: Use BulmaPhlex::Grid for more options
108
+ @template.content_tag(:div, class: "grid") do
109
+ @template.concat(cells)
110
+ end
111
+ end
112
+
113
+ private
114
+
115
+ def wrap_field(method, options, add_class: "input", &delivered)
116
+ options = options.dup
117
+ options[:class] = Array.wrap(options[:class]) << add_class if add_class
118
+
119
+ form_field_options = options.extract!(:help, :icon_left, :icon_right, :column, :grid)
120
+ .with_defaults(column: @columns_flag, grid: @grid_flag)
121
+
122
+ form_field = FormField.new(**form_field_options) do |f|
123
+ f.label { label(method).html_safe } unless options.delete(:suppress_label)
124
+ f.control { delivered.call(method, options) }
125
+ end
126
+
127
+ form_field.render_in(@template)
128
+ end
129
+
130
+ def wrap_select_field(method, html_options, &delivered)
131
+ wrap_field(method, html_options, add_class: false) do |m, html_opts|
132
+ @template.content_tag(:div, class: "select") do
133
+ delivered.call(m, html_opts)
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module BulmaPhlex
4
4
  module Rails
5
- VERSION = "0.2.1"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
@@ -14,6 +14,7 @@ end
14
14
  loader = Zeitwerk::Loader.for_gem_extension(BulmaPhlex)
15
15
  loader.collapse("#{__dir__}/rails/components")
16
16
  loader.collapse("#{__dir__}/rails/helpers")
17
+ loader.collapse("#{__dir__}/rails/models")
17
18
  loader.setup
18
19
 
19
20
  require "bulma_phlex/rails/engine"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bulma-phlex-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Kummer
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
10
+ date: 2026-01-31 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: actionpack
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.8.0
32
+ version: 0.9.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 0.8.0
39
+ version: 0.9.0
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: phlex-rails
42
42
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,9 @@ files:
80
80
  - config/importmap.rb
81
81
  - lib/bulma-phlex-rails.rb
82
82
  - lib/bulma_phlex/rails.rb
83
+ - lib/bulma_phlex/rails/components/checkbox.rb
83
84
  - lib/bulma_phlex/rails/engine.rb
85
+ - lib/bulma_phlex/rails/form_builder.rb
84
86
  - lib/bulma_phlex/rails/helpers/card_helper.rb
85
87
  - lib/bulma_phlex/rails/helpers/table_helper.rb
86
88
  - lib/bulma_phlex/rails/version.rb