Class: Tracing::HtmlAppender

Inherits:
FileAppender show all
Defined in:
lib/appenders/types/html_appender.rb

Instance Attribute Summary collapse

Attributes inherited from BaseAppender

#options, #templates

Attributes included from FilterUse

#filters

Attributes included from Filter::ExecUse

#filter_executor

Attributes included from Filter::Registration

#filters

Instance Method Summary collapse

Methods inherited from FileAppender

#file_path, #insert_into_file, #is_old_file?, #write_file

Methods included from DefaultPath

#default_path, #default_path=

Methods inherited from BaseAppender

create_template, #handle, register_templates, #time_limit

Methods included from Filter::Registration

#_register_filters, #create_filters, #register_filters, #unregister_filters

Constructor Details

#initialize(init_options = nil) ⇒ HtmlAppender

Returns a new instance of HtmlAppender.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/appenders/types/html_appender.rb', line 5

def initialize(init_options = nil)
  @tracer = Tracing::HtmlTemplate.new      
  super(init_options)  
  @html_output = html_begin 

  return if !init_options
  # write to file
  @to_file = init_options[:to_file]  
  
  # override default path for class
  @default_path = init_options[:default_path]  
  
  if @to_file    
    write_wrap_file(to_file)
  else
    html_output << html_begin << html_end
  end
end

Instance Attribute Details

#html_outputObject

Returns the value of attribute html_output.



3
4
5
# File 'lib/appenders/types/html_appender.rb', line 3

def html_output
  @html_output
end

#to_fileObject

Returns the value of attribute to_file.



3
4
5
# File 'lib/appenders/types/html_appender.rb', line 3

def to_file
  @to_file
end

Instance Method Details

#allow_append(txt, context) ⇒ Object

perform append perform append



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/appenders/types/html_appender.rb', line 58

def allow_append(txt, context)            
  # check if BEGIN or END
  if txt.include?('BEGIN')
    txt = tracer.handle_before_call(context)
  elsif txt.include?('END')
    txt = tracer.handle_after_call(context)
  end
  
  if to_file                   
    insert_into_file(to_file, txt, html_end) 
  else
    # insert into string
    html_output = txt[0..-html_end.length] + txt + html_end 
  end
end

#create_initial_file(file) ⇒ Object



32
33
34
# File 'lib/appenders/types/html_appender.rb', line 32

def create_initial_file(file)
  write_wrap_file(file)      
end

#html_beginObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/appenders/types/html_appender.rb', line 36

def html_begin
  %q{<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <title>Tracing :: abc</title>
  <link rel="stylesheet" href="tracing.css" type="text/css" media="screen" title="tracing" charset="utf-8">
  <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
  <script type="text/javascript" src="tracing.js"></script> 
</head>
<body>}
end

#html_endObject



49
50
51
52
53
54
# File 'lib/appenders/types/html_appender.rb', line 49

def html_end
  %q{
</body>
</html> 
  }
end

#not_allow_append(lines, context) ⇒ Object

silently ignore



75
76
# File 'lib/appenders/types/html_appender.rb', line 75

def not_allow_append(lines, context)
end

#write_wrap_file(file) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/appenders/types/html_appender.rb', line 24

def write_wrap_file(file)
  file = file_path(file)
  File.open(file, "w") do |file|
    file.puts html_begin
    file.puts html_end
  end
end