form_props 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +714 -0
  3. data/lib/form_props/action_view_extensions/form_helper.rb +120 -0
  4. data/lib/form_props/form_builder.rb +223 -0
  5. data/lib/form_props/form_options_helper.rb +158 -0
  6. data/lib/form_props/inputs/base.rb +164 -0
  7. data/lib/form_props/inputs/check_box.rb +69 -0
  8. data/lib/form_props/inputs/collection_check_boxes.rb +36 -0
  9. data/lib/form_props/inputs/collection_helpers.rb +53 -0
  10. data/lib/form_props/inputs/collection_radio_buttons.rb +35 -0
  11. data/lib/form_props/inputs/collection_select.rb +30 -0
  12. data/lib/form_props/inputs/color_field.rb +27 -0
  13. data/lib/form_props/inputs/date_field.rb +17 -0
  14. data/lib/form_props/inputs/datetime_field.rb +32 -0
  15. data/lib/form_props/inputs/datetime_local_field.rb +17 -0
  16. data/lib/form_props/inputs/email_field.rb +13 -0
  17. data/lib/form_props/inputs/file_field.rb +13 -0
  18. data/lib/form_props/inputs/grouped_collection_select.rb +31 -0
  19. data/lib/form_props/inputs/hidden_field.rb +16 -0
  20. data/lib/form_props/inputs/month_field.rb +17 -0
  21. data/lib/form_props/inputs/number_field.rb +21 -0
  22. data/lib/form_props/inputs/password_field.rb +18 -0
  23. data/lib/form_props/inputs/radio_button.rb +48 -0
  24. data/lib/form_props/inputs/range_field.rb +13 -0
  25. data/lib/form_props/inputs/search_field.rb +28 -0
  26. data/lib/form_props/inputs/select.rb +42 -0
  27. data/lib/form_props/inputs/submit.rb +26 -0
  28. data/lib/form_props/inputs/tel_field.rb +13 -0
  29. data/lib/form_props/inputs/text_area.rb +37 -0
  30. data/lib/form_props/inputs/text_field.rb +28 -0
  31. data/lib/form_props/inputs/time_field.rb +17 -0
  32. data/lib/form_props/inputs/time_zone_select.rb +22 -0
  33. data/lib/form_props/inputs/url_field.rb +13 -0
  34. data/lib/form_props/inputs/week_field.rb +17 -0
  35. data/lib/form_props/inputs/weekday_select.rb +28 -0
  36. data/lib/form_props/version.rb +5 -0
  37. data/lib/form_props.rb +45 -0
  38. metadata +120 -0
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "action_view/helpers/tags/placeholderable"
4
+
5
+ module FormProps
6
+ module Inputs
7
+ class TextField < Base
8
+ include ActionView::Helpers::Tags::Placeholderable
9
+
10
+ def render
11
+ @options[:size] = @options[:max_length] unless @options.key?(:size)
12
+ @options[:type] ||= field_type
13
+ @options[:value] = @options.fetch(:value) { value_before_type_cast } unless field_type == "file"
14
+
15
+ json.set!(sanitized_method_name) do
16
+ add_default_name_and_id(@options)
17
+ input_props(@options)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def field_type
24
+ "text"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FormProps
4
+ module Inputs
5
+ class TimeField < DatetimeField
6
+ private
7
+
8
+ def format_date(value)
9
+ value&.strftime("%T.%L")
10
+ end
11
+
12
+ def field_type
13
+ "time"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FormProps
4
+ module Inputs
5
+ class TimeZoneSelect < Base
6
+ include FormOptionsHelper
7
+
8
+ def initialize(object_name, method_name, template_object, priority_zones, options, html_options)
9
+ @priority_zones = priority_zones
10
+ @html_options = html_options
11
+
12
+ super(object_name, method_name, template_object, options)
13
+ end
14
+
15
+ def render
16
+ select_content_props(
17
+ time_zone_options_for_select(value || @options[:default], @priority_zones, @options[:model] || ActiveSupport::TimeZone), @options, @html_options
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FormProps
4
+ module Inputs
5
+ class UrlField < TextField
6
+ private
7
+
8
+ def field_type
9
+ "url"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FormProps
4
+ module Inputs
5
+ class WeekField < DatetimeField
6
+ private
7
+
8
+ def format_date(value)
9
+ value&.strftime("%Y-W%V")
10
+ end
11
+
12
+ def field_type
13
+ "week"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FormProps
4
+ module Inputs
5
+ class WeekdaySelect < Base
6
+ include FormOptionsHelper
7
+
8
+ def initialize(object_name, method_name, template_object, options, html_options)
9
+ @html_options = html_options
10
+
11
+ super(object_name, method_name, template_object, options)
12
+ end
13
+
14
+ def render
15
+ select_content_props(
16
+ weekday_options_for_select(
17
+ value || @options[:selected],
18
+ index_as_value: @options.fetch(:index_as_value, false),
19
+ day_format: @options.fetch(:day_format, :day_names),
20
+ beginning_of_week: @options.fetch(:beginning_of_week, Date.beginning_of_week)
21
+ ),
22
+ @options,
23
+ @html_options
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FormProps
4
+ VERSION = "0.0.1"
5
+ end
data/lib/form_props.rb ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "action_view"
4
+ require "action_pack"
5
+ require "form_props/action_view_extensions/form_helper"
6
+ require "form_props/form_options_helper"
7
+ require "form_props/inputs/base"
8
+ require "form_props/inputs/text_field"
9
+ require "form_props/inputs/text_area"
10
+ require "form_props/inputs/check_box"
11
+ require "form_props/inputs/select"
12
+ require "form_props/inputs/collection_helpers"
13
+ require "form_props/inputs/collection_select"
14
+ require "form_props/inputs/grouped_collection_select"
15
+ require "form_props/inputs/collection_check_boxes"
16
+ require "form_props/inputs/collection_radio_buttons"
17
+ require "form_props/inputs/search_field"
18
+ require "form_props/inputs/radio_button"
19
+ require "form_props/inputs/url_field"
20
+ require "form_props/inputs/email_field"
21
+ require "form_props/inputs/number_field"
22
+ require "form_props/inputs/range_field"
23
+ require "form_props/inputs/tel_field"
24
+ require "form_props/inputs/color_field"
25
+ require "form_props/inputs/password_field"
26
+ require "form_props/inputs/datetime_field"
27
+ require "form_props/inputs/datetime_local_field"
28
+ require "form_props/inputs/date_field"
29
+ require "form_props/inputs/time_field"
30
+ require "form_props/inputs/file_field"
31
+ require "form_props/inputs/week_field"
32
+ require "form_props/inputs/month_field"
33
+ require "form_props/inputs/hidden_field"
34
+ require "form_props/inputs/time_zone_select"
35
+ require "form_props/inputs/weekday_select"
36
+ require "form_props/inputs/submit"
37
+ require "form_props/form_builder"
38
+
39
+ module FormProps
40
+ extend ActiveSupport::Autoload
41
+
42
+ def self.set(json, template)
43
+ template.instance_variable_set(:@__json, json)
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: form_props
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Johny Ho
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 7.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionview
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 7.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 7.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: props_tempate
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.23.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.23.0
55
+ description: Form props is a Rails form builder that renders form attributes in JSON
56
+ email: johny@thoughtbot.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - README.md
62
+ - lib/form_props.rb
63
+ - lib/form_props/action_view_extensions/form_helper.rb
64
+ - lib/form_props/form_builder.rb
65
+ - lib/form_props/form_options_helper.rb
66
+ - lib/form_props/inputs/base.rb
67
+ - lib/form_props/inputs/check_box.rb
68
+ - lib/form_props/inputs/collection_check_boxes.rb
69
+ - lib/form_props/inputs/collection_helpers.rb
70
+ - lib/form_props/inputs/collection_radio_buttons.rb
71
+ - lib/form_props/inputs/collection_select.rb
72
+ - lib/form_props/inputs/color_field.rb
73
+ - lib/form_props/inputs/date_field.rb
74
+ - lib/form_props/inputs/datetime_field.rb
75
+ - lib/form_props/inputs/datetime_local_field.rb
76
+ - lib/form_props/inputs/email_field.rb
77
+ - lib/form_props/inputs/file_field.rb
78
+ - lib/form_props/inputs/grouped_collection_select.rb
79
+ - lib/form_props/inputs/hidden_field.rb
80
+ - lib/form_props/inputs/month_field.rb
81
+ - lib/form_props/inputs/number_field.rb
82
+ - lib/form_props/inputs/password_field.rb
83
+ - lib/form_props/inputs/radio_button.rb
84
+ - lib/form_props/inputs/range_field.rb
85
+ - lib/form_props/inputs/search_field.rb
86
+ - lib/form_props/inputs/select.rb
87
+ - lib/form_props/inputs/submit.rb
88
+ - lib/form_props/inputs/tel_field.rb
89
+ - lib/form_props/inputs/text_area.rb
90
+ - lib/form_props/inputs/text_field.rb
91
+ - lib/form_props/inputs/time_field.rb
92
+ - lib/form_props/inputs/time_zone_select.rb
93
+ - lib/form_props/inputs/url_field.rb
94
+ - lib/form_props/inputs/week_field.rb
95
+ - lib/form_props/inputs/weekday_select.rb
96
+ - lib/form_props/version.rb
97
+ homepage: https://github.com/thoughtbot/form_props/
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '2.5'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.1.4
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Form props is a Rails form builder that renders form attributes in JSON
120
+ test_files: []