super 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,6 +27,8 @@ module Super
27
27
  case type
28
28
  when :datetime
29
29
  @type.timestamp
30
+ when :time
31
+ @type.time
30
32
  else
31
33
  @type.text
32
34
  end
@@ -92,9 +92,10 @@ module Super
92
92
  alias text string
93
93
 
94
94
  def timestamp; real(&:to_s); end
95
+ def time; real { |value| value.strftime("%H:%M:%S") }; end
95
96
 
96
97
  def rich_text
97
- real do |value|
98
+ computed do |value|
98
99
  Partial.new("display_rich_text", locals: { rich_text: value })
99
100
  end
100
101
  end
@@ -58,6 +58,62 @@ module Super
58
58
  @builder.check_box(attribute, options, checked_value, unchecked_value)
59
59
  end
60
60
 
61
+ def flatpickr_date(attribute, options = {})
62
+ options, defaults = split_defaults(
63
+ options,
64
+ class: "super-input w-full",
65
+ data: {
66
+ controller: "flatpickr",
67
+ flatpickr_options_value: {
68
+ dateFormat: "Y-m-d",
69
+ }
70
+ }
71
+ )
72
+ options[:class] = join_classes(defaults[:class], options[:class])
73
+ options[:data] = defaults[:data].deep_merge(options[:data] || {})
74
+
75
+ @builder.text_field(attribute, options)
76
+ end
77
+
78
+ def flatpickr_datetime(attribute, options = {})
79
+ options, defaults = split_defaults(
80
+ options,
81
+ class: "super-input w-full",
82
+ data: {
83
+ controller: "flatpickr",
84
+ flatpickr_options_value: {
85
+ enableSeconds: true,
86
+ enableTime: true,
87
+ dateFormat: "Z",
88
+ }
89
+ }
90
+ )
91
+ options[:class] = join_classes(defaults[:class], options[:class])
92
+ options[:data] = defaults[:data].deep_merge(options[:data] || {})
93
+
94
+ @builder.text_field(attribute, options)
95
+ end
96
+
97
+ def flatpickr_time(attribute, options = {})
98
+ options, defaults = split_defaults(
99
+ options,
100
+ class: "super-input w-full",
101
+ data: {
102
+ controller: "flatpickr",
103
+ flatpickr_options_value: {
104
+ enableSeconds: true,
105
+ enableTime: true,
106
+ noCalendar: true,
107
+ dateFormat: "H:i:S",
108
+ }
109
+ }
110
+ )
111
+ options[:class] = join_classes(defaults[:class], options[:class])
112
+ options[:data] = defaults[:data].deep_merge(options[:data] || {})
113
+
114
+ @builder.text_field(attribute, options)
115
+ end
116
+
61
117
  def password_field(attribute, options = {})
62
118
  options, defaults = split_defaults(options, class: "super-input w-full")
63
119
  options[:class] = join_classes(defaults[:class], options[:class])
@@ -129,6 +185,42 @@ module Super
129
185
  end
130
186
  end
131
187
 
188
+ def flatpickr_date!(attribute, label: {}, field: {}, show_errors: true)
189
+ container do
190
+ compact_join([
191
+ public_send(:label, attribute, label),
192
+ %(<div class="mt-1">).html_safe,
193
+ public_send(:flatpickr_date, attribute, field),
194
+ show_errors && inline_errors(attribute),
195
+ %(</div>).html_safe,
196
+ ])
197
+ end
198
+ end
199
+
200
+ def flatpickr_datetime!(attribute, label: {}, field: {}, show_errors: true)
201
+ container do
202
+ compact_join([
203
+ public_send(:label, attribute, label),
204
+ %(<div class="mt-1">).html_safe,
205
+ public_send(:flatpickr_datetime, attribute, field),
206
+ show_errors && inline_errors(attribute),
207
+ %(</div>).html_safe,
208
+ ])
209
+ end
210
+ end
211
+
212
+ def flatpickr_time!(attribute, label: {}, field: {}, show_errors: true)
213
+ container do
214
+ compact_join([
215
+ public_send(:label, attribute, label),
216
+ %(<div class="mt-1">).html_safe,
217
+ public_send(:flatpickr_time, attribute, field),
218
+ show_errors && inline_errors(attribute),
219
+ %(</div>).html_safe,
220
+ ])
221
+ end
222
+ end
223
+
132
224
  def password_field!(attribute, label: {}, field: {}, show_errors: true)
133
225
  container do
