forked from gsamokovarov/web-console
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a build environment for the Chrome Extension
For the development: ``` $ git clone https://github.com/rails/web-console.git $ cd web-console $ bundle install $ bundle exec rake ext:chrome:run => Chrome will be launched with the extension. ``` And provide some rake tasks for the extension: - "ext:chrome" is to build the extension - "ext:chrome:run" is to launch a browser with the extension - "ext:chrome:zip" is to generate .zip - "ext:chrome:crx" is to generate .crx
- Loading branch information
1 parent
5e4bce6
commit 7098a7e
Showing
9 changed files
with
201 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ test/dummy/tmp/ | |
test/dummy/.sass-cache | ||
Gemfile.lock | ||
node_modules/ | ||
dist/ | ||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Web Console Browser Extensions | ||
|
||
## Development | ||
|
||
### Quickstart | ||
|
||
``` | ||
$ git clone https://github.com/rails/web-console.git | ||
$ cd web-console | ||
$ bundle install | ||
$ bundle exec rake ext:chrome:run | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "dev", | ||
"version": "0.0.0", | ||
"devDependencies": { | ||
"crx": "^3.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/sh | ||
|
||
is_command() { | ||
type $1 > /dev/null 2>&1 | ||
} | ||
|
||
find_chrome_binary() { | ||
for name in 'chromium' 'google-chrome' 'chromium-browser'; do | ||
if is_command $name; then | ||
echo $name | ||
return | ||
fi | ||
done | ||
} | ||
|
||
CHROME_BINARY=${CHROME_BINARY:-`find_chrome_binary`} | ||
|
||
if is_command $CHROME_BINARY; then | ||
$CHROME_BINARY $@ | ||
else | ||
echo 'ERROR: Chrome is not found.' | ||
echo 'Please try "CHROME_BINARY=path/to/chrome".' | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'web_console/testing/helper' | ||
require 'web_console/testing/fake_middleware' | ||
|
||
module WebConsole | ||
module Testing | ||
# This class is to pre-compile 'templates/*.erb'. | ||
class ERBPrecompiler | ||
def initialize(path) | ||
@erb = ERB.new(File.read(path)) | ||
@view = FakeMiddleware.new( | ||
view_path: Helper.gem_root.join('lib/web_console/templates'), | ||
).view | ||
end | ||
|
||
def build | ||
@erb.result(binding) | ||
end | ||
|
||
def method_missing(name, *args, &block) | ||
return super unless @view.respond_to?(name) | ||
@view.send(name, *args, &block) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'action_view' | ||
require 'action_dispatch' | ||
require 'json' | ||
require 'web_console/whitelist' | ||
require 'web_console/request' | ||
|
||
module WebConsole | ||
module Testing | ||
class FakeMiddleware | ||
DEFAULT_HEADERS = { "Content-Type" => "application/javascript" } | ||
|
||
def initialize(opts) | ||
@headers = opts.fetch(:headers, DEFAULT_HEADERS) | ||
@req_path_regex = opts[:req_path_regex] | ||
@view_path = opts[:view_path] | ||
end | ||
|
||
def call(env) | ||
[ 200, @headers, [ render(req_path(env)) ] ] | ||
end | ||
|
||
def view | ||
@view ||= create_view | ||
end | ||
|
||
private | ||
|
||
# extract target path from REQUEST_PATH | ||
def req_path(env) | ||
env["REQUEST_PATH"].match(@req_path_regex)[1] | ||
end | ||
|
||
def render(template) | ||
view.render(template: template, layout: nil) | ||
end | ||
|
||
def create_view | ||
lookup_context = ActionView::LookupContext.new(@view_path) | ||
lookup_context.cache = false | ||
FakeView.new(lookup_context) | ||
end | ||
|
||
class FakeView < ActionView::Base | ||
def render_inlined_string(template) | ||
render(template: template, layout: "layouts/inlined_string") | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module WebConsole | ||
module Testing | ||
module Helper | ||
def self.gem_root | ||
Pathname(File.expand_path('../../../../', __FILE__)) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters