ulysseslin_test_gem 1.0.1 → 1.0.3
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.
- checksums.yaml +4 -4
- data/lib/ulysseslin_test_gem.rb +65 -30
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed1fc633f51c42e95467019ed96b72ed24c799b7
|
4
|
+
data.tar.gz: ecdb3b5556bae92c75031330adf0e3ffb8d6d01d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d23458ce018f6be0ee793c5c23ac7e3db2ff47fdb39ba387d0a364d6344a69010493a19aa90570a00836fd588e0d4069cf112bef255dfb029fea20d73973b8b1
|
7
|
+
data.tar.gz: 8a8b762f2f88acce8eaedacffaca27885baca4b51b7e6ac2c2226d136df9626b0ab3cc99b16f70ea0bfc2b716eaebaf444c106b7a6e34475cd6ce428d44112be
|
data/lib/ulysseslin_test_gem.rb
CHANGED
@@ -1,49 +1,84 @@
|
|
1
1
|
class Make
|
2
|
-
#
|
3
|
-
|
4
|
-
|
2
|
+
# attr_accessor :html
|
3
|
+
def initialize
|
4
|
+
@thead=''
|
5
|
+
@tbody=''
|
6
|
+
end
|
7
|
+
# Must provide model as a String, uppercase
|
8
|
+
def table model,*rest
|
9
|
+
controller=model.downcase+"s"
|
10
|
+
# Convert given model String into Object
|
11
|
+
model=model.constantize.all
|
12
|
+
|
5
13
|
# These are the table keys to ignore when rendering table
|
6
14
|
@keys_to_ignore=['id','created_at','updated_at']
|
7
15
|
columns=model.column_names-@keys_to_ignore
|
8
|
-
@html='<table><thead><tr>'
|
9
16
|
# HEADER
|
10
17
|
# No headers specified; default headers used
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
18
|
+
columns.each {|key|
|
19
|
+
if key[-3..-1]=='_id'
|
20
|
+
key=key[0...-3]
|
21
|
+
end
|
22
|
+
@thead+="\n\t\t\t<th>"+key.gsub('_',' ').titleize+'</th>'
|
23
|
+
}
|
24
|
+
@thead+="\n\t\t\t<th>Action</th>"
|
19
25
|
|
20
26
|
# BODY
|
21
|
-
@html+='<tbody>'
|
22
|
-
# Make custom table if no model given
|
23
|
-
if model==0
|
24
|
-
for r in 1..rest[2]
|
25
|
-
@html+='<tr>'
|
26
|
-
for c in 1..rest[1]
|
27
|
-
@html+='<td>%d</td>' % c
|
28
|
-
end
|
29
|
-
@html+='</tr>'
|
30
|
-
end
|
31
27
|
# Make table from given model and row limit, if any
|
32
|
-
|
28
|
+
if rest.length
|
33
29
|
limit=model.length-1
|
34
|
-
if
|
35
|
-
|
30
|
+
# Set limit to custom value if not nil, 0, or model.length
|
31
|
+
if ![nil,0,model.length].include?(rest[1])
|
32
|
+
limit=rest[1]-1
|
36
33
|
end
|
37
34
|
# Show rows from models array until specified or default limit
|
38
35
|
model[0..limit].each {|user|
|
39
|
-
@
|
36
|
+
@tbody+="\n\t\t<tr>"
|
40
37
|
user.attributes.except(*@keys_to_ignore).each {|key,val|
|
41
|
-
|
38
|
+
if key[-3..-1]=='_id'
|
39
|
+
# Use '.keys' & '.values' to get certain # key or value from hash
|
40
|
+
val=key[0...-3].capitalize.constantize.find(val).attributes.values[val]
|
41
|
+
end
|
42
|
+
@tbody+="\n\t\t\t<td>"+val.to_s+'</td>'
|
42
43
|
}
|
43
|
-
|
44
|
+
crud="\n\t\t\t<td><a href=\"/"+controller+"/"+user.id.to_s+"\">Show</a> | <a href=\"/"+controller+"/"+user.id.to_s+"/edit\">Edit</a> | <a href=\"/"+controller+"/"+user.id.to_s+"\" data-method=\"delete\">Delete</a></td>"
|
45
|
+
@tbody+=crud+"\n\t\t</tr>"
|
44
46
|
}
|
45
47
|
end
|
46
|
-
|
47
|
-
|
48
|
+
return self
|
49
|
+
end
|
50
|
+
|
51
|
+
# Make custom headers
|
52
|
+
def th *ths
|
53
|
+
@thead=''
|
54
|
+
ths.each { |custom_header| @thead+="\n\t\t\t<th>%s</th>" % custom_header }
|
55
|
+
return self
|
56
|
+
end
|
57
|
+
|
58
|
+
# Make custom-sized table; send in 0 for default col/row #
|
59
|
+
def custom columns,rows
|
60
|
+
for row in 1..rows
|
61
|
+
@tbody+="\n\t\t<tr>"
|
62
|
+
for column in 1..columns
|
63
|
+
@tbody+="\n\t\t\t<td></td>"
|
64
|
+
end
|
65
|
+
@tbody+="\n\t\t</tr>"
|
66
|
+
end
|
67
|
+
return self
|
68
|
+
end
|
69
|
+
|
70
|
+
def crud
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
# Writes table html code to 'table_html.txt' file located in application's root folder
|
75
|
+
def file
|
76
|
+
File.open('table_html.txt', 'w') { |f| f.write(("<table>\n\t<thead>\n\t\t<tr>"+@thead+"\n\t\t</tr>\n\t</thead>\n\t<tbody>"+@tbody+"\n\t</tbody>\n</table>")) }
|
77
|
+
return self
|
78
|
+
end
|
79
|
+
|
80
|
+
# Needs to be at end of links
|
81
|
+
def now!
|
82
|
+
return ('<table><thead><tr>'+@thead+'</tr></thead><tbody>'+@tbody+'</tbody></table>').html_safe
|
48
83
|
end
|
49
84
|
end
|
metadata
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ulysseslin_test_gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ulysses Lin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Allows user to create tables simply by referencing a table in the database
|
14
|
-
|
13
|
+
description: Allows user to create tables simply by referencing a table in the database,
|
14
|
+
defining headers, and changing size. Version 1.0.2 allow for cross-table recognition
|
15
|
+
of headers and values needed; for example, a two-model table would show "Electronics"
|
16
|
+
for "Category" instead of "2" for "category_id". Version 1.0.3 allows for method
|
17
|
+
chaining, printing of table code into an external file, and default (C)RUD links.
|
15
18
|
email: utemoc@gmail.com
|
16
19
|
executables: []
|
17
20
|
extensions: []
|