jserror-rails 0.6.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/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
6
+ spec/dummy/log/*
7
+ spec/dummy/tmp/*
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ gemspec
2
+
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "jserror-rails"
5
+ s.version = "0.6.2"
6
+ s.authors = ["Jeremy Geros"]
7
+ s.email = ["jeremy453@gmail.com"]
8
+ s.homepage = ""
9
+ s.summary = %q{Try catch wrap for sprockets.}
10
+ s.description = %q{Adds try catch around all functions to allow better error debugging in javascript.}
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
+ s.require_paths = ["lib"]
15
+
16
+ end
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,8 @@
1
+ module JserrorRails
2
+ class Railtie < Rails::Engine
3
+ initializer "sprockets.jserror_template", :after => "sprockets.environment", :group => :all do |app|
4
+ next unless app.assets
5
+ app.assets.register_engine(".debug", JserrorTemplate)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,128 @@
1
+ require 'sprockets'
2
+ require 'tilt'
3
+
4
+ module JserrorRails
5
+ class JserrorTemplate < Tilt::Template
6
+
7
+ def self.default_mime_type
8
+ 'application/javascript'
9
+ end
10
+
11
+ def prepare
12
+ end
13
+
14
+ def evaluate(scope, locals, &block)
15
+ data_copy = data
16
+ scanning_data = data
17
+ functions = []
18
+ capture = true
19
+ while capture
20
+ function = (/(^.*= function.*$)/).match(scanning_data)
21
+ if function
22
+ old_lines = []
23
+ new_code_lines = []
24
+
25
+ scanning_data = function.post_match
26
+ method_line = function.captures.first
27
+
28
+ tabs = method_line.partition(method_line.strip[0]).first
29
+ name = method_line.match(/(.*) = function/).captures.first.strip
30
+
31
+ arguments = method_line.gsub(tabs, '').gsub(name, '').gsub(/\s*=\s*function\s*\(/, '').gsub(/\)\s*{.*$/, '').strip.split(', ').map {|a| "{#{a}: #{a}}"}
32
+
33
+ new_code_lines << method_line
34
+ old_lines << method_line
35
+
36
+ new_code_lines << "\n#{tabs}\ttry {"
37
+
38
+ bracket_count = 1 #start scanning until we find the ending bracket
39
+ scanning_data.each_line do |line|
40
+ line.chars do |char|
41
+ bracket_count += 1 if char == '{'
42
+ bracket_count -= 1 if char == '}'
43
+ end
44
+ new_code_lines << "\t" + line
45
+ old_lines << line
46
+ break if bracket_count <= 0
47
+ end
48
+
49
+ new_code_lines.pop #pop of the last }; to add catch block before closing bracket in function
50
+
51
+ console_line = "javascript_error({name: '#{name.gsub('\'', '"')}',
52
+ error_message: e.message,
53
+ error_name: e.name,
54
+ code_block: '#{old_lines.join('').gsub("\n", '[::n::]').gsub('\'', '')}',
55
+ arguments: [#{arguments.join(', ')}],
56
+ source: $('*').html()
57
+ });"
58
+
59
+ new_code_lines << "#{tabs}\t} catch (e) { \n#{tabs}\t\t#{console_line}\n#{tabs}\t}\n"
60
+ new_code_lines << "#{tabs}};\n"
61
+ functions << {:replace => old_lines.join(''), :new => new_code_lines.join('')}
62
+ else
63
+ capture = false
64
+ end
65
+ end
66
+
67
+ scanning_data = data_copy.clone
68
+ capture = true
69
+ while capture
70
+ function = (/(.*\(.+function\(.*\).*\{.*$)/).match(scanning_data)
71
+ if function
72
+ old_lines = []
73
+ new_code_lines = []
74
+
75
+ scanning_data = function.post_match
76
+ method_line = function.captures.first
77
+
78
+ tabs = method_line.partition(method_line.strip[0]).first
79
+
80
+ name = method_line
81
+ arguments = (/.*\(.+function\((.*)\).*\{.*$/).match(method_line).captures.first.split(', ').map {|a| "{#{a}: #{a}}"}
82
+
83
+ new_code_lines << method_line
84
+ old_lines << method_line
85
+
86
+ new_code_lines << "\n#{tabs}\ttry {"
87
+
88
+ bracket_count = 1 #start scanning until we find the ending bracket
89
+ scanning_data.each_line do |line|
90
+ line.chars do |char|
91
+ bracket_count += 1 if char == '{'
92
+ bracket_count -= 1 if char == '}'
93
+ end
94
+ new_code_lines << "\t" + line
95
+ old_lines << line
96
+ break if bracket_count <= 0
97
+ end
98
+
99
+ new_code_lines.pop #pop of the last }; to add catch block before closing bracket in function
100
+
101
+ console_line = "javascript_error({name: '#{name.gsub('\'', '"')}',
102
+ error_message: e.message,
103
+ error_name: e.name,
104
+ code_block: '#{old_lines.join('').gsub("\n", '[::n::]').gsub('\'', '')}',
105
+ arguments: [#{arguments.join(', ')}],
106
+ source: $('*').html()
107
+ });"
108
+
109
+ new_code_lines << "#{tabs}\t} catch (e) { \n#{tabs}\t\t#{console_line}\n#{tabs}\t}\n"
110
+ new_code_lines << "#{tabs}});\n"
111
+ functions << {:replace => old_lines.join(''), :new => new_code_lines.join('')}
112
+ else
113
+ capture = false
114
+ end
115
+ end
116
+
117
+
118
+ functions.each do |s|
119
+ data_copy.gsub!(s[:replace], s[:new])
120
+ end
121
+
122
+ output = "try {"
123
+ output << data_copy
124
+ output << "} catch (e) { javascript_error({name: 'unfound javascript error', error_message: e.message, error_name: e.name, code_block: '#{scope.logical_path.to_s}', arguments: [], source: $('*').html()}); }"
125
+ output
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,2 @@
1
+ require "jserror-rails/jserror_template"
2
+ require "jserror-rails/engine"
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jserror-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Geros
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-14 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Adds try catch around all functions to allow better error debugging in
15
+ javascript.
16
+ email:
17
+ - jeremy453@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .DS_Store
23
+ - .gitignore
24
+ - Gemfile
25
+ - jserror-rails.gemspec
26
+ - lib/.DS_Store
27
+ - lib/jserror-rails.rb
28
+ - lib/jserror-rails/engine.rb
29
+ - lib/jserror-rails/jserror_template.rb
30
+ homepage: ''
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.15
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Try catch wrap for sprockets.
54
+ test_files: []