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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/table_setting/cell.rb +23 -19
- data/lib/table_setting/column.rb +5 -9
- data/lib/table_setting/row.rb +15 -1
- data/lib/table_setting/sheet.rb +13 -15
- data/lib/table_setting/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45fb00aa69cdcb9a6fe02ec44574625f418e0a0d
|
4
|
+
data.tar.gz: c03067f432d44c205c434e3bbe46a136a07cb842
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac15d0b2d486f8c4c7778448ce709d1cdf646ed7c8b804ad0b5d1d1218f87c257ad6d3e92306f8f6a8dc804da0078c5baadf5042ddfe62fac7dfc2d1869abaef
|
7
|
+
data.tar.gz: f166ebb6509cbece553d00ca8e6fe7de51fb608d629c462bea16514be381debc8d22ff027efc56eeb225b795eb27f601e3aecf93d4637feaef899b0d4bd4628a
|
data/Gemfile.lock
CHANGED
data/lib/table_setting/cell.rb
CHANGED
@@ -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} #{
|
67
|
+
<td #{html_classes} #{span_attributes}>#{cell_index}#{contents.blank? ? ' ' : 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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
110
|
-
span =
|
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 >
|
120
|
+
if span > 1
|
117
121
|
return %Q{colspan="#{span}"}
|
118
122
|
end
|
119
123
|
''
|
data/lib/table_setting/column.rb
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
class TableSetting::Column
|
2
|
-
|
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
|
data/lib/table_setting/row.rb
CHANGED
@@ -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")}
|
data/lib/table_setting/sheet.rb
CHANGED
@@ -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 =
|
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
|
-
|
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
|
-
|
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">
|
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.
|
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-
|
11
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|