greentable 0.0.7 → 0.0.8

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.
data/greentable.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "greentable"
3
- s.version = "0.0.7"
3
+ s.version = "0.0.8"
4
4
  s.author = "Wael Chatila"
5
5
  s.homepage = "https://github.com/waelchatila/greentable"
6
6
  s.summary = "Rails declarative html tables with export features"
@@ -13,7 +13,10 @@ module Greentable
13
13
  @defaults_td = (defaults.delete(:td) || {}).deep_merge(opts.delete(:td) || {})
14
14
  @opts = defaults.deep_merge(opts)
15
15
 
16
+ #rows
16
17
  @tr_attributes = []
18
+
19
+ #cols
17
20
  @th_attributes = []
18
21
  @th_html = []
19
22
  @td_attributes = []
@@ -51,22 +54,22 @@ module Greentable
51
54
 
52
55
  def to_s
53
56
  ret = ""
54
- ret << "<table#{do_attributes(@opts)}>"
57
+ ret << "<table#{do_attributes(nil,@opts)}>"
55
58
  unless @th_html.compact.empty?
56
59
  ret << "<thead>"
57
60
  ret << "<tr>"
58
- @th_html.each_with_index do |th,i|
59
- ret << "<th#{do_attributes(@defaults_th.deep_merge(@th_attributes[i]||{}))}>#{th.is_a?(Proc) ? th.call.to_s : th}</th>"
61
+ @th_html.each_with_index do |th,col|
62
+ ret << "<th#{do_attributes(nil,@th_attributes[col])}>#{th.is_a?(Proc) ? th.call.to_s : th}</th>"
60
63
  end
61
64
  ret << "</tr>"
62
65
  ret << "</thead>"
63
66
  end
64
67
  ret << "<tbody>"
65
68
 
66
- @row_counter.i.times do |i|
67
- ret << "<tr#{do_attributes(@defaults_tr.deep_merge(@tr_attributes[i]||{}))}>"
68
- @td_html[i].each do |td|
69
- ret << "<td#{do_attributes(@defaults_td.deep_merge(@td_attributes[i]||{}))}>#{td}</td>"
69
+ @row_counter.i.times do |row|
70
+ ret << "<tr#{do_attributes(row,@defaults_tr.deep_merge(@tr_attributes[row]||{}))}>"
71
+ @td_html[row].each_with_index do |td,col|
72
+ ret << "<td#{do_attributes(row,@defaults_td.deep_merge(@td_attributes[col]||{}))}>#{td}</td>"
70
73
  end
71
74
  ret << "</tr>"
72
75
  end
@@ -75,9 +78,10 @@ module Greentable
75
78
  end
76
79
 
77
80
  private
78
- def do_attributes(o)
81
+ def do_attributes(i,o)
82
+ instance = i.nil? ? nil : @records[i]
79
83
  return "" if o.nil? || o.empty?
80
- ret = o.map{|k,v| "#{k.is_a?(Proc) ? k.call.to_s : k.to_s}=\"#{v.is_a?(Proc) ? v.call.to_s : v.to_s}\""}.join(" ").strip
84
+ ret = o.map{|k,v| "#{k.is_a?(Proc) ? instance.instance_eval(&k).to_s : k.to_s}=\"#{v.is_a?(Proc) ? instance.instance_eval(&v).to_s : v.to_s}\""}.join(" ").strip
81
85
  ret = " " + ret unless ret.empty?
82
86
  return ret
83
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greentable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-06 00:00:00.000000000 Z
12
+ date: 2013-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake