firephruby 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -0,0 +1,2 @@
1
+ 0.2 -- changed headers to comply to FirePHP 0.2, added labels, added support
2
+ for Rails, added version check, added 'DUMP'
data/LICENSE CHANGED
@@ -1 +1,165 @@
1
- LGPL
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README CHANGED
@@ -0,0 +1,10 @@
1
+ FirePHRuby currently supports only the log/info/warn/error and the dump-command.
2
+ The syntax is
3
+
4
+ fire_log message, label=nil
5
+
6
+ where message can be any jsonizable data.
7
+
8
+ I now hacked FirePHRuby into Rails. It's only tested with 2.1.2. I'm quite new
9
+ to Ruby and Rails and so FirePHRuby is probably highly 'optimizable' to say the
10
+ least. If you have any comments, suggestions or critics email me: tnt@banza.net
data/lib/firephruby.rb CHANGED
@@ -1,81 +1,153 @@
1
1
  #!/usr/local/bin/ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
+ # Version 0.2.0
5
+
4
6
  require 'json'
5
7
 
6
8
  module FirePHRuby
7
-
9
+
10
+ FPHR_FUNCTION_NAMES = %w(LOG INFO WARN ERROR)
8
11
  module Common
9
- FPHR_INIT_HEADERS = { 'X-FirePHP-Data-100000000001' => '{',
10
- 'X-FirePHP-Data-999999999999' => '"__SKIP__":"__SKIP__"}' }
11
- FPHR_INIT_HEADERS_LOG = { 'X-FirePHP-Data-300000000001' => '"FirePHP.Firebug.Console":[',
12
- 'X-FirePHP-Data-399999999999' => '["__SKIP__"]],' }
13
- FPHR_INIT_HEADERS_DUMP = { 'X-FirePHP-Data-200000000001' => '"FirePHP.Dump":{',
14
- 'X-FirePHP-Data-299999999999' => '"__SKIP__":"__SKIP__"},' }
12
+ FPHR_INIT_HEADERS = { 'X-Wf-Protocol-1' => 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2',
13
+ 'X-Wf-1-Plugin-1' =>'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.2.0'}
14
+ FPHR_INIT_HEADERS_LOG = { 'X-Wf-1-Structure-1' => 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1' }
15
+ FPHR_INIT_HEADERS_DUMP = { 'X-Wf-1-Structure-2' => 'http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1' }
15
16
  FPHR_KINDS = %w(LOG INFO WARN ERROR DUMP TRACE EXCEPTION TABLE)
16
-
17
- def build_headers msg,kind='LOG'
17
+ FPHR_LEGACY_WARNING = { 'X-FirePHP-Data-100000000001' => '{' ,
18
+ 'X-FirePHP-Data-300000000001' => '"FirePHP.Firebug.Console":[',
19
+ 'X-FirePHP-Data-300000000002' => '[ "INFO", "This version of FirePHP is no longer supported by FirePHRuby. Please update to 0.2 or higher." ],',
20
+ 'X-FirePHP-Data-399999999999' => '["__SKIP__"]],',
21
+ 'X-FirePHP-Data-999999999999' => '"__SKIP__":"__SKIP__"}' }
22
+ MAX_LENGTH = 4000
23
+
24
+ def build_headers msg,kind='LOG',label=nil
18
25
  headers = []
19
- t_pref,g_kind = kind == 'DUMP' ? [ 2, 'DUMP' ] : [ 3, 'LOG' ]
20
- c_time = Time.new
21
- digits = "#{c_time.tv_sec.to_s[-5,5]}#{c_time.usec}"
22
- headers << [ "X-FirePHP-Data-#{t_pref}#{digits}", "[ \"#{kind}\", #{msg.to_json} ]," ]
26
+ t_pref,g_kind = kind == 'DUMP' ? [ 2, 'DUMP' ] : [ 1, 'LOG' ]
27
+ file, line, function = caller[2].split ':'
28
+ msg_meta = { 'Type' => kind, 'File' => file, 'Line' => line }
29
+ msg_meta['Label'] = label if label
30
+ @fire_msg_index = 0 unless instance_variables.member? '@fire_msg_index'
31
+ msg = kind == 'DUMP' ? "{#{label.to_json}:#{msg.to_json}}" : "[#{msg_meta.to_json},#{msg.to_json}]"
32
+ #puts msg.to_json
33
+ (msg.gsub /.{#{MAX_LENGTH}}/ do |m| "#{m}\n" end).split( "\n" ).each_with_index do |msg_part,ind|
34
+ @fire_msg_index += 1
35
+ headers << [ "X-Wf-1-#{t_pref}-1-#{@fire_msg_index}", "#{msg.size if ind == 0}|#{msg_part}|#{'\\' if ind < msg.size/MAX_LENGTH}" ] # int/int = int
36
+ #puts " msg_part: #{msg.size if ind == 0}|#{msg_part}|"
37
+ end
23
38
  unless instance_variables.member? "@firephruby_inited_#{g_kind.downcase}"
24
39
  FirePHRuby::Common::const_get( "FPHR_INIT_HEADERS_#{g_kind}" ).each_pair { |k,v| headers << [ k, v ] }
25
40
  instance_variable_set( "@firephruby_inited_#{g_kind.downcase}", true )
26
41
  end
27
42
  return headers
28
43
  end
44
+ def initialize_request ua
45
+ @firephp_version = ua.match( /FirePHP\/(\d+)\.(\d+)\.([\db.]+)/)
46
+ @firephp_version = @firephp_version[1,3].map {|i| i.to_i} if @firephp_version
47
+ firephp_01_version = ( @firephp_version || [0,2] )[0,2].join('.').to_f<0.2
48
+ @firephpruby_skip = @firephp_version == nil || firephp_01_version
49
+ firephp_01_version ? FPHR_LEGACY_WARNING : FPHR_INIT_HEADERS
50
+ end
29
51
  end
30
52
 
31
53
  class CGI
32
54
  include Common
33
55
  def initialize
34
- FPHR_INIT_HEADERS.each_pair { |k,v| puts "#{k}: #{v}" }
35
- #FPHR_INIT_HEADERS_LOG.each_pair { |k,v| puts "#{k}: #{v}" }
56
+ ENV['HTTP_USER_AGENT'] = 'FirePHP/0.2.b.7' unless ENV['HTTP_USER_AGENT'] # for being callable from shell
57
+ headers = initialize_request ENV['HTTP_USER_AGENT']
58
+ return if @firephpruby_skip
59
+ headers.each_pair { |k,v| puts "#{k}: #{v}" }
36
60
  end
37
- def firelog msg,kind='LOG'
38
- headers = build_headers msg,kind
61
+ def firelog msg,kind='LOG', label=nil
62
+ return if @firephpruby_skip
63
+ headers = build_headers msg,kind,label
39
64
  headers.each { |h| puts "#{h[0]}: #{h[1]}" }
40
65
  end
41
- def log msg
42
- firelog msg,'LOG'
66
+ FPHR_FUNCTION_NAMES.each { |x| self.class_eval "def #{x.downcase} msg, label=nil; firelog msg,'#{x}',label; end" }
67
+ def dump obj, label=''
68
+ firelog obj,'DUMP', label
43
69
  end
44
- def info msg
45
- firelog msg,'INFO'
46
- end
47
- def warn msg
48
- firelog msg,'WARN'
49
- end
50
- def error msg
51
- firelog msg,'ERROR'
70
+ def send_index_header # not needed since 0.2.b.4 or something like
71
+ puts "X-Wf-1-Index: #{@fire_msg_index.to_s}"
52
72
  end
53
73
  end
54
74
 
55
- module WEBrick
75
+ module HTTPResponse
56
76
  include Common
57
- def fire_log msg,kind='LOG'
58
- headers = build_headers msg,kind
77
+ def fire_clog msg,kind='LOG', label=nil
78
+ return if defined?( @firephpruby_skip ) && @firephpruby_skip
79
+ headers = build_headers msg,kind,label
59
80
  headers.each { |h| @header[h[0]] = h[1] }
60
- unless defined? @firephruby_inited
61
- FPHR_INIT_HEADERS.each_pair { |k,v| @header[k] = v }
62
- @firephruby_inited = true
63
- end
81
+ return if defined? @firephruby_inited
82
+ initialize_request( @firephruby_user_agent ).each_pair { |k,v| @header[k] = v }
83
+ @firephruby_inited = true
64
84
  end
65
- def fire_info msg
66
- fire_log msg,'INFO'
85
+ FPHR_FUNCTION_NAMES.each { |x| self.module_eval "def fire_#{x.downcase} msg, label=nil; fire_clog msg,'#{x}',label; end" }
86
+ def fire_dump obj, label=''
87
+ fire_clog obj,'DUMP', label
67
88
  end
68
- def fire_warn msg
69
- fire_log msg,'WARN'
89
+ def fire_set_user_agent ua
90
+ @firephruby_user_agent = ua
91
+ end
92
+ end
93
+
94
+ module Rails
95
+ include HTTPResponse
96
+ def set_header_var # the @header-hash from WEBrick/Mongrel-response-classes
97
+ @header = @headers # is called @headers in the Rails-response-class
70
98
  end
71
- def fire_error msg
72
- fire_log msg,'ERROR'
99
+ module Interface
100
+ FPHR_FUNCTION_NAMES.each { |x| self.module_eval "def fire_#{x.downcase} msg, label=nil; response.fire_clog msg,'#{x}',label; end" }
101
+ def fire_dump obj, label=''
102
+ response.fire_clog obj,'DUMP', label
103
+ end
73
104
  end
74
- end
105
+ end
75
106
  end
76
107
 
77
- module WEBrick
78
- class HTTPResponse
79
- include FirePHRuby::WEBrick
80
- end
108
+ if defined? ActionController # guessing Rails should be a little bit more detailed.
109
+ module ActionController
110
+ class Base
111
+ include FirePHRuby::Rails::Interface
112
+ unless defined? the_original_process_method
113
+ puts "alias the_original_process_method process"
114
+ alias the_original_process_method process
115
+ def process(request, response, method = :perform_action, *arguments)
116
+ response.fire_set_user_agent request.env['HTTP_USER_AGENT']
117
+ response.set_header_var
118
+ the_original_process_method(request, response, method, *arguments)
119
+ end
120
+ end
121
+ end
122
+ class AbstractResponse
123
+ include FirePHRuby::Rails
124
+ end
125
+ end
126
+ module ActionView
127
+ class Base
128
+ include FirePHRuby::Rails::Interface
129
+ end
130
+ end
131
+ elsif defined? WEBrick
132
+ module WEBrick
133
+ class HTTPResponse
134
+ include FirePHRuby::HTTPResponse
135
+ end
136
+ class HTTPServer
137
+ alias the_original_service_method service # 'duck punching' the service method
138
+ def service(req,res) # to get req.properties to the response object
139
+ res.fire_set_user_agent( req.meta_vars['HTTP_USER_AGENT'] )
140
+ the_original_service_method(req,res)
141
+ end
142
+ end
143
+ end
144
+ elsif defined? Mongrel
145
+ module Mongrel
146
+ class HttpResponse
147
+ include FirePHRuby::HTTPResponse
148
+ def fire_init req
149
+ fire_set_user_agent req.params['HTTP_USER_AGENT']
150
+ end
151
+ end
152
+ end
81
153
  end
@@ -1,6 +1,7 @@
1
1
  #!/usr/local/bin/ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
+ require 'rubygems'
4
5
  require 'firephruby'
5
6
 
6
7
  console = Fireruby::CGI.new
@@ -9,6 +10,8 @@ console.log 'HMMMmmm...'
9
10
  console.info 'Übrigens...'
10
11
  console.warn "Achtunk!"
11
12
  console.error "Scheiße!"
13
+ console.log %w(eins zwei drei), 'Label 1'
14
+ console.dump [].public_methods.sort, 'array methods'
12
15
 
13
16
  puts "Content-Type: text/plain; charset=utf-8\n\n"
14
17
  puts 'so far it worked'
@@ -0,0 +1,30 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'rubygems'
5
+ require 'mongrel'
6
+ require 'firephruby'
7
+
8
+ class SimpleHandler < Mongrel::HttpHandler
9
+ def process(request, response)
10
+ response.fire_init request # required in mongrel
11
+ response.fire_log 'HMMMmmm...'
12
+ response.fire_info 'Übrigens...', 'label'
13
+ response.fire_info :bla=>'blahhh', :blubb=>'bluhhbb'
14
+ response.fire_warn "Achtunk!"
15
+ response.fire_error "Schiet!"
16
+ response.fire_dump [].public_methods.sort, 'array methods'
17
+
18
+ response.start(200) do |head,out|
19
+ head["Content-Type"] = "text/plain"
20
+ out.write("hello!\n")
21
+ end
22
+ end
23
+ end
24
+
25
+ h = Mongrel::HttpServer.new("0.0.0.0", "3000")
26
+ h.register("/firetest", SimpleHandler.new)
27
+ h.run.join
28
+
29
+
30
+
@@ -0,0 +1,15 @@
1
+ class FphrdemoController < ApplicationController
2
+ def index
3
+ end
4
+
5
+ def fphr_ajax
6
+ fire_log 'Hello'
7
+ fire_info 'Hello'
8
+ fire_warn 'Hello'
9
+ fire_error 'Hello'
10
+ fire_log %w(eins zwei drei), 'Label 1'
11
+ fire_dump [].public_methods.sort, 'array methods'
12
+ render :json => [ 'sweet', 'sweet', "AJAX World" ]
13
+ end
14
+
15
+ end
@@ -0,0 +1,12 @@
1
+ <%= javascript_include_tag :defaults %>
2
+
3
+ Hello
4
+ <div id="ajax">response goes here</div>
5
+
6
+ <%= link_to_remote("klick me", {
7
+ :update => :ajax,
8
+ :url => { :action => :fphr_ajax } }) %>
9
+
10
+ <p><% fire_dump self.public_methods.sort, '"self.public_methods" of a view'
11
+ fire_log 'hiho','from the view' %>
12
+
@@ -1,17 +1,19 @@
1
1
  #! /usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
+ require 'rubygems'
4
5
  require 'webrick'
5
- include WEBrick
6
6
  require 'firephruby'
7
7
 
8
- server = HTTPServer.new(:Port => 8085)
8
+ server = WEBrick::HTTPServer.new(:Port => 8085)
9
9
 
10
10
  server.mount_proc('/firetest') do |request, response|
11
11
  response.fire_log 'HMMMmmm...'
12
12
  response.fire_info 'Übrigens...'
13
13
  response.fire_warn "Achtunk!"
14
- response.fire_error "Scheiße!"
14
+ response.fire_error "Schiet!"
15
+ response.fire_log %w(eins zwei drei), 'Label 1'
16
+ response.fire_dump [].public_methods.sort, 'array methods'
15
17
  response.body = "so far it worked"
16
18
  end
17
19
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firephruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -34,8 +34,11 @@ files:
34
34
  - README
35
35
  - Changelog
36
36
  - LICENSE
37
- - webrick_sample.rb
38
- - cgi_sample.rb
37
+ - samples/mongrel_sample.rb
38
+ - samples/rails/app/controllers/fphrdemo_controller.rb
39
+ - samples/rails/app/views/fphrdemo/index.html.erb
40
+ - samples/webrick_sample.rb
41
+ - samples/cgi_sample.rb
39
42
  - lib/firephruby.rb
40
43
  has_rdoc: false
41
44
  homepage: http://firephruby.rubyforge.org/