make 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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/make +11 -2
  3. data/lib/make/form.rb +83 -21
  4. data/lib/make.rb +3 -5
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 358db4322a2767db4c9dd0c00e99ee89ca7951a1
4
- data.tar.gz: b50babfd88a375ca57b3d86a7844e442a9c59c0d
3
+ metadata.gz: d9859b1011471276787c7de7c4bea66ba257db0c
4
+ data.tar.gz: 92d00aa9ef8415f62387577cdbed417d6f0ee036
5
5
  SHA512:
6
- metadata.gz: 51f33682f3ec11e429d66a596ccf475741fc91940b23fd88a48f56284fbf65af61218215527b11fdb0e24afb9954f56373ec39f8dcba5297adede38a46727732
7
- data.tar.gz: 53c09c37b3e70b2456c529610c7e85b8be709c06b73b75caeb2c40856132e000ae40fb5da1792b41c5fb3794e7b19b54cb8a4946bc74745bedfcb0f7e9e701fd
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 'sarawong'
4
- puts Sarawong.hi(ARGV[0])
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
- module Form
2
- def self.form(model, columnNames, options = {})
1
+ class Form
2
+ def initialize
3
3
  # Convert given model into String
4
- controller=model.to_s.downcase+"s"
5
- # Set form action and method to create using REST conventions
6
- form = '<form action="/' + controller + '" method="post">'
7
- # if default optional parameters are passed in, make hidden inputs
8
- if options[:default]
9
- options[:default].each_pair do |key, value|
10
- form = form + '<input type="hidden" name="'+key.to_s+'" value="'+value.to_s+'">'
11
- # remove the created inputs from the columns Array (columnNames).
12
- columnNames.delete(key.to_s)
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
- # These are some typical form keys to ignore when rendering form
16
- toRemove = ['id', 'created_at', 'updated_at', 'salt', 'encrypted_password']
17
- toRemove.each do |item|
18
- columnNames.delete(item)
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 for simple form creation
21
- columnNames.each do |column|
22
- form = form + '<label>' + column.titleize + '</label><input type="text" name="'+column+'">'
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
- # Add authentication to each form requested
25
- form += '<input id="authenticity_token" name="authenticity_token" type="hidden" value="<%= form_authenticity_token %>"><input type="submit" value="Submit"></form>'
26
- return form
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(input, options = {})
12
- string = Form.form(input.to_s, input.column_names, options)
13
- string = string.html_safe
14
- return string
11
+ def self.form
12
+ Form.new
15
13
  end
16
14
  def self.table
17
- return Table.new
15
+ Table.new
18
16
  end
19
17
  end
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sara Wong