134
226
  compact_join([
@@ -22,7 +22,16 @@ module Super
22
22
  private
23
23
 
24
24
  def attribute_type_for(attribute_name)
25
- @type.string
25
+ case @model.type_for_attribute(attribute_name).type
26
+ when :datetime
27
+ @type.flatpickr_datetime
28
+ when :time
29
+ @type.flatpickr_time
30
+ when :date
31
+ @type.flatpickr_date
32
+ else
33
+ @type.string
34
+ end
26
35
  end
27
36
  end
28
37
  end
@@ -11,6 +11,7 @@ module Super
11
11
  end
12
12
 
13
13
  attr_reader :nested_fields
14
+ attr_reader :extras
14
15
 
15
16
  def each_attribute
16
17
  if block_given?
@@ -86,6 +87,18 @@ module Super
86
87
  Generic.new(partial_path: "form_field_checkbox", extras: extras, nested: {})
87
88
  end
88
89
 
90
+ def flatpickr_date(**extras)
91
+ Generic.new(partial_path: "form_field_flatpickr_date", extras: extras, nested: {})
92
+ end
93
+
94
+ def flatpickr_datetime(**extras)
95
+ Generic.new(partial_path: "form_field_flatpickr_datetime", extras: extras, nested: {})
96
+ end
97
+
98
+ def flatpickr_time(**extras)
99
+ Generic.new(partial_path: "form_field_flatpickr_time", extras: extras, nested: {})
100
+ end
101
+
89
102
  def has_many(reader, **extras)
90
103
  nested = @fields.nested do
91
104
  yield
data/lib/super/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Super
4
- VERSION = "0.0.12"
4
+ VERSION = "0.0.13"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-04 00:00:00.000000000 Z
11
+ date: 2021-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -220,10 +220,8 @@ extensions: []
220
220
  extra_rdoc_files: []
221
221
  files:
222
222
  - ".yardopts"
223
- - CONTRIBUTING.md
224
223
  - LICENSE
225
224
  - README.md
226
- - Rakefile
227
225
  - app/assets/config/super_manifest.js
228
226
  - app/assets/javascripts/super/application.js
229
227
  - app/assets/stylesheets/super/application.css
@@ -243,6 +241,9 @@ files:
243
241
  - app/views/super/application/_form.html.erb
244
242
  - app/views/super/application/_form_field__destroy.html.erb
245
243
  - app/views/super/application/_form_field_checkbox.html.erb
244
+ - app/views/super/application/_form_field_flatpickr_date.html.erb
245
+ - app/views/super/application/_form_field_flatpickr_datetime.html.erb
246
+ - app/views/super/application/_form_field_flatpickr_time.html.erb
246
247
  - app/views/super/application/_form_field_rich_text_area.html.erb
247
248
  - app/views/super/application/_form_field_select.html.erb
248
249
  - app/views/super/application/_form_field_text.html.erb
data/CONTRIBUTING.md DELETED
@@ -1,56 +0,0 @@
1
- # Contributing
2
-
3
- Thank you for thinking about contributing to Super!
4
-
5
-
6
- ## General guidelines
7
-
8
- There are a few ground rules that to adhere to:
9
-
10
- * be friendly and patient,
11
- * be welcoming,
12
- * be considerate,
13
- * be respectful,
14
- * be careful in the words that you choose and be kind to others,
15
- * when we disagree, try to understand why.
16
-
17
- This isn't an exhaustive list of things that you can't do. Rather, take it in
18
- the spirit in which it's intended - a guide to make it easier to communicate and
19
- participate in the community.
20
-
21
- This applies to all spaces managed by the Super project.
22
-
23
- If you believe someone is violating the code of conduct, we ask that you report
24
- it by emailing: super+conduct at zachahn.com
25
-
26
- Offenders may be banned, asked to apologize, etc.
27
-
28
- (These guidelines are based on the [FreeBSD CoC][FreeBSD CoC], which in turn is
29
- based on [LLVM Project's draft CoC][LLVM CoC], which in turn is based on the
30
- [Django Project Code of Conduct][Django CoC], which is in turn based on wording
31
- from the Speak Up! project.)
32
-
33
-
34
- ## Bug reports / issues
35
-
36
- 1. Please tell us what version of Super, Ruby, and Rails you are using
37
- 1. Please search the issues before posting your problem
38
- 1. Please ask questions in a public place to benefit all Super users
39
- 1. Please email security-related problems to super+security [at] zachahn.com
40
-
41
-
42
- ## Feature requests / pull requests
43
-
44
- Contributors will need to sign a CLA. This isn't set up yet, so I won't be able
45
- to accept contributions.
46
-
47
- 1. Please note that pull requests may be closed/denied for any reason.
48
- Your feature may be better as its own repository. If so, I will link to your
49
- project from the README!
50
- 1. Please allow Super's contributors to modify your PR before merging.
51
- It might make the process a bit smoother, but this isn't a necessity.
52
-
53
-
54
- [FreeBSD CoC]: https://www.freebsd.org/internal/code-of-conduct.html
55
- [LLVM CoC]: https://llvm.org/docs/CodeOfConduct.html
56
- [Django CoC]: https://www.djangoproject.com/conduct/
data/Rakefile DELETED
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- begin
4
- require "bundler/setup"
5
- rescue LoadError
6
- puts "You must `gem install bundler` and `bundle install` to run rake tasks"
7
- end
8
-
9
- require "rdoc/task"
10
-
11
- RDoc::Task.new(:rdoc) do |rdoc|
12
- rdoc.rdoc_dir = "rdoc"
13
- rdoc.title = "Super"
14
- rdoc.options << "--line-numbers"
15
- rdoc.rdoc_files.include("README.md")
16
- rdoc.rdoc_files.include("lib/**/*.rb")
17
- end
18
-
19
- require_relative "dummy_path"
20
-
21
- APP_RAKEFILE = File.expand_path("#{SUPER_DUMMY_PATH}/Rakefile", __dir__)
22
- load "rails/tasks/engine.rake"
23
-
24
- load "rails/tasks/statistics.rake"
25
-
26
- require "bundler/gem_tasks"
27
-
28
- require "rake/testtask"
29
-
30
- Rake::TestTask.new(:test) do |t|
31
- t.libs << "test"
32
- t.pattern = "test/**/*_test.rb"
33
- t.verbose = false
34
- end
35
-
36
- task default: :test