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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11568951dd88c8fa3d8790e965114fbc316d1453
4
- data.tar.gz: 28ca9775167da3c132ba14a383c0c6762db8f661
3
+ metadata.gz: 1d90fa0a6d8b2ac46cbb6c8b412794ec196bd6b3
4
+ data.tar.gz: fee7347ba0ee77b07f12faf74e5865a2bca743fa
5
5
  SHA512:
6
- metadata.gz: 4160f5bf15487a4b43c914c34835300d50380b4b6e916c0da2c4bde588d6293d3a53c9929d6a8d67d7e88afc34e7d54e85d3a1142cc2e2f8445395dca18cdbe4
7
- data.tar.gz: 137a1658518dca98a7eee704697b950225ff082b6ed05cf5bc270925d60e37dd87827e17ef09befe5dfc610315d1cbbf1c823655a03783716c92da88e30536ff
6
+ metadata.gz: 17d63a3268e88615a6f7df1e68dae6910cbcab079229eb9efefeab6045a51a642362ef8a385f86ee7991571080614e8809a44651fb47b686a962051c1592c130
7
+ data.tar.gz: 41333b68d01a4adbbb3627fbdef332fb4053a27306add4ce9f40464e7ceec1b31856b83f580d4c3276332c6ae6c292ad0b97246dfb569c1d3555c79acc5469d4
data/.travis.yml CHANGED
@@ -14,3 +14,8 @@ rvm:
14
14
  branches:
15
15
  only:
16
16
  - master
17
+
18
+ matrix:
19
+ allow_failures:
20
+ - rvm: ruby-head
21
+ - rvm: jruby-head
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.20.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
- def table_by(array_of_hash)
4
-
5
- headers = array_of_hash.reduce([]) do |trs, hash|
6
- trs.push(*hash.keys)
7
- trs.uniq!
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
- o = Object.new
12
- o.extend(Rack::App::FrontEnd::Helpers::HtmlDsl)
11
+ o = Object.new
12
+ o.extend(Rack::App::FrontEnd::Helpers::HtmlDsl)
13
13
 
14
- table_html = o.__send__ :table_tag do
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
- tr_tag do
17
- headers.each do |header|
18
- td_tag String(header)
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
- array_of_hash.each do |hash|
23
- tr_tag do
24
- headers.each do |header|
25
- td_tag String(hash[header])
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
- end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app-front_end
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi