Class: HTMLTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/customlogger/html_template.rb

Class Method Summary collapse

Class Method Details

.html(title, error_colors) ⇒ Object



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
# File 'lib/customlogger/html_template.rb', line 3

def html(title, error_colors)
  <<-HTML
  <!DOCTYPE html>
  <html>
  <head>
<meta charset="UTF-8">
<title>#{title}</title>
<style>
  .error {
    font-family: monospace, monospace, serif;
    font-size: 0.9em;
    color: #{error_colors[:error]};
    background-color: #f2dede;
    border-color: #8b0000;
    padding: 8px;
    border: 1px solid darkred;
    border-radius: 4px;
    margin-bottom: 4px;
  }
  .error header {
    font-size: 1.2em;;
    font-weight: bold;
    padding-bottom: 4px;
  }
  .error summary { padding-left: 8px; }
  .error time {
    font-family: monospace, monospace, serif;
    font-size: 0.68em;
    display: block;
    padding-top: 8px;
  }

  .warning {
    font-family: monospace, monospace, serif;
    font-size: 0.9em;
    color: #{error_colors[:warning]};
    background-color: #faebcc;
    border-color: #b4a48a;
    padding: 8px;
    border: 1px solid #b4a48a;
    border-radius: 4px;
    margin-bottom: 4px;
  }
  .warning header {
    font-size: 1.2em;;
    font-weight: bold;
    padding-bottom: 4px;
  }
  .warning summary { padding-left: 8px; }
  .warning time {
    font-family: monospace, monospace, serif;
    font-size: 0.68em;
    display: block;
    padding-top: 8px;
  }

  .debug {
    font-family: monospace, monospace, serif;
    font-size: 0.9em;
    color: #{error_colors[:debug]};
    background-color: #eafbe2;
    border-color: #bbcbad;
    padding: 8px;
    border: 1px solid #bbcbad;
    border-radius: 4px;
    margin-bottom: 4px;
  }
  .debug header {
    font-size: 1.2em;;
    font-weight: bold;
    padding-bottom: 4px;
  }
  .debug summary { padding-left: 8px; }
  .debug time {
    font-family: monospace, monospace, serif;
    font-size: 0.68em;
    display: block;
    padding-top: 8px;
  }

  .info {
    font-family: monospace, monospace, serif;
    font-size: 0.9em;
    color: #{error_colors[:info]};
    background-color: #e0f5ff;
    border-color: #a6ccd4;
    padding: 8px;
    border: 1px solid #a6ccd4;
    border-radius: 4px;
    margin-bottom: 4px;
  }
  .info header {
    font-size: 1.2em;;
    font-weight: bold;
    padding-bottom: 4px;
  }
  .info summary { padding-left: 8px; }
  .info time {
    font-family: monospace, monospace, serif;
    font-size: 0.68em;
    display: block;
    padding-top: 8px;
  }

  .raw {
    font-family: monospace, monospace, serif;
    font-size: 0.9em;
    color: #303030;
    background-color: #dcdcdc;
    border-color: #a0a0a0;
    padding: 8px;
    border: 1px solid #a0a0a0;
    border-radius: 4px;
    margin-bottom: 4px;
  }
  .raw header {
    font-size: 1.2em;;
    font-weight: bold;
    padding-bottom: 4px;
  }
  .raw pre { padding-left: 8px; }
  .raw time {
    font-family: monospace, monospace, serif;
    font-size: 0.68em;
    display: block;
    padding-top: 8px;
  }

  section { padding: 28px; }
</style>
  </head>
  <body>
  <h2>Custome Logger</h2>
  </body></html>
  HTML
end

.log_to_html(state, message, title) ⇒ Object



150
151
152
153
154
155
156
157
158
# File 'lib/customlogger/html_template.rb', line 150

def log_to_html(state, message, title)
  if title.nil?
    [ '<div class="', state, '">', message, '<time>',
      Time.now, '</time></div>' ].join
  else
    [ '<div class="', state, '"><header>', title, '</header>',
      message, '<time>', Time.now, '</time></div>' ].join
  end
end

.raw_to_html(message, title) ⇒ Object



140
141
142
143
144
145
146
147
148
# File 'lib/customlogger/html_template.rb', line 140

def raw_to_html(message, title)
  if title.nil?
    [ '<div class="raw"><pre>', message, '</pre><time>', Time.now,
      '</time></div>' ].join
  else
    [ '<div class="raw"><header>', title, '</header><pre>', message,
      '</pre><time>', Time.now, '</time></div>' ].join
  end
end