digup 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/Rakefile +1 -0
- data/digup.gemspec +25 -0
- data/lib/digup/digup_railtie.rb +7 -0
- data/lib/digup/extension.rb +7 -0
- data/lib/digup/logger.rb +78 -0
- data/lib/digup/rack.rb +26 -0
- data/lib/digup/responder.rb +87 -0
- data/lib/digup/setting.rb +68 -0
- data/lib/digup/template.rb +134 -0
- data/lib/digup/version.rb +3 -0
- data/lib/digup.rb +68 -0
- data/lib/generators/digup/model_generator.rb +25 -0
- data/lib/generators/digup/templates/_hook.html.erb +42 -0
- data/lib/generators/digup/templates/create_digup_log.rb +16 -0
- data/lib/generators/digup/templates/create_request_response_info.rb +18 -0
- data/lib/generators/digup/templates/digup_log.rb +5 -0
- data/lib/generators/digup/templates/request_response_info.rb +5 -0
- data/lib/generators/digup/view_generator.rb +15 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZGU1YjNlNDZhNmJmMWJiNjI5ZWRlYzFjYTM5OGFiNWMyMjdlMmY4OQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Yjg0OWQ4Yjg3ZGNjM2M2ZmI3YzAwOTRjN2QzZGZiMmZhZTc0NThmMA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjM4ZDg2NDMxZDlhMWU5YjY4YTVhZWZiYmRlNmVmNTA3ZmRkNGYxZTg5ZGQ0
|
10
|
+
ZGZiNTJkNTMwYzhhM2FkMzBkN2JjODdiODIyYzFjZWE1Y2Y3ZTI3OTVkM2Q0
|
11
|
+
YzFhZWI1YmVlMzllYWMwYjk4NGM3YmRiOTA2MWVlOWIyOTg1NDU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OWFmOWRjZWQyNjAzY2FkYjFlNDcxOGM2ZmZiOTFjZDA4YmE1NWZhZmZhZTZj
|
14
|
+
Y2Y0MmNmYjBiMjNhMjU0YWNiYzU5ZTQ0MzIwNGQ1ZWI5OWZlZGU3MDM5M2Ey
|
15
|
+
OTJiMWJmYmRhMjI0ZjVmOGE2MjhlOGQ3OGI2OTMzNmY4M2YxMjM=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Rohan Pujari
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Digup
|
2
|
+
|
3
|
+
Digup is a simple gem for debugging errors by printing outputs.
|
4
|
+
Digup allows you to debug your application by printing everything in html page or web console. Digup have diffrent logging mode file, db logging and logging data directly to console and html page.
|
5
|
+
It is a gem for those who still follow old debugging techniques of printing output and inspecting bug by using methods like 'puts' and 'p'. Digup can also be used as logger as it alows logging data to file.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'digup'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install digup
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Digup have several settings to be set to operate diffrently.
|
24
|
+
Once gem is installed go to config/environment/development.rb file and configure the gem. Paste following code
|
25
|
+
|
26
|
+
config.after_initialize do
|
27
|
+
Digup::Setting.options = :default
|
28
|
+
end
|
29
|
+
|
30
|
+
Above setting will make Digup operate with default setting
|
31
|
+
|
32
|
+
After you have configured Digup gem you can use digup_write method to out data you want.
|
33
|
+
|
34
|
+
digup_write 'Print this to web console and other places'
|
35
|
+
|
36
|
+
Digup uses following setting as default
|
37
|
+
|
38
|
+
Digup::Setting.options = {
|
39
|
+
:response_type => [:js, :json, :html],
|
40
|
+
:log_to => [:console, :html_body],
|
41
|
+
:cursor_info => true
|
42
|
+
}
|
43
|
+
|
44
|
+
You can configure digup to operate the way you want.
|
45
|
+
- response_type: It takes single value as symbol or array of symbols to specify multiple options. It sets response_type for which the log will be sent
|
46
|
+
|
47
|
+
eg) If it includes :json, then log will be appended to json response otherwise it would not be appended
|
48
|
+
|
49
|
+
Possible options for responset type are :js, :json, :html
|
50
|
+
- log_to: It takes single value as symbol or array of symbol to specify multiple options. It sets places where the output should be logged.
|
51
|
+
|
52
|
+
Possible options
|
53
|
+
1. :console => When this option is used then the data printed through digup_write method is shown on browser web console.
|
54
|
+
2. :html_body => When this option is used then the data printed through digup_write method is displayed as footer in web page. You can generate default view that the digup provides using digup:view generator. It is recommended to generate the default view if this option is to be used.
|
55
|
+
|
56
|
+
rails generate digup:view
|
57
|
+
Above command will generate file named _hook.html.erb inside app/views/diup folde. This view will be apended to html page when :html_body option is set. You can customize this view as you want.
|
58
|
+
3. :db => When this option is used then the data printed through digup_write method is stored in database. Before you can use this option you should generate model and migration file required. You can do this using digup:model generators.
|
59
|
+
|
60
|
+
rails generate digup:model
|
61
|
+
Above command will generate two model file(digup_write.rb, request_response_info.rb) and corresponding migration files. You should run migration before you can use :db option
|
62
|
+
|
63
|
+
NOTE => If you are using :db option ActiveRecord is mandatory.
|
64
|
+
|
65
|
+
4. :file => When this option is used then the data printed through digup_write method is logged inside digup.log file. digup.log is inside log folder.
|
66
|
+
|
67
|
+
- cursor_info => If this option is true then file name along with the line number where digup_write method was used will be diplayed along with message that is printed.
|
68
|
+
|
69
|
+
If :db or :file logging is used then some extra information is also logged. Extra informations logged are request method(get, post, put etc), request accepts([text/html, application/xml, */*] etc), response status(it would always 200), response type(text/html, application/json etc), params
|
70
|
+
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
Licensed under the MIT license, see the separate LICENSE.txt file.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/digup.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'digup/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "digup"
|
8
|
+
spec.version = Digup::VERSION
|
9
|
+
spec.authors = ["Rohan Pujari"]
|
10
|
+
spec.email = ["rohanpujaris@gmail.com"]
|
11
|
+
spec.description = %q{Debug by printing data directly as html or in web console. Digup have diffrent logging mode file logging, db logging and logging debug data directly to console and html page. Digup can also be used as a logger}
|
12
|
+
spec.summary = %q{Digup allows you to debug your application by printing everything in html page. Digup have diffrent logging mode file, db logging and logging debug data directly to console and html page}
|
13
|
+
spec.homepage = "https://github.com/rohanpujaris/digup"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'rails', '>= 3.0.0', '< 4.2.0'
|
25
|
+
end
|
data/lib/digup/logger.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
module Digup
|
2
|
+
|
3
|
+
class Logger
|
4
|
+
|
5
|
+
def self.file_path
|
6
|
+
Rails.root.join('log', 'digup.log').to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(responder)
|
10
|
+
@responder = responder
|
11
|
+
end
|
12
|
+
|
13
|
+
# appends log as html footer
|
14
|
+
def log_to_html_body
|
15
|
+
template = case
|
16
|
+
when @responder.html_response?
|
17
|
+
Template.html_template
|
18
|
+
when @responder.javascript_response?
|
19
|
+
Template.javascript_template
|
20
|
+
else
|
21
|
+
new_json_template
|
22
|
+
end
|
23
|
+
@responder.append_template_to_response(template)
|
24
|
+
end
|
25
|
+
|
26
|
+
# appends log as web console
|
27
|
+
def log_to_console
|
28
|
+
template = case
|
29
|
+
when @responder.html_response?
|
30
|
+
Template.console_template_for_html_response
|
31
|
+
when @responder.javascript_response?
|
32
|
+
Template.console_template_for_javascript_response
|
33
|
+
else
|
34
|
+
new_json_template
|
35
|
+
end
|
36
|
+
@responder.append_template_to_response(template)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Add log to database. ActiveRecord required
|
40
|
+
def log_to_db
|
41
|
+
RequestResponseInfo.create(
|
42
|
+
:request_method => @responder.request.request_method,
|
43
|
+
:request_accepts => @responder.request.accepts,
|
44
|
+
:response_type => @responder.response.content_type,
|
45
|
+
:response_status => @responder.status,
|
46
|
+
:params => @responder.request.filtered_parameters
|
47
|
+
).digup_logs.create(Digup.message_store)
|
48
|
+
end
|
49
|
+
|
50
|
+
# add log to file inside log/digup.log
|
51
|
+
def log_to_file
|
52
|
+
File.open(Logger.file_path, 'a') do |f|
|
53
|
+
f.write(Template.file_template(@responder))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# log to every available option
|
58
|
+
def log_all
|
59
|
+
if Digup.message_store.present?
|
60
|
+
log_to_html_body if Setting.log_to_html_body?
|
61
|
+
log_to_console if Setting.log_to_console?
|
62
|
+
log_to_db if Setting.log_to_db?
|
63
|
+
log_to_file if Setting.log_to_file?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def response_body
|
68
|
+
@responder.response_body
|
69
|
+
end
|
70
|
+
|
71
|
+
# creates json template depending on the last character of response(} or ])
|
72
|
+
def new_json_template
|
73
|
+
Template.json_template(response_body[response_body.length - 1])
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/lib/digup/rack.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Digup
|
2
|
+
|
3
|
+
class Rack
|
4
|
+
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
responder = Responder.new(@app.call(env))
|
11
|
+
if Setting.enabled? && responder.valid?
|
12
|
+
logger = Logger.new(responder)
|
13
|
+
logger.log_all
|
14
|
+
responder.append_javascript_to_evaluate_json if Setting.handle_json? && responder.html_response?
|
15
|
+
responder.headers['Content-Length'] = responder.response_body.bytesize.to_s
|
16
|
+
responder.clear_digup_message_store
|
17
|
+
responder.build_response
|
18
|
+
else
|
19
|
+
responder.clear_digup_message_store
|
20
|
+
end
|
21
|
+
responder.build_response
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Digup
|
2
|
+
|
3
|
+
class Responder
|
4
|
+
|
5
|
+
attr_accessor :status, :headers, :response, :response_body
|
6
|
+
|
7
|
+
def initialize(original_response)
|
8
|
+
@original_response = original_response
|
9
|
+
@status, @headers, @response = original_response
|
10
|
+
end
|
11
|
+
|
12
|
+
def request
|
13
|
+
response.request
|
14
|
+
end
|
15
|
+
|
16
|
+
# Appends template to reponse depending on the settings
|
17
|
+
def append_template_to_response(template)
|
18
|
+
position = if response_body.include?('</body>')
|
19
|
+
response_body.rindex('</body>')
|
20
|
+
else
|
21
|
+
javascript_response? ? response_body.length : response_body.length - 1
|
22
|
+
end
|
23
|
+
response_body.insert(position, (json_response? ? '' : "\n") + template )
|
24
|
+
end
|
25
|
+
|
26
|
+
# Appends javascript to every page when response_type Setting includes :json
|
27
|
+
# Appends javascript to display json response appendes to original response
|
28
|
+
def append_javascript_to_evaluate_json
|
29
|
+
if response_body.include?('</body>')
|
30
|
+
position = response_body.rindex('</body>')
|
31
|
+
response_body.insert(position, Template.javascript_template_to_evaluate_json)
|
32
|
+
else
|
33
|
+
response_body << Template.javascript_template_to_evaluate_json
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def response_not_a_file?
|
38
|
+
headers["Content-Transfer-Encoding"] != "binary"
|
39
|
+
end
|
40
|
+
|
41
|
+
def empty_response?
|
42
|
+
(@response.is_a?(Array) && @response.size <= 1) ||
|
43
|
+
!@response.respond_to?(:body) ||
|
44
|
+
!response_body.respond_to?(:empty?) ||
|
45
|
+
response_body.empty?
|
46
|
+
end
|
47
|
+
|
48
|
+
# If responsder is valid, then only response is modified
|
49
|
+
def valid?
|
50
|
+
!empty_response? && !response_body.frozen? && response_not_a_file? &&
|
51
|
+
status == 200 && can_handle_response?
|
52
|
+
end
|
53
|
+
|
54
|
+
# build a response to be sent to client
|
55
|
+
def build_response
|
56
|
+
valid? ? [status, headers, [response_body]] : @original_response
|
57
|
+
end
|
58
|
+
|
59
|
+
# clears log message unless its not a redirection
|
60
|
+
# If its redirection log needs to be displayed on redirected page. So its not cleared
|
61
|
+
def clear_digup_message_store
|
62
|
+
Digup.message_store.clear unless [301, 302].include?(status)
|
63
|
+
end
|
64
|
+
|
65
|
+
def response_body
|
66
|
+
@response_body ||= response.body.instance_of?(Array) ? response.body.first : response.body
|
67
|
+
end
|
68
|
+
|
69
|
+
def can_handle_response?
|
70
|
+
Setting.content_type_to_handle.include?(response.content_type)
|
71
|
+
end
|
72
|
+
|
73
|
+
def html_response?
|
74
|
+
response.content_type == 'text/html'
|
75
|
+
end
|
76
|
+
|
77
|
+
def javascript_response?
|
78
|
+
response.content_type == 'text/javascript'
|
79
|
+
end
|
80
|
+
|
81
|
+
def json_response?
|
82
|
+
response.content_type == 'application/json'
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Digup
|
2
|
+
|
3
|
+
class Setting
|
4
|
+
|
5
|
+
RESPONSE_TYPE = [:js, :json, :html]
|
6
|
+
LOG_TO = [:console, :html_body, :db, :file]
|
7
|
+
BOOLEAN_SETTINGS = [:cursor_info]
|
8
|
+
DEFAULT_SETTINGS = {
|
9
|
+
:response_type => [:js, :json, :html],
|
10
|
+
:log_to => [:console, :html_body],
|
11
|
+
:cursor_info => true
|
12
|
+
}
|
13
|
+
|
14
|
+
class << self
|
15
|
+
attr_accessor :options
|
16
|
+
|
17
|
+
def build_functions
|
18
|
+
RESPONSE_TYPE.each do |rt|
|
19
|
+
self.class.send(:define_method, "handle_#{rt}?") { options[:response_type].include?(rt) }
|
20
|
+
end
|
21
|
+
|
22
|
+
LOG_TO.each do |lt|
|
23
|
+
self.class.send(:define_method, "log_to_#{lt}?") { options[:log_to].include?(lt) }
|
24
|
+
end
|
25
|
+
|
26
|
+
BOOLEAN_SETTINGS.each do |s|
|
27
|
+
self.class.send(:define_method, "#{s}?") { options[s] }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def enabled?
|
32
|
+
@options.present?
|
33
|
+
end
|
34
|
+
|
35
|
+
def options=(options)
|
36
|
+
if options.is_a? Hash
|
37
|
+
options.slice!(:response_type, :log_to, :cursor_info)
|
38
|
+
options[:response_type] = option_to_array(options, :response_type)
|
39
|
+
options[:log_to] = option_to_array(options, :log_to)
|
40
|
+
@options = DEFAULT_SETTINGS.merge(options)
|
41
|
+
elsif options == :default
|
42
|
+
@options = DEFAULT_SETTINGS
|
43
|
+
end
|
44
|
+
build_functions
|
45
|
+
end
|
46
|
+
|
47
|
+
def option_to_array(options, key)
|
48
|
+
return DEFAULT_SETTINGS[key] unless options[key]
|
49
|
+
if options[key].is_a? Array
|
50
|
+
options[key]
|
51
|
+
else
|
52
|
+
[options[key]]
|
53
|
+
end & DEFAULT_SETTINGS[key]
|
54
|
+
end
|
55
|
+
|
56
|
+
def content_type_to_handle
|
57
|
+
content_type = []
|
58
|
+
content_type << 'text/html' if handle_html?
|
59
|
+
content_type << 'text/javascript' if handle_js?
|
60
|
+
content_type << 'application/json' if handle_json?
|
61
|
+
content_type
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
module Digup
|
2
|
+
|
3
|
+
class Template
|
4
|
+
|
5
|
+
HTML_TEMPLATE_FORMAT = <<-HTML
|
6
|
+
<div class='digup-content'>
|
7
|
+
<div class='digup-html-message'>
|
8
|
+
{notification_message}
|
9
|
+
</div>
|
10
|
+
</div>
|
11
|
+
HTML
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
# hook.html.haml is appended to response
|
16
|
+
# html_message and message_store is passed as locals to view which can be used
|
17
|
+
# to design custom template for displaying log.
|
18
|
+
# html_message is inside li tag so its prefered to use it instead of raw log in message_store
|
19
|
+
def html_template
|
20
|
+
begin
|
21
|
+
ApplicationController.new.render_to_string(
|
22
|
+
:partial => 'digup/hook',
|
23
|
+
:locals => {
|
24
|
+
:html_message => Digup.html_message,
|
25
|
+
:message_store => Digup.message_store
|
26
|
+
}
|
27
|
+
)
|
28
|
+
rescue
|
29
|
+
HTML_TEMPLATE_FORMAT.sub('{notification_message}', Digup.html_message)
|
30
|
+
end.html_safe
|
31
|
+
end
|
32
|
+
|
33
|
+
def javascript_template
|
34
|
+
code = <<-CODE
|
35
|
+
if ($('.digup-html-message').length) {
|
36
|
+
$('.digup-html-message').html("#{Digup.html_message}")
|
37
|
+
} else {
|
38
|
+
$('body').append("#{html_template.squish}")
|
39
|
+
}
|
40
|
+
CODE
|
41
|
+
code.html_safe
|
42
|
+
end
|
43
|
+
|
44
|
+
# code for printing log in console when response is js
|
45
|
+
def console_template_for_javascript_response
|
46
|
+
code = <<-CODE
|
47
|
+
if (typeof(console) !== 'undefined' && console.log) {
|
48
|
+
if (console.groupCollapsed && console.groupEnd) {
|
49
|
+
console.groupCollapsed('Digup');
|
50
|
+
console.log("#{Digup.console_message}");
|
51
|
+
console.groupEnd();
|
52
|
+
} else {
|
53
|
+
console.log("#{Digup.console_message}");
|
54
|
+
}
|
55
|
+
}
|
56
|
+
CODE
|
57
|
+
code.html_safe
|
58
|
+
end
|
59
|
+
|
60
|
+
# code for printing log in console when response is html.
|
61
|
+
# console_template_for_javascript_response is enclosed in script tag
|
62
|
+
def console_template_for_html_response
|
63
|
+
code = <<-CODE
|
64
|
+
<script type='text/javascript'>
|
65
|
+
#{console_template_for_javascript_response}
|
66
|
+
</script>
|
67
|
+
CODE
|
68
|
+
end
|
69
|
+
|
70
|
+
# json message to be appended is decided depending on last character(} or ])
|
71
|
+
def json_template(end_character)
|
72
|
+
Digup.json_message(end_character).html_safe
|
73
|
+
end
|
74
|
+
|
75
|
+
# This code is appended to every page if Setting response_type includes :json
|
76
|
+
def javascript_template_to_evaluate_json
|
77
|
+
executable_javascript = ''
|
78
|
+
if Setting.log_to_html_body?
|
79
|
+
executable_javascript = <<-CODE
|
80
|
+
if (!$('.digup-html-message').length) {
|
81
|
+
$('body').append("#{html_template.squish}")
|
82
|
+
}
|
83
|
+
var list = '<ul>'
|
84
|
+
$.each(digupData, function(index, value) {
|
85
|
+
list += #{html_for_json_evaluation}
|
86
|
+
})
|
87
|
+
list += '</ul>'
|
88
|
+
$('.digup-html-message').html(list)
|
89
|
+
CODE
|
90
|
+
end
|
91
|
+
executable_javascript += console_template_for_javascript_response if Setting.log_to_console?
|
92
|
+
code = <<-CODE
|
93
|
+
<script type='text/javascript'>
|
94
|
+
$(document).bind("ajaxComplete", function(event, xhr, settings){
|
95
|
+
jsonResponse = xhr.responseJSON;
|
96
|
+
if (jsonResponse) {
|
97
|
+
if ($.isArray(jsonResponse)) {
|
98
|
+
digupData = jsonResponse[jsonResponse.length - 1]
|
99
|
+
} else {
|
100
|
+
digupData = jsonResponse.digup
|
101
|
+
}
|
102
|
+
#{executable_javascript}
|
103
|
+
}
|
104
|
+
});
|
105
|
+
</script>
|
106
|
+
CODE
|
107
|
+
end
|
108
|
+
|
109
|
+
def html_for_json_evaluation
|
110
|
+
list = ''
|
111
|
+
if Setting.cursor_info?
|
112
|
+
list += "'<li>' + value['cursor_info'] + ' : ' + value['message'] + '</li>'"
|
113
|
+
else
|
114
|
+
list += "'<li>' + value['message'] + '</li>'"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# template for logginf in log/digup.log
|
119
|
+
def file_template(responder)
|
120
|
+
file_log = "Time #{Time.now}\n"
|
121
|
+
file_log += "Request method: #{responder.request.request_method} | "
|
122
|
+
file_log += "Request accepts: #{responder.request.accepts}\n"
|
123
|
+
file_log += "response status: #{responder.status} | "
|
124
|
+
file_log += "response type: #{responder.response.content_type}\n"
|
125
|
+
file_log += "params: #{responder.request.filtered_parameters}"
|
126
|
+
file_log += Digup.text_message
|
127
|
+
file_log += "\n\n#{'=' * 180}\n\n"
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
data/lib/digup.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'digup/setting'
|
2
|
+
require 'digup/rack'
|
3
|
+
require 'digup/template'
|
4
|
+
require 'digup/responder'
|
5
|
+
require 'digup/logger'
|
6
|
+
require 'digup/digup_railtie'
|
7
|
+
require 'digup/extension'
|
8
|
+
|
9
|
+
module Digup
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :message_store
|
13
|
+
|
14
|
+
def message_store
|
15
|
+
@message_store ||= []
|
16
|
+
end
|
17
|
+
|
18
|
+
def html_message
|
19
|
+
html = '<ul>'
|
20
|
+
message_store.each do |record|
|
21
|
+
html += '<li>'
|
22
|
+
html += "#{record[:cursor_info]} => " if cursor_info?(record)
|
23
|
+
html += "#{record[:message]}"
|
24
|
+
html += '</li>'
|
25
|
+
end
|
26
|
+
(html + '</ul>').html_safe
|
27
|
+
end
|
28
|
+
|
29
|
+
def console_message
|
30
|
+
console_data = ''
|
31
|
+
message_store.each do |record|
|
32
|
+
console_data += "#{record[:cursor_info]} : " if cursor_info?(record)
|
33
|
+
console_data += "#{record[:message]}\\n"
|
34
|
+
end
|
35
|
+
console_data
|
36
|
+
end
|
37
|
+
|
38
|
+
def json_message(end_character)
|
39
|
+
if end_character == ']'
|
40
|
+
", {\"digup\": #{message_store.to_json}}"
|
41
|
+
else
|
42
|
+
", \"digup\": #{message_store.to_json}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def text_message
|
47
|
+
text = ''
|
48
|
+
message_store.each do |record|
|
49
|
+
text += "\n#{record[:cursor_info]} : "
|
50
|
+
text += "#{record[:message]}"
|
51
|
+
end
|
52
|
+
text
|
53
|
+
end
|
54
|
+
|
55
|
+
def write_up(message, args=nil)
|
56
|
+
message_hash = {:date => Time.now, :message => message}
|
57
|
+
message_hash.merge!(:cursor_info => caller[0].sub(Rails.root.to_s, ''))
|
58
|
+
message_store.push(message_hash)
|
59
|
+
end
|
60
|
+
|
61
|
+
alias_method :log, :write_up
|
62
|
+
|
63
|
+
def cursor_info?(record)
|
64
|
+
Setting.cursor_info? && record[:cursor_info]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module Digup
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < Rails::Generators::Base
|
6
|
+
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
|
11
|
+
def self.next_migration_number(dirname)
|
12
|
+
next_migration_number = current_migration_number(dirname) + 1
|
13
|
+
ActiveRecord::Migration.next_migration_number(next_migration_number)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_digup_models
|
17
|
+
template 'digup_log.rb', 'app/models/digup_log.rb'
|
18
|
+
migration_template 'create_digup_log.rb', 'db/migrate/create_digup_log.rb'
|
19
|
+
template 'request_response_info.rb', 'app/models/request_response_info.rb'
|
20
|
+
migration_template 'create_request_response_info.rb', 'db/migrate/create_request_response_info.rb'
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<div id='digup-wrapper'>
|
2
|
+
<style type='text/css'>
|
3
|
+
.digup-content{
|
4
|
+
background-color: #333;
|
5
|
+
bottom: 0px;
|
6
|
+
height: 50px;
|
7
|
+
left: 0px;
|
8
|
+
opacity: 0.9;
|
9
|
+
overflow-y: auto;
|
10
|
+
padding: 3px 0px;
|
11
|
+
position: fixed;
|
12
|
+
width: 100%;
|
13
|
+
}
|
14
|
+
.digup-content li {
|
15
|
+
color: #eee;
|
16
|
+
word-break: break-all;
|
17
|
+
}
|
18
|
+
.vertical{
|
19
|
+
-webkit-transform:rotate(-90deg);
|
20
|
+
-moz-transform:rotate(-90deg);
|
21
|
+
-o-transform: rotate(-90deg);
|
22
|
+
-ms-transform:rotate(-90deg);
|
23
|
+
white-space:nowrap;
|
24
|
+
background-color: #FF2222;
|
25
|
+
bottom:14px;
|
26
|
+
color: #fff;
|
27
|
+
display:block;
|
28
|
+
left:-14px;
|
29
|
+
padding: 5px 0px;
|
30
|
+
position: fixed;
|
31
|
+
text-align: center;
|
32
|
+
width: 56px;
|
33
|
+
}
|
34
|
+
.digup-html-message {
|
35
|
+
margin: 0px 20px;
|
36
|
+
}
|
37
|
+
</style>
|
38
|
+
<div class='hook digup-content'>
|
39
|
+
<div><div class='vertical'>Digup</div></div>
|
40
|
+
<div class='digup-html-message'><%= html_message %></div>
|
41
|
+
</div>
|
42
|
+
</div>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateDigupLog < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :digup_logs do |t|
|
5
|
+
t.string :cursor_info
|
6
|
+
t.string :message
|
7
|
+
t.references :request_response_info
|
8
|
+
t.datetime :date
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
remove_table :digup_logs
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateRequestResponseInfo < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :request_response_infos do |t|
|
5
|
+
t.string :request_method
|
6
|
+
t.string :request_accepts
|
7
|
+
t.string :response_type
|
8
|
+
t.string :response_status
|
9
|
+
t.string :params
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
remove_table :digup_logs
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module Digup
|
4
|
+
module Generators
|
5
|
+
class ViewGenerator < Rails::Generators::Base
|
6
|
+
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
def create_hook
|
10
|
+
copy_file '_hook.html.erb', 'app/views/digup/_hook.html.erb'
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: digup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rohan Pujari
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
- - <
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 4.2.0
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 3.0.0
|
58
|
+
- - <
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 4.2.0
|
61
|
+
description: Debug by printing data directly as html or in web console. Digup have
|
62
|
+
diffrent logging mode file logging, db logging and logging debug data directly to
|
63
|
+
console and html page. Digup can also be used as a logger
|
64
|
+
email:
|
65
|
+
- rohanpujaris@gmail.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- digup.gemspec
|
76
|
+
- lib/digup.rb
|
77
|
+
- lib/digup/digup_railtie.rb
|
78
|
+
- lib/digup/extension.rb
|
79
|
+
- lib/digup/logger.rb
|
80
|
+
- lib/digup/rack.rb
|
81
|
+
- lib/digup/responder.rb
|
82
|
+
- lib/digup/setting.rb
|
83
|
+
- lib/digup/template.rb
|
84
|
+
- lib/digup/version.rb
|
85
|
+
- lib/generators/digup/model_generator.rb
|
86
|
+
- lib/generators/digup/templates/_hook.html.erb
|
87
|
+
- lib/generators/digup/templates/create_digup_log.rb
|
88
|
+
- lib/generators/digup/templates/create_request_response_info.rb
|
89
|
+
- lib/generators/digup/templates/digup_log.rb
|
90
|
+
- lib/generators/digup/templates/request_response_info.rb
|
91
|
+
- lib/generators/digup/view_generator.rb
|
92
|
+
homepage: https://github.com/rohanpujaris/digup
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.2.2
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Digup allows you to debug your application by printing everything in html
|
116
|
+
page. Digup have diffrent logging mode file, db logging and logging debug data directly
|
117
|
+
to console and html page
|
118
|
+
test_files: []
|