rails-web-console 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1956b78ee5cb2191f15180797569c85955d42b1
4
- data.tar.gz: f74438c098e505b5094eff6e2feb7b87b5f1db62
3
+ metadata.gz: 48a0115d62369530d97294128030118e370cae80
4
+ data.tar.gz: 942163e1f2658d5496c2414a594ed09f376df4ef
5
5
  SHA512:
6
- metadata.gz: f7a77900c9937f07a0f55580b2ee08bc4f0973cab88e3f38a4f64cc0760bff377b5706ab5755fd3da1e67a368a8c21b6bf71406741e2a08939b739518d424179
7
- data.tar.gz: 096ab909bcab8863555dd1b8f36065b95013bf5037490036c70f51d0a34d7bcfd6c1c1335bd5a8e334f6ab981ca709896b18b8056de757af18887ad507175c6c
6
+ metadata.gz: b9a4c721832189b0a4887aa9dcf2451eb336da962bb0960a0aadeaaa01cc7ef2e628da9bd1ba4e0c0c1abfb2955db3c4cc3bfc4315f283593105b942f3f17087
7
+ data.tar.gz: 8b9c8e30d3d95efc6bb2537eb04fa6a5c9b6735032354ee86eae6fd1b6659f070c14d8735d7245f071f04852f67877d2811b997e86a688ecf347a31b2d2f29d7
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Rodrigo Rosenfeld Rosas
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,61 @@
1
+ # RailsWebConsole
2
+
3
+ A Rails mountable engine for running Ruby scripts on the browser in the context of a
4
+ controller action.
5
+
6
+ ## Dependencies
7
+
8
+ It doesn't assume anything about Sprockets being available and will embed any JS directly into
9
+ the views to avoid any dependencies on Sprockets.
10
+
11
+ ActionView is required though but it's not declared as a dependency in the gemspec as it's a
12
+ separate gem just as of Rails 4.1.x, so it would prevent this gem from working with older Rails
13
+ versions, but you should make sure your Rails application include support to ActionView.
14
+
15
+ ## Browser support
16
+
17
+ All modern browsers and IE >= 8 should be supported.
18
+
19
+ ## Minimal Ruby supported version
20
+
21
+ 1.9 is the minimal required version due to usage of `require_relative` and the new hash syntax.
22
+
23
+ Patches for supporting older Ruby versions won't be accepted.
24
+
25
+ ## Install
26
+
27
+ In your Gemfile, put the dependency like this:
28
+
29
+ ```ruby
30
+ gem 'rails-web-console', group: :development
31
+ ```
32
+
33
+ This will automatically mount it in /console. If you want to specify a different mount point,
34
+ use:
35
+
36
+ ```ruby
37
+ gem 'rails-web-console', require: 'rails_web_console/engine', group: :development
38
+ ```
39
+
40
+ And add this to your config/routes.rb:
41
+
42
+ ```ruby
43
+ mount RailsWebConsole::Engine => '/inspect' if Rails.env.development?
44
+ ```
45
+
46
+ If you intend to use this in production environment (strongly discouraged), be sure to protect console routes. Do it on your own risk!
47
+
48
+ ## Usage
49
+
50
+ Just access "/console" (or whatever path you've chosen) in your browser.
51
+
52
+ ## Support for older versions of Rails
53
+
54
+ I won't be supporting older versions of Rails to keep the source as simple as possible.
55
+
56
+ Take a look at older releases of this gem for supporting older Rails.
57
+
58
+
59
+ Copyright (c) 2014 [Rodrigo Rosenfeld Rosas], released under the MIT license
60
+
61
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rosenfeld/rails-web-console/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,33 @@
1
+ require 'stringio'
2
+
3
+ module RailsWebConsole
4
+ class ConsoleController < ::ActionController::Base
5
+ skip_before_action :verify_authenticity_token
6
+ layout false
7
+
8
+ def index
9
+ end
10
+
11
+ def run
12
+ session[:script] = params[:script]
13
+ stdout_orig = $stdout
14
+ $stdout = StringIO.new
15
+ begin
16
+ result_eval = eval params[:script], binding
17
+ $stdout.rewind
18
+ result = %Q{<div class="stdout">#{escape $stdout.read}</div>
19
+ <div class="return">#{escape result_eval.inspect}</div>}
20
+ rescue => e
21
+ result = e.to_s
22
+ end
23
+ $stdout = stdout_orig
24
+ render text: result.gsub("\n", "<br>\n")
25
+ end
26
+
27
+ private
28
+
29
+ def escape(content)
30
+ view_context.escape_once content
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,63 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Console</title>
5
+ <style>
6
+ #script {width: 100%}
7
+ .console_result {
8
+ background-color: black;
9
+ color: white;
10
+ margin: 1em 0;
11
+ }
12
+
13
+ .return {
14
+ background-color: blue;
15
+ }
16
+ </style>
17
+ </head>
18
+ <body>
19
+ <textarea id="script" rows="10" cols="80"><%= session[:script] %></textarea>
20
+ <div>
21
+ <button id=clear-results>Clear (Esc, Esc)</button>
22
+ <button id=run-script>Run (Ctrl+Enter)</button>
23
+ </div>
24
+ <div id="results"></div>
25
+
26
+ <script>
27
+ var run_path = '<%= rails_web_console.run_path %>', lastEscTime = 0,
28
+ results = $el('results'), runScriptButton = $el('run-script'),
29
+ clearResultsButton = $el('clear-results'), script = $el('script'), request
30
+ function $el(id){ return document.getElementById(id) }
31
+ addEventListener(clearResultsButton, 'click', clearResults)
32
+ addEventListener(runScriptButton, 'click', runScript)
33
+ addEventListener(script, 'keydown', onKeyDown)
34
+ function addEventListener(el, eventName, handler) {
35
+ if (el.addEventListener) el.addEventListener(eventName, handler);
36
+ else el.attachEvent('on' + eventName, handler);
37
+ }
38
+ function clearResults() {
39
+ results.innerHTML = ''
40
+ }
41
+ function runScript() {
42
+ request = new XMLHttpRequest()
43
+ request.open('POST', run_path, true)
44
+ request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
45
+ request.onreadystatechange = function() {
46
+ if (!(this.readyState === 4 && this.status >= 200 && this.status < 400)) return
47
+ var div = document.createElement('div')
48
+ div.setAttribute('class', 'console_result')
49
+ div.innerHTML = this.responseText
50
+ results.appendChild(div)
51
+ }
52
+ request.send('script=' + encodeURIComponent(script.value))
53
+ }
54
+ function onKeyDown(ev) {
55
+ if (ev.ctrlKey && ev.keyCode == 13) runScript() // Ctrl + Enter
56
+ if (ev.keyCode == 27) {
57
+ if (new Date().getTime() - lastEscTime < 1000) clearResults() // Esc, Esc within a second
58
+ lastEscTime = new Date().getTime()
59
+ }
60
+ }
61
+ </script>
62
+ </body>
63
+ </html>
data/config/routes.rb CHANGED
@@ -1,4 +1,4 @@
1
- Rails.application.routes.draw do
2
- get 'console' => 'console#index'
3
- post 'console/run' => 'console#run'
1
+ RailsWebConsole::Engine.routes.draw do
2
+ root to: 'console#index'
3
+ post 'run' => 'console#run', as: :run
4
4
  end
@@ -1 +1,7 @@
1
- require 'console'
1
+ require_relative 'rails_web_console/engine'
2
+
3
+ RailsWebConsole::Engine.initializer 'rails_web_console.mount_default' do
4
+ Rails.application.routes.prepend do
5
+ mount RailsWebConsole::Engine => '/console'
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module RailsWebConsole
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace RailsWebConsole
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module RailsWebConsole
2
+ VERSION = "0.3.0"
3
+ end
metadata CHANGED
@@ -1,45 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-web-console
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Rosenfeld Rosas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-07 00:00:00.000000000 Z
11
+ date: 2014-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: jeweler
14
+ name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 3.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 3.1.0
27
27
  description: Run any Ruby script from the context of a web request.
28
- email: rr.rosas@gmail.com
28
+ email:
29
+ - rr.rosas@gmail.com
29
30
  executables: []
30
31
  extensions: []
31
- extra_rdoc_files:
32
- - README.markdown
32
+ extra_rdoc_files: []
33
33
  files:
34
- - app/assets/javascripts/console.js
35
- - app/assets/stylesheets/console.css
36
- - app/controllers/console_controller.rb
37
- - app/views/console/index.html.erb
38
- - app/views/layouts/console.html.erb
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/controllers/rails_web_console/console_controller.rb
38
+ - app/views/rails_web_console/console/index.html.erb
39
39
  - config/routes.rb
40
- - lib/console.rb
41
40
  - lib/rails-web-console.rb
42
- - README.markdown
41
+ - lib/rails_web_console/engine.rb
42
+ - lib/rails_web_console/version.rb
43
43
  homepage: https://github.com/rosenfeld/rails-web-console
44
44
  licenses:
45
45
  - MIT
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  version: '0'
61
61
  requirements: []
62
62
  rubyforge_project:
63
- rubygems_version: 2.1.2
63
+ rubygems_version: 2.2.2
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: A web console for Rails
data/README.markdown DELETED
@@ -1,41 +0,0 @@
1
- Console
2
- =======
3
-
4
- A Rails 3.1 and above engine for running Ruby scripts on the browser in the context of a controller action.
5
-
6
- You can install it as a gem or putting it in your vendor/plugins/console directory.
7
-
8
- Installing as a Gem (preferred method)
9
- -------------------------------------
10
-
11
- In your Gemfile, put the dependency like this:
12
-
13
- <pre>
14
- gem 'rails-web-console', :group => :development
15
- </pre>
16
-
17
- If you intend to use this in production environment (strongly discouraged), be sure to protect console routes. Do it on your own risk!
18
-
19
- Installing with a clone
20
- -----------------------
21
-
22
- Just put it in your vendor/plugins/console. For instance:
23
-
24
- <pre>
25
- git submodule add git://github.com/rosenfeld/rails-web-console.git vendor/plugins/console
26
- </pre>
27
-
28
- Usage
29
- -----
30
-
31
- Just access "/console" in your browser.
32
-
33
- Support for older versions of Rails
34
- -----------------------------------
35
-
36
- I won't be supporting older versions of Rails to keep the source as simple as possible.
37
-
38
- Take a look at older releases of this gem for supporting older Rails.
39
-
40
-
41
- Copyright (c) 2010 [Rodrigo Rosenfeld Rosas], released under the MIT license
@@ -1,16 +0,0 @@
1
- var lastEscTime = 0
2
- jQuery(function($) {
3
- $('#clearResults').click(function() { $('#results').empty() })
4
- $('#runScript').click(function() {
5
- $.post('/console/run', {script: $('#script').val()}, function(data) {
6
- $('<div/>').attr('class', 'console_result').html(data).appendTo('#results')
7
- })
8
- })
9
- $('#script').keydown(function(ev) {
10
- if (ev.ctrlKey && ev.keyCode == 13) $('#runScript').click() // Ctrl + Enter
11
- if (ev.keyCode == 27) {
12
- if (new Date().getTime() - lastEscTime < 1000) $('#clearResults').click() // Esc, Esc within a second
13
- lastEscTime = new Date().getTime()
14
- }
15
- })
16
- })
@@ -1,10 +0,0 @@
1
- #script {width: 100%}
2
- .console_result {
3
- background-color: black;
4
- color: white;
5
- margin: 1em 0;
6
- }
7
-
8
- .return {
9
- background-color: blue;
10
- }
@@ -1,29 +0,0 @@
1
- require 'stringio'
2
- class ConsoleController < ApplicationController
3
-
4
- skip_before_filter :verify_authenticity_token
5
-
6
- def index
7
- end
8
-
9
- def run
10
- session[:script] = params[:script]
11
- stdout_orig = $stdout
12
- $stdout = StringIO.new
13
- begin
14
- result_eval = eval params[:script], binding
15
- $stdout.rewind
16
- result = %Q{<div class="stdout">#{escape $stdout.read}</div>
17
- <div class="return">#{escape result_eval.inspect}</div>}
18
- rescue Exception => e
19
- result = e.to_s
20
- end
21
- $stdout = stdout_orig
22
- render :text => result.gsub("\n", "<br />\n")
23
- end
24
-
25
- private
26
- def escape(content)
27
- view_context.escape_once content
28
- end
29
- end
@@ -1,3 +0,0 @@
1
- <textarea id="script" rows="10" cols="80"><%= session[:script] %></textarea>
2
- <div><input type="button" value="Clear (Esc, Esc)" id="clearResults" /><input type="button" value="Run (Ctrl+Enter)" id="runScript" /></div>
3
- <div id="results"></div>
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Console</title>
5
- <%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' %>
6
- <%= javascript_include_tag 'console' %>
7
- <%= stylesheet_link_tag 'console' %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
data/lib/console.rb DELETED
@@ -1,4 +0,0 @@
1
- module Console
2
- class Engine < Rails::Engine
3
- end
4
- end