table_setting 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63c40c25789795050dc7263feef891495355d4fa
4
- data.tar.gz: c65c25bba4e6335aa6706387764a153553462472
3
+ metadata.gz: 45fb00aa69cdcb9a6fe02ec44574625f418e0a0d
4
+ data.tar.gz: c03067f432d44c205c434e3bbe46a136a07cb842
5
5
  SHA512:
6
- metadata.gz: 5d5bc712d9a5e61aa1a6dcd3a4cba1255c89a12b46c604cadc0dd31f85e3813a402d9e25005a989a4450667e07ddfeac86ed24812d2e02a4147f9f919e59f168
7
- data.tar.gz: adc6634d47602631a50b561c4d0358fe58520e3b22bfdc388bcaf62e985483b2f0bf50bff9d81622fdcee60af834b527eebe64d5e66c211070c3d2cbf1b10fff
6
+ metadata.gz: ac15d0b2d486f8c4c7778448ce709d1cdf646ed7c8b804ad0b5d1d1218f87c257ad6d3e92306f8f6a8dc804da0078c5baadf5042ddfe62fac7dfc2d1869abaef
7
+ data.tar.gz: f166ebb6509cbece553d00ca8e6fe7de51fb608d629c462bea16514be381debc8d22ff027efc56eeb225b795eb27f601e3aecf93d4637feaef899b0d4bd4628a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- table_setting (0.2.0)
4
+ table_setting (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,5 +1,5 @@
1
1
  class TableSetting::Cell
2
- attr_reader :row, :contents, :span, :style, :left_index
2
+ attr_reader :row, :contents, :span, :style, :left_index, :rowspan
3
3
 
4
4
  def initialize(row, contents, options = {})
5
5
  @row = row
@@ -7,12 +7,14 @@ class TableSetting::Cell
7
7
 
8
8
  @contents = contents
9
9
  @span = options[:span] || 1
10
-
10
+ @rowspan = options[:rowspan] || 1
11
+
11
12
  @style = TableSetting::Style.new(self, options)
12
13
 
13
14
  @left_index = column_index
14
15
  end
15
16
 
17
+
16
18
  def set_style(options)
17
19
  style.update(options)
18
20
  end
@@ -56,8 +58,13 @@ class TableSetting::Cell
56
58
  end
57
59
 
58
60
  def to_html
61
+ if sheet.debug
62
+ cell_index = "#{left_index} :: "
63
+ else
64
+ cell_index = ''
65
+ end
59
66
  <<-HTML
60
- <td #{html_classes} #{span_attribute}>#{contents.blank? ? '&nbsp;' : contents}</td>
67
+ <td #{html_classes} #{span_attributes}>#{cell_index}#{contents.blank? ? '&nbsp;' : contents}</td>
61
68
  HTML
62
69
  end
63
70
 
@@ -88,32 +95,29 @@ class TableSetting::Cell
88
95
  %Q{<Cell #{column_attribute} ss:StyleID="#{style.name}"><Data ss:Type="String">#{contents}</Data></Cell>\n}
89
96
  end
90
97
 
91
- # def left_index
92
- # preceeding_cells.map{|c| c.span}.sum
93
- # end
94
-
95
98
  private
96
99
 
97
100
  def html_classes
98
- list = []
99
- if bold?
100
- list << 'bold'
101
- end
102
- list.push(style.name)
103
- unless list.empty?
104
- return %Q{class="#{list.join(' ')}"}
105
- end
106
- ''
101
+ return %Q{class="#{style.name}"} unless style.name.blank?
102
+ end
103
+
104
+ def span_attributes
105
+ %Q{#{rowspan_attribute} #{colspan_attribute}}.strip
106
+ end
107
+
108
+ def rowspan_attribute
109
+ return '' unless rowspan and rowspan > 1
110
+ %Q{rowspan="#{rowspan}"}
107
111
  end
108
112
 
109
- def span_attribute
110
- span = 0
113
+ def colspan_attribute
114
+ span = 1
111
115
  if @span == 'all'
112
116
  span = sheet.num_columns
113
117
  elsif @span
114
118
  span = @span
115
119
  end
116
- if span > 0
120
+ if span > 1
117
121
  return %Q{colspan="#{span}"}
118
122
  end
119
123
  ''
@@ -1,14 +1,10 @@
1
1
  class TableSetting::Column
2
- def initialize(title, method, options = {})
3
- @title = title
4
- @method = method
5
- end
2
+ attr_reader :title, :style_options, :method_token
6
3
 
7
- def title
8
- @title
4
+ def initialize(title, method_token, options = {})
5
+ @title = title
6
+ @method_token = method_token
7
+ @style_options = options
9
8
  end
10
9
 
11
- def method
12
- @method
13
- end
14
10
  end
@@ -22,7 +22,20 @@ class TableSetting::Row
22
22
  end
23
23
  total_width += width
24
24
  end
25
- total_width
25
+ total_width + num_inherited_columns
26
+ end
27
+
28
+ def num_inherited_columns
29
+ spanned_columns = 0
30
+ sheet.rows.each do |row|
31
+ row.cells.each do |cell|
32
+ next unless cell.rowspan > 1
33
+ if (sheet.rows.index(row) + (cell.rowspan - 1)) >= sheet.rows.index(self)
34
+ spanned_columns += cell.span
35
+ end
36
+ end
37
+ end
38
+ spanned_columns
26
39
  end
27
40
 
28
41
  def bold?
@@ -42,6 +55,7 @@ class TableSetting::Row
42
55
  end
43
56
 
44
57
  def to_html
58
+ fill
45
59
  <<-HTML
46
60
  <tr>
47
61
  #{cells.map(&:to_html).join("\n")}
@@ -1,38 +1,32 @@
1
1
  class TableSetting::Sheet
2
- attr_reader :stack
2
+ attr_reader :stack, :debug
3
3
  attr_accessor :name, :rows
4
4
 
5
5
  @@counter = 0
6
6
 
7
- def initialize(parent_stack = TableSetting::Stack.new, options = {})
8
- @stack = parent_stack
7
+ def initialize(parent_stack = nil, options = {})
8
+ @stack = parent_stack || TableSetting::Stack.new
9
9
  @stack.sheets.push(self)
10
10
  @rows = []
11
+ @debug = options[:debug]
11
12
 
12
13
  @@counter += 1
13
14
  @name = options[:name] || "Sheet#{@@counter}"
14
15
  end
15
16
 
16
17
  def cells
17
- list = []
18
- rows.each do |row|
19
- list.concat(row.cells)
20
- end
21
- list
18
+ rows.map(&:cells).flatten
22
19
  end
23
20
 
24
21
  def num_columns
25
- max = 0
26
- rows.each do |row|
27
- if row.num_columns > max
28
- max = row.num_columns
29
- end
30
- end
31
- max
22
+ rows.map{|row| row.num_columns}.sort.last
32
23
  end
33
24
 
34
25
  def style_column(number, options)
35
26
  rows.each do |row|
27
+ if options[:skip_row] and options[:skip_row] == rows.index(row) + 1
28
+ next
29
+ end
36
30
  row.fill
37
31
  row.cells.select{|c| c.in_column?(number)}.map{|c| c.set_style(options)}
38
32
  end
@@ -55,6 +49,10 @@ class TableSetting::Sheet
55
49
  csv_string
56
50
  end
57
51
 
52
+ def index
53
+ @index ||= sheet.rows.index(self)
54
+ end
55
+
58
56
  def to_html
59
57
  <<-HTML
60
58
  <style type="text/css">
@@ -1,3 +1,3 @@
1
1
  module TableSetting
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_setting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Gehman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-08 00:00:00.000000000 Z
11
+ date: 2013-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler