Skip to content

Commit dc41ae7

Browse files
committed
v0.3.0: turn rails-web-console into a mountable engine
changes: - allow engine routes to be mounted anywhere - remove dependency on sprockets (embed assets) - remove dependency on jQuery (supports IE >= 8) - add a test_app for easier manual testing - remove dependency on jeweler It still automatically mounts on /console by default though.
1 parent 7526f4d commit dc41ae7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+690
-189
lines changed

.gitignore

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
*.swp
2-
pkg
3-
Marshal*
4-
latest_specs*
5-
prerelease_specs*
6-
quick
7-
specs.*
8-
yaml*
1+
.bundle/
2+
log/*.log
3+
pkg/
4+
/test_app/log/*.log
5+
/test_app/tmp

Gemfile

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

3-
gem 'jeweler'
3+
# Declare your gem's dependencies in rails_web_console.gemspec.
4+
# Bundler will treat runtime dependencies like base dependencies, and
5+
# development dependencies will be added by default to the :development group.
6+
gemspec
7+
8+
# Declare any dependencies that are still in development here instead of in
9+
# your gemspec. These might include edge Rails or gems from your path or
10+
# Git. Remember to move these dependencies to your gemspec before releasing
11+
# your gem to rubygems.org.
12+
13+
# To use debugger
14+
# gem 'debugger'

Gemfile.lock

+52-41
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,62 @@
1+
PATH
2+
remote: .
3+
specs:
4+
rails-web-console (0.3.0)
5+
railties (>= 3.1.0)
6+
17
GEM
28
remote: https://rubygems.org/
39
specs:
4-
addressable (2.3.5)
5-
builder (3.2.2)
6-
faraday (0.8.8)
7-
multipart-post (~> 1.2.0)
8-
git (1.2.6)
9-
github_api (0.10.1)
10-
addressable
11-
faraday (~> 0.8.1)
12-
hashie (>= 1.2)
13-
multi_json (~> 1.4)
14-
nokogiri (~> 1.5.2)
15-
oauth2
16-
hashie (2.0.5)
17-
highline (1.6.19)
18-
httpauth (0.2.0)
19-
jeweler (1.8.7)
20-
builder
21-
bundler (~> 1.0)
22-
git (>= 1.2.5)
23-
github_api (= 0.10.1)
24-
highline (>= 1.6.15)
25-
nokogiri (= 1.5.10)
26-
rake
27-
rdoc
28-
json (1.8.0)
29-
jwt (0.1.8)
30-
multi_json (>= 1.5)
31-
multi_json (1.8.0)
32-
multi_xml (0.5.5)
33-
multipart-post (1.2.0)
34-
nokogiri (1.5.10)
35-
oauth2 (0.9.2)
36-
faraday (~> 0.8)
37-
httpauth (~> 0.2)
38-
jwt (~> 0.1.4)
10+
actionpack (3.2.13)
11+
activemodel (= 3.2.13)
12+
activesupport (= 3.2.13)
13+
builder (~> 3.0.0)
14+
erubis (~> 2.7.0)
15+
journey (~> 1.0.4)
16+
rack (~> 1.4.5)
17+
rack-cache (~> 1.2)
18+
rack-test (~> 0.6.1)
19+
sprockets (~> 2.2.1)
20+
activemodel (3.2.13)
21+
activesupport (= 3.2.13)
22+
builder (~> 3.0.0)
23+
activesupport (3.2.13)
24+
i18n (= 0.6.1)
3925
multi_json (~> 1.0)
40-
multi_xml (~> 0.5)
41-
rack (~> 1.2)
42-
rack (1.5.2)
43-
rake (10.1.0)
44-
rdoc (4.0.1)
26+
builder (3.0.4)
27+
erubis (2.7.0)
28+
hike (1.2.3)
29+
i18n (0.6.1)
30+
journey (1.0.4)
31+
json (1.8.1)
32+
multi_json (1.9.0)
33+
rack (1.4.5)
34+
rack-cache (1.2)
35+
rack (>= 0.4)
36+
rack-ssl (1.3.3)
37+
rack
38+
rack-test (0.6.2)
39+
rack (>= 1.0)
40+
railties (3.2.13)
41+
actionpack (= 3.2.13)
42+
activesupport (= 3.2.13)
43+
rack-ssl (~> 1.3.2)
44+
rake (>= 0.8.7)
45+
rdoc (~> 3.4)
46+
thor (>= 0.14.6, < 2.0)
47+
rake (10.1.1)
48+
rdoc (3.12.2)
4549
json (~> 1.4)
50+
sprockets (2.2.2)
51+
hike (~> 1.2)
52+
multi_json (~> 1.0)
53+
rack (~> 1.0)
54+
tilt (~> 1.1, != 1.3.0)
55+
thor (0.18.1)
56+
tilt (1.4.1)
4657

4758
PLATFORMS
4859
ruby
4960

5061
DEPENDENCIES
51-
jeweler
62+
rails-web-console!

MIT-LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2010 [Rodrigo Rosenfeld Rosas]
1+
Copyright 2014 Rodrigo Rosenfeld Rosas
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

README.md

+61
Original file line numberDiff line numberDiff line change
@@ -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")

Rakefile

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
begin
2-
require "jeweler"
3-
Jeweler::Tasks.new do |gem|
4-
gem.name = "rails-web-console"
5-
gem.summary = "A web console for Rails"
6-
gem.email = "rr.rosas@gmail.com"
7-
gem.authors = ["Rodrigo Rosenfeld Rosas"]
8-
gem.homepage = "https://github.com/rosenfeld/rails-web-console"
9-
gem.files = Dir["{lib}/**/*", "{app}/**/*", "{public}/**/*", "{config}/**/*"]
10-
gem.licenses = ["MIT"]
11-
gem.description = "Run any Ruby script from the context of a web request."
12-
end
13-
Jeweler::GemcutterTasks.new
14-
rescue
15-
puts "Jeweler or dependency not available."
2+
require 'bundler/setup'
3+
rescue LoadError
4+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
165
end
6+
7+
Bundler::GemHelper.install_tasks

VERSION

-1
This file was deleted.

app/assets/javascripts/console.js

-16
This file was deleted.

app/assets/stylesheets/console.css

-10
This file was deleted.

app/controllers/console_controller.rb

-29
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -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

app/views/console/index.html.erb

-3
This file was deleted.

app/views/layouts/console.html.erb

-14
This file was deleted.

0 commit comments

Comments
 (0)