better_sjr 1.0.0.beta2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8bd12e13eaff8aea79b56f44d00afca72bc3fd95
4
+ data.tar.gz: 9a51b6f72a7e889b23d832bc67b1d6ca0002c459
5
+ SHA512:
6
+ metadata.gz: 56b2ae8d222a50dfeadbadaca8b62846d693a84f4235801f99f8179aadc45822fae62c76f49013c5781fd4388da8d9a896c7ec78d6f3b9fc7a27ccca9241e9b0
7
+ data.tar.gz: da74643c1df10443d27f5c8f7f89e2fb5174911bccfb28a3aa2e37fd29a2a4927e9febde9aa82d058888a780a2ad2eae78fe2be31c31f5defc0cbda8eaaf94b4
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /gemfiles/*.gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.hound.yml ADDED
@@ -0,0 +1,2 @@
1
+ ruby:
2
+ config_file: .rubocop.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ Style/DotPosition:
2
+ EnforcedStyle: trailing
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ - 2.1
6
+ gemfile:
7
+ - gemfiles/rails_5.0.gemfile
8
+ - gemfiles/rails_4.2.gemfile
9
+ - gemfiles/rails_4.1.gemfile
10
+ - gemfiles/rails_4.0.gemfile
11
+ matrix:
12
+ exclude:
13
+ - rvm: 2.1
14
+ gemfile: gemfiles/rails_5.0.gemfile
15
+ before_install: gem install bundler -v 1.13.6
data/Appraisals ADDED
@@ -0,0 +1,27 @@
1
+ if RUBY_VERSION >= "2.2.2"
2
+
3
+ appraise "rails-5.0" do
4
+ gem "rails", "~> 5.0.0"
5
+ end
6
+
7
+ end
8
+
9
+ appraise "rails-4.2" do
10
+ gem "rails", "~> 4.2.0"
11
+ end
12
+
13
+ appraise "rails-4.1" do
14
+ gem "rails", "~> 4.1.0"
15
+ end
16
+
17
+ appraise "rails-4.0" do
18
+ gem "rails", "~> 4.0.0"
19
+ end
20
+
21
+ appraise "rails-3.2" do
22
+ gem "rails", "~> 3.2.0"
23
+
24
+ if RUBY_VERSION >= "2.2.2"
25
+ gem "test-unit", "~> 3.0"
26
+ end
27
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in better_sjr.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # BetterSJR
2
+
3
+ [![Build Status](https://travis-ci.org/carlosramireziii/better_sjr.svg?branch=master)](https://travis-ci.org/carlosramireziii/better_sjr)
4
+ [![Inline docs](http://inch-ci.org/github/carlosramireziii/better_sjr.svg?branch=master)](http://inch-ci.org/github/carlosramireziii/better_sjr)
5
+
6
+ BetterSJR improves server-generated JavaScript (SJR) responses in Rails by adding error messages for debugging.
7
+
8
+ When enabled, all SJR response templates will be automatically wrapped in a try-catch statement,
9
+ and the error message of any thrown exception will be printed to the console.
10
+
11
+ For more information on common SJR errors, [read this article](http://www.carlosramireziii.com/3-reasons-why-your-sjr-template-isnt-working.html?utm_source=github&utm_campaign=better_sjr).
12
+
13
+ ## Requirements
14
+
15
+ ### Ruby and Rails
16
+
17
+ This gem has been tested against Ruby **>= 2.1** and Rails **>= 4.0**.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'better_sjr'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install better_sjr
34
+
35
+ ## Usage
36
+
37
+ Debugging is not enabled by default.
38
+
39
+ To enable in development only (recommended), add an initializer and set `debug_sjr`.
40
+
41
+ ```ruby
42
+ # config/initializers/better_sjr.rb
43
+ BetterSJR.debug_sjr = Rails.env.development?
44
+ ```
45
+
46
+ JavaScript runtime errors will now be caught and printed to the browser console instead of failing silently.
47
+
48
+ ![Image of JavaScript runtime error in browser console](docs/assets/javascript_runtime_error_in_console.png)
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+
54
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/carlosramireziii/better_sjr.
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'better_sjr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "better_sjr"
8
+ spec.version = BetterSJR::VERSION
9
+ spec.authors = ["Carlos Ramirez III"]
10
+ spec.email = ["carlos.e.ramirez.iii@gmail.com"]
11
+
12
+ spec.summary = %q{Improvements to server-generated JavaScript (SJR) responses in Rails}
13
+ spec.homepage = "https://github.com/carlosramireziii/better_sjr"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ if RUBY_VERSION < '2.2.2'
24
+ spec.add_development_dependency "activesupport", "< 5"
25
+ else
26
+ spec.add_development_dependency "activesupport"
27
+ end
28
+ spec.add_development_dependency "appraisal", "~> 2.1"
29
+ spec.add_development_dependency "bundler", "~> 1.13"
30
+ spec.add_development_dependency "combustion", "~> 0.5"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "rspec-rails", "~> 3.5"
34
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "better_sjr"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config.ru ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Combustion.initialize! :all
7
+ run Combustion::Application
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_DISABLE_SHARED_GEMS: "true"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 3.2.0"
6
+ gem "test-unit", "~> 3.0"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.0.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.1.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.2.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.0.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1 @@
1
+ ActionView::Renderer.prepend BetterSJR::RendererExtensions
@@ -0,0 +1,12 @@
1
+ require "rails"
2
+
3
+ module BetterSJR
4
+ # Makes BetterSJR behavior available to Rails apps on initialization
5
+ class Railtie < Rails::Railtie
6
+ initializer "better_sjr.initialize" do
7
+ ActiveSupport.on_load(:action_view) do
8
+ require "better_sjr/on_load_action_view"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ module BetterSJR
2
+ # Wraps JavaScript formatted templates in a try-catch statement when rendered
3
+ module RendererExtensions
4
+ # Overrides default behavior by wrapping rendered content in a try-catch
5
+ # statement.
6
+ #
7
+ # If debugging is enabled and the template is JavaScript format, wrap the
8
+ # rendered content in a try-catch statement.
9
+ #
10
+ # @return [String] the rendered template content
11
+ def render_template(*)
12
+ if debugging_sjr? && rendering_js?
13
+ TryCatchStatement.new(super).wrapped_code
14
+ else
15
+ super
16
+ end
17
+ end
18
+
19
+ def debugging_sjr?
20
+ BetterSJR.debug_sjr
21
+ end
22
+
23
+ def rendering_js?
24
+ lookup_context.rendered_format.to_s == "js"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module BetterSJR
2
+ # Wraps a given code snippet in a JavaScript try-catch statement
3
+ class TryCatchStatement
4
+ # @return [String] the code without a try-catch statement surrounding it
5
+ attr_accessor :original_code
6
+
7
+ # Returns a new instance of TryCatchStatement
8
+ #
9
+ # @param code [String] the code to be surrounded by a try-catch statement
10
+ def initialize(code)
11
+ @original_code = code
12
+ end
13
+
14
+ # Wraps the original code in a try-catch statement
15
+ #
16
+ # @return [String] the try-catch statement
17
+ def wrapped_code
18
+ <<-TRYCATCH
19
+ try {
20
+ #{original_code}
21
+ } catch(e) {
22
+ console.error("Rails SJR error", e);
23
+ }
24
+ TRYCATCH
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module BetterSJR
2
+ VERSION = "1.0.0.beta2".freeze
3
+ end
data/lib/better_sjr.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "better_sjr/version"
2
+ require "better_sjr/renderer_extensions"
3
+ require "better_sjr/try_catch_statement"
4
+ require "better_sjr/railtie"
5
+
6
+ # Facilitates better debugging of Rails SJR templates
7
+ module BetterSJR
8
+ class << self
9
+ # Controls whether or not debugging behavior is enabled
10
+ # @return [Boolean] value
11
+ attr_accessor :debug_sjr
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: better_sjr
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta2
5
+ platform: ruby
6
+ authors:
7
+ - Carlos Ramirez III
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "<"
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "<"
25
+ - !ruby/object:Gem::Version
26
+ version: '5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: combustion
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.5'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.5'
111
+ description:
112
+ email:
113
+ - carlos.e.ramirez.iii@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".hound.yml"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - ".travis.yml"
123
+ - Appraisals
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - better_sjr.gemspec
129
+ - bin/console
130
+ - bin/setup
131
+ - config.ru
132
+ - docs/assets/javascript_runtime_error_in_console.png
133
+ - gemfiles/.bundle/config
134
+ - gemfiles/rails_3.2.gemfile
135
+ - gemfiles/rails_4.0.gemfile
136
+ - gemfiles/rails_4.1.gemfile
137
+ - gemfiles/rails_4.2.gemfile
138
+ - gemfiles/rails_5.0.gemfile
139
+ - lib/better_sjr.rb
140
+ - lib/better_sjr/on_load_action_view.rb
141
+ - lib/better_sjr/railtie.rb
142
+ - lib/better_sjr/renderer_extensions.rb
143
+ - lib/better_sjr/try_catch_statement.rb
144
+ - lib/better_sjr/version.rb
145
+ homepage: https://github.com/carlosramireziii/better_sjr
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">"
161
+ - !ruby/object:Gem::Version
162
+ version: 1.3.1
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.2.2
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: Improvements to server-generated JavaScript (SJR) responses in Rails
169
+ test_files: []