rack-app-front_end 0.20.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/VERSION +1 -1
- data/lib/rack/app/front_end/helpers.rb +1 -0
- data/lib/rack/app/front_end/helpers/table.rb +44 -20
- 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: 1d90fa0a6d8b2ac46cbb6c8b412794ec196bd6b3
|
4
|
+
data.tar.gz: fee7347ba0ee77b07f12faf74e5865a2bca743fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17d63a3268e88615a6f7df1e68dae6910cbcab079229eb9efefeab6045a51a642362ef8a385f86ee7991571080614e8809a44651fb47b686a962051c1592c130
|
7
|
+
data.tar.gz: 41333b68d01a4adbbb3627fbdef332fb4053a27306add4ce9f40464e7ceec1b31856b83f580d4c3276332c6ae6c292ad0b97246dfb569c1d3555c79acc5469d4
|
data/.travis.yml
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.21.0
|
@@ -5,6 +5,7 @@ module Rack::App::FrontEnd::Helpers
|
|
5
5
|
require 'rack/app/front_end/helpers/rendering'
|
6
6
|
|
7
7
|
include Rack::App::FrontEnd::Helpers::Rendering
|
8
|
+
include Rack::App::FrontEnd::Helpers::Table
|
8
9
|
|
9
10
|
def path_to(*args)
|
10
11
|
@request.env[::Rack::App::Constants::ENV::HANDLER].path_to(*args)
|
@@ -1,35 +1,59 @@
|
|
1
1
|
module Rack::App::FrontEnd::Helpers::Table
|
2
|
+
module Builder
|
3
|
+
extend(self)
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
trs
|
9
|
-
end
|
5
|
+
def from_array_of_hash(array_of_hash)
|
6
|
+
headers = array_of_hash.each_with_object([]) do |hash, trs|
|
7
|
+
trs.push(*hash.keys)
|
8
|
+
trs.uniq!
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
o = Object.new
|
12
|
+
o.extend(Rack::App::FrontEnd::Helpers::HtmlDsl)
|
13
13
|
|
14
|
-
|
14
|
+
table_html = o.__send__ :table_tag do
|
15
|
+
tr_tag do
|
16
|
+
headers.each do |header|
|
17
|
+
td_tag String(header)
|
18
|
+
end
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
|
18
|
-
|
21
|
+
array_of_hash.each do |hash|
|
22
|
+
tr_tag do
|
23
|
+
headers.each do |header|
|
24
|
+
td_tag String(hash[header])
|
25
|
+
end
|
26
|
+
end
|
19
27
|
end
|
20
28
|
end
|
21
29
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
30
|
+
table_html
|
31
|
+
end
|
32
|
+
|
33
|
+
def from_hash(hash)
|
34
|
+
o = Object.new
|
35
|
+
o.extend(Rack::App::FrontEnd::Helpers::HtmlDsl)
|
36
|
+
|
37
|
+
table_html = o.__send__ :table_tag do
|
38
|
+
hash.each do |key, value|
|
39
|
+
tr_tag do
|
40
|
+
td_tag String(key)
|
41
|
+
td_tag String(value)
|
26
42
|
end
|
27
43
|
end
|
28
44
|
end
|
29
45
|
|
46
|
+
table_html
|
30
47
|
end
|
31
|
-
|
32
|
-
table_html
|
33
48
|
end
|
34
49
|
|
35
|
-
|
50
|
+
def table_by(object)
|
51
|
+
if object.is_a?(Array) && object.all? { |e| e.is_a?(Hash) }
|
52
|
+
Builder.from_array_of_hash(object)
|
53
|
+
elsif object.is_a?(Hash)
|
54
|
+
Builder.from_hash(object)
|
55
|
+
else
|
56
|
+
raise("don't know how to build table from this: #{object}")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|