airbrake-sinatra 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.3@airbrake-sinatra
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in airbrake-sinatra.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Sam Rose
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,56 @@
1
+ # Airbrake::Sinatra
2
+
3
+ The helper method provided with the official Airbrake gem is specific to Rails
4
+ and requires a bit of hacking to get working in Sinatra. This gem exists to
5
+ serve as a Sinatra helper method for the Airbrake Javascript.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'airbrake-sinatra'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install airbrake-sinatra
20
+
21
+ ## Usage
22
+
23
+ There are two sample applications in the source code on Github. You will find
24
+ them under the `examples/` directory. One of them shows how to use this gem with
25
+ a standard Sinatra `server.rb` file. The other shows how to use this gem with
26
+ your own class that extends `Sinatra::Base`. There is a subtle difference :)
27
+
28
+ Essentially all it boils down to is using the `airbrake_javascript_sinatra`
29
+ helper in your views. An example layout might look something like this:
30
+
31
+ ``` haml
32
+ %head
33
+ = airbrake_javascript_sinatra
34
+ %body
35
+ %p
36
+ The Airbrake javascript helper is outputting the following into the header:
37
+ %pre= h airbrake_javascript_sinatra
38
+ ```
39
+
40
+ ## Developing
41
+
42
+ There are two Rake tasks that are there for development purposes:
43
+
44
+ $ rake example:one
45
+ $ rake example:two
46
+
47
+ Both of these cd into the appropriate `example/` directory and execute the
48
+ `shotgun` command.
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'fileutils'
4
+
5
+ include FileUtils
6
+
7
+ namespace :example do
8
+ desc "Run the first sample Sinatra application."
9
+ task :one do
10
+ cd File.join(File.dirname(__FILE__), 'example', 'one')
11
+ exec "shotgun"
12
+ end
13
+
14
+ desc "Run the second sample Sinatra application."
15
+ task :two do
16
+ cd File.join(File.dirname(__FILE__), 'example', 'two')
17
+ exec "shotgun"
18
+ end
19
+ end
@@ -0,0 +1,45 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/airbrake-sinatra/version', __FILE__)
3
+
4
+ module AirbrakeSinatra
5
+ # Hash of:
6
+ #
7
+ # "gem-name" => "version"
8
+ #
9
+ # pairs. Set version to nil if you want the latest.
10
+ DEPENDENCIES ||= {
11
+ :app => {
12
+ "haml" => nil,
13
+ "sinatra" => nil,
14
+ "airbrake" => nil,
15
+ },
16
+
17
+ :dev => {
18
+ "rake" => nil,
19
+ "shotgun" => nil,
20
+ }
21
+ }
22
+ end
23
+
24
+ Gem::Specification.new do |gem|
25
+ gem.authors = ["Sam Rose"]
26
+ gem.email = ["sam.rose@forward.co.uk"]
27
+ gem.description = %q{A view helper for Airbrake desgined for Sinatra.}
28
+ gem.summary = %q{The Airbrake view helper in the official "airbrake" gem is designed for Rails. This is a version that works out of the box with Sinatra.}
29
+ gem.homepage = ""
30
+
31
+ gem.files = `git ls-files`.split($\)
32
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
33
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
34
+ gem.name = "airbrake-sinatra"
35
+ gem.require_paths = ["lib"]
36
+ gem.version = Airbrake::Sinatra::VERSION
37
+
38
+ AirbrakeSinatra::DEPENDENCIES[:app].each do |k, v|
39
+ gem.add_dependency(*([k, v].compact))
40
+ end
41
+
42
+ AirbrakeSinatra::DEPENDENCIES[:dev].each do |k, v|
43
+ gem.add_development_dependency(*([k, v].compact))
44
+ end
45
+ end
@@ -0,0 +1,4 @@
1
+ require 'sinatra'
2
+ require File.join(File.dirname(__FILE__), 'server.rb')
3
+
4
+ run Sinatra::Application.new
@@ -0,0 +1,35 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'airbrake-sinatra')
2
+
3
+ require 'sinatra'
4
+ require 'sinatra/airbrake-javascript'
5
+ require 'erb'
6
+ require 'haml'
7
+ require 'airbrake'
8
+
9
+ helpers do
10
+ include Rack::Utils
11
+ alias_method :h, :escape_html
12
+ end
13
+
14
+ configure do
15
+ set :logging, Logger::DEBUG
16
+
17
+ Airbrake.configure do |config|
18
+ config.api_key = 'sample'
19
+ config.js_api_key = 'sample'
20
+ config.host = 'example.com'
21
+ config.port = 80
22
+ config.secure = config.port == 443
23
+ end
24
+
25
+ use Airbrake::Rack
26
+ enable :raise_errors
27
+ end
28
+
29
+ get '/erb' do
30
+ erb :erb_index
31
+ end
32
+
33
+ get '/haml' do
34
+ haml :haml_index
35
+ end
@@ -0,0 +1,11 @@
1
+ <head>
2
+ <%= airbrake_javascript_sinatra %>
3
+ </head>
4
+ <body>
5
+ <p>
6
+ The Airbrake javascript helper is outputting the following into the header:
7
+ <pre>
8
+ <%= h airbrake_javascript_sinatra %>
9
+ </pre>
10
+ </p>
11
+ </body>
@@ -0,0 +1,6 @@
1
+ %head
2
+ = airbrake_javascript_sinatra
3
+ %body
4
+ %p
5
+ The Airbrake javascript helper is outputting the following into the header:
6
+ %pre= h airbrake_javascript_sinatra
@@ -0,0 +1,4 @@
1
+ require 'sinatra'
2
+ require File.join(File.dirname(__FILE__), 'server.rb')
3
+
4
+ run Server.new
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'airbrake-sinatra')
2
+
3
+ require 'sinatra'
4
+ require 'sinatra/airbrake-javascript'
5
+ require 'erb'
6
+ require 'haml'
7
+ require 'airbrake'
8
+
9
+ class Server < Sinatra::Base
10
+ helpers do
11
+ include Rack::Utils
12
+ include Sinatra::AirbrakeJavascript
13
+ alias_method :h, :escape_html
14
+ end
15
+
16
+ configure do
17
+ set :logging, Logger::DEBUG
18
+
19
+ Airbrake.configure do |config|
20
+ config.api_key = 'sample'
21
+ config.js_api_key = 'sample'
22
+ config.host = 'example.com'
23
+ config.port = 80
24
+ config.secure = config.port == 443
25
+ end
26
+
27
+ use Airbrake::Rack
28
+ enable :raise_errors
29
+ end
30
+
31
+ get '/erb' do
32
+ erb :erb_index
33
+ end
34
+
35
+ get '/haml' do
36
+ haml :haml_index
37
+ end
38
+ end
@@ -0,0 +1,11 @@
1
+ <head>
2
+ <%= airbrake_javascript_sinatra %>
3
+ </head>
4
+ <body>
5
+ <p>
6
+ The Airbrake javascript helper is outputting the following into the header:
7
+ <pre>
8
+ <%= h airbrake_javascript_sinatra %>
9
+ </pre>
10
+ </p>
11
+ </body>
@@ -0,0 +1,6 @@
1
+ %head
2
+ = airbrake_javascript_sinatra
3
+ %body
4
+ %p
5
+ The Airbrake javascript helper is outputting the following into the header:
6
+ %pre= h airbrake_javascript_sinatra
@@ -0,0 +1,4 @@
1
+ libdir = File.dirname(__FILE__)
2
+ $LOAD_PATH << libdir unless $LOAD_PATH.include? libdir
3
+
4
+ require 'airbrake-sinatra/version'
@@ -0,0 +1,5 @@
1
+ module Airbrake
2
+ module Sinatra
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,64 @@
1
+ require 'sinatra/base'
2
+ require 'logger'
3
+
4
+ module Sinatra
5
+ module AirbrakeJavascript
6
+ def airbrake_javascript_sinatra options = {}
7
+ abconfig = Airbrake.configuration rescue nil
8
+
9
+ if abconfig.nil?
10
+ logger.debug "Could not load the Airbrake config. Is Airbrake loaded?"
11
+ return
12
+ end
13
+
14
+ return unless abconfig.public?
15
+
16
+ log = options[:logger] || logger || Logger.new(STDOUT)
17
+ views = options [:views] || File.join(File.dirname(__FILE__), '..', 'templates')
18
+ host = options[:host] || Airbrake.configuration.host.dup
19
+ port = options[:port] || Airbrake.configuration.port
20
+ host << ":#{port}" unless [80, 443].include?(port)
21
+
22
+ js_api_key = (options[:js_api_key] || abconfig.js_api_key) rescue nil
23
+ api_key = (options[:api_key] || abconfig.api_key)
24
+ url = (options[:url] || request.url) rescue nil
25
+
26
+ if js_api_key.nil?
27
+ logger.debug "Could not find a js_api_key in options or the Airbrake config."
28
+ end
29
+
30
+ if api_key.nil?
31
+ logger.debug "Could not find an api_key in options or the Airbrake config."
32
+ end
33
+
34
+ unless respond_to? :request
35
+ logger.debug "No request object found in the current scope."
36
+ end
37
+
38
+ options = {
39
+ :views => views,
40
+ :layout => false,
41
+ :use_full_path => false,
42
+ :locals => {
43
+ :host => host,
44
+ :api_key => api_key,
45
+ :js_api_key => api_key,
46
+ :environment => options[:environment] || ENV['RACK_ENV'],
47
+ :url => url
48
+ }
49
+ }
50
+
51
+ erb :airbrake_javascript_sinatra, options
52
+ end
53
+
54
+ def escape_javascript(html_content)
55
+ return '' unless html_content
56
+ javascript_mapping = { '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n' }
57
+ javascript_mapping.merge("\r" => '\n', '"' => '\\"', "'" => "\\'")
58
+ escaped_string = html_content.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { javascript_mapping[$1] }
59
+ "\"#{escaped_string}\""
60
+ end
61
+ end
62
+
63
+ helpers AirbrakeJavascript
64
+ end
@@ -0,0 +1,14 @@
1
+ <script type="text/javascript">
2
+ (function(){
3
+ var notifierJsScheme = (("https:" == document.location.protocol) ? "https://" : "http://");
4
+ document.write(unescape("%3Cscript src='" + notifierJsScheme + "<%= host %>/javascripts/notifier.js' type='text/javascript'%3E%3C/script%3E"));
5
+ })();
6
+ </script>
7
+
8
+ <script type="text/javascript">
9
+ window.Airbrake = (typeof(Airbrake) == 'undefined' && typeof(Hoptoad) != 'undefined') ? Hoptoad : Airbrake
10
+ Airbrake.setKey('<%= js_api_key || api_key %>');
11
+ Airbrake.setHost('<%= host %>');
12
+ Airbrake.setEnvironment('<%= environment %>');
13
+ Airbrake.setErrorDefaults({ url: <%= escape_javascript url %> });
14
+ </script>
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: airbrake-sinatra
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sam Rose
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: haml
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sinatra
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: airbrake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: shotgun
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: A view helper for Airbrake desgined for Sinatra.
95
+ email:
96
+ - sam.rose@forward.co.uk
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .rvmrc
103
+ - Gemfile
104
+ - LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - airbrake-sinatra.gemspec
108
+ - example/one/config.ru
109
+ - example/one/server.rb
110
+ - example/one/views/erb_index.erb
111
+ - example/one/views/haml_index.haml
112
+ - example/two/config.ru
113
+ - example/two/server.rb
114
+ - example/two/views/erb_index.erb
115
+ - example/two/views/haml_index.haml
116
+ - lib/airbrake-sinatra.rb
117
+ - lib/airbrake-sinatra/version.rb
118
+ - lib/sinatra/airbrake-javascript.rb
119
+ - lib/templates/airbrake_javascript_sinatra.erb
120
+ homepage: ''
121
+ licenses: []
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ segments:
133
+ - 0
134
+ hash: -4025992488192137976
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ segments:
142
+ - 0
143
+ hash: -4025992488192137976
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 1.8.24
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: The Airbrake view helper in the official "airbrake" gem is designed for Rails.
150
+ This is a version that works out of the box with Sinatra.
151
+ test_files: []