inline_forms 7.11.0 → 7.13.2

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.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +70 -0
  4. data/app/controllers/inline_forms_controller.rb +21 -0
  5. data/app/helpers/inline_forms_helper.rb +1 -6
  6. data/app/views/inline_forms/_versions_list.html.erb +16 -5
  7. data/archived/form_elements/README.md +1 -7
  8. data/inline_forms.gemspec +3 -3
  9. data/lib/generators/inline_forms_generator.rb +1 -1
  10. data/lib/inline_forms/form_element_registry.rb +46 -0
  11. data/lib/inline_forms/form_elements/audio_field_helper.rb +36 -0
  12. data/lib/inline_forms/form_elements/check_box_helper.rb +23 -0
  13. data/lib/inline_forms/form_elements/check_list_helper.rb +45 -0
  14. data/lib/inline_forms/form_elements/ckeditor_helper.rb +23 -0
  15. data/lib/inline_forms/form_elements/date_helper.rb +28 -0
  16. data/lib/inline_forms/form_elements/decimal_field_helper.rb +22 -0
  17. data/lib/inline_forms/form_elements/devise_password_field_helper.rb +26 -0
  18. data/lib/inline_forms/form_elements/dns_records_helper.rb +23 -0
  19. data/lib/inline_forms/form_elements/dropdown_helper.rb +58 -0
  20. data/lib/inline_forms/form_elements/dropdown_with_integers_helper.rb +29 -0
  21. data/lib/inline_forms/form_elements/dropdown_with_other_helper.rb +160 -0
  22. data/lib/inline_forms/form_elements/dropdown_with_values_helper.rb +40 -0
  23. data/lib/inline_forms/form_elements/dropdown_with_values_with_stars_helper.rb +24 -0
  24. data/lib/inline_forms/form_elements/file_field_helper.rb +27 -0
  25. data/lib/inline_forms/form_elements/header_helper.rb +24 -0
  26. data/lib/inline_forms/form_elements/helper_includes.rb +15 -0
  27. data/lib/inline_forms/form_elements/image_field_helper.rb +31 -0
  28. data/lib/inline_forms/form_elements/info_helper.rb +52 -0
  29. data/lib/inline_forms/form_elements/info_list_helper.rb +30 -0
  30. data/lib/inline_forms/form_elements/integer_field_helper.rb +22 -0
  31. data/lib/inline_forms/form_elements/money_field_helper.rb +22 -0
  32. data/lib/inline_forms/form_elements/month_select_helper.rb +24 -0
  33. data/lib/inline_forms/form_elements/month_year_picker_helper.rb +27 -0
  34. data/lib/inline_forms/form_elements/multi_image_field_helper.rb +31 -0
  35. data/lib/inline_forms/form_elements/pdf_link_helper.rb +41 -0
  36. data/lib/inline_forms/form_elements/plain_text_area_helper.rb +26 -0
  37. data/lib/inline_forms/form_elements/plain_text_helper.rb +31 -0
  38. data/lib/inline_forms/form_elements/question_list_helper.rb +52 -0
  39. data/lib/inline_forms/form_elements/radio_button_helper.rb +34 -0
  40. data/lib/inline_forms/form_elements/rich_text_helper.rb +44 -0
  41. data/lib/inline_forms/form_elements/scale_with_integers_helper.rb +30 -0
  42. data/lib/inline_forms/form_elements/scale_with_values_helper.rb +29 -0
  43. data/lib/inline_forms/form_elements/simple_file_field_helper.rb +36 -0
  44. data/lib/inline_forms/form_elements/slider_with_values_helper.rb +99 -0
  45. data/lib/inline_forms/form_elements/text_area_helper.rb +26 -0
  46. data/lib/inline_forms/form_elements/text_area_without_ckeditor_helper.rb +27 -0
  47. data/lib/inline_forms/form_elements/text_field_helper.rb +26 -0
  48. data/lib/inline_forms/form_elements/time_helper.rb +28 -0
  49. data/lib/inline_forms/form_elements.rb +27 -0
  50. data/lib/inline_forms/version.rb +1 -1
  51. data/lib/inline_forms.rb +19 -3
  52. data/script/migrate_form_elements.rb +62 -0
  53. metadata +52 -48
  54. data/app/helpers/form_elements/audio_field.rb +0 -28
  55. data/app/helpers/form_elements/check_box.rb +0 -16
  56. data/app/helpers/form_elements/check_list.rb +0 -37
  57. data/app/helpers/form_elements/ckeditor.rb +0 -15
  58. data/app/helpers/form_elements/date.rb +0 -20
  59. data/app/helpers/form_elements/decimal_field.rb +0 -15
  60. data/app/helpers/form_elements/devise_password_field.rb +0 -19
  61. data/app/helpers/form_elements/dns_records.rb +0 -15
  62. data/app/helpers/form_elements/dropdown.rb +0 -50
  63. data/app/helpers/form_elements/dropdown_with_integers.rb +0 -21
  64. data/app/helpers/form_elements/dropdown_with_other.rb +0 -153
  65. data/app/helpers/form_elements/dropdown_with_values.rb +0 -32
  66. data/app/helpers/form_elements/dropdown_with_values_with_stars.rb +0 -16
  67. data/app/helpers/form_elements/file_field.rb +0 -20
  68. data/app/helpers/form_elements/header.rb +0 -17
  69. data/app/helpers/form_elements/image_field.rb +0 -24
  70. data/app/helpers/form_elements/info.rb +0 -44
  71. data/app/helpers/form_elements/info_list.rb +0 -22
  72. data/app/helpers/form_elements/integer_field.rb +0 -15
  73. data/app/helpers/form_elements/money_field.rb +0 -15
  74. data/app/helpers/form_elements/month_select.rb +0 -16
  75. data/app/helpers/form_elements/month_year_picker.rb +0 -19
  76. data/app/helpers/form_elements/multi_image_field.rb +0 -24
  77. data/app/helpers/form_elements/pdf_link.rb +0 -33
  78. data/app/helpers/form_elements/plain_text.rb +0 -23
  79. data/app/helpers/form_elements/plain_text_area.rb +0 -18
  80. data/app/helpers/form_elements/question_list.rb +0 -44
  81. data/app/helpers/form_elements/radio_button.rb +0 -27
  82. data/app/helpers/form_elements/rich_text.rb +0 -36
  83. data/app/helpers/form_elements/scale_with_integers.rb +0 -23
  84. data/app/helpers/form_elements/scale_with_values.rb +0 -22
  85. data/app/helpers/form_elements/simple_file_field.rb +0 -28
  86. data/app/helpers/form_elements/slider_with_values.rb +0 -91
  87. data/app/helpers/form_elements/text_area.rb +0 -18
  88. data/app/helpers/form_elements/text_area_without_ckeditor.rb +0 -19
  89. data/app/helpers/form_elements/text_field.rb +0 -18
  90. data/app/helpers/form_elements/time.rb +0 -21
