firephruby 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ LGPL
data/README ADDED
File without changes
data/cgi_sample.rb ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/local/bin/ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'firephruby'
5
+
6
+ console = Fireruby::CGI.new
7
+
8
+ console.log 'HMMMmmm...'
9
+ console.info 'Übrigens...'
10
+ console.warn "Achtunk!"
11
+ console.error "Scheiße!"
12
+
13
+ puts "Content-Type: text/plain; charset=utf-8\n\n"
14
+ puts 'so far it worked'
data/lib/firephruby.rb ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/local/bin/ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'json'
5
+
6
+ module FirePHRuby
7
+
8
+ 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__"},' }
15
+ FPHR_KINDS = %w(LOG INFO WARN ERROR DUMP TRACE EXCEPTION TABLE)
16
+
17
+ def build_headers msg,kind='LOG'
18
+ 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} ]," ]
23
+ unless instance_variables.member? "@firephruby_inited_#{g_kind.downcase}"
24
+ FirePHRuby::Common::const_get( "FPHR_INIT_HEADERS_#{g_kind}" ).each_pair { |k,v| headers << [ k, v ] }
25
+ instance_variable_set( "@firephruby_inited_#{g_kind.downcase}", true )
26
+ end
27
+ return headers
28
+ end
29
+ end
30
+
31
+ class CGI
32
+ include Common
33
+ 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}" }
36
+ end
37
+ def firelog msg,kind='LOG'
38
+ headers = build_headers msg,kind
39
+ headers.each { |h| puts "#{h[0]}: #{h[1]}" }
40
+ end
41
+ def log msg
42
+ firelog msg,'LOG'
43
+ 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'
52
+ end
53
+ end
54
+
55
+ module WEBrick
56
+ include Common
57
+ def fire_log msg,kind='LOG'
58
+ headers = build_headers msg,kind
59
+ 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
64
+ end
65
+ def fire_info msg
66
+ fire_log msg,'INFO'
67
+ end
68
+ def fire_warn msg
69
+ fire_log msg,'WARN'
70
+ end
71
+ def fire_error msg
72
+ fire_log msg,'ERROR'
73
+ end
74
+ end
75
+ end
76
+
77
+ module WEBrick
78
+ class HTTPResponse
79
+ include FirePHRuby::WEBrick
80
+ end
81
+ end
data/webrick_sample.rb ADDED
@@ -0,0 +1,20 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'webrick'
5
+ include WEBrick
6
+ require 'firephruby'
7
+
8
+ server = HTTPServer.new(:Port => 8085)
9
+
10
+ server.mount_proc('/firetest') do |request, response|
11
+ response.fire_log 'HMMMmmm...'
12
+ response.fire_info 'Übrigens...'
13
+ response.fire_warn "Achtunk!"
14
+ response.fire_error "Scheiße!"
15
+ response.body = "so far it worked"
16
+ end
17
+
18
+ trap('INT') { server.shutdown }
19
+ server.start
20
+
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: firephruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors: []
7
+
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-21 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.0
24
+ version:
25
+ description: FirePHRuby is a Ruby module for the "FirePHP" Firefox/Firebug extension to make AJAX development easier.
26
+ email: tnt@banza.net
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - README
35
+ - Changelog
36
+ - LICENSE
37
+ - webrick_sample.rb
38
+ - cgi_sample.rb
39
+ - lib/firephruby.rb
40
+ has_rdoc: false
41
+ homepage: http://firephruby.rubyforge.org/
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 1.8.6
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project: firephruby
62
+ rubygems_version: 1.2.0
63
+ signing_key:
64
+ specification_version: 2
65
+ summary: Module for AJAX development with Firebug.
66
+ test_files: []
67
+