forked from puppetlabs/prosvc-preview_report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreview_report.rb
executable file
·807 lines (773 loc) · 33.8 KB
/
preview_report.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
#!/opt/puppet/bin/ruby
require 'markaby'
require 'json'
require 'uri'
require 'getoptlong'
UNKNOWN_FILE_PATH = 'unknown location'
PUPPET_LOGO = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAKQWlDQ1BJQ0MgUHJvZmlsZQAASA2dlndUU9kWh8+9N73QEiIgJfQaegkg0jtIFQRRiUmAUAKGhCZ2RAVGFBEpVmRUwAFHhyJjRRQLg4Ji1wnyEFDGwVFEReXdjGsJ7601896a/cdZ39nnt9fZZ+9917oAUPyCBMJ0WAGANKFYFO7rwVwSE8vE9wIYEAEOWAHA4WZmBEf4RALU/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BhSbO3fuqKRoWmlReVCQCFy7Jt8DrsXOLKnATuKDb9rY/fWQyitrohKgRMaxRSYdC5otsztdyttP4elW7OOzHgsA0dpXE+QlISfKuw3iPyoDSwe/jfJOoSwjYBYJD08napmJkNYpKytTIHhaRSIRldXZH5uOqXkEw9yjKeBaWq4ws2LYhB2WmKB/UnCiDMm73JAiMqaw+W9fmnMRLZVGYVmOPHv2TAl4+/ZtxeHIkSOqJVDS8y+fq5YJ00sBi0xR25IL/nHHRcNnITi+soMmEIOKYUw8/18K1WULjxUCobY7OztRU1ODrq4u7N+/H8ePH0dra6tyH46Tbty4oVq6nJcCmV0pXdbMXKLklm+qMxAVxTCvFEM6s1P7tbW1WT/XwUsXYwVM4QmSCZPx0tfXh8bGRuzYsSPPrbh3wCJ0LYbB9kYD9Cp6VCFiNzN5sSAK8fL36WDWJQtBsIDs6OhQU/3WYGfaXj5OBDMpx/SwfD1ksiv0G5X+mUD62M35SkswuV2+fFkViVzAPiZjCn3v3j0cPXpUZX1aw5sINfOAa+mBpWz9rsW9eIFqa2vDq1ev0N7ernLK5OQkmEfOnz+vquGmpiaMjY0pl/PLF3At/4Q39c5YYHV74cIFnD59Om9bFom0wvj4eEEQnLxigFAYWoUutWvXLpU3CI53D13p6sOAc/20ooBQOArPREdQxVDBYC+GwULm6txAHnyeTeNz7bMsFmGeqK6uxpkzZ9SHBWZtHrW8mzOv+CvbuUBwfFlOLW5MCzx69IiPWWKdxdKD7lUsLRsQCsrPP8wVWnAet/q5WCDL4lpayEKJTY8V2y5rsBcr7Gzz3xog/wdjyGDqXjzftQAAAABJRU5ErkJggg=='
opts = GetoptLong.new(
[ '--format_json', '-f', GetoptLong::REQUIRED_ARGUMENT],
[ '--write_html', '-w', GetoptLong::REQUIRED_ARGUMENT],
[ '--pie_chart', '-p', GetoptLong::NO_ARGUMENT ],
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
)
def show_usage()
puts <<-EOF
preview_report.rb [OPTIONS]
-h, --help
show help
-f, --format_json [/path/to/output.json]
The path to overview-json file created by puppet preview i.e. --view overview-json
-w, --write_html [/path/to/saved_report.html]
The path to where you would like to save the html report
-p, --pie_chart
Enable the "pie" charts for resource counts || defaults to off
EOF
exit 1
end
opts.each do |opt,arg|
case opt
when '--help'
show_usage
when '--format_json'
@overview_json = arg
when '--write_html'
@html_file = arg
when '--pie_chart'
@pie_chart = true
end
end
if (@overview_json.nil? or @html_file.nil?)
show_usage
end
def load_json(filename)
JSON.parse( IO.read(filename) )
end
def find_diffs(diff_path)
found_diffs = []
Dir.glob("#{diff_path}/*/catalog_diff.json") do |catalog_diff|
found_diffs << catalog_diff
end
found_diffs
end
overview = load_json(@overview_json)
stats = overview['stats']
preview = overview['preview']
baseline = overview['baseline']
mab = Markaby::Builder.new
mab.html do
def make_error_readable(error)
h5.entryTitle "Information about this issue"
case error
# MIGRATE4_REVIEW_IN_EXPRESSION
when 'MIGRATE4_REVIEW_IN_EXPRESSION'
tag! :body, :id => "overview_#{error}_#{rand()}" do
<<-eos
In Puppet 3, the #{tag! :code, 'in'} operator was not well specified and there were several undefined behaviors. This relates to, but is not limited to:
eos
end
ul do
li 'String / numeric automatic conversions.'
li 'Applying regular expressions to non string values causing auto conversion.'
li 'Confusion over comparisons between empty string/undef/nil (internal) values.'
li 'In-operator not using case independent comparisons in Puppet 3.'
end
br
body 'To fix, review the expectations against the Puppet language specification.'
br
body "For a detailed description of this issue, see "
a 'PUP-4130', :href => 'https://tickets.puppetlabs.com/browse/PUP-4130'
else
tag! :body, :id => "overview_#{error}_#{rand()}" do
a :href => "https://forge.puppet.com/puppetlabs/catalog_preview#%s" % error.downcase , :class => 'tooltip', :title => error do
tag! :i, "No information defined for this error click here for more information"
end
end
end
end
def normalize_name(name)
URI.escape(name).gsub(/[\-\[\] :\/\.]/,'_').to_s
end
def read_code_off_disk(header,manifest,line_number)
line_number = (line_number.to_i + 1)
# Read the file off disk to find the code question.
# Catch if the file is not on disk
return body "#{manifest} does not exist: no line preview available" unless File.exists?(manifest)
file = File.readlines(manifest)
#### Manifests Code Block
css = [
'color: black',
'background-color: white',
'border-width: 1px',
'border-bottom-width: 1px;',
'border-bottom-style: dotted',
'border-left-width: 4px',
'border-style: dotted solid',
'border-color: rgb(221, 221, 221);',
'padding-bottom: 10px;',
]
div :style=>css.join(';') do
tag! :code, :id => "manifest_#{header}_#{manifest}_#{line_number}_#{rand()}" do
((line_number - 1)..(line_number + 1)).each do |nu|
div.entryContent do
if nu == line_number - 1
div :style=> "background-color:rgb(248,238,199)" do
tag! :font, :color => 'black' do
"#{tag! :b, nu}:#{file[(nu - 1)]}"
end
end
else
div :style=> "background-color:white" do
tag! :font, :color => 'black' do
"#{nu}:#{file[(nu - 1)]}"
end
end
end
end
end
end
end
end
def node_break_down(nodes, resource =nil)
ul do
# Only show 10 nodes
body "This issue occured on #{nodes.length} nodes"
ul do
nodes[0..10].each do |node|
div :style=>"font-size: 1.0rem;" do
tag! :font, :color => 'black' do
# LINK 2 or LINK 3
li do
if resource.nil?
a node, :href => '#%s' % normalize_name(node)
else
a node, :href => '#%s' % normalize_name("#{node}_#{resource}")
end
end
end
end
end
end
end
end
def process_breakdown(header,type,detail)
h3 "Detected #{header} #{type} resources"
detail.each do |title,breakdown|
ul do
li do
div :style=>"font-size: 1.3rem;" do
# LINK 01
a :name => normalize_name("#{header}_#{type}_#{title}") do
"#{type}[#{title}] is #{header}"
end
end
end
breakdown.each do |path,nodes|
#### Example nodes
css = [
'color: black',
'border-radius: 10px',
'background-color: white',
'font-family: "Helvetica Neue",Helvetica,Arial,sans-serif";',
'border-bottom-width: 1px;',
'border-bottom-style: dotted;',
'border-bottom-color: rgb(221, 221, 221);',
'padding-bottom: 20px;',
]
div :style=>css.join(';') do
ul do
ul do
# Path for classes is unknown
unless path == UNKNOWN_FILE_PATH
file_path,line_number = path.split(':')
h5.entryTitle "#{header.capitalize} resource ending on line #{line_number} (view node report for details)"
p path
read_code_off_disk(header,file_path,line_number)
br
end
end
# N number of example nodes
node_break_down(nodes,"#{type}[#{title}]")
br
end
end
end
end
end
end
def pie_chart(catalog_diff)
td do
graph = {
'baseline_resource_count' => 'grey',
'preview_resource_count' => 'black',
'missing_resource_count' => 'red',
'added_resource_count' => 'green',
'conflicting_resource_count' => 'blue',
}
table do
graph.each do |key,color|
next if catalog_diff[key].nil?
next if catalog_diff[key].zero?
css = [
'color: white',
"background-color: #{color}",
'text-align: center ',
'position: relative',
"width: #{(catalog_diff[key])}px",
"line-height: #{(catalog_diff[key])}px",
'border-radius: 50%',
'text-align: center',
]
td do
div :style => css.join(';') do
body catalog_diff[key]
end
div :style => 'font-size: smaller;color: black;' do
tag! :b, key.capitalize.gsub('_',' ')
end
end
end
end
end
end
def compilation_errors_breakdown(section)
return '' unless section['compilation_errors']
section['compilation_errors'].each do |error|
ul do
li "#{error['nodes'].size} nodes failed to compile: #{error['manifest']}"
ul do
div.entry do
#### Error by line breakdown
error['errors'].each do |e|
h4.entryTitle "#{e['message']} on line #{e['line']}"
# Find file path in error if we don't have a file path from preview
match = /(\S*(\/\S*\.pp|\.erb))/.match(e['message'].to_s)
if error['manifest'].nil? and match
error['manifest'] = match[1]
end
# Extract line number from error message when manifest is null
if e['line'].nil? and match
line_number = match[3]
else
line_number = e['line']
end
if error['manifest']
# Read the file off disk to find the code question
read_code_off_disk('failed',error['manifest'],line_number)
end
#### Example nodes
node_break_down(error['nodes'])
end
end
end
end
end
end
def compilation_errors_baseline_breakdown(section)
return '' unless section['compilation_errors']
section['compilation_errors'].each do |error|
ul do
# Matching the message to the node by index here as they are positionally related.
div.entry do
#### Error by line breakdown
error['errors'].each_with_index do |e,index|
li do
"#{tag! :b, error['nodes'][index]} failed to compile the baseline catalog"
end
ul do
li do
h4.entryTitle "#{e['message']} on line #{e['line']}"
# Find file path in error if we don't have a file path from preview
match = /(\S*(\/\S*\.pp|\.erb)):?([0-9]+)/.match(e['message'].to_s)
if error['manifest'].nil? and match
error['manifest'] = match[1]
end
# Extract line number from error message when manifest is null
if e['line'].nil? and match
line_number = match[3]
else
line_number = e['line']
end
if error['manifest']
# Read the file off disk to find the code question
read_code_off_disk('failed',error['manifest'],line_number)
end
#### Example nodes
node_break_down(Array[error['nodes'][index]])
end
end
end
end
end
end
end
def process_issues(preview_log)
ul do
preview_log.each do |issue|
li do
# Find file path in error if we don't have a file path from preview
match = /(\S*(\/\S*\.pp|\.erb))/.match(issue['message'].to_s)
if issue['file'].nil? and match
issue['file'] = match[1]
end
# Catch errors without a file and set the Error as the file
issue['file'] = issue['message'] if issue['file'].nil?
# Work around the fact overview doesn't have human readable messages
# we store them here and then use them in the breakdown below
@error_message[issue['issue_code']] = issue['message']
a :href => "#%s" % normalize_name(issue['file']), :class => 'tooltip', :title => issue['issue_code'] do
"#{tag! :b,issue['level'].capitalize}: #{issue['file']}:#{issue['line']}"
end
end
end
end
end
def header1(title)
css = [
'color: #33353f',
'background-color: #dcdcdc',
'font-size: 10px',
'line-height: 20px',
'display: block',
'letter-spacing: normal',
'padding: 15px',
'border-radius: 10px',
'margin: 0',
'font-family: "Helvetica Neue",Helvetica,Arial,sans-serif";'
]
div :style=>css.join(';') do
h1 do
a title, :name => normalize_name(title)
end
end
end
def header2(title)
css = [
'color: #33353f',
'background-color: #f5f5f5',
'font-size: 20px',
'line-height: 20px',
'display: block',
'letter-spacing: normal',
'padding: 15px',
'border-radius: 15px',
'margin: 0',
'font-family: "Helvetica Neue",Helvetica,Arial,sans-serif";'
]
div :style=>css.join(';') do
h2 title
end
end
def header4(title)
css = [
'color: #33353f',
'background-color: #f5f5f5',
'font-size: 1.0rem',
'line-height: 10px',
'display: block',
'letter-spacing: normal',
'padding: 5px',
'border-radius: 5px',
'margin: 0',
'font-family: "Helvetica Neue",Helvetica,Arial,sans-serif";'
]
div :style=>css.join(';') do
h4 title
end
end
head do
title "Diff Overview"
meta :name => "keywords", :content => "puppet, diff, preview"
style :type => "text/css" do
%[
body { font: 20px/120% "Helvetica Neue",Helvetica,Arial, sans-serif }
.tooltip{
display: inline;
position: relative;
}
.tooltip:hover:after{
background: #333;
background: rgba(0,0,0,.8);
border-radius: 5px;
bottom: 26px;
color: #fff;
content: attr(title);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 320px;
}
.tooltip:hover:before{
border: solid;
border-color: #333 transparent;
border-width: 6px 6px 0 6px;
bottom: 20px;
content: "";
left: 50%;
position: absolute;
z-index: 99;
}
]
end
end
body :bgcolor => '#ffffff' do
css = [
'color: white',
#'background-color: #f9f9f9',
'background-color: #1a1a1a',
'line-height: 20px',
'display: block',
'letter-spacing: normal',
'height: 50px',
'padding: 0px',
'margin: 0',
'border-bottom-width: 3px',
'border-bottom-style: solid',
'border-bottom-color: rgb(204,204,204)',
'font-family: "Helvetica Neue",Helvetica,Arial,sans-serif"',
'font-size: 2.0rem',
'margin-left: 60px;',
'float: left',
]
div :style=>css.join(';') do
img :src => PUPPET_LOGO
end
@error_message = Hash.new
# TOC
header1 "Catalog Preview Report"
ul do
[
"Top 10 nodes with issues",
"Catalog Compliation Known Issues",
"Resource Breakdown",
"Node breakdown",
].each do |title|
li do
a title, :href => "#%s" % normalize_name(title)
end
end
end
# TOP TEN
header1 "Top 10 nodes with issues"
hr
body "The following nodes had the most issues including missing or conflicting catalogs."
br
body "These nodes are likely the best for testing the breakdown issue list below."
ul do
# PRE-101 Format changes removed this (beta) key , this raise will catch someone trying to generate an old report
if overview['top_ten']
top_ten = overview['top_ten']
else
top_ten = overview['all_nodes'][0..9]
end
top_ten.each do |node|
preview_log = load_json("/var/lib/puppet/preview/#{node['name']}/preview_log.json")
# PRE-103 Compatibility with old format
issue_count = (node['error_count'] + node['warning_count']) || node['issue_count']
li do
a :href => '#%s' % normalize_name(node['name']), :title => "#{node['error_count']} Errors and #{node['warning_count']} Warnings", :class => 'tooltip' do
css = [
'color: black',
'text-decoration: none',
'font-size: 1.2rem',
]
div :style=>css.join(';') do
"#{tag! :b,issue_count} issues on #{tag! :b, node['name']}"
end
end
end
unless preview_log.empty?
errors = preview_log.select{ |h| h['level'] == 'error' }
process_issues(errors) unless errors.empty?
warnings = preview_log.select{ |h| h['level'] == 'warning' }
process_issues(warnings) unless warnings.empty?
end
end
end
total_failures = stats['failures']['total'] || 0
# FAILURES
unless total_failures == 0 and baseline.nil? || baseline['compilation_errors'].nil?
header1 "Catalog Compliation Failures"
div.failure_overview! {
# 0 out X summary
# Top level failures key does not show baseline failure or percentage
failures = baseline['compilation_errors'].map{|h| h['nodes']}.flatten.size if total_failures == 0
percent = stats['failures']['percent'] || (failures.to_f / stats['node_count'].to_f) * 100.0
<<-eos
#{tag! :strong,failures} out of #{stats['node_count']} nodes failed to compile their catalog.
This is #{tag! :strong, percent.round(2)}% failure rate across your infrastructure
eos
}
# Compliation Errors Breakdown
unless baseline.nil?
header1 "Baseline compilation failures"
ul do
compilation_errors_baseline_breakdown(baseline)
end
end
unless preview.nil?
header1 "Preview compilation failures"
ul do
compilation_errors_breakdown(preview)
end
end
end
# CONFLICTS (KNOWN ISSUES)
if stats['conflicting']
header1 "Catalog Compliation Known Issues"
hr
total_conflicts = stats['conflicting']['total'] || 0
css = [
'border-left-width: 3px',
'border-left-style: solid',
'border-left-color: rgb(0, 136, 204)',
'background-color: #fff',
'box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05)',
'padding-top: 15px',
'padding-right: 15px',
'padding-bottom: 15px',
'padding-left: 15px',
]
div :style=>css.join(';') do
# 0 out X summary
<<-eos
#{tag! :strong,total_conflicts} out of #{stats['node_count']} nodes have conflicts/differences in their catalog.
This is #{tag! :strong, stats['conflicting']['percent']}% conflict rate across your infrastructure
eos
end
preview['warning_count_by_issue_code'].each do |issue|
css = [
'color: black',
'font-family: "Helvetica Neue",Helvetica,Arial,sans-serif";',
]
div :style=>css.join(';') do
ul do
issue['manifests'].each do |manifest,lines|
if lines.empty?
body ""
next
end
li do
a :name => normalize_name(manifest) do
css = [
'color: black',
'text-decoration: none',
'font-size: 1.2rem',
]
div :style=>css.join(';') do
tag! :b, manifest
end
end
end
ul do
#### Error by line breakdown
lines.uniq.each do |linepos|
line_number = linepos.split(':')[0]
# Use the preview message human readable and fallback to issue code when not present
h4.entryTitle do
css = [
'color: #666',
]
div :style=>css.join(';') do
"Line #{line_number}: #{@error_message[issue['issue_code']] || issue['issue_code']}"
end
end
read_code_off_disk('warning',manifest,line_number)
br
# Show human reable error or link
make_error_readable(issue['issue_code'])
end
end
end
end
end
end
# CHANGES
if overview['changes']
header1 "Resource Breakdown"
hr
overview['changes']['resource_type_changes'].each do |type,details|
ul do
# Type i.e. Class,File
header2 type
hr
if details['missing_resources']
process_breakdown('missing',type,details['missing_resources'])
end
if details['conflicting_resources']
process_breakdown('conflicting',type,details['conflicting_resources'])
end
end
end
end
# NODES
header1 "Node breakdown"
ul do
# PRE-101 changes to formating
if overview['top_ten']
diffs = find_diffs('/var/lib/puppet/preview/')
else
# PRE-103 As the top ten list is sorted by issues, sort the node breakdown by catalog changes
# This is actually the default if the nodes have no issues, but if all nodes have at least
# 1 known issue, then this sorting is skewed in favor of that, thus we always sort explicitly
diffs = overview['all_nodes'].sort_by{ |h| h['added_resource_count'] + h['missing_resource_count'] + h['conflicting_resource_count'] }.map{ |node| "/var/lib/puppet/preview/#{node['name']}/catalog_diff.json" }
end
diffs.each do |catalog_diff_file|
#puts catalog_diff_file
if File.zero?(catalog_diff_file)
body "Diff file empty on disk: #{catalog_diff_file}"
next
end
catalog_diff = load_json(catalog_diff_file)
li do
h3 do
a catalog_diff['node_name'], :name => normalize_name(catalog_diff['node_name'])
end
end
# Node stats table
ul do
table do
if @pie_chart
pie_chart(catalog_diff)
end
end
table do
count = 0
catalog_diff.each do |key,value|
next if ['added_resources','missing_resources','conflicting_resources','missing_edges','produced_by','timestamp','node_name'].include?(key)
next if value.nil?
if value.kind_of?(Array) then next if value.empty? end
next if value == 0
count += 1
if count.even?
color = 'white'
else
color = '#f5f5f5'
end
css = [
'color: black',
'font-family: Helvetica, Arial, sans-serif',
'border-collapse: collapse',
'border-style: solid',
'border-spacing: 1px',
'border-width: 1px',
'padding-bottom: 1px',
'background-clip: padding-box',
"background-color: #{color}",
'border-color: #dcdcdc',
'width: 768px',
]
div :style=>css.join(';') do
table do
th_css = [
'background: grey',
'font-weight: bold',
]
div :style=>th_css.join(';') do
th "#{key.capitalize.gsub(/_/,' ')}:"
end
td_css = [
'background: #FAFAFA',
'text-align: center',
]
div :style=>td_css.join(';') do
td value
end
end
end
end
end
tag! :i, "Last compiled: #{catalog_diff['timestamp']} with #{catalog_diff['produced_by']}"
end
# NODE Level Conflicts
if catalog_diff['missing_resources']
header4 "Missing Resources on #{catalog_diff['node_name']}" unless catalog_diff['missing_resource_count'].zero?
catalog_diff['missing_resources'].sort_by{ |h| h['type']}.each do |missing|
ul do
li do
# LINK 01
a :href => normalize_name("#missing_#{missing['type']}_#{missing['title']}") do
'%s[%s]' % [missing['type'],missing['title']]
end
end
end
end
end
if catalog_diff['added_resources']
header4 "Added Resources on #{catalog_diff['node_name']}" unless catalog_diff['added_resource_count'].zero?
catalog_diff['added_resources'].sort_by{ |h| h['type']}.each do |added|
ul do
li do
# LINK 01
a :href => normalize_name("#added_#{added['type']}_#{added['title']}") do
'%s[%s]' % [added['type'],added['title']]
end
end
end
end
end
if catalog_diff['conflicting_resources'] && ! catalog_diff['conflicting_resources'].empty?
header4 "Conflicting Resources on #{catalog_diff['node_name']}"
ul do
catalog_diff['conflicting_resources'].each do |conflict|
li do
a :href => '#%s' % normalize_name("conflicting_#{conflict['type']}_#{conflict['title']}"),:name => normalize_name("#{catalog_diff['node_name']}_#{conflict['type']}[#{conflict['title']}]") do
"#{conflict['type']}[#{conflict['title']}]"
end
end
ul do
ul do
conflict['conflicting_attributes'].each do |attribute|
css = [
'color: black',
'background-color: white',
'border-width: 1px',
'border-bottom-width: 1px;',
'border-bottom-style: dotted',
'border-style: dotted solid',
'border-color: rgb(221, 221, 221);',
'padding-top: 15px',
'padding-right: 15px',
'padding-bottom: 15px',
'padding-left: 15px',
'border-left-width: 4px',
'width: 768',
]
div :style=>css.join(';') do
['%s{ \'%s\':' % [conflict['type'].downcase,conflict['title'].downcase],
'- %s => %s' % [attribute['name'],attribute['baseline_value'].inspect],
'+ %s => %s' % [attribute['name'],attribute['preview_value'].inspect],
'}',
].each do |line|
tag! :code do
if line =~ /^\-.*/
div :style=> "background-color:#ffecec" do
tag! :font, :color => '#bd2c00' do
"#{line} "
end
end
elsif line =~/^\+.*/
div :style=> "background-color:#eaffea" do
tag! :font, :color => '#55a532' do
"#{line} "
end
end
else
line
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
File.write(@html_file, mab.to_s)