back_office 0.1.3 → 0.1.4
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 +4 -4
- data/lib/back_office.rb +1 -1
- data/lib/back_office/version.rb +1 -1
- metadata +1 -2
- data/lib/back_office/form_builder.rb +0 -117
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96184dd90fabf30fe828e8c8f47abf2768490234
|
4
|
+
data.tar.gz: 0cbe873f11a2d2c5248a0691d9d32d324a1f48b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73574594122f86d24197082180bb0afc5461b505f64574e5a0c81ef6e9b3ad98c12962e37f17155a5ff73a89638c22e689febb36e09b9788621b7ddb8f0b4598
|
7
|
+
data.tar.gz: 29bf93cc7a2463b636d096ac2b5aa763e31a7a51599f78a783b3008dde8cb93930d5d9379dbdaf9d456f70ae69dbdb25a68958623824740d7d08b2a29cc30c38
|
data/lib/back_office.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'back_office/engine'
|
2
2
|
require 'back_office/auth'
|
3
|
+
require 'back_office/rest'
|
3
4
|
require 'back_office/authorization'
|
4
5
|
require 'back_office/cursor'
|
5
|
-
require 'back_office/form_builder'
|
6
6
|
require 'back_office/password'
|
7
7
|
require 'back_office/reset'
|
8
8
|
require 'back_office/searchable'
|
data/lib/back_office/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: back_office
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gustavo Beathyate
|
@@ -54,7 +54,6 @@ files:
|
|
54
54
|
- lib/back_office/authorization.rb
|
55
55
|
- lib/back_office/cursor.rb
|
56
56
|
- lib/back_office/engine.rb
|
57
|
-
- lib/back_office/form_builder.rb
|
58
57
|
- lib/back_office/password.rb
|
59
58
|
- lib/back_office/reset.rb
|
60
59
|
- lib/back_office/rest.rb
|
@@ -1,117 +0,0 @@
|
|
1
|
-
module BackOffice
|
2
|
-
class FormBuilder < ActionView::Helpers::FormBuilder
|
3
|
-
FIELD_CLASS = 'field'.freeze
|
4
|
-
LABEL_CLASS = 'label'.freeze
|
5
|
-
ACTION_CLASS = 'action'.freeze
|
6
|
-
HINT_CLASS = 'hint'.freeze
|
7
|
-
ERRORS_CLASS = 'errors'.freeze
|
8
|
-
FIELD_METHODS = %w(
|
9
|
-
text_field
|
10
|
-
number_field
|
11
|
-
text_area
|
12
|
-
email_field
|
13
|
-
phone_field
|
14
|
-
password_field
|
15
|
-
file_field
|
16
|
-
collection_select
|
17
|
-
collection_check_boxes
|
18
|
-
check_box
|
19
|
-
date_select
|
20
|
-
time_zone_select
|
21
|
-
).freeze
|
22
|
-
|
23
|
-
delegate :content_tag, :tag, :capture, to: :@template
|
24
|
-
|
25
|
-
FIELD_METHODS.each do |method_name|
|
26
|
-
define_method method_name do |name, *args, &block|
|
27
|
-
options = args.extract_options!
|
28
|
-
hint = options.delete(:hint)
|
29
|
-
confirm = options.delete(:confirm)
|
30
|
-
classes = object.class.validators_on(name).map { |v| v.to_s.underscore }
|
31
|
-
content = field_label(name, options) +
|
32
|
-
super(name, *args, options, &block) +
|
33
|
-
discloser(method_name) +
|
34
|
-
confirmation(confirm) +
|
35
|
-
hint_label(hint)
|
36
|
-
|
37
|
-
content_tag(:div, content, class: classes.push(FIELD_CLASS))
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def submit(value = nil, options = {}, &block)
|
42
|
-
content = if block
|
43
|
-
block_before ? capture(&block) + super : super + capture(&block)
|
44
|
-
else
|
45
|
-
super
|
46
|
-
end
|
47
|
-
|
48
|
-
content_tag(:div, content, class: ACTION_CLASS)
|
49
|
-
end
|
50
|
-
|
51
|
-
def field_input(confirm: false)
|
52
|
-
field = object.field
|
53
|
-
options = { label: field.name, hint: field.hint, confirm: confirm }
|
54
|
-
|
55
|
-
case field.data_type
|
56
|
-
when 'string'
|
57
|
-
if field.options.present?
|
58
|
-
collection_select(:value, field.options.lines.map(&:chomp), :itself, :itself, options)
|
59
|
-
elsif field.scale.positive?
|
60
|
-
text_area(:value, options.merge(rows: field.scale))
|
61
|
-
else
|
62
|
-
text_field(:value, options)
|
63
|
-
end
|
64
|
-
when 'datetime'
|
65
|
-
text_field(:value, options.merge(class: 'datepicker'))
|
66
|
-
when 'boolean'
|
67
|
-
check_box(:value, options)
|
68
|
-
else
|
69
|
-
text_field(:value, options)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def confirmation(confirm)
|
74
|
-
check_box(:confirm, label: false, hint: false) if confirm
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
def field_label(name, options)
|
80
|
-
base_text = case options[:label]
|
81
|
-
when false
|
82
|
-
''
|
83
|
-
when nil
|
84
|
-
object.class.human_attribute_name(name)
|
85
|
-
else
|
86
|
-
options[:label]
|
87
|
-
end
|
88
|
-
|
89
|
-
if base_text.present? && object.errors[name].first
|
90
|
-
|
91
|
-
|
92
|
-
end
|
93
|
-
label_text = label_and_error_text(name, options)
|
94
|
-
|
95
|
-
label(name, label_text, class: css_classes)
|
96
|
-
end
|
97
|
-
|
98
|
-
def label_and_error_text(name, options)
|
99
|
-
label_text = options.fetch(:label, )
|
100
|
-
error_text =
|
101
|
-
|
102
|
-
[label_text, error_text].compact.join(SEPARATOR)
|
103
|
-
end
|
104
|
-
|
105
|
-
def objectify_options(options)
|
106
|
-
super.except(:label)
|
107
|
-
end
|
108
|
-
|
109
|
-
def hint_label(text)
|
110
|
-
content_tag(:span, text.try(:html_safe), class: HINT_CLASS) unless text == false
|
111
|
-
end
|
112
|
-
|
113
|
-
def discloser(method_name, css_class = 'discloser')
|
114
|
-
method_name.to_s.end_with?('select') ? content_tag(:span, class: css_class) {} : ''
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|