chromembed_rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.project +17 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/chromembed_rails.gemspec +85 -0
- data/lib/chromembed_rails/controller.rb +63 -0
- data/lib/chromembed_rails/engine.rb +25 -0
- data/lib/chromembed_rails/generators/all_generator.rb +40 -0
- data/lib/chromembed_rails/generators/templates/001_create_chrome_extension_caches.rb +13 -0
- data/lib/chromembed_rails/generators/templates/chrome_extension_cache.rb +6 -0
- data/lib/chromembed_rails/generators/templates/chrome_extension_caches.yml +3 -0
- data/lib/chromembed_rails/generators/templates/chrome_extension_controller.rb +6 -0
- data/lib/chromembed_rails/generators/templates/chrome_extension_controller_test.rb +12 -0
- data/lib/chromembed_rails/generators/templates/chrome_extension_initializer.rb +1 -0
- data/lib/chromembed_rails/generators/templates/desktop/chrome_extension/images/ruby128.png +0 -0
- data/lib/chromembed_rails/generators/templates/desktop/chrome_extension/images/ruby16.png +0 -0
- data/lib/chromembed_rails/generators/templates/desktop/chrome_extension/images/ruby19.png +0 -0
- data/lib/chromembed_rails/generators/templates/desktop/chrome_extension/manifest.json +22 -0
- data/lib/chromembed_rails/generators/templates/desktop/chrome_extension.pem.erb +1 -0
- data/lib/chromembed_rails/model.rb +101 -0
- data/lib/chromembed_rails/routes.rb +23 -0
- data/lib/chromembed_rails.rb +11 -0
- metadata +215 -0
data/.project
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>chromembed_rails</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>com.aptana.ide.core.unifiedBuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>com.aptana.ruby.core.rubynature</nature>
|
16
|
+
</natures>
|
17
|
+
</projectDescription>
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
gem "crxmake", ">= 2.0.3"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "bundler", "~> 1.0.0"
|
10
|
+
gem "jeweler", "~> 1.5.2"
|
11
|
+
gem "rcov", ">= 0"
|
12
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
crxmake (2.0.3)
|
5
|
+
zipruby (>= 0.3.2)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.5.2)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
rake (0.8.7)
|
12
|
+
rcov (0.9.9)
|
13
|
+
zipruby (0.3.6)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
bundler (~> 1.0.0)
|
20
|
+
crxmake (>= 2.0.3)
|
21
|
+
jeweler (~> 1.5.2)
|
22
|
+
rcov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Victor Costan
|
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.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= chromembed_rails
|
2
|
+
|
3
|
+
Rails Engine for applications that are strongly coupled to Chrome extensions.
|
4
|
+
|
5
|
+
== Contributing to chromembed_rails
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Victor Costan. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "chromembed_rails"
|
16
|
+
gem.homepage = "http://github.com/pwnall/chromembed_rails"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Serves a Chrome extension embedded in a Rails application}
|
19
|
+
gem.description = %Q{Ruby on Rails engine for Web applications that are strongly coupled with Chrome extensions}
|
20
|
+
gem.email = "costan@gmail.com"
|
21
|
+
gem.authors = ["Victor Costan"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
gem.add_runtime_dependency 'crxmake', '>= 2.0.3'
|
25
|
+
gem.add_development_dependency 'bundler', '~> 1.0.0'
|
26
|
+
gem.add_development_dependency 'jeweler', '~> 1.5.2'
|
27
|
+
gem.add_development_dependency 'rcov', '>= 0'
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
30
|
+
|
31
|
+
require 'rake/testtask'
|
32
|
+
Rake::TestTask.new(:test) do |test|
|
33
|
+
test.libs << 'lib' << 'test'
|
34
|
+
test.pattern = 'test/**/*_test.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
|
38
|
+
task :default => :test
|
39
|
+
|
40
|
+
require 'rake/rdoctask'
|
41
|
+
Rake::RDocTask.new do |rdoc|
|
42
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
43
|
+
|
44
|
+
rdoc.rdoc_dir = 'rdoc'
|
45
|
+
rdoc.title = "new #{version}"
|
46
|
+
rdoc.rdoc_files.include('README*')
|
47
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{chromembed_rails}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Victor Costan"]
|
12
|
+
s.date = %q{2011-03-30}
|
13
|
+
s.description = %q{Ruby on Rails engine for Web applications that are strongly coupled with Chrome extensions}
|
14
|
+
s.email = %q{costan@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".project",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"chromembed_rails.gemspec",
|
28
|
+
"lib/chromembed_rails.rb",
|
29
|
+
"lib/chromembed_rails/controller.rb",
|
30
|
+
"lib/chromembed_rails/engine.rb",
|
31
|
+
"lib/chromembed_rails/generators/all_generator.rb",
|
32
|
+
"lib/chromembed_rails/generators/templates/001_create_chrome_extension_caches.rb",
|
33
|
+
"lib/chromembed_rails/generators/templates/chrome_extension_cache.rb",
|
34
|
+
"lib/chromembed_rails/generators/templates/chrome_extension_caches.yml",
|
35
|
+
"lib/chromembed_rails/generators/templates/chrome_extension_controller.rb",
|
36
|
+
"lib/chromembed_rails/generators/templates/chrome_extension_controller_test.rb",
|
37
|
+
"lib/chromembed_rails/generators/templates/chrome_extension_initializer.rb",
|
38
|
+
"lib/chromembed_rails/generators/templates/desktop/chrome_extension.pem.erb",
|
39
|
+
"lib/chromembed_rails/generators/templates/desktop/chrome_extension/images/ruby128.png",
|
40
|
+
"lib/chromembed_rails/generators/templates/desktop/chrome_extension/images/ruby16.png",
|
41
|
+
"lib/chromembed_rails/generators/templates/desktop/chrome_extension/images/ruby19.png",
|
42
|
+
"lib/chromembed_rails/generators/templates/desktop/chrome_extension/manifest.json",
|
43
|
+
"lib/chromembed_rails/model.rb",
|
44
|
+
"lib/chromembed_rails/routes.rb"
|
45
|
+
]
|
46
|
+
s.homepage = %q{http://github.com/pwnall/chromembed_rails}
|
47
|
+
s.licenses = ["MIT"]
|
48
|
+
s.require_paths = ["lib"]
|
49
|
+
s.rubygems_version = %q{1.5.3}
|
50
|
+
s.summary = %q{Serves a Chrome extension embedded in a Rails application}
|
51
|
+
|
52
|
+
if s.respond_to? :specification_version then
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<crxmake>, [">= 2.0.3"])
|
57
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
59
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
60
|
+
s.add_runtime_dependency(%q<crxmake>, [">= 2.0.3"])
|
61
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
63
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<crxmake>, [">= 2.0.3"])
|
66
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
68
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
69
|
+
s.add_dependency(%q<crxmake>, [">= 2.0.3"])
|
70
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
72
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
73
|
+
end
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<crxmake>, [">= 2.0.3"])
|
76
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
77
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
78
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
79
|
+
s.add_dependency(%q<crxmake>, [">= 2.0.3"])
|
80
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
81
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
82
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'action_controller'
|
2
|
+
require 'crxmake'
|
3
|
+
|
4
|
+
# :nodoc: namespace
|
5
|
+
module ChromembedRails
|
6
|
+
|
7
|
+
# :nodoc: namespace
|
8
|
+
module Session
|
9
|
+
|
10
|
+
# Mixed into ActiveController::Base
|
11
|
+
module ControllerMixin
|
12
|
+
def self.included(base)
|
13
|
+
base.send :extend, ControllerClassMethods
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Methods here become ActiveController::Base class methods.
|
18
|
+
module ControllerClassMethods
|
19
|
+
# Turns the current controller into the Chrome extension serving controller.
|
20
|
+
#
|
21
|
+
# Right now, this should be called from ChromeExtensionController. The
|
22
|
+
# controller name is hardwired in other parts of the implementation.
|
23
|
+
def chrome_extension_controller
|
24
|
+
include ControllerInstanceMethods
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Included in controllers that call config_vars_controller.
|
29
|
+
module ControllerInstanceMethods
|
30
|
+
# GET /chrome_extension.crx
|
31
|
+
def show
|
32
|
+
extension_data =
|
33
|
+
ChromeExtensionCache.extension_data(chrome_extension_update_url)
|
34
|
+
send_data extension_data.crx_bits, :disposition => 'attachment',
|
35
|
+
:content_type => 'application/x-chrome-extension'
|
36
|
+
end
|
37
|
+
|
38
|
+
# GET /chrome_extension/update.xml
|
39
|
+
def update
|
40
|
+
extension_data =
|
41
|
+
ChromeExtensionCache.extension_data(chrome_extension_update_url)
|
42
|
+
render :text => update_xml(extension_data)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Contents of the update XML document for an extension.
|
46
|
+
def update_xml(extension_data)
|
47
|
+
<<END_XML
|
48
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
49
|
+
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
|
50
|
+
<app appid='#{extension_data.appid}'>
|
51
|
+
<updatecheck codebase='#{chrome_extension_url}' version='#{extension_data.version}' />
|
52
|
+
</app>
|
53
|
+
</gupdate>
|
54
|
+
END_XML
|
55
|
+
end
|
56
|
+
private :update_xml
|
57
|
+
end # module ChromembedRails::Session::ControllerInstanceMethods
|
58
|
+
|
59
|
+
ActionController::Base.send :include, ControllerMixin
|
60
|
+
|
61
|
+
end # namespace ChromembedRails::Session
|
62
|
+
|
63
|
+
end # namespace ChromembedRails
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'chromembed_rails'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
# :nodoc: namespace
|
5
|
+
module ChromembedRails
|
6
|
+
|
7
|
+
class Engine < Rails::Engine
|
8
|
+
paths.app = "app"
|
9
|
+
paths.app.controllers = "app/controllers"
|
10
|
+
paths.app.helpers = "app/helpers"
|
11
|
+
paths.app.models = "app/models"
|
12
|
+
paths.app.views = "app/views"
|
13
|
+
# paths.lib = "lib"
|
14
|
+
# paths.lib.tasks = "lib/tasks"
|
15
|
+
# paths.config = "config"
|
16
|
+
# paths.config.initializers = "config/initializers"
|
17
|
+
# paths.config.locales = "config/locales"
|
18
|
+
# paths.config.routes = "config/routes.rb"
|
19
|
+
|
20
|
+
generators do
|
21
|
+
require 'chromembed_rails/generators/all_generator.rb'
|
22
|
+
end
|
23
|
+
end # class ChromembedRails::Engine
|
24
|
+
|
25
|
+
end # namespace ChromembedRails
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
# :nodoc: namespace
|
6
|
+
module ChromembedRails
|
7
|
+
|
8
|
+
# Name chosen to get chromembed_rails:all
|
9
|
+
class AllGenerator < Rails::Generators::Base
|
10
|
+
source_root File.expand_path("../templates", __FILE__)
|
11
|
+
|
12
|
+
def create_chrome_extension
|
13
|
+
copy_file 'chrome_extension_cache.rb',
|
14
|
+
File.join('app', 'models', 'chrome_extension_cache.rb')
|
15
|
+
copy_file '001_create_chrome_extension_caches.rb', File.join('db',
|
16
|
+
'migrate', '20110330000001_create_chrome_extension_caches.rb')
|
17
|
+
copy_file 'chrome_extension_caches.yml',
|
18
|
+
File.join('test', 'fixtures', 'chrome_extension_caches.yml')
|
19
|
+
|
20
|
+
copy_file 'chrome_extension_controller.rb',
|
21
|
+
File.join('app', 'controllers', 'chrome_extension_controller.rb')
|
22
|
+
copy_file File.join('chrome_extension_controller_test.rb'),
|
23
|
+
File.join('test', 'functional', 'chrome_extension_controller_test.rb')
|
24
|
+
route 'chrome_extension'
|
25
|
+
|
26
|
+
copy_file 'chrome_extension_initializer.rb',
|
27
|
+
File.join('config', 'initializers', 'chrome_extension.rb')
|
28
|
+
|
29
|
+
copy_file File.join('desktop', 'chrome_extension', 'manifest.json'),
|
30
|
+
File.join('desktop', 'chrome_extension', 'manifest.json')
|
31
|
+
['ruby16.png', 'ruby19.png', 'ruby128.png'].each do |view_name|
|
32
|
+
copy_file File.join('desktop', 'chrome_extension', 'images', view_name),
|
33
|
+
File.join('desktop', 'chrome_extension', 'images', view_name)
|
34
|
+
end
|
35
|
+
template File.join('desktop', 'chrome_extension.pem.erb'),
|
36
|
+
File.join('desktop', 'chrome_extension.pem')
|
37
|
+
end
|
38
|
+
end # class ChromembedRails::ConfigVarsGenerator
|
39
|
+
|
40
|
+
end # namespace ChromembedRails
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateChromeExtensionCaches < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :chrome_extension_caches do |t|
|
4
|
+
t.string :appid, :length => 128, :null => false
|
5
|
+
t.string :version, :length => 64, :null => false
|
6
|
+
t.binary :crx_bits, :length => 64.megabytes, :null => false
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
drop_table :chrome_extension_caches
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ChromeExtensionControllerTest < ActionController::TestCase
|
4
|
+
setup do
|
5
|
+
@config_var = config_vars(:app_uri)
|
6
|
+
end
|
7
|
+
|
8
|
+
test "cannot access config vars without authentication" do
|
9
|
+
get :index
|
10
|
+
assert_response :unauthorized
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# The path to your extension's embedded code.
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"name": "Rails-backed",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "My awesome Rails-backed extension",
|
5
|
+
"icons": {
|
6
|
+
"16": "images/ruby16.png",
|
7
|
+
"128": "images/ruby128.png"
|
8
|
+
},
|
9
|
+
|
10
|
+
"incognito": "split",
|
11
|
+
"minimum_chrome_version": "5.0.316.0",
|
12
|
+
"permissions": [
|
13
|
+
"geolocation",
|
14
|
+
"notifications",
|
15
|
+
"unlimitedStorage"
|
16
|
+
],
|
17
|
+
|
18
|
+
"browser_action": {
|
19
|
+
"default_icon": "images/ruby19.png",
|
20
|
+
"default_title": "Hi"
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= OpenSSL::PKey::RSA.generate(1024).export.html_safe %>
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'English'
|
2
|
+
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
# :nodoc: namespace
|
6
|
+
module ChromembedRails
|
7
|
+
|
8
|
+
# :nodoc: namespace
|
9
|
+
module Model
|
10
|
+
|
11
|
+
|
12
|
+
# Mixed into ActiveRecord::Base
|
13
|
+
module ModelMixin
|
14
|
+
def self.included(base)
|
15
|
+
base.send :extend, ModelClassMethods
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
# Methods here become ActiveRecord::Base class methods.
|
21
|
+
module ModelClassMethods
|
22
|
+
# Extends the model to cache data for serving an embedded Chrome extension.
|
23
|
+
def chrome_extension_cache_model
|
24
|
+
# The extension's appid.
|
25
|
+
validates :appid, :uniqueness => true, :length => 1..128, :presence => true
|
26
|
+
|
27
|
+
# The extension version listed in manifest.json.
|
28
|
+
validates :version, :length => { :in => 0..64, :allow_nil => false }
|
29
|
+
|
30
|
+
extend ModelMetaclassMethods
|
31
|
+
include ModelInstanceMethods
|
32
|
+
end
|
33
|
+
end # module ChromembedRails::Model::ModelClassMethods
|
34
|
+
|
35
|
+
|
36
|
+
# Included in the metaclass of models that call chrome_extension_cache_model.
|
37
|
+
module ModelMetaclassMethods
|
38
|
+
# ChromeExtensionCache entry for the latest extension bits.
|
39
|
+
def extension_data(chrome_extension_update_url)
|
40
|
+
self.new.update_with_current_bits(
|
41
|
+
'update_url' => chrome_extension_update_url)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Path to the extension files.
|
45
|
+
def extension_path
|
46
|
+
Rails.root.join 'desktop', 'chrome_extension'
|
47
|
+
end
|
48
|
+
|
49
|
+
# Path to the private key used to sign the extension.
|
50
|
+
def key_path
|
51
|
+
Rails.root.join 'desktop', 'chrome_extension.pem'
|
52
|
+
end
|
53
|
+
end # module ChromembedRails::Model::ModelMetaclassMethods
|
54
|
+
|
55
|
+
|
56
|
+
# Included in models that call chrome_extension_cache_model.
|
57
|
+
module ModelInstanceMethods
|
58
|
+
# Updates this cache entry to reflect the current extension code.
|
59
|
+
#
|
60
|
+
# Args:
|
61
|
+
# manifest_changes:: hash to be merged into the extension's manifest JSON;
|
62
|
+
# 'update_url' and 'version' might be good keys to change
|
63
|
+
def update_with_current_bits(manifest_changes)
|
64
|
+
extension_path = self.class.extension_path
|
65
|
+
manifest_path = File.join extension_path, 'manifest.json'
|
66
|
+
manifest_json = ActiveSupport::JSON.decode File.read(manifest_path)
|
67
|
+
manifest_json.merge! manifest_changes
|
68
|
+
self.version = manifest_json['version']
|
69
|
+
|
70
|
+
key_path = self.class.key_path
|
71
|
+
key = OpenSSL::PKey::RSA.new File.read(key_path)
|
72
|
+
# Source: http://supercollider.dk/2010/01/calculating-chrome-extension-id-from-your-private-key-233
|
73
|
+
alg = ["30819F300D06092A864886F70D010101050003818D00"].pack('H*')
|
74
|
+
hash = Digest::SHA256.hexdigest(alg + key.public_key.to_der)[0...32]
|
75
|
+
self.appid = hash.unpack('C*').map{ |c| c < 97 ? c + 49 : c + 10 }.
|
76
|
+
pack('C*')
|
77
|
+
|
78
|
+
tmp_path = Rails.root.join 'tmp', "chrome_ext_#{Time.now.to_f}_#{$PID}"
|
79
|
+
ext_path = File.join tmp_path, 'chrome_extension'
|
80
|
+
FileUtils.mkdir_p ext_path
|
81
|
+
FileUtils.cp_r File.join(extension_path, '.'), ext_path
|
82
|
+
man_path = File.join ext_path, 'manifest.json'
|
83
|
+
File.open(man_path, 'wb') do |f|
|
84
|
+
f.write ActiveSupport::JSON.encode manifest_json
|
85
|
+
end
|
86
|
+
|
87
|
+
crx_path = File.join tmp_path, 'chrome_extension.crx'
|
88
|
+
CrxMake.make :ex_dir => ext_path, :pkey => key_path,
|
89
|
+
:crx_output => crx_path, :verbose => false
|
90
|
+
self.crx_bits = File.read crx_path
|
91
|
+
FileUtils.rm_r tmp_path
|
92
|
+
|
93
|
+
self
|
94
|
+
end
|
95
|
+
end # module ChromembedRails::Model::ModelInstanceMethods
|
96
|
+
|
97
|
+
ActiveRecord::Base.send :include, ModelMixin
|
98
|
+
|
99
|
+
end # namespace ChromembedRails::Model
|
100
|
+
|
101
|
+
end # namespace ChromembedRails
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'action_pack'
|
2
|
+
|
3
|
+
# :nodoc: namespace
|
4
|
+
module ChromembedRails
|
5
|
+
|
6
|
+
# :nodoc: namespace
|
7
|
+
module Routes
|
8
|
+
|
9
|
+
# :nodoc: mixed into ActionPack's route mapper.
|
10
|
+
module MapperMixin
|
11
|
+
def chrome_extension
|
12
|
+
get 'chrome_extension.crx' => 'chrome_extension#show',
|
13
|
+
:as => :chrome_extension
|
14
|
+
get 'chrome_extension/update.xml' => 'chrome_extension#update',
|
15
|
+
:as => :chrome_extension_update
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ActionDispatch::Routing::Mapper.send :include, MapperMixin
|
20
|
+
|
21
|
+
end # namespace ChromembedRails::Routes
|
22
|
+
|
23
|
+
end # namespace ChromembedRails
|
metadata
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chromembed_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Victor Costan
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-30 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: crxmake
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 9
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 0
|
32
|
+
- 3
|
33
|
+
version: 2.0.3
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 23
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 0
|
48
|
+
- 0
|
49
|
+
version: 1.0.0
|
50
|
+
prerelease: false
|
51
|
+
type: :development
|
52
|
+
requirement: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: jeweler
|
55
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 7
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 5
|
64
|
+
- 2
|
65
|
+
version: 1.5.2
|
66
|
+
prerelease: false
|
67
|
+
type: :development
|
68
|
+
requirement: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rcov
|
71
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
prerelease: false
|
81
|
+
type: :development
|
82
|
+
requirement: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: crxmake
|
85
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 9
|
91
|
+
segments:
|
92
|
+
- 2
|
93
|
+
- 0
|
94
|
+
- 3
|
95
|
+
version: 2.0.3
|
96
|
+
prerelease: false
|
97
|
+
type: :runtime
|
98
|
+
requirement: *id005
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: bundler
|
101
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ~>
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 23
|
107
|
+
segments:
|
108
|
+
- 1
|
109
|
+
- 0
|
110
|
+
- 0
|
111
|
+
version: 1.0.0
|
112
|
+
prerelease: false
|
113
|
+
type: :development
|
114
|
+
requirement: *id006
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: jeweler
|
117
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ~>
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 7
|
123
|
+
segments:
|
124
|
+
- 1
|
125
|
+
- 5
|
126
|
+
- 2
|
127
|
+
version: 1.5.2
|
128
|
+
prerelease: false
|
129
|
+
type: :development
|
130
|
+
requirement: *id007
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: rcov
|
133
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
hash: 3
|
139
|
+
segments:
|
140
|
+
- 0
|
141
|
+
version: "0"
|
142
|
+
prerelease: false
|
143
|
+
type: :development
|
144
|
+
requirement: *id008
|
145
|
+
description: Ruby on Rails engine for Web applications that are strongly coupled with Chrome extensions
|
146
|
+
email: costan@gmail.com
|
147
|
+
executables: []
|
148
|
+
|
149
|
+
extensions: []
|
150
|
+
|
151
|
+
extra_rdoc_files:
|
152
|
+
- LICENSE.txt
|
153
|
+
- README.rdoc
|
154
|
+
files:
|
155
|
+
- .project
|
156
|
+
- Gemfile
|
157
|
+
- Gemfile.lock
|
158
|
+
- LICENSE.txt
|
159
|
+
- README.rdoc
|
160
|
+
- Rakefile
|
161
|
+
- VERSION
|
162
|
+
- chromembed_rails.gemspec
|
163
|
+
- lib/chromembed_rails.rb
|
164
|
+
- lib/chromembed_rails/controller.rb
|
165
|
+
- lib/chromembed_rails/engine.rb
|
166
|
+
- lib/chromembed_rails/generators/all_generator.rb
|
167
|
+
- lib/chromembed_rails/generators/templates/001_create_chrome_extension_caches.rb
|
168
|
+
- lib/chromembed_rails/generators/templates/chrome_extension_cache.rb
|
169
|
+
- lib/chromembed_rails/generators/templates/chrome_extension_caches.yml
|
170
|
+
- lib/chromembed_rails/generators/templates/chrome_extension_controller.rb
|
171
|
+
- lib/chromembed_rails/generators/templates/chrome_extension_controller_test.rb
|
172
|
+
- lib/chromembed_rails/generators/templates/chrome_extension_initializer.rb
|
173
|
+
- lib/chromembed_rails/generators/templates/desktop/chrome_extension.pem.erb
|
174
|
+
- lib/chromembed_rails/generators/templates/desktop/chrome_extension/images/ruby128.png
|
175
|
+
- lib/chromembed_rails/generators/templates/desktop/chrome_extension/images/ruby16.png
|
176
|
+
- lib/chromembed_rails/generators/templates/desktop/chrome_extension/images/ruby19.png
|
177
|
+
- lib/chromembed_rails/generators/templates/desktop/chrome_extension/manifest.json
|
178
|
+
- lib/chromembed_rails/model.rb
|
179
|
+
- lib/chromembed_rails/routes.rb
|
180
|
+
has_rdoc: true
|
181
|
+
homepage: http://github.com/pwnall/chromembed_rails
|
182
|
+
licenses:
|
183
|
+
- MIT
|
184
|
+
post_install_message:
|
185
|
+
rdoc_options: []
|
186
|
+
|
187
|
+
require_paths:
|
188
|
+
- lib
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
190
|
+
none: false
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
hash: 3
|
195
|
+
segments:
|
196
|
+
- 0
|
197
|
+
version: "0"
|
198
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
|
+
none: false
|
200
|
+
requirements:
|
201
|
+
- - ">="
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
hash: 3
|
204
|
+
segments:
|
205
|
+
- 0
|
206
|
+
version: "0"
|
207
|
+
requirements: []
|
208
|
+
|
209
|
+
rubyforge_project:
|
210
|
+
rubygems_version: 1.5.3
|
211
|
+
signing_key:
|
212
|
+
specification_version: 3
|
213
|
+
summary: Serves a Chrome extension embedded in a Rails application
|
214
|
+
test_files: []
|
215
|
+
|