make 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/make/form.rb +38 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 035d5c815e1b884c05b5f081161873c5f9b67ea9
|
4
|
+
data.tar.gz: 29cb4a36ebc3370c9a7f2a24c2270660c795aefd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 225e70762995508be506fc5dc4c5e06cdeeeea1022ad8bfe997e98748b3bfab88ab2e541dddd562360bc6e0ab0de0d356680578baa5b3bc36eaca1e00bc96f99
|
7
|
+
data.tar.gz: e0635632134bdbd3544e60493c79c977ab6ef530289914656b9786c8ab47c1a160b81a7b68a4700ff49c93860dac8cd29e8ff1c9fd17d37ff3e6188ef3fef5f9
|
data/lib/make/form.rb
CHANGED
@@ -4,6 +4,7 @@ class Form
|
|
4
4
|
@formClass='make-form'
|
5
5
|
# By default, set form action and method to create using REST conventions
|
6
6
|
@formMethod='post'
|
7
|
+
@formMethodHidden=nil
|
7
8
|
@formStart=''
|
8
9
|
@formMiddle=[]
|
9
10
|
@formEnd='<input id="authenticity_token" name="authenticity_token" type="hidden" value="<%= form_authenticity_token %>"><input type="submit" value="Submit"></form>'
|
@@ -14,23 +15,47 @@ class Form
|
|
14
15
|
@selections = []
|
15
16
|
@password_confirmation = true
|
16
17
|
@model = {}
|
18
|
+
@modelName = ''
|
17
19
|
@columns = []
|
20
|
+
@id = nil
|
18
21
|
end
|
22
|
+
# First class method accessed in form, passing in form as a string
|
23
|
+
def model model
|
24
|
+
@modelName = model
|
25
|
+
# Set default form's Action based on REST conventions /users
|
26
|
+
@formAction = "/" + @modelName.downcase + "s"
|
27
|
+
@model = model.constantize
|
28
|
+
return self
|
29
|
+
end
|
30
|
+
# change action url if specific and does not follow REST
|
31
|
+
def action url
|
32
|
+
@formAction = url
|
33
|
+
return self
|
34
|
+
end
|
35
|
+
# Change form class
|
36
|
+
def class myClass
|
37
|
+
@formClass = myClass
|
38
|
+
return self
|
39
|
+
end
|
40
|
+
# Determine default value for a specific field. Because no options exist, it will be hidden.
|
19
41
|
def default column, value
|
20
42
|
@defaults = @defaults.merge({column => value})
|
21
43
|
# remove the created inputs from the columns Array (columnNames).
|
22
44
|
@potential_keys_to_ignore.push(column.to_s)
|
23
45
|
return self
|
24
46
|
end
|
25
|
-
|
47
|
+
# Default requires password confirmation, if none is needed change it will no longer require it.
|
48
|
+
def no_pw_confirm
|
26
49
|
@password_confirmation = false
|
27
50
|
return self
|
28
51
|
end
|
29
|
-
|
30
|
-
|
31
|
-
@
|
52
|
+
# Change the form method to put, patch, or delete.
|
53
|
+
def method type, id
|
54
|
+
@formMethodHidden = type
|
55
|
+
@id = id
|
32
56
|
return self
|
33
57
|
end
|
58
|
+
# Similar to default, but instead of a hidden specific value you pass in an array and create a select/option field.
|
34
59
|
def select column, array, assoc = false
|
35
60
|
columnName = column.titleize
|
36
61
|
input = '<label>' + columnName + '</label><select name="' + column + '" value="' + column + '">'
|
@@ -49,10 +74,16 @@ class Form
|
|
49
74
|
@formMiddle.push(input)
|
50
75
|
return self
|
51
76
|
end
|
52
|
-
# Build code from class variables
|
77
|
+
# Build starting code from class variables called upon by now!
|
53
78
|
def starter
|
54
|
-
|
79
|
+
if @formMethodHidden
|
80
|
+
@formStart = '<form class="' + @formClass + '" action="' + @formAction + '/'+ @id.to_s + '" method="' + @formMethod + '">'
|
81
|
+
@formStart += '<input name="_method" type="hidden" value="' + @formMethodHidden + '">'
|
82
|
+
else
|
83
|
+
@formStart = '<form class="' + @formClass + '" action="' + @formAction + '" method="' + @formMethod + '">'
|
84
|
+
end
|
55
85
|
end
|
86
|
+
# Build remaining code from class variables called upon by now!
|
56
87
|
def middle
|
57
88
|
@columns = @keys_to_show + @model.column_names - @default_keys_to_ignore
|
58
89
|
@potential_keys_to_ignore.each do |item|
|
@@ -82,6 +113,7 @@ class Form
|
|
82
113
|
@formMiddle.push(input)
|
83
114
|
end
|
84
115
|
end
|
116
|
+
# At the end of building the form, return the final string.
|
85
117
|
def now!
|
86
118
|
starter
|
87
119
|
middle
|