elskwid-munger 0.1.4.3 → 0.1.4.4
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/lib/munger/render/html.rb +62 -51
- data/lib/munger/render/sortable_html.rb +72 -61
- data/munger.gemspec +1 -1
- data/spec/munger/render/html_spec.rb +12 -0
- metadata +3 -3
data/lib/munger/render/html.rb
CHANGED
|
@@ -27,70 +27,81 @@ module Munger #:nodoc:
|
|
|
27
27
|
|
|
28
28
|
x.table(:class => @classes[:table]) do
|
|
29
29
|
|
|
30
|
-
x.
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
x.thead do
|
|
31
|
+
x.tr do
|
|
32
|
+
@report.columns.each do |column|
|
|
33
|
+
x.th(:class => 'columnTitle') { x << @report.column_title(column) }
|
|
34
|
+
end
|
|
33
35
|
end
|
|
34
36
|
end
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
x.tbody do
|
|
39
|
+
@report.process_data.each do |row|
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
classes = []
|
|
42
|
+
classes << row[:meta][:row_styles]
|
|
43
|
+
classes << 'group' + row[:meta][:group].to_s if row[:meta][:group]
|
|
44
|
+
classes << cycle('even', 'odd')
|
|
45
|
+
classes.compact!
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
if row[:meta][:group_header]
|
|
48
|
+
classes << 'groupHeader' + row[:meta][:group_header].to_s
|
|
49
|
+
end
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
row_attrib = {}
|
|
52
|
+
row_attrib = {:class => classes.join(' ')} if classes.size > 0
|
|
50
53
|
|
|
51
|
-
x.tr(row_attrib) do
|
|
52
54
|
if row[:meta][:group_header]
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
cell_attrib = {}
|
|
59
|
-
if cst = row[:meta][:cell_styles]
|
|
60
|
-
cst = Item.ensure(cst)
|
|
61
|
-
if cell_styles = cst[column]
|
|
62
|
-
cell_attrib = {:class => cell_styles.join(' ')}
|
|
63
|
-
end
|
|
55
|
+
x.thead do
|
|
56
|
+
x.tr(row_attrib) do
|
|
57
|
+
header = @report.column_title(row[:meta][:group_name]) + ' : ' + row[:meta][:group_value].to_s
|
|
58
|
+
x.th(:colspan => @report.columns.size) { x << header }
|
|
64
59
|
end
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
data = col_data.respond_to?(:data) ? col_data.data : col_data
|
|
76
|
-
formatter.call(data)
|
|
77
|
-
elsif col_data[column].respond_to? formatter
|
|
78
|
-
col_data[column].send(formatter, *args)
|
|
79
|
-
elsif
|
|
80
|
-
col_data[column].to_s
|
|
60
|
+
end
|
|
61
|
+
else
|
|
62
|
+
x.tr(row_attrib) do
|
|
63
|
+
@report.columns.each do |column|
|
|
64
|
+
|
|
65
|
+
cell_attrib = {}
|
|
66
|
+
if cst = row[:meta][:cell_styles]
|
|
67
|
+
cst = Item.ensure(cst)
|
|
68
|
+
if cell_styles = cst[column]
|
|
69
|
+
cell_attrib = {:class => cell_styles.join(' ')}
|
|
81
70
|
end
|
|
82
|
-
else
|
|
83
|
-
formatted = col_data[column].to_s
|
|
84
71
|
end
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
72
|
+
|
|
73
|
+
# x.td(cell_attrib) { x << row[:data][column].to_s }
|
|
74
|
+
# TODO: Clean this up, I don't like it but it's working
|
|
75
|
+
# output the cell
|
|
76
|
+
# x.td(cell_attrib) { x << row[:data][column].to_s }
|
|
77
|
+
x.td(cell_attrib) do
|
|
78
|
+
formatter,*args = *@report.column_formatter(column)
|
|
79
|
+
col_data = row[:data] #[column]
|
|
80
|
+
if formatter && col_data[column]
|
|
81
|
+
formatted = if formatter.class == Proc
|
|
82
|
+
data = col_data.respond_to?(:data) ? col_data.data : col_data
|
|
83
|
+
formatter.call(data)
|
|
84
|
+
elsif col_data[column].respond_to? formatter
|
|
85
|
+
col_data[column].send(formatter, *args)
|
|
86
|
+
elsif
|
|
87
|
+
col_data[column].to_s
|
|
88
|
+
end
|
|
89
|
+
else
|
|
90
|
+
formatted = col_data[column].to_s
|
|
91
|
+
end
|
|
92
|
+
x << formatted.to_s
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end # columns
|
|
96
|
+
end # x.tr
|
|
89
97
|
end
|
|
90
|
-
|
|
91
|
-
|
|
98
|
+
|
|
99
|
+
end # rows
|
|
100
|
+
|
|
101
|
+
end # x.tbody
|
|
92
102
|
|
|
93
|
-
end
|
|
103
|
+
end # x.table
|
|
104
|
+
|
|
94
105
|
end
|
|
95
106
|
|
|
96
107
|
def cycle(one, two)
|
|
@@ -31,81 +31,92 @@ module Munger #:nodoc:
|
|
|
31
31
|
|
|
32
32
|
x.table(:class => @classes[:table]) do
|
|
33
33
|
|
|
34
|
-
x.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
x.thead do
|
|
35
|
+
x.tr do
|
|
36
|
+
@report.columns.each do |column|
|
|
37
|
+
# TODO: Should be able to see if a column is 'sortable'
|
|
38
|
+
# Assume all columns are sortable here - for now.
|
|
39
|
+
sorted_state = 'unsorted'
|
|
40
|
+
direction = 'asc'
|
|
41
|
+
if [column.to_s, @report.column_data_field(column)].include?(@options[:sort])
|
|
42
|
+
sorted_state = "sorted"
|
|
43
|
+
direction = @options[:order] == 'asc' ? 'desc' : 'asc'
|
|
44
|
+
direction_class = "sorted-#{direction}"
|
|
45
|
+
end
|
|
46
|
+
new_params = @options[:params].merge({'sort' => @report.column_data_field(column),'order' => direction})
|
|
47
|
+
x.th(:class => "columnTitle #{sorted_state} #{direction_class}" ) do
|
|
48
|
+
# x << @report.column_title(column)
|
|
49
|
+
x << "<a href=\"#{@options[:url]}?#{create_querystring(new_params)}\">#{@report.column_title(column)}</a>"
|
|
50
|
+
end
|
|
44
51
|
end
|
|
45
|
-
new_params = @options[:params].merge({'sort' => @report.column_data_field(column),'order' => direction})
|
|
46
|
-
x.th(:class => "columnTitle #{sorted_state} #{direction_class}" ) do
|
|
47
|
-
# x << @report.column_title(column)
|
|
48
|
-
x << "<a href=\"#{@options[:url]}?#{create_querystring(new_params)}\">#{@report.column_title(column)}</a>"
|
|
49
|
-
end
|
|
50
52
|
end
|
|
51
|
-
end
|
|
53
|
+
end # x.thead
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
x.tbody do
|
|
56
|
+
@report.process_data.each do |row|
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
classes = []
|
|
59
|
+
classes << row[:meta][:row_styles]
|
|
60
|
+
classes << 'group' + row[:meta][:group].to_s if row[:meta][:group]
|
|
61
|
+
classes << cycle('even', 'odd')
|
|
62
|
+
classes.compact!
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
if row[:meta][:group_header]
|
|
65
|
+
classes << 'groupHeader' + row[:meta][:group_header].to_s
|
|
66
|
+
end
|
|
64
67
|
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
row_attrib = {}
|
|
69
|
+
row_attrib = {:class => classes.join(' ')} if classes.size > 0
|
|
67
70
|
|
|
68
|
-
x.tr(row_attrib) do
|
|
69
71
|
if row[:meta][:group_header]
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
x.thead do
|
|
73
|
+
x.tr(row_attrib) do
|
|
74
|
+
header = @report.column_title(row[:meta][:group_name]) + ' : ' + row[:meta][:group_value].to_s
|
|
75
|
+
x.th(:colspan => @report.columns.size) { x << header }
|
|
76
|
+
end
|
|
77
|
+
end
|
|
72
78
|
else
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
cst =
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
x.tr(row_attrib) do
|
|
80
|
+
@report.columns.each do |column|
|
|
81
|
+
|
|
82
|
+
cell_attrib = {}
|
|
83
|
+
if cst = row[:meta][:cell_styles]
|
|
84
|
+
cst = Item.ensure(cst)
|
|
85
|
+
if cell_styles = cst[column]
|
|
86
|
+
cell_attrib = {:class => cell_styles.join(' ')}
|
|
87
|
+
end
|
|
80
88
|
end
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
formatter
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
# TODO: Clean this up, I don't like it but it's working
|
|
90
|
+
# output the cell
|
|
91
|
+
# x.td(cell_attrib) { x << row[:data][column].to_s }
|
|
92
|
+
x.td(cell_attrib) do
|
|
93
|
+
formatter,*args = *@report.column_formatter(column)
|
|
94
|
+
col_data = row[:data] #[column]
|
|
95
|
+
if formatter && col_data[column]
|
|
96
|
+
formatted = if formatter.class == Proc
|
|
97
|
+
data = col_data.respond_to?(:data) ? col_data.data : col_data
|
|
98
|
+
formatter.call(data)
|
|
99
|
+
elsif col_data[column].respond_to? formatter
|
|
100
|
+
col_data[column].send(formatter, *args)
|
|
101
|
+
elsif
|
|
102
|
+
col_data[column].to_s
|
|
103
|
+
end
|
|
104
|
+
else
|
|
105
|
+
formatted = col_data[column].to_s
|
|
96
106
|
end
|
|
97
|
-
|
|
98
|
-
formatted = col_data[column].to_s
|
|
107
|
+
x << formatted.to_s
|
|
99
108
|
end
|
|
100
|
-
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
end
|
|
109
|
+
|
|
110
|
+
end # columns
|
|
111
|
+
end # x.tr
|
|
104
112
|
end
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
|
|
114
|
+
end # rows
|
|
115
|
+
|
|
116
|
+
end # x.tbody
|
|
107
117
|
|
|
108
|
-
end
|
|
118
|
+
end # x.table
|
|
119
|
+
|
|
109
120
|
end
|
|
110
121
|
|
|
111
122
|
def cycle(one, two)
|
data/munger.gemspec
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.platform = Gem::Platform::RUBY
|
|
3
3
|
s.name = "elskwid-munger"
|
|
4
|
-
s.version = "0.1.4.
|
|
4
|
+
s.version = "0.1.4.4"
|
|
5
5
|
s.authors = ['Scott Chacon', 'Brandon Mitchell', 'Don Morrison', 'Eric Lindvall']
|
|
6
6
|
s.email = "elskwid@gmail.com"
|
|
7
7
|
s.summary = "A reporting engine in Ruby - the elskwid fork!"
|
|
@@ -21,6 +21,18 @@ describe Munger::Render::Html do
|
|
|
21
21
|
html.should have_tag('tr', :count => count + 1) # rows plus header
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
it "should render a thead section for the table" do
|
|
25
|
+
@render = Munger::Render::Html.new(@report.process)
|
|
26
|
+
html = @render.render
|
|
27
|
+
html.should have_tag('thead', :count => 1)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should render a tbody section for the table" do
|
|
31
|
+
@render = Munger::Render::Html.new(@report.process)
|
|
32
|
+
html = @render.render
|
|
33
|
+
html.should have_tag('tbody', :count => 1)
|
|
34
|
+
end
|
|
35
|
+
|
|
24
36
|
it "should accept a custom table class" do
|
|
25
37
|
rep = Munger::Render::Html.new(@report.process, :classes => {:table => 'helloClass'})
|
|
26
38
|
html = rep.render
|
metadata
CHANGED
|
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
|
6
6
|
- 0
|
|
7
7
|
- 1
|
|
8
8
|
- 4
|
|
9
|
-
-
|
|
10
|
-
version: 0.1.4.
|
|
9
|
+
- 4
|
|
10
|
+
version: 0.1.4.4
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Scott Chacon
|
|
@@ -18,7 +18,7 @@ autorequire:
|
|
|
18
18
|
bindir: bin
|
|
19
19
|
cert_chain: []
|
|
20
20
|
|
|
21
|
-
date: 2010-04
|
|
21
|
+
date: 2010-09-04 00:00:00 -07:00
|
|
22
22
|
default_executable:
|
|
23
23
|
dependencies: []
|
|
24
24
|
|