@@ -0,0 +1,52 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module QuestionListHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ # checklist
9
+ def question_list_show(object, attribute)
10
+ out = '<ul class="question_list">'
11
+ out << link_to_inline_edit(object, attribute, from_callee: __callee__) if object.send(attribute).empty?
12
+ object.send(attribute).sort.each do | item |
13
+ out << '<li>'
14
+ out << link_to_inline_edit(object, attribute, item._presentation, from_callee: __callee__ )
15
+ out << '</li>'
16
+ end
17
+ out << '</ul>'
18
+ out.html_safe
19
+ end
20
+
21
+ def question_list_edit(object, attribute)
22
+ object.send(attribute).build if object.send(attribute).empty?
23
+ values = object.send(attribute).first.class.name.constantize.find(:all) # TODO bring order
24
+ out = '<div class="edit_form_checklist">'
25
+ out << '<ul>'
26
+ Question.all.each do | question |
27
+ out << '<li>'
28
+ out << h(question._presentation)
29
+ unless question.subquestions.empty?
30
+ out << '<ul>'
31
+ question.subquestions.each do | subquestion |
32
+ out << '<li>'
33
+ out << h(subquestion._presentation)
34
+ out << '</li>'
35
+ end
36
+ out << '</ul>'
37
+ end
38
+ out << '</li>'
39
+ end
40
+ out << '</ul>'
41
+ out << '</div>'
42
+ out.html_safe
43
+ end
44
+
45
+ def question_list_update(object, attribute)
46
+ params[attribute] ||= {}
47
+ object.send(attribute.singularize + '_ids=', params[attribute].keys)
48
+ end
49
+ INLINE_FORMS_FORM_ELEMENT
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module RadioButtonHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+ # radio buttons are integers in this version
8
+ # us like this:
9
+ # [ :sex , "gender", :radio_button, { 1 => 'male', 2 => 'female' } ],
10
+
11
+ def radio_button_show(object, attribute)
12
+ values = attribute_values(object, attribute)
13
+ link_to_inline_edit object, attribute, object.send(attribute) ? values.assoc(object.send(attribute))[1] : "", from_callee: __callee__
14
+ end
15
+
16
+ def radio_button_edit(object, attribute)
17
+ out =''
18
+ values = attribute_values(object, attribute)
19
+ values.each do |key,value|
20
+ out << "<div class='row #{cycle('odd', 'even')}'>"
21
+ out << radio_button_tag(attribute.to_s, key, key == object.send(attribute))
22
+ out << "<label for=#{key}>#{value}</label>"
23
+ out << '</div>'
24
+ end
25
+ out.html_safe
26
+ end
27
+
28
+ def radio_button_update(object, attribute)
29
+ object[attribute.to_s.to_sym] = params[attribute.to_s.to_sym]
30
+ end
31
+ INLINE_FORMS_FORM_ELEMENT
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,44 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module RichTextHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ def rich_text_show(object, attribute)
9
+ rich = object.respond_to?(attribute) ? object.public_send(attribute) : nil
10
+ is_blank =
11
+ rich.nil? ||
12
+ (rich.respond_to?(:blank?) && rich.blank?) ||
13
+ (rich.respond_to?(:to_plain_text) && rich.to_plain_text.to_s.strip.empty?)
14
+ display_value = is_blank ? "<i class='fi-plus'></i>".html_safe : rich.to_s.html_safe
15
+ link_to_inline_edit object, attribute, display_value, from_callee: __callee__
16
+ end
17
+
18
+ def rich_text_edit(object, attribute)
19
+ rich = object.respond_to?(attribute) ? object.public_send(attribute) : nil
20
+ body =
21
+ if rich.respond_to?(:body) && !rich.body.nil?
22
+ rich.body.to_s
23
+ elsif rich.respond_to?(:to_s)
24
+ rich.to_s
25
+ else
26
+ ''
27
+ end
28
+ input_id = "trix_input_#{object.class.name.underscore}_#{object.id || 'new'}_#{attribute}"
29
+ hidden_field_tag(attribute, body, id: input_id) +
30
+ content_tag(:'trix-editor', ''.html_safe, input: input_id, class: 'trix-content attribute_rich_text_area')
31
+ end
32
+
33
+ def rich_text_update(object, attribute)
34
+ object.public_send("#{attribute}=", params[attribute.to_sym])
35
+ end
36
+
37
+ def rich_text_info(object, attribute)
38
+ value = object.respond_to?(attribute) ? object.public_send(attribute) : nil
39
+ value.to_s
40
+ end
41
+ INLINE_FORMS_FORM_ELEMENT
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module ScaleWithIntegersHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ # scale_with_integers generates a scale
9
+ # with the given list of integers as options
10
+ #
11
+ # values must be a Range or a one-dimensional array of Integers
12
+ #
13
+ def scale_with_integers_show(object, attribute)
14
+ values = attribute_values(object, attribute)
15
+ link_to_inline_edit object, attribute, values[object.send(attribute).to_s], from_callee: __callee__
16
+ end
17
+
18
+ def scale_with_integers_edit(object, attribute)
19
+ # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form!
20
+ values = attribute_values(object, attribute)
21
+ collection_select( ('_' + object.class.to_s.underscore).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute))
22
+ end
23
+
24
+ def scale_with_integers_update(object, attribute)
25
+ object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym]
26
+ end
27
+ INLINE_FORMS_FORM_ELEMENT
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module ScaleWithValuesHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ # scale_with_values generates a scale
9
+ # with the given list of values as options
10
+ #
11
+ # values must be a hash { integer => string, ... } or an one-dimensional array of strings
12
+ def scale_with_values_show(object, attribute)
13
+ values = attribute_values(object, attribute)
14
+ link_to_inline_edit object, attribute, values[object.send(attribute)][1], from_callee: __callee__
15
+ end
16
+
17
+ def scale_with_values_edit(object, attribute)
18
+ # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form!
19
+ values = attribute_values(object, attribute)
20
+ collection_select( ('_' + object.class.to_s.underscore).to_sym, attribute.to_sym, values, 'first', 'last', :selected => object.send(attribute))
21
+ end
22
+
23
+ def scale_with_values_update(object, attribute)
24
+ object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym]
25
+ end
26
+ INLINE_FORMS_FORM_ELEMENT
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module SimpleFileFieldHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ def simple_file_field_show(object, attribute)
9
+ o = object.send(attribute)
10
+ method = attribute_values(object, attribute)[0][1]
11
+ if o.send(:present?)
12
+ filename = o.to_s
13
+ model = object.class.to_s.pluralize.underscore
14
+ link_to filename, "/#{model}/#{method}/#{object.id}" # route must exist!!
15
+ else
16
+ link_to_inline_edit object, attribute, "<i class='fi-plus'></i>".html_safe, from_callee: __callee__
17
+ end
18
+ end
19
+
20
+ def simple_file_field_edit(object, attribute)
21
+ file_field_tag attribute, :class => 'input_text_field'
22
+ end
23
+
24
+ def simple_file_field_update(object, attribute)
25
+ object.send(attribute.to_s + '=', params[attribute.to_sym])
26
+ end
27
+
28
+ # You need to add a route to your routes.rb file:
29
+ # get '/:model/dl/:id' => 'your_controller#download', :as => 'download'
30
+ # and a method to your controller:
31
+ # def download
32
+ # FIXME
33
+ INLINE_FORMS_FORM_ELEMENT
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,99 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module SliderWithValuesHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ # slider_with_values
9
+ def slider_with_values_show(object, attribute)
10
+ values = attribute_values(object, attribute)
11
+ value = object.send(attribute).to_i # should be an int
12
+ display_value = values.assoc(value)[1] # values should be [ [ 0, value ], [ 3, value2 ] .... ] and we lookup the key, not the place in the array!
13
+ css_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}"
14
+ if value == 0
15
+ out = "?" # we use this as the 'unknown' value. So in the data, 0 should always be the unknown value. This gives problems with sliders where the real value is 0.
16
+ else
17
+ out = "".html_safe
18
+ out << "<div class='slider slider_#{attribute.to_s}' id='slider_#{css_id}'></div>".html_safe
19
+ out << "<div class='slider_value' id='value_#{css_id}'>#{display_value}</div>".html_safe
20
+ out << "<div style='clear: both' />".html_safe
21
+ out << "<input type='hidden' name='_#{object.class.to_s.underscore}[#{attribute}]' value='0' id='input_#{css_id}' />".html_safe
22
+ out << ('<script>
23
+ $(function() {
24
+ var displayvalues = ' + values.collect {|x| x[1]}.inspect + ';
25
+ $( "#slider_' + css_id + '" ).slider(
26
+ {
27
+ value:' + value.to_s + ',
28
+ range: "min",
29
+ disabled: true,
30
+ min: 0,
31
+ max: ' + values.length.to_s + ',
32
+ step: 1,
33
+ }
34
+ );
35
+ });
36
+ </script>').html_safe
37
+ end
38
+ link_to_inline_edit object, attribute, out, from_callee: __callee__
39
+ end
40
+
41
+ def slider_with_values_edit(object, attribute)
42
+ # the leading underscore is to avoid name conflicts, like 'email' and 'email_type' will result in 'email' and 'email[email_type_id]' in the form!
43
+ values = attribute_values(object, attribute)
44
+ value = object.send(attribute).to_i # should be an int, will be 0 if nil
45
+ css_id = "#{object.class.to_s.underscore}_#{object.id}_#{attribute}"
46
+ display_value = values.assoc(value)[1] # values should be [ [ 0, value ], [ 3, value2 ] .... ] and we lookup the key, not the place in the array!
47
+ out = "".html_safe
48
+ out << "<div class='slider slider_#{attribute.to_s}' id='slider_#{css_id}'></div>".html_safe
49
+ out << "<div class='slider_value' id='value_#{css_id}'>#{display_value}</div>".html_safe
50
+ out << "<div style='clear: both' />".html_safe
51
+ out << "<input type='hidden' name='_#{object.class.to_s.underscore}[#{attribute}]' value='0' id='input_#{css_id}' />".html_safe
52
+ out << ('<script>
53
+ $(function() {
54
+ var displayvalues = ' + values.collect {|x| x[1]}.inspect + ';
55
+ $( "#slider_' + css_id + '" ).slider(
56
+ {
57
+ value:' + value.to_s + ',
58
+ range: "min",
59
+ min: 0,
60
+ max: 5,
61
+ step: 1,
62
+ slide: function( event, ui ) {
63
+ $( "#input_' + css_id + '" ).val( ui.value );
64
+ $( "#value_' + css_id + '" ).html( displayvalues[ui.value] );
65
+ }
66
+ }
67
+ );').html_safe
68
+ out << ('$( "#value_' + css_id + '" ).html(displayvalues[' + value.to_s + ']);').html_safe
69
+ out << ('$( "#input_' + css_id + '" ).val(' + value.to_s + ');').html_safe
70
+ out << ('});
71
+ </script>').html_safe
72
+ out
73
+ end
74
+
75
+ def slider_with_values_update(object, attribute)
76
+ object[attribute.to_sym] = params[('_' + object.class.to_s.underscore).to_sym][attribute.to_sym]
77
+ end
78
+
79
+ #<style>
80
+ # #demo-frame > div.demo { padding: 10px !important; };
81
+ # </style>
82
+ #
83
+ #
84
+ #
85
+ #<div class="demo">
86
+ #
87
+ #<p>
88
+ # <label for="amount">Donation amount ($50 increments):</label>
89
+ # <input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;" />
90
+ #</p>
91
+ #
92
+ #<div id="slider"></div>
93
+ #
94
+ #</div><!-- End demo -->
95
+ #
96
+ INLINE_FORMS_FORM_ELEMENT
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module TextAreaHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ def text_area_show(object, attribute)
9
+ rich_text_show(object, attribute)
10
+ end
11
+
12
+ def text_area_edit(object, attribute)
13
+ rich_text_edit(object, attribute)
14
+ end
15
+
16
+ def text_area_update(object, attribute)
17
+ rich_text_update(object, attribute)
18
+ end
19
+
20
+ def text_area_info(object, attribute)
21
+ rich_text_info(object, attribute)
22
+ end
23
+ INLINE_FORMS_FORM_ELEMENT
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module TextAreaWithoutCkeditorHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+ # Legacy alias for plain :text_area (CKEditor removed).
8
+
9
+ def text_area_without_ckeditor_show(object, attribute)
10
+ plain_text_show(object, attribute)
11
+ end
12
+
13
+ def text_area_without_ckeditor_edit(object, attribute)
14
+ plain_text_edit(object, attribute)
15
+ end
16
+
17
+ def text_area_without_ckeditor_update(object, attribute)
18
+ plain_text_update(object, attribute)
19
+ end
20
+
21
+ def text_area_without_ckeditor_info(object, attribute)
22
+ plain_text_info(object, attribute)
23
+ end
24
+ INLINE_FORMS_FORM_ELEMENT
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module TextFieldHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ def text_field_show(object, attribute, turbo_frame: false)
9
+ link_to_inline_edit object, attribute, object[attribute].blank? ? "<i class='fi-plus'></i>".html_safe : object[attribute], from_callee: __callee__, turbo_frame: turbo_frame
10
+ end
11
+
12
+ def text_field_edit(object, attribute)
13
+ text_field_tag attribute, (object.send attribute.to_sym), :class => 'input_text_field' # for abide: , :required => true
14
+ end
15
+
16
+ def text_field_update(object, attribute)
17
+ object.send :write_attribute, attribute.to_sym, params[attribute.to_sym]
18
+ end
19
+
20
+ def text_field_info(object, attribute)
21
+ object[attribute]
22
+ end
23
+ INLINE_FORMS_FORM_ELEMENT
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module InlineForms
3
+ module FormElements
4
+ module TimeHelper
5
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
6
+ # -*- encoding : utf-8 -*-
7
+
8
+ # time
9
+ def time_select_show(object, attribute)
10
+ link_to_inline_edit object, attribute, object.send(attribute).nil? ? "<i class='fi-plus'></i>".html_safe : object.send(attribute).to_datetime.strftime("%l:%M%P"), from_callee: __callee__
11
+ end
12
+
13
+ def time_select_edit(object, attribute)
14
+ css_id = 'timepicker_' + object.class.to_s.underscore + '_' + object.id.to_s + '_' + attribute.to_s
15
+ out = text_field_tag attribute, ( object.send(attribute).nil? ? "" : object.send(attribute).to_datetime.strftime("%l:%M%P") ), :id => css_id, :class =>'timepicker'
16
+ end
17
+
18
+ def time_select_update(object, attribute)
19
+ object[attribute.to_sym] = params[attribute.to_sym]
20
+ end
21
+
22
+ def time_select_info(object, attribute)
23
+ object.send(attribute).nil? ? "-" : object.send(attribute).to_date
24
+ end
25
+ INLINE_FORMS_FORM_ELEMENT
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "inline_forms/form_elements/helper_includes"
4
+
5
+ module InlineForms
6
+ module FormElements
7
+ module_function
8
+
9
+ def load_helpers!
10
+ return if @helpers_loaded
11
+
12
+ helpers_root = InlineForms::Engine.root.join("lib/inline_forms/form_elements")
13
+ Dir[helpers_root.join("*_helper.rb")].sort.each { |path| require path.to_s }
14
+ @helpers_loaded = true
15
+ end
16
+
17
+ def helper_modules
18
+ load_helpers!
19
+ Dir[InlineForms::Engine.root.join("lib/inline_forms/form_elements/*_helper.rb")]
20
+ .sort
21
+ .filter_map do |path|
22
+ const_name = File.basename(path, ".rb").camelize
23
+ const_get(const_name) if const_defined?(const_name, false)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module InlineForms
3
- VERSION = "7.11.0"
3
+ VERSION = "7.13.2"
4
4
  end
data/lib/inline_forms.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # -*- encoding : utf-8 -*-
2
- require ('inline_forms/version.rb')
3
- require_relative ('inline_forms/form_element_from_callee')
4
- require_relative ('inline_forms/archived_form_elements')
2
+ require "inline_forms/version"
3
+ require "inline_forms/form_element_from_callee"
4
+ require "inline_forms/archived_form_elements"
5
+ require "inline_forms/form_element_registry"
6
+ require "inline_forms/form_elements"
5
7
  # InlineForms is a Rails Engine that let you setup an admin interface quick and
6
8
  # easy. Please install it as a gem or include it in your Gemfile.
7
9
  module InlineForms
@@ -181,6 +183,20 @@ module InlineForms
181
183
  # Declare as a Rails::Engine, see http://www.ruby-forum.com/topic/211017#927932
182
184
  class Engine < Rails::Engine
183
185
 
186
+ initializer "inline_forms.form_element_registry" do
187
+ InlineForms::FormElementRegistry.apply!
188
+ end
189
+
190
+ initializer "inline_forms.form_element_helpers" do
191
+ InlineForms::FormElements.load_helpers!
192
+ end
193
+
194
+ initializer "inline_forms.ignore_form_element_autoload", before: :setup_autoloaders do
195
+ path = root.join("lib/inline_forms/form_elements")
196
+ Rails.autoloaders.main.ignore(path)
197
+ Rails.autoloaders.once.ignore(path) if Rails.autoloaders.respond_to?(:once)
198
+ end
199
+
184
200
  # validation_hints 6.x registers its ActiveModel patch via on_load, but apps
185
201
  # require rails/all before Bundler.require, so active_model is already loaded.
186
202
  initializer "inline_forms.validation_hints" do
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "active_support/core_ext/string/inflections"
5
+
6
+ root = File.expand_path("..", __dir__)
7
+ src = File.join(root, "app/helpers/form_elements")
8
+ dst = File.join(root, "app/helpers/inline_forms/form_elements")
9
+ registry = {}
10
+
11
+ Dir.chdir(src)
12
+ Dir.glob("*.rb").sort.each do |basename|
13
+ content = File.read(basename)
14
+ content.scan(/InlineForms::SPECIAL_COLUMN_TYPES\[:(\w+)\]\s*=\s*:(\w+)/) do |k, v|
15
+ registry[k.to_sym] = v.to_sym
16
+ end
17
+
18
+ body = content.lines.reject do |l|
19
+ l =~ /InlineForms::SPECIAL_COLUMN_TYPES/ ||
20
+ l =~ /^#.*SPECIAL_COLUMN_TYPES/ ||
21
+ l =~ /^#\s*-*\s*encoding/
22
+ end.join
23
+ body = body.strip
24
+ next if body.empty?
25
+
26
+ mod = File.basename(basename, ".rb").camelize + "Helper"
27
+ out = <<~RUBY
28
+ # -*- encoding : utf-8 -*-
29
+ module InlineForms
30
+ module FormElements
31
+ module #{mod}
32
+ module_eval(<<~'INLINE_FORMS_FORM_ELEMENT', __FILE__, __LINE__ + 1)
33
+ #{body.gsub(/^/, " ")}
34
+ INLINE_FORMS_FORM_ELEMENT
35
+ end
36
+ end
37
+ end
38
+ RUBY
39
+
40
+ FileUtils.mkdir_p(dst)
41
+ File.write(File.join(dst, "#{File.basename(basename, '.rb')}_helper.rb"), out)
42
+ end
43
+
44
+ registry_path = File.join(root, "lib/inline_forms/form_element_registry.rb")
45
+ entries = registry.map { |k, v| " #{k.inspect} => #{v.inspect}," }.join("\n")
46
+ File.write(registry_path, <<~RUBY)
47
+ # frozen_string_literal: true
48
+
49
+ module InlineForms
50
+ module FormElementRegistry
51
+ ENTRIES = {
52
+ #{entries}
53
+ }.freeze
54
+
55
+ def self.apply!
56
+ SPECIAL_COLUMN_TYPES.merge!(ENTRIES)
57
+ end
58
+ end
59
+ end
60
+ RUBY
61
+
62
+ puts "Migrated #{Dir.glob(File.join(dst, '*_helper.rb')).size} helpers"