report_html 0.3.6 → 0.3.8

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: b8683ee4132fbb874b2290820f0a67c34ce65711
4
- data.tar.gz: 87a669a4111c195c664649bae22434e439a63af3
3
+ metadata.gz: 2b8ee279be0f36ce41ddbbc5b848e12048a6b123
4
+ data.tar.gz: a4bacf30d6cb11643dff6104d7ced86beeb867dc
5
5
  SHA512:
6
- metadata.gz: 46eb9d82931b880e976374f5ce911c4d03c4822c1636a7895de06419634fdab02c3e1754ff42116b43c8b94481d5967d0f9d3e5a4b9343e42f746615a9755f5c
7
- data.tar.gz: 32877980c4dec7226bb042ddb668951532f8b76e06b84b449292bb07d55b4e3bbd81c03e75139942e0d2bec5dff2ae494cc99cd96526b2b469ca3eca882fdc12
6
+ metadata.gz: 85a5b2203768cbd79f3908026019e57df7bb7358027d587e1ef29e4cfff6e2141a374075f2cc5b422cdcb9ebf0efdde52b7f87f31773e45e899203d08167e001
7
+ data.tar.gz: 33fc1d2038d5ae2504c17528b005bca35ccd89bfb6a3cff22ff988e3fc2765d8ecf56d1ba8bba5f70eb85d5f165f48ec9b9756141fa2bdd47dd6294344cc065a
@@ -13,6 +13,7 @@ class Report_html
13
13
  @data_from_files = data_from_files
14
14
  @plots_data = []
15
15
  @count_objects = 0
16
+ @dt_tables = [] #Tables to be styled with the DataTables js lib"
16
17
  end
17
18
 
18
19
  def build(template)
@@ -26,26 +27,86 @@ class Report_html
26
27
  end
27
28
 
28
29
  def build_body
29
- @all_report << "<body onload=\"initPage();\">\n#{yield}\n</body>\n"
30
+ if !@plots_data.empty?
31
+ @all_report << "<body onload=\"initPage();\">\n#{yield}\n</body>\n"
32
+ else
33
+ @all_report << "<body>\n#{yield}\n</body>\n"
34
+ end
35
+ end
36
+
37
+ def load_js_libraries(js_libraries)
38
+ loaded_libraries = []
39
+ js_libraries.each do |js_lib|
40
+ js_file = File.open(File.join(JS_FOLDER, js_lib)).read
41
+ loaded_libraries << Base64.encode64(js_file)
42
+ end
43
+ return loaded_libraries
44
+ end
45
+
46
+ def load_css(css_files)
47
+ loaded_css = []
48
+ css_files.each do |css_lib|
49
+ loaded_css << File.open(File.join(JS_FOLDER, css_lib)).read
50
+ end
51
+ return loaded_css
30
52
  end
31
53
 
32
54
  def make_head
33
55
  @all_report << "\t<title>#{@title}</title>
34
56
  <head>
57
+ <meta charset=\"utf-8\">
35
58
  <meta http-equiv=\"CACHE-CONTROL\" CONTENT=\"NO-CACHE\">
36
59
  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
37
- <meta http-equiv=\"Content-Language\" content=\"en-us\" />
60
+ <meta http-equiv=\"Content-Language\" content=\"en-us\" />\n"
61
+
62
+ # ADD JS LIBRARIES AND CSS
63
+ js_libraries = []
64
+ css_files = []
65
+ if !@plots_data.empty?
66
+ js_libraries << 'canvasXpress.min.js'
67
+ css_files << 'canvasXpress.css'
68
+ end
69
+ if !@dt_tables.empty? # CDN load, this library is difficult to embed in html file
70
+ @all_report << '<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.3.1/dt-1.10.21/datatables.min.css"/>'+"\n"
71
+ @all_report << '<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-3.3.1/dt-1.10.21/datatables.min.js"></script>'+"\n"
72
+ end
73
+ loaded_js_libraries = load_js_libraries(js_libraries)
74
+ loaded_css = load_css(css_files)
75
+ loaded_css.each do |css|
76
+ @all_report << "<style type=\"text/css\"/>
77
+ #{css}
78
+ </style>\n"
79
+ end
80
+ loaded_js_libraries.each do |lib|
81
+ @all_report << "<script src=\"data:application/javascript;base64,#{lib}\" type=\"application/javascript\"></script>\n"
82
+ end
83
+
84
+ # ADD CUSTOM FUNCTIONS TO USE LOADED JS LIBRARIES
85
+ #canvasXpress objects
86
+ if !@plots_data.empty?
87
+ @all_report << "<script>
88
+ var initPage = function () {
89
+ <% @plots_data.each do |plot_data| %>
90
+ <%= plot_data %>
91
+ <% end %>
92
+ }
93
+ </script>"
94
+ end
95
+
96
+ #DT tables
97
+ if !@dt_tables.empty?
98
+ @all_report << "<script>
99
+ <% @dt_tables.each do |dt_table| %>
100
+ $(document).ready(function () {
101
+ $('#<%= dt_table %>').DataTable();
102
+ });
103
+
104
+ <% end %>
105
+ </script>\n"
106
+ end
107
+
38
108
 
39
- <link rel=\"stylesheet\" href=\"js/canvasXpress.css\" type=\"text/css\"/>
40
- <script type=\"text/javascript\" src=\"js/canvasXpress.min.js\"></script>
41
- <script>
42
- var initPage = function () {
43
- <% @plots_data.each do |plot_data| %>
44
- <%= plot_data %>
45
- <% end %>
46
- }
47
- </script>
48
- </head>\n"
109
+ @all_report << "</head>\n"
49
110
  end
50
111
 
51
112
  def get_report #return all html string
@@ -54,9 +115,9 @@ class Report_html
54
115
  end
55
116
 
56
117
  def write(file)
57
- dir = File.dirname(file)
118
+ #dir = File.dirname(file)
58
119
  string_report = get_report
59
- FileUtils.cp_r(JS_FOLDER, dir)
120
+ #FileUtils.cp_r(JS_FOLDER, dir)
60
121
  File.open(file, 'w'){|f| f.puts string_report}
61
122
  end
62
123
 
@@ -158,9 +219,18 @@ class Report_html
158
219
  array_data = get_data(options)
159
220
  block.call(array_data) if !block.nil?
160
221
  rowspan, colspan = get_col_n_row_span(array_data)
222
+ table_id = 'table_' + @count_objects.to_s
223
+ @dt_tables << table_id if options[:styled] == 'dt'
224
+ tbody_tag = false
161
225
  html = "
162
- <table border=\"#{options[:border]}\" #{table_attr}>
226
+ <table id=\"#{table_id}\" border=\"#{options[:border]}\" #{table_attr}>
227
+ <% if options[:header] %>
228
+ <thead>
229
+ <% end %>
163
230
  <% array_data.each_with_index do |row, i| %>
231
+ <% if options[:header] && i == 1 %>
232
+ <tbody>
233
+ <% end %>
164
234
  <tr>
165
235
  <% row.each_with_index do |cell, j|
166
236
  if cell != 'colspan' && cell != 'rowspan'
@@ -172,9 +242,16 @@ class Report_html
172
242
  end %>
173
243
  <% end %>
174
244
  </tr>
245
+ <% if i == 0 && options[:header] %>
246
+ </thead>
247
+ <% end %>
248
+ <% end %>
249
+ <% if options[:header] %>
250
+ </tbody>
175
251
  <% end %>
176
252
  </table>
177
253
  "
254
+ @count_objects += 1
178
255
  return ERB.new(html).result(binding)
179
256
  end
180
257
 
@@ -1,3 +1,3 @@
1
1
  module ReportHtml
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: report_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - seoanezonjic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-15 00:00:00.000000000 Z
11
+ date: 2020-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler