bard-tag_field 0.1.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.
@@ -0,0 +1,2 @@
1
+ node_modules
2
+
Binary file
data/bard-tag/index.js ADDED
@@ -0,0 +1 @@
1
+ import "@botandrose/input-tag"
@@ -0,0 +1,15 @@
1
+ {
2
+ "type": "module",
3
+ "scripts": {
4
+ "clean": "rm -f ../app/assets/javascripts/input-tag.js",
5
+ "build": "rollup -c"
6
+ },
7
+ "devDependencies": {
8
+ "@rollup/plugin-commonjs": "^25.0.7",
9
+ "@rollup/plugin-node-resolve": "^15.2.3",
10
+ "rollup": "^4.5.2"
11
+ },
12
+ "dependencies": {
13
+ "@botandrose/input-tag": "0.3.0"
14
+ }
15
+ }
@@ -0,0 +1,19 @@
1
+ import resolve from "@rollup/plugin-node-resolve"
2
+ import commonjs from '@rollup/plugin-commonjs';
3
+
4
+ export default [
5
+ {
6
+ input: "./index.js",
7
+ output: [
8
+ {
9
+ file: "../app/assets/javascripts/input-tag.js",
10
+ format: "es",
11
+ },
12
+ ],
13
+ context: "window",
14
+ plugins: [
15
+ resolve(),
16
+ commonjs(),
17
+ ]
18
+ },
19
+ ]
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/bard/tag_field/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bard-tag_field"
7
+ spec.version = Bard::TagField::VERSION
8
+ spec.authors = ["Micah Geisel"]
9
+ spec.email = ["micah@botandrose.com"]
10
+
11
+ spec.summary = "form.tag_field using @botandrose/input-tag custom element"
12
+ spec.description = "form.tag_field using @botandrose/input-tag custom element"
13
+ spec.homepage = "https://github.com/botandrose/bard-tag_field"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.2.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = spec.homepage + "/blob/master/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "rails", ">= 7.1"
33
+
34
+ spec.add_development_dependency "rspec-rails"
35
+ spec.add_development_dependency "equivalent-xml"
36
+ spec.add_development_dependency "appraisal"
37
+
38
+ # For more information and examples about making a new gem, checkout our
39
+ # guide at: https://bundler.io/guides/creating_gem.html
40
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "bard/tag_field"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 7.1.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 7.2.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 8.0.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,80 @@
1
+ module Bard
2
+ module TagField
3
+ class Field < ActionView::Helpers::Tags::TextField
4
+ def render &block
5
+ add_default_name_and_id(@options)
6
+
7
+ # Remove choices from HTML options before rendering
8
+ choices = @options.delete(:choices)
9
+
10
+ # Store choices for render_object_values method
11
+ @choices = choices
12
+
13
+ # Generate unique datalist ID if we have choices and no block
14
+ datalist_id = nil
15
+ if choices&.any? && !block
16
+ datalist_id = "#{@options[:id]}_datalist"
17
+ @options[:list] = datalist_id
18
+ end
19
+
20
+ result = @template_object.content_tag("input-tag", @options) do
21
+ next block.call(@options) if block
22
+ render_object_values
23
+ end
24
+
25
+ # Add datalist after input-tag if we have choices and no block
26
+ if choices&.any? && !block
27
+ result += render_datalist(datalist_id, choices)
28
+ end
29
+
30
+ result
31
+ end
32
+
33
+ private
34
+
35
+ def render_datalist(datalist_id, choices)
36
+ @template_object.content_tag("datalist", id: datalist_id) do
37
+ choices.map do |choice|
38
+ case choice
39
+ when Array
40
+ # Handle nested arrays [display, value]
41
+ display_text, submit_value = choice.first(2)
42
+ @template_object.content_tag("option", display_text, value: submit_value)
43
+ else
44
+ # Handle simple strings
45
+ @template_object.content_tag("option", choice, value: choice)
46
+ end
47
+ end.join("\n").html_safe
48
+ end
49
+ end
50
+
51
+ def render_object_values
52
+ choice_map = build_choice_map(@choices)
53
+
54
+ Array(@object.try(@method_name)).map do |tag|
55
+ # Use label from choices if available, otherwise use tag as both value and label
56
+ label = choice_map[tag] || tag
57
+ @template_object.content_tag("tag-option", label, value: tag)
58
+ end.join("\n").html_safe
59
+ end
60
+
61
+ def build_choice_map(choices)
62
+ return {} unless choices.is_a?(Array)
63
+
64
+ choice_map = {}
65
+ choices.each do |choice|
66
+ case choice
67
+ when Array
68
+ # Handle nested arrays [display, value]
69
+ display_text, submit_value = choice.first(2)
70
+ choice_map[submit_value] = display_text
71
+ else
72
+ # Handle simple strings - value and label are the same
73
+ choice_map[choice] = choice
74
+ end
75
+ end
76
+ choice_map
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "field"
2
+
3
+ module Bard
4
+ module TagField
5
+ module FormBuilder
6
+ def bard_tag_field method, choices = nil, options = {}, html_options = {}, &block
7
+ # Handle different method signatures to match Rails select helper
8
+ case choices
9
+ when Hash
10
+ # bard_tag_field(:method, { class: "form-control" })
11
+ html_options = options
12
+ options = choices
13
+ choices = nil
14
+ when Array
15
+ # bard_tag_field(:method, choices_array, { class: "form-control" })
16
+ html_options = options if options.is_a?(Hash)
17
+ when NilClass
18
+ # bard_tag_field(:method)
19
+ html_options = options
20
+ options = {}
21
+ end
22
+
23
+ # Merge options and html_options for Rails compatibility
24
+ merged_options = objectify_options(options.merge(html_options))
25
+
26
+ # Pass choices to the Field class
27
+ merged_options[:choices] = choices if choices
28
+
29
+ Field.new(@object_name, method, @template, merged_options).render(&block)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bard
4
+ module TagField
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "tag_field/version"
4
+ require_relative "tag_field/form_builder"
5
+
6
+ module Bard
7
+ module TagField
8
+ class Engine < ::Rails::Engine
9
+ initializer "bard-tag_field.assets" do
10
+ if Rails.application.config.respond_to?(:assets)
11
+ Rails.application.config.assets.precompile += ["input-tag.js"]
12
+ end
13
+ end
14
+
15
+ config.after_initialize do
16
+ ActionView::Base.default_form_builder.include FormBuilder
17
+ end
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bard-tag_field
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Micah Geisel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '7.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '7.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: equivalent-xml
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: appraisal
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: form.tag_field using @botandrose/input-tag custom element
70
+ email:
71
+ - micah@botandrose.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".rspec"
77
+ - Appraisals
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - app/assets/javascripts/input-tag.js
83
+ - bard-tag/.gitignore
84
+ - bard-tag/bun.lockb
85
+ - bard-tag/index.js
86
+ - bard-tag/package.json
87
+ - bard-tag/rollup.config.js
88
+ - bard-tag_field.gemspec
89
+ - bin/console
90
+ - bin/setup
91
+ - gemfiles/rails_7.1.gemfile
92
+ - gemfiles/rails_7.2.gemfile
93
+ - gemfiles/rails_8.0.gemfile
94
+ - lib/bard/tag_field.rb
95
+ - lib/bard/tag_field/field.rb
96
+ - lib/bard/tag_field/form_builder.rb
97
+ - lib/bard/tag_field/version.rb
98
+ homepage: https://github.com/botandrose/bard-tag_field
99
+ licenses:
100
+ - MIT
101
+ metadata:
102
+ homepage_uri: https://github.com/botandrose/bard-tag_field
103
+ source_code_uri: https://github.com/botandrose/bard-tag_field
104
+ changelog_uri: https://github.com/botandrose/bard-tag_field/blob/master/CHANGELOG.md
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 3.2.0
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubygems_version: 3.5.11
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: form.tag_field using @botandrose/input-tag custom element
124
+ test_files: []