make 0.1.8 → 0.1.9

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/make/form.rb +38 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6edbcf13869122e86247eb3fae3e2125536899f3
4
- data.tar.gz: 4a753ba447898bb7938bf38eef4c5a0bcd24de42
3
+ metadata.gz: 035d5c815e1b884c05b5f081161873c5f9b67ea9
4
+ data.tar.gz: 29cb4a36ebc3370c9a7f2a24c2270660c795aefd
5
5
  SHA512:
6
- metadata.gz: d79b384a7f41e8547da259ec3133bfab9e64540a51450850d3d31bf44c1d179982541e87d900f264c62ae9175a0fc8a6ac8875480228733d04a3d35d6b0e658d
7
- data.tar.gz: e55a3771bea39a6902ed6b254070cca907aa2b88f83a7b428e114af0e90b79d6058471a9336422b1427bef04d961106ecc12af808caacd50c4c76e0a92422eb4
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
- def confirm change
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
- def model model
30
- @formAction = '/' + model.downcase+"s"
31
- @model = model.constantize
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
- @formStart = '<form class="' + @formClass + '" action="' + @formAction + '" method="' + @formMethod + '">'
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: make
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sara Wong