make 0.1.1 → 0.1.2

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/make.rb +7 -4
  3. data/lib/make/builder.rb +21 -10
  4. metadata +7 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 044fd86ac94adba956b2ca5707e4d0187e60a0c7
4
- data.tar.gz: 1507d9437e23eb1fb3f4a0ae4f2363105dda3b4e
3
+ metadata.gz: fdb05908a60e9123a53a661f39d8c86050f21261
4
+ data.tar.gz: fa17b88c27383792c321620785348540c8fd80c5
5
5
  SHA512:
6
- metadata.gz: 704f905f2bab46019d0e9527e3585fc30356e6728e6ad0f62247dbf8441340ce6087b0ef283cd49740bd915f12bb4d440369f27b38a5f08349f2635654ed1c86
7
- data.tar.gz: 48b7c678670699c27546dc3f484e4a55b571652f83d95eb3ba2d6926abaf404c2d235c26a2ca00b210b30da5f59e0e246143902df27a08f1a1ca20e15ba7d1c5
6
+ metadata.gz: 19940ec381374c5b9a21ba2181419a6d44d1c35a7a85ce15dc050886a3c0bec092d58b4cf3cb9c10ab8662e9c95ac72dee0dacd80c258ad00f3cdb906e7b07bf
7
+ data.tar.gz: 940ea0f3bab7942ba5b1e13d7cb054c27a8b3f882cbc9efd6e07e96a6d6fcf26fb72155631f720426677dde53035f3a83a5e0bbf6274f971325143b65893739f
@@ -1,13 +1,16 @@
1
- require 'make/builder'
2
-
1
+ require 'make/builder.rb'
3
2
  module Make
3
+ def initialize
4
+ @thead=''
5
+ @tbody=''
6
+ end
4
7
  def self.header(title = 'title here')
5
8
  string = Builder.header(title)
6
9
  string = string.html_safe
7
10
  return string
8
11
  end
9
- def self.form(input)
10
- string = Builder.form(input.to_s, input.column_names)
12
+ def self.form(input, options = {})
13
+ string = Builder.form(input.to_s, input.column_names, options)
11
14
  string = string.html_safe
12
15
  return string
13
16
  end
@@ -2,18 +2,29 @@ module Builder
2
2
  def self.header(title)
3
3
  return '<meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>'+title+'</title><meta name="description" content=""><meta name="viewport" content="width=device-width, initial-scale=1">'
4
4
  end
5
- def self.form(db, columnNames)
6
- puts 'in builder form'
7
- form = '<form action="/' + db.to_s.downcase + 's" method="post">'
8
- columnNames.each do |column|
9
- if column == 'id' || column == 'created_at' || column == 'updated_at'
10
- puts column
11
- elsif column[-3..-1] == '_id'
12
- puts 'found an _id column'
13
- else
14
- form = form + '<label>' + column.titleize + '</label><input type="text" name="'+column+'">'
5
+ def self.form(model, columnNames, options = {})
6
+ # Convert given model into String
7
+ controller=model.to_s.downcase+"s"
8
+ # Set form action and method to create using REST conventions
9
+ form = '<form action="/' + controller + '" method="post">'
10
+ # if default optional parameters are passed in, make hidden inputs
11
+ if options[:default]
12
+ options[:default].each_pair do |key, value|
13
+ form = form + '<input type="hidden" name="'+key.to_s+'" value="'+value.to_s+'">'
14
+ # remove the created inputs from the columns Array (columnNames).
15
+ columnNames.delete(key.to_s)
15
16
  end
16
17
  end
18
+ # These are some typical form keys to ignore when rendering form
19
+ toRemove = ['id', 'created_at', 'updated_at', 'salt', 'encrypted_password']
20
+ toRemove.each do |item|
21
+ columnNames.delete(item)
22
+ end
23
+ # Create text input labels for simple form creation
24
+ columnNames.each do |column|
25
+ form = form + '<label>' + column.titleize + '</label><input type="text" name="'+column+'">'
26
+ end
27
+ # Add authentication to each form requested
17
28
  form += '<input id="authenticity_token" name="authenticity_token" type="hidden" value="<%= form_authenticity_token %>"><input type="submit" value="Submit"></form>'
18
29
  return form
19
30
  end
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: make
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
- - Sara Wong, Ulysses Lin
7
+ - Sara Wong
8
+ - Ulysses Lin
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
@@ -15,7 +16,9 @@ description: A gem that shortcuts typing out forms for SQL users. Assuming your
15
16
  and it will return an html-safe string from your column names for creating a new
16
17
  record. In addition, you can type <%= Make.table(DB_Name.all) %> to automatically
17
18
  generate a table. More functions to follow!
18
- email: swong2@wellesley.edu, utemoc@gmail.com
19
+ email:
20
+ - swong2@wellesley.edu
21
+ - utemoc@gmail.com
19
22
  executables:
20
23
  - make
21
24
  extensions: []
@@ -27,6 +30,7 @@ files:
27
30
  homepage: http://rubygems.org/gems/make
28
31
  licenses:
29
32
  - Sara Wong
33
+ - Ulysses Lin
30
34
  metadata: {}
31
35
  post_install_message:
32
36
  rdoc_options: []