rconsole 0.1.0

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: 5308fb25a24e1518c04da5afe10620bd20661818
4
+ data.tar.gz: 6f5eed2802219b004f805273e8bc0beb59445299
5
+ SHA512:
6
+ metadata.gz: 69ef0459617c51621d361f76e0a6ea0916010bc63c69c1aace575f74bb854f90b8c18498e86a385dafc2822720c865bf83b44147b698c012f87e70d962b28361
7
+ data.tar.gz: 3f0346b120701edad2486522e59a6be1573d0fefefd09cb9701bc57be8affd03487b8548ee89c4c545d366e8bb4574fbb2299bd95e8540417ca6edd5c8ef40e1
data/.gitignore ADDED
File without changes
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Sergey Rezvanov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ Rconsole
2
+ ========
3
+
4
+ Rconsole is a Rails plugin which allows you to output debug messages from ruby code to the
5
+ browser console.
6
+
7
+ ## Installation
8
+
9
+ First add the following lines to your application `Gemfile`:
10
+
11
+ ``` ruby
12
+ group :development
13
+ gem 'rconsole', '~> 0.1.0'
14
+ end
15
+ ```
16
+
17
+ Then run `bundle install` to update your's gems bundle.
18
+
19
+ Now you need include `rconsole.js` asset file by adding the following lines to
20
+ your layout view:
21
+
22
+ ``` ruby
23
+ javascript_include_tag(:rconsole) if Rails.env.development?
24
+ ```
25
+
26
+ Really easy!
27
+
28
+ ## Usage
29
+
30
+ Just use `rconsole.log` anywhere you need, e.g:
31
+
32
+ ``` ruby
33
+ class HomeController < ActionController::Base
34
+ def index
35
+ rconsole.log 'Hello from Ruby!'
36
+ respond_with({})
37
+ end
38
+ end
39
+ ```
40
+
41
+ Then you will see the message on your browser console. Just like this:
42
+
43
+ ![Hello from Ruby!](https://dl.dropboxusercontent.com/u/11845683/hello_from_ruby.png)
44
+
45
+ Enjoy!
46
+
47
+ ## Contributors
48
+
49
+ + [Sergey Rezvanov](http://github.com/rezwyi)
50
+
51
+ ## Copyright
52
+
53
+ See LICENSE file.
@@ -0,0 +1,7 @@
1
+ class RconsoleController < ActionController::Base
2
+ respond_to :json
3
+
4
+ def dump
5
+ respond_with rconsole.dump
6
+ end
7
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ get '/rconsole' => 'rconsole#dump'
3
+ end
data/lib/rconsole.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'rconsole/version'
2
+ require 'rconsole/base'
3
+ require 'rconsole/helpers'
4
+ require 'rconsole/middleware'
5
+ require 'rconsole/engine'
@@ -0,0 +1,21 @@
1
+ require 'singleton'
2
+
3
+ module Rconsole
4
+ class Base
5
+ include Singleton
6
+
7
+ def initialize
8
+ @dump = []
9
+ end
10
+
11
+ def log(message)
12
+ @dump << message
13
+ end
14
+
15
+ def dump
16
+ dump = @dump.dup
17
+ @dump.clear
18
+ dump
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Rconsole
2
+ class Engine < ::Rails::Engine
3
+ initializer 'rconsole.middleware' do |app|
4
+ app.middleware.use Rconsole::Middleware
5
+ end
6
+
7
+ initializer 'rconsole.include_helpers' do
8
+ ActiveSupport.on_load :action_controller do
9
+ ActionController::Base.send :include, Rconsole::Helpers
10
+ end
11
+
12
+ ActiveSupport.on_load :active_record do
13
+ ActiveRecord::Base.send :include, Rconsole::Helpers
14
+ end
15
+
16
+ ActiveSupport.on_load :action_view do
17
+ ActionView::Base.send :include, Rconsole::Helpers
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Rconsole
2
+ module Helpers
3
+ def self.included(base)
4
+ base.send :include, InstanceMethods
5
+ end
6
+
7
+ module InstanceMethods
8
+ def rconsole
9
+ Base.instance
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module Rconsole
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ @app.call env
9
+ rescue Exception => e
10
+ Rconsole::Base.instance.dump
11
+ raise e
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Rconsole
2
+ VERSION = '0.1.0'
3
+ end
data/rconsole.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../lib/rconsole/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'rconsole'
5
+ s.summary = 'Simple way to print debug messages from ruby code directly to browser console'
6
+ s.description = s.summary
7
+
8
+ s.version = Rconsole::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+
11
+ s.authors = ['Sergey Rezvanov']
12
+ s.email = ['sergey@rezvanov.info']
13
+ s.homepage = 'https://github.com/rezwyi/rconsole'
14
+
15
+ s.licenses = ['MIT']
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.require_paths = ['lib']
19
+ end
@@ -0,0 +1,23 @@
1
+ var Rconsole = {};
2
+ XMLHttpRequest.prototype.originOpen = XMLHttpRequest.prototype.open;
3
+
4
+ (Rconsole.dump = function() {
5
+ var xhr = new XMLHttpRequest()
6
+ dump = []
7
+ i = 0;
8
+
9
+ xhr.originOpen('get', '/rconsole.json', false);
10
+ xhr.send();
11
+
12
+ if (xhr.readyState === 4 && xhr.status === 200) {
13
+ dump = JSON.parse(xhr.responseText);
14
+ for (i; i < dump.length; i++) console.log(dump[i]);
15
+ }
16
+ })();
17
+
18
+ XMLHttpRequest.prototype.open = function() {
19
+ this.addEventListener('readystatechange', function(){
20
+ if (this.readyState === 4 && this.status === 200) Rconsole.dump();
21
+ });
22
+ XMLHttpRequest.prototype.originOpen.apply(this, arguments);
23
+ }
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rconsole
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Rezvanov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple way to print debug messages from ruby code directly to browser
14
+ console
15
+ email:
16
+ - sergey@rezvanov.info
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - LICENSE
23
+ - README.md
24
+ - app/controllers/rconsole_controller.rb
25
+ - config/routes.rb
26
+ - lib/rconsole.rb
27
+ - lib/rconsole/base.rb
28
+ - lib/rconsole/engine.rb
29
+ - lib/rconsole/helpers.rb
30
+ - lib/rconsole/middleware.rb
31
+ - lib/rconsole/version.rb
32
+ - rconsole.gemspec
33
+ - vendor/assets/javascripts/rconsole.js
34
+ homepage: https://github.com/rezwyi/rconsole
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.0.3
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Simple way to print debug messages from ruby code directly to browser console
58
+ test_files: []