-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2fb9d64
Showing
9 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
*.gem | |||
*.rbc | |||
.bundle | |||
.config | |||
.yardoc | |||
Gemfile.lock | |||
InstalledFiles | |||
_yardoc | |||
coverage | |||
doc/ | |||
lib/bundler/man | |||
pkg | |||
rdoc | |||
spec/reports | |||
test/tmp | |||
test/version_tmp | |||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
source 'https://rubygems.org' | |||
|
|||
# Specify your gem's dependencies in loudmouthjs-rails.gemspec | |||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
Copyright (c) 2012 Pete Campbell | |||
|
|||
MIT License | |||
|
|||
Permission is hereby granted, free of charge, to any person obtaining | |||
a copy of this software and associated documentation files (the | |||
"Software"), to deal in the Software without restriction, including | |||
without limitation the rights to use, copy, modify, merge, publish, | |||
distribute, sublicense, and/or sell copies of the Software, and to | |||
permit persons to whom the Software is furnished to do so, subject to | |||
the following conditions: | |||
|
|||
The above copyright notice and this permission notice shall be | |||
included in all copies or substantial portions of the Software. | |||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
# Loudmouthjs::Rails | |||
|
|||
TODO: Write a gem description | |||
|
|||
## Installation | |||
|
|||
Add this line to your application's Gemfile: | |||
|
|||
gem 'loudmouthjs-rails' | |||
|
|||
And then execute: | |||
|
|||
$ bundle | |||
|
|||
Or install it yourself as: | |||
|
|||
$ gem install loudmouthjs-rails | |||
|
|||
## Usage | |||
|
|||
TODO: Write usage instructions here | |||
|
|||
## Contributing | |||
|
|||
1. Fork it | |||
2. Create your feature branch (`git checkout -b my-new-feature`) | |||
3. Commit your changes (`git commit -am 'Added some feature'`) | |||
4. Push to the branch (`git push origin my-new-feature`) | |||
5. Create new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
#!/usr/bin/env rake | |||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
require "loudmouthjs-rails/version" | |||
|
|||
module Loudmouthjs | |||
module Rails | |||
class Engine < ::Rails::Engine | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
module Loudmouthjs | |||
module Rails | |||
VERSION = "0.1.0" | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
# -*- encoding: utf-8 -*- | |||
require File.expand_path('../lib/loudmouthjs-rails/version', __FILE__) | |||
|
|||
Gem::Specification.new do |gem| | |||
gem.authors = ["Pete Campbell"] | |||
gem.email = ["pete@sumirolabs.com"] | |||
gem.description = "Shout about JavaScript errors and alerts in both dev and production." | |||
gem.summary = "Loudmouth tells you about JavaScript errors that occur in your app. It can complain loudly (eg. alerts) or silently (posting the error info back to your server). It can also tell you what alerts the users have seen." | |||
gem.homepage = "http://code.livingsocial.net/petecampbell/loudmouth" | |||
|
|||
gem.files = `git ls-files`.split($\) | |||
gem.name = "loudmouthjs-rails" | |||
gem.require_paths = ["lib"] | |||
gem.version = Loudmouthjs::Rails::VERSION | |||
gem.add_dependency "railties", "~> 3.1" | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,109 @@ | |||
// Make sure the developer knows that there is a JS error | |||
|
|||
var Loudmouth = (function(my){ | |||
var complaints = [], original_onerror = window.onerror, config = {}, original_alert = window.alert; | |||
|
|||
var complainLoudly = function(){ | |||
if (complaints.length > 0) { | |||
|
|||
var complaints_str = 'There was a JavaScript exception'; | |||
if (complaints.length > 1) complaints_str = 'There were ' + complaints.length + ' JavaScript exceptions'; | |||
complaints_str += " when the page was loading:\n"; | |||
|
|||
var error; | |||
while ( (complaint = complaints.pop()) != null){ | |||
complaints_str += "\n-------------------"; | |||
for ( var p in complaint){ | |||
if (complaint.hasOwnProperty(p)) complaints_str += "\n" + p + " : " + complaint[p]; | |||
} | |||
}; | |||
complaints_str += "\n-------------------\n\n"; | |||
|
|||
alert(complaints_str); | |||
} else { | |||
console.log("This loudmouth has nothing to complain about, kthxbye!"); | |||
}; | |||
|
|||
return this; | |||
}; | |||
|
|||
var complainSilently = function(){ | |||
var complaint; | |||
while( (complaint = complaints.pop()) != null){ | |||
hollaback(complaint); | |||
}; | |||
}; | |||
|
|||
// Report errors back to the server | |||
var hollaback = function(error_info) { | |||
error_info.href = window.location.href; | |||
if ( Loudmouth.hollaback_url() ) { | |||
var image_str = "<img src='" + Loudmouth.hollaback_url() + '?error_info=' + JSON.stringify(error_info) + "'>"; | |||
console.log(image_str); | |||
$(document).append(image_str); | |||
} else { | |||
console.log("Warning: Loudmouth.js captured a complaint, but the hollaback server URL is not defined, so I'm telling you about the problem: "); | |||
console.log(error_info); | |||
}; | |||
}; | |||
|
|||
// URL for reporting errors | |||
my.hollaback_url = function(target_url){ | |||
if (target_url) config.hollaback_url = target_url; | |||
return config.hollaback_url; | |||
}; | |||
|
|||
var addError = function(errorMessage, url, lineNumber){ | |||
addComplaint('error', {errorMessage: errorMessage, url: url, lineNumber: lineNumber}); | |||
}; | |||
|
|||
var addComplaint = function(type, error_info){ | |||
error_info.type = type; | |||
complaints.push(error_info); | |||
}; | |||
|
|||
my.captureAlerts = function(){ | |||
console.log("Loudmouth will capture all window.alert calls"); | |||
window.alert = function() { | |||
addComplaint('alert', {alert_message: arguments[0]}); | |||
console.log("Loudmouth saw this alert: " + arguments[0]); | |||
return original_alert.apply(this, arguments); | |||
}; | |||
return this; // Enable chaining | |||
}; | |||
|
|||
// Complain right away | |||
my.watch = function(){ | |||
var watch_onerror = function(errorMessage, url, lineNumber){ | |||
addError(errorMessage, url, lineNumber); | |||
complainLoudly(); | |||
return original_onerror ? original_onerror.call(errorMessage, url, lineNumber) : original_onerror; | |||
}; | |||
window.onerror = watch_onerror; | |||
return this; // Enable chaining | |||
}; | |||
|
|||
// Keep track of all complaints quietly | |||
my.lurk = function(){ | |||
var lurk_onerror = function(errorMessage, url, lineNumber){ | |||
addError(errorMessage, url, lineNumber); | |||
complainSilently(); | |||
return original_onerror ? original_onerror.call(errorMessage, url, lineNumber) : original_onerror; | |||
}; | |||
window.onerror = lurk_onerror; | |||
if ( ! Loudmouth.hollaback_url() ) { | |||
console.log("Warning: The hollaback server URL is not defined, so errors will not be reported back to the server. Use Loudmouth.hollaback_url(<your url>) to tell Loudmouth where to shout."); | |||
} | |||
return this; // Enable chaining | |||
}; | |||
|
|||
// Stop watching | |||
my.goAway = function(){ | |||
window.onerror = original_onerror; | |||
return this; // Enable chaining | |||
}; | |||
|
|||
return my; | |||
|
|||
})(Loudmouth || {}); | |||
|