make 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/make +11 -2
- data/lib/make/form.rb +83 -21
- data/lib/make.rb +3 -5
- 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: d9859b1011471276787c7de7c4bea66ba257db0c
|
4
|
+
data.tar.gz: 92d00aa9ef8415f62387577cdbed417d6f0ee036
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ff5eace2e3a8faa6fb6d2cbabb1076eac85780d016db77d00d36d110094286c4d86c25f00e9e571d04a0e5655a68890a1ad3911c26e91c69f682e0610cd9f5a
|
7
|
+
data.tar.gz: 21e46222eddbf85b2fb6bcd58dca215ef77e77380180ffbcfa81769aa52a2c4ebd6b70ba887885dea1a9bdd214f94211eb6e778115d2866304470536b7a3f093
|
data/bin/make
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
4
|
-
puts
|
3
|
+
require 'make'
|
4
|
+
puts print "Please input your Model name"
|
5
|
+
model = gets
|
6
|
+
puts print "Would you like a table or form? (t or f)"
|
7
|
+
type = gets
|
8
|
+
if type == 't'
|
9
|
+
result = Make.model(model).now!
|
10
|
+
else
|
11
|
+
result = Make.form(model).now!
|
12
|
+
end
|
13
|
+
print result
|
data/lib/make/form.rb
CHANGED
@@ -1,28 +1,90 @@
|
|
1
|
-
|
2
|
-
def
|
1
|
+
class Form
|
2
|
+
def initialize
|
3
3
|
# Convert given model into String
|
4
|
-
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
@formClass='make-form'
|
5
|
+
# By default, set form action and method to create using REST conventions
|
6
|
+
@formMethod='post'
|
7
|
+
@formStart=''
|
8
|
+
@formMiddle=[]
|
9
|
+
@formEnd='<input id="authenticity_token" name="authenticity_token" type="hidden" value="<%= form_authenticity_token %>"><input type="submit" value="Submit"></form>'
|
10
|
+
@default_keys_to_ignore = ['id', 'created_at', 'updated_at']
|
11
|
+
@potential_keys_to_ignore = ['salt']
|
12
|
+
@defaults = {}
|
13
|
+
@keys_to_show=[]
|
14
|
+
@selections = []
|
15
|
+
@password_confirmation = true
|
16
|
+
@model = {}
|
17
|
+
@columns = []
|
18
|
+
end
|
19
|
+
def default column, value
|
20
|
+
@defaults = @defaults.merge({column => value})
|
21
|
+
# remove the created inputs from the columns Array (columnNames).
|
22
|
+
@potential_keys_to_ignore.push(column.to_s)
|
23
|
+
return self
|
24
|
+
end
|
25
|
+
def confirm change
|
26
|
+
@password_confirmation = false
|
27
|
+
return self
|
28
|
+
end
|
29
|
+
def model model
|
30
|
+
@formAction = '/' + model.downcase+"s"
|
31
|
+
@model = model.constantize
|
32
|
+
return self
|
33
|
+
end
|
34
|
+
def select column, array, assoc = false
|
35
|
+
columnName = column.titleize
|
36
|
+
input = '<label>' + columnName + '</label><select name="' + column + '" value="' + column + '">'
|
37
|
+
if assoc #if association is checked true
|
38
|
+
array.each do |id|
|
39
|
+
val = column[0...-3].capitalize.constantize.find(id).attributes.values[1]
|
40
|
+
input += '<option value="' + id.to_s + '">' + val.to_s + '</option>'
|
41
|
+
end
|
42
|
+
else #if no associations exist for array
|
43
|
+
array.each do |item|
|
44
|
+
input += '<option value="' + item.to_s + '">' + item.to_s + '</option>'
|
13
45
|
end
|
14
46
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
47
|
+
@potential_keys_to_ignore.push(column)
|
48
|
+
input += '</select>'
|
49
|
+
@formMiddle.push(input)
|
50
|
+
return self
|
51
|
+
end
|
52
|
+
# Build code from class variables
|
53
|
+
def starter
|
54
|
+
@formStart = '<form class="' + @formClass + '" action="' + @formAction + '" method="' + @formMethod + '">'
|
55
|
+
end
|
56
|
+
def middle
|
57
|
+
@columns = @keys_to_show + @model.column_names - @default_keys_to_ignore
|
58
|
+
@potential_keys_to_ignore.each do |item|
|
59
|
+
puts 'got in potential'
|
60
|
+
@columns.delete(item)
|
61
|
+
puts @columns
|
62
|
+
puts @item
|
19
63
|
end
|
20
|
-
# Create text input labels
|
21
|
-
|
22
|
-
|
64
|
+
# Create text input labels
|
65
|
+
@columns.each do |column|
|
66
|
+
if column.include? 'password'
|
67
|
+
input = '<label>Password</label><input type="text" name="password">'
|
68
|
+
@formMiddle.push(input)
|
69
|
+
if @password_confirmation
|
70
|
+
input = '<label>Confirm Password</label><input type="text" name="password_confirmation">'
|
71
|
+
@formMiddle.push(input)
|
72
|
+
end
|
73
|
+
else
|
74
|
+
input = '<label>' + column.titleize + '</label><input type="text" name="'+column+'">'
|
75
|
+
@formMiddle.push(input)
|
76
|
+
end
|
23
77
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
78
|
+
@defaults.each_pair do |key, value|
|
79
|
+
input = '<input type="hidden" name="'+key.to_s+'" value="'+value.to_s+'">'
|
80
|
+
puts input
|
81
|
+
puts @formMiddle
|
82
|
+
@formMiddle.push(input)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
def now!
|
86
|
+
starter
|
87
|
+
middle
|
88
|
+
return (@formStart+@formMiddle.join+@formEnd).html_safe
|
27
89
|
end
|
28
90
|
end
|
data/lib/make.rb
CHANGED
@@ -8,12 +8,10 @@ module Make
|
|
8
8
|
string = string.html_safe
|
9
9
|
return string
|
10
10
|
end
|
11
|
-
def self.form
|
12
|
-
|
13
|
-
string = string.html_safe
|
14
|
-
return string
|
11
|
+
def self.form
|
12
|
+
Form.new
|
15
13
|
end
|
16
14
|
def self.table
|
17
|
-
|
15
|
+
Table.new
|
18
16
|
end
|
19
17
|
end
|