djr 0.0.3 → 0.0.4pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +9 -5
- data/README.md +78 -0
- data/Rakefile +1 -1
- data/app/controllers/djr_controller.rb +1 -1
- data/config/application.rb +59 -0
- data/config/boot.rb +6 -0
- data/config/database.yml +25 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +37 -0
- data/config/environments/production.rb +67 -0
- data/config/environments/test.rb +37 -0
- data/config/initializers/backtrace_silencers.rb +7 -0
- data/config/initializers/inflections.rb +15 -0
- data/config/initializers/mime_types.rb +5 -0
- data/config/initializers/secret_token.rb +7 -0
- data/config/initializers/session_store.rb +8 -0
- data/config/initializers/wrap_parameters.rb +14 -0
- data/config/locales/en.yml +5 -0
- data/config.ru +4 -0
- data/db/development.sqlite3 +0 -0
- data/db/seeds.rb +7 -0
- data/db/test.sqlite3 +0 -0
- data/doc/README_FOR_APP +2 -0
- data/lib/assets/.gitkeep +0 -0
- data/lib/djr/version.rb +1 -1
- data/lib/tasks/.gitkeep +0 -0
- data/log/.gitkeep +0 -0
- data/public/404.html +26 -0
- data/public/422.html +26 -0
- data/public/500.html +25 -0
- data/public/favicon.ico +0 -0
- data/public/index.html +241 -0
- data/public/robots.txt +5 -0
- data/script/rails +6 -0
- data/spec/djr_controller_spec.rb +63 -0
- data/spec/spec_helper.rb +17 -4
- metadata +39 -8
- data/README.rdoc +0 -46
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
gem "rails", "
|
3
|
+
gem "rails", "3.1.3"
|
4
4
|
|
5
|
-
group :development do
|
6
|
-
gem "
|
7
|
-
gem "
|
8
|
-
gem
|
5
|
+
group :development, :test do
|
6
|
+
gem "sqlite3"
|
7
|
+
gem "rspec", "2.8.0"
|
8
|
+
gem 'rspec-rails', "2.8.1"
|
9
|
+
gem 'simplecov'
|
10
|
+
gem 'shoulda'
|
11
|
+
gem "rdoc", "3.12"
|
12
|
+
gem "bundler", "1.0.21"
|
9
13
|
end
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
## DJR
|
2
|
+
|
3
|
+
DJR (Direct jQuery Remoting) will generate the JavaScript code from Rails Controllers to allow browsers to securely call into Ruby code almost as if it was running locally
|
4
|
+
|
5
|
+
## Getting started
|
6
|
+
|
7
|
+
Add it to your Gemfile with:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'djr'
|
11
|
+
```
|
12
|
+
|
13
|
+
Run the bundle command to install it.
|
14
|
+
|
15
|
+
Configure assets in app/assets/application.js file:
|
16
|
+
|
17
|
+
```javascript
|
18
|
+
//= require jquery
|
19
|
+
//= require djr
|
20
|
+
//= require_tree .
|
21
|
+
```
|
22
|
+
|
23
|
+
Import script in your pages:
|
24
|
+
|
25
|
+
```html
|
26
|
+
<script type="text/javascript" charset="utf-8" src="/djr"></script>
|
27
|
+
```
|
28
|
+
|
29
|
+
In javascript, call your Controller like:
|
30
|
+
|
31
|
+
```javascript
|
32
|
+
productsController = new ProductsController
|
33
|
+
|
34
|
+
productsController.save({
|
35
|
+
name: "IPhone 4s",
|
36
|
+
value: "500.00"
|
37
|
+
}, callbackFunction);
|
38
|
+
|
39
|
+
//or more complete
|
40
|
+
|
41
|
+
productsController.index({
|
42
|
+
query: "IPhone"
|
43
|
+
}, function(productsListAsJson){
|
44
|
+
showProductsFunction(productsListAsJson);
|
45
|
+
}, function(error) {
|
46
|
+
errorHandler(error);
|
47
|
+
});
|
48
|
+
|
49
|
+
```
|
50
|
+
|
51
|
+
Your controller should be something like that:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
class ProductsController < ApplicationController
|
55
|
+
|
56
|
+
respond_to :html, :json
|
57
|
+
|
58
|
+
def index
|
59
|
+
@query = params[:query]
|
60
|
+
@products = Product.search do
|
61
|
+
fulltext @query
|
62
|
+
end
|
63
|
+
respond_with @products
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
## Conventions
|
71
|
+
|
72
|
+
```javascript
|
73
|
+
controller.action( dataAsJson, callbackFunction, errorHandler );
|
74
|
+
```
|
75
|
+
|
76
|
+
## License
|
77
|
+
|
78
|
+
MIT License. Copyright (c) 2012 Milfont Consulting. http://milfont.org
|
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
if defined?(Bundler)
|
6
|
+
# If you precompile assets before deploying to production, use this line
|
7
|
+
Bundler.require(*Rails.groups(:assets => %w(development test)))
|
8
|
+
# If you want your assets lazily compiled in production, use this line
|
9
|
+
# Bundler.require(:default, :assets, Rails.env)
|
10
|
+
end
|
11
|
+
|
12
|
+
module Djr
|
13
|
+
class Application < Rails::Application
|
14
|
+
# Settings in config/environments/* take precedence over those specified here.
|
15
|
+
# Application configuration should go into files in config/initializers
|
16
|
+
# -- all .rb files in that directory are automatically loaded.
|
17
|
+
|
18
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
19
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
20
|
+
|
21
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
22
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
23
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
24
|
+
|
25
|
+
# Activate observers that should always be running.
|
26
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
27
|
+
|
28
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
29
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
30
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
31
|
+
|
32
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
33
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
34
|
+
# config.i18n.default_locale = :de
|
35
|
+
|
36
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
37
|
+
config.encoding = "utf-8"
|
38
|
+
|
39
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
40
|
+
config.filter_parameters += [:password]
|
41
|
+
|
42
|
+
# Use SQL instead of Active Record's schema dumper when creating the database.
|
43
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
44
|
+
# like if you have constraints or database-specific column types
|
45
|
+
# config.active_record.schema_format = :sql
|
46
|
+
|
47
|
+
# Enforce whitelist mode for mass assignment.
|
48
|
+
# This will create an empty whitelist of attributes available for mass-assignment for all models
|
49
|
+
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
|
50
|
+
# parameters by using an attr_accessible or attr_protected declaration.
|
51
|
+
# config.active_record.whitelist_attributes = true
|
52
|
+
|
53
|
+
# Enable the asset pipeline
|
54
|
+
config.assets.enabled = true
|
55
|
+
|
56
|
+
# Version of your assets, change this if you want to expire all your assets
|
57
|
+
config.assets.version = '1.0'
|
58
|
+
end
|
59
|
+
end
|
data/config/boot.rb
ADDED
data/config/database.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
development:
|
7
|
+
adapter: sqlite3
|
8
|
+
database: db/development.sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
# Warning: The database defined as "test" will be erased and
|
13
|
+
# re-generated from your development database when you run "rake".
|
14
|
+
# Do not set this db to the same as development or production.
|
15
|
+
test:
|
16
|
+
adapter: sqlite3
|
17
|
+
database: db/test.sqlite3
|
18
|
+
pool: 5
|
19
|
+
timeout: 5000
|
20
|
+
|
21
|
+
production:
|
22
|
+
adapter: sqlite3
|
23
|
+
database: db/production.sqlite3
|
24
|
+
pool: 5
|
25
|
+
timeout: 5000
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Djr::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Only use best-standards-support built into browsers
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
24
|
+
|
25
|
+
# Raise exception on mass assignment protection for Active Record models
|
26
|
+
#config.active_record.mass_assignment_sanitizer = :strict
|
27
|
+
|
28
|
+
# Log the query plan for queries taking more than this (works
|
29
|
+
# with SQLite, MySQL, and PostgreSQL)
|
30
|
+
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
31
|
+
|
32
|
+
# Do not compress assets
|
33
|
+
config.assets.compress = false
|
34
|
+
|
35
|
+
# Expands the lines which load the assets
|
36
|
+
config.assets.debug = true
|
37
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
Djr::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# Code is not reloaded between requests
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Full error reports are disabled and caching is turned on
|
8
|
+
config.consider_all_requests_local = false
|
9
|
+
config.action_controller.perform_caching = true
|
10
|
+
|
11
|
+
# Disable Rails's static asset server (Apache or nginx will already do this)
|
12
|
+
config.serve_static_assets = false
|
13
|
+
|
14
|
+
# Compress JavaScripts and CSS
|
15
|
+
config.assets.compress = true
|
16
|
+
|
17
|
+
# Don't fallback to assets pipeline if a precompiled asset is missed
|
18
|
+
config.assets.compile = false
|
19
|
+
|
20
|
+
# Generate digests for assets URLs
|
21
|
+
config.assets.digest = true
|
22
|
+
|
23
|
+
# Defaults to Rails.root.join("public/assets")
|
24
|
+
# config.assets.manifest = YOUR_PATH
|
25
|
+
|
26
|
+
# Specifies the header that your server uses for sending files
|
27
|
+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
28
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
29
|
+
|
30
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
31
|
+
# config.force_ssl = true
|
32
|
+
|
33
|
+
# See everything in the log (default is :info)
|
34
|
+
# config.log_level = :debug
|
35
|
+
|
36
|
+
# Prepend all log lines with the following tags
|
37
|
+
# config.log_tags = [ :subdomain, :uuid ]
|
38
|
+
|
39
|
+
# Use a different logger for distributed setups
|
40
|
+
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
41
|
+
|
42
|
+
# Use a different cache store in production
|
43
|
+
# config.cache_store = :mem_cache_store
|
44
|
+
|
45
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
46
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
47
|
+
|
48
|
+
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
49
|
+
# config.assets.precompile += %w( search.js )
|
50
|
+
|
51
|
+
# Disable delivery errors, bad email addresses will be ignored
|
52
|
+
# config.action_mailer.raise_delivery_errors = false
|
53
|
+
|
54
|
+
# Enable threaded mode
|
55
|
+
# config.threadsafe!
|
56
|
+
|
57
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
58
|
+
# the I18n.default_locale when a translation can not be found)
|
59
|
+
config.i18n.fallbacks = true
|
60
|
+
|
61
|
+
# Send deprecation notices to registered listeners
|
62
|
+
config.active_support.deprecation = :notify
|
63
|
+
|
64
|
+
# Log the query plan for queries taking more than this (works
|
65
|
+
# with SQLite, MySQL, and PostgreSQL)
|
66
|
+
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
67
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Djr::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Configure static asset server for tests with Cache-Control for performance
|
11
|
+
config.serve_static_assets = true
|
12
|
+
config.static_cache_control = "public, max-age=3600"
|
13
|
+
|
14
|
+
# Log error messages when you accidentally call methods on nil
|
15
|
+
config.whiny_nils = true
|
16
|
+
|
17
|
+
# Show full error reports and disable caching
|
18
|
+
config.consider_all_requests_local = true
|
19
|
+
config.action_controller.perform_caching = false
|
20
|
+
|
21
|
+
# Raise exceptions instead of rendering exception templates
|
22
|
+
config.action_dispatch.show_exceptions = false
|
23
|
+
|
24
|
+
# Disable request forgery protection in test environment
|
25
|
+
config.action_controller.allow_forgery_protection = false
|
26
|
+
|
27
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
28
|
+
# The :test delivery method accumulates sent emails in the
|
29
|
+
# ActionMailer::Base.deliveries array.
|
30
|
+
config.action_mailer.delivery_method = :test
|
31
|
+
|
32
|
+
# Raise exception on mass assignment protection for Active Record models
|
33
|
+
#config.active_record.mass_assignment_sanitizer = :strict
|
34
|
+
|
35
|
+
# Print deprecation notices to the stderr
|
36
|
+
config.active_support.deprecation = :stderr
|
37
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# These inflection rules are supported but not enabled by default:
|
13
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
14
|
+
# inflect.acronym 'RESTful'
|
15
|
+
# end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Djr::Application.config.secret_token = 'ea5e283e2ba06cffc3643ddd948d7d1612a591444c27348dcfb8bbafb8b040a1d2421dede351f77bdefa069849ba662ca9d07e02ee4f92ae47ecf88669208606'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Djr::Application.config.session_store :cookie_store, key: '_djr_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Djr::Application.config.session_store :active_record_store
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
#
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Disable root element in JSON by default.
|
12
|
+
ActiveSupport.on_load(:active_record) do
|
13
|
+
self.include_root_in_json = false
|
14
|
+
end
|
data/config.ru
ADDED
File without changes
|
data/db/seeds.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
|
7
|
+
# Mayor.create(name: 'Emanuel', city: cities.first)
|
data/db/test.sqlite3
ADDED
File without changes
|
data/doc/README_FOR_APP
ADDED
data/lib/assets/.gitkeep
ADDED
File without changes
|
data/lib/djr/version.rb
CHANGED
data/lib/tasks/.gitkeep
ADDED
File without changes
|
data/log/.gitkeep
ADDED
File without changes
|
data/public/404.html
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
data/public/422.html
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
data/public/500.html
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
data/public/favicon.ico
ADDED
File without changes
|
data/public/index.html
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Ruby on Rails: Welcome aboard</title>
|
5
|
+
<style type="text/css" media="screen">
|
6
|
+
body {
|
7
|
+
margin: 0;
|
8
|
+
margin-bottom: 25px;
|
9
|
+
padding: 0;
|
10
|
+
background-color: #f0f0f0;
|
11
|
+
font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
|
12
|
+
font-size: 13px;
|
13
|
+
color: #333;
|
14
|
+
}
|
15
|
+
|
16
|
+
h1 {
|
17
|
+
font-size: 28px;
|
18
|
+
color: #000;
|
19
|
+
}
|
20
|
+
|
21
|
+
a {color: #03c}
|
22
|
+
a:hover {
|
23
|
+
background-color: #03c;
|
24
|
+
color: white;
|
25
|
+
text-decoration: none;
|
26
|
+
}
|
27
|
+
|
28
|
+
|
29
|
+
#page {
|
30
|
+
background-color: #f0f0f0;
|
31
|
+
width: 750px;
|
32
|
+
margin: 0;
|
33
|
+
margin-left: auto;
|
34
|
+
margin-right: auto;
|
35
|
+
}
|
36
|
+
|
37
|
+
#content {
|
38
|
+
float: left;
|
39
|
+
background-color: white;
|
40
|
+
border: 3px solid #aaa;
|
41
|
+
border-top: none;
|
42
|
+
padding: 25px;
|
43
|
+
width: 500px;
|
44
|
+
}
|
45
|
+
|
46
|
+
#sidebar {
|
47
|
+
float: right;
|
48
|
+
width: 175px;
|
49
|
+
}
|
50
|
+
|
51
|
+
#footer {
|
52
|
+
clear: both;
|
53
|
+
}
|
54
|
+
|
55
|
+
#header, #about, #getting-started {
|
56
|
+
padding-left: 75px;
|
57
|
+
padding-right: 30px;
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
#header {
|
62
|
+
background-image: url("assets/rails.png");
|
63
|
+
background-repeat: no-repeat;
|
64
|
+
background-position: top left;
|
65
|
+
height: 64px;
|
66
|
+
}
|
67
|
+
#header h1, #header h2 {margin: 0}
|
68
|
+
#header h2 {
|
69
|
+
color: #888;
|
70
|
+
font-weight: normal;
|
71
|
+
font-size: 16px;
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
#about h3 {
|
76
|
+
margin: 0;
|
77
|
+
margin-bottom: 10px;
|
78
|
+
font-size: 14px;
|
79
|
+
}
|
80
|
+
|
81
|
+
#about-content {
|
82
|
+
background-color: #ffd;
|
83
|
+
border: 1px solid #fc0;
|
84
|
+
margin-left: -55px;
|
85
|
+
margin-right: -10px;
|
86
|
+
}
|
87
|
+
#about-content table {
|
88
|
+
margin-top: 10px;
|
89
|
+
margin-bottom: 10px;
|
90
|
+
font-size: 11px;
|
91
|
+
border-collapse: collapse;
|
92
|
+
}
|
93
|
+
#about-content td {
|
94
|
+
padding: 10px;
|
95
|
+
padding-top: 3px;
|
96
|
+
padding-bottom: 3px;
|
97
|
+
}
|
98
|
+
#about-content td.name {color: #555}
|
99
|
+
#about-content td.value {color: #000}
|
100
|
+
|
101
|
+
#about-content ul {
|
102
|
+
padding: 0;
|
103
|
+
list-style-type: none;
|
104
|
+
}
|
105
|
+
|
106
|
+
#about-content.failure {
|
107
|
+
background-color: #fcc;
|
108
|
+
border: 1px solid #f00;
|
109
|
+
}
|
110
|
+
#about-content.failure p {
|
111
|
+
margin: 0;
|
112
|
+
padding: 10px;
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
#getting-started {
|
117
|
+
border-top: 1px solid #ccc;
|
118
|
+
margin-top: 25px;
|
119
|
+
padding-top: 15px;
|
120
|
+
}
|
121
|
+
#getting-started h1 {
|
122
|
+
margin: 0;
|
123
|
+
font-size: 20px;
|
124
|
+
}
|
125
|
+
#getting-started h2 {
|
126
|
+
margin: 0;
|
127
|
+
font-size: 14px;
|
128
|
+
font-weight: normal;
|
129
|
+
color: #333;
|
130
|
+
margin-bottom: 25px;
|
131
|
+
}
|
132
|
+
#getting-started ol {
|
133
|
+
margin-left: 0;
|
134
|
+
padding-left: 0;
|
135
|
+
}
|
136
|
+
#getting-started li {
|
137
|
+
font-size: 18px;
|
138
|
+
color: #888;
|
139
|
+
margin-bottom: 25px;
|
140
|
+
}
|
141
|
+
#getting-started li h2 {
|
142
|
+
margin: 0;
|
143
|
+
font-weight: normal;
|
144
|
+
font-size: 18px;
|
145
|
+
color: #333;
|
146
|
+
}
|
147
|
+
#getting-started li p {
|
148
|
+
color: #555;
|
149
|
+
font-size: 13px;
|
150
|
+
}
|
151
|
+
|
152
|
+
|
153
|
+
#sidebar ul {
|
154
|
+
margin-left: 0;
|
155
|
+
padding-left: 0;
|
156
|
+
}
|
157
|
+
#sidebar ul h3 {
|
158
|
+
margin-top: 25px;
|
159
|
+
font-size: 16px;
|
160
|
+
padding-bottom: 10px;
|
161
|
+
border-bottom: 1px solid #ccc;
|
162
|
+
}
|
163
|
+
#sidebar li {
|
164
|
+
list-style-type: none;
|
165
|
+
}
|
166
|
+
#sidebar ul.links li {
|
167
|
+
margin-bottom: 5px;
|
168
|
+
}
|
169
|
+
|
170
|
+
.filename {
|
171
|
+
font-style: italic;
|
172
|
+
}
|
173
|
+
</style>
|
174
|
+
<script type="text/javascript">
|
175
|
+
function about() {
|
176
|
+
info = document.getElementById('about-content');
|
177
|
+
if (window.XMLHttpRequest)
|
178
|
+
{ xhr = new XMLHttpRequest(); }
|
179
|
+
else
|
180
|
+
{ xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
|
181
|
+
xhr.open("GET","rails/info/properties",false);
|
182
|
+
xhr.send("");
|
183
|
+
info.innerHTML = xhr.responseText;
|
184
|
+
info.style.display = 'block'
|
185
|
+
}
|
186
|
+
</script>
|
187
|
+
</head>
|
188
|
+
<body>
|
189
|
+
<div id="page">
|
190
|
+
<div id="sidebar">
|
191
|
+
<ul id="sidebar-items">
|
192
|
+
<li>
|
193
|
+
<h3>Browse the documentation</h3>
|
194
|
+
<ul class="links">
|
195
|
+
<li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
|
196
|
+
<li><a href="http://api.rubyonrails.org/">Rails API</a></li>
|
197
|
+
<li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li>
|
198
|
+
<li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li>
|
199
|
+
</ul>
|
200
|
+
</li>
|
201
|
+
</ul>
|
202
|
+
</div>
|
203
|
+
|
204
|
+
<div id="content">
|
205
|
+
<div id="header">
|
206
|
+
<h1>Welcome aboard</h1>
|
207
|
+
<h2>You’re riding Ruby on Rails!</h2>
|
208
|
+
</div>
|
209
|
+
|
210
|
+
<div id="about">
|
211
|
+
<h3><a href="rails/info/properties" onclick="about(); return false">About your application’s environment</a></h3>
|
212
|
+
<div id="about-content" style="display: none"></div>
|
213
|
+
</div>
|
214
|
+
|
215
|
+
<div id="getting-started">
|
216
|
+
<h1>Getting started</h1>
|
217
|
+
<h2>Here’s how to get rolling:</h2>
|
218
|
+
|
219
|
+
<ol>
|
220
|
+
<li>
|
221
|
+
<h2>Use <code>rails generate</code> to create your models and controllers</h2>
|
222
|
+
<p>To see all available options, run it without parameters.</p>
|
223
|
+
</li>
|
224
|
+
|
225
|
+
<li>
|
226
|
+
<h2>Set up a default route and remove <span class="filename">public/index.html</span></h2>
|
227
|
+
<p>Routes are set up in <span class="filename">config/routes.rb</span>.</p>
|
228
|
+
</li>
|
229
|
+
|
230
|
+
<li>
|
231
|
+
<h2>Create your database</h2>
|
232
|
+
<p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p>
|
233
|
+
</li>
|
234
|
+
</ol>
|
235
|
+
</div>
|
236
|
+
</div>
|
237
|
+
|
238
|
+
<div id="footer"> </div>
|
239
|
+
</div>
|
240
|
+
</body>
|
241
|
+
</html>
|
data/public/robots.txt
ADDED
data/script/rails
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe DjrController, :type => :controller do
|
7
|
+
|
8
|
+
context "When simple Controller" do
|
9
|
+
|
10
|
+
before do
|
11
|
+
routes = Rails.application.routes
|
12
|
+
routes.disable_clear_and_finalize = true
|
13
|
+
routes.clear!
|
14
|
+
Rails.application.routes_reloader.paths.each { |path| load(path) }
|
15
|
+
routes.draw do
|
16
|
+
match "/products" => "products#index"
|
17
|
+
end
|
18
|
+
routes.disable_clear_and_finalize = false
|
19
|
+
routes.finalize!
|
20
|
+
|
21
|
+
@generated_javascript = ";DjrController = function(){DJR.call(this);}; DjrController.prototype.routes = {};ProductsController = function(){DJR.call(this);}; ProductsController.prototype.routes = {}; DjrController.prototype.routes['djr'] = {url: \"/djr(.:format)\", method: \"GET\" }; ProductsController.prototype.routes['index'] = {url: \"/products(.:format)\", method: \"GET\" };"
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#djr" do
|
25
|
+
|
26
|
+
it "Generate js" do
|
27
|
+
get :djr
|
28
|
+
response.body.should == @generated_javascript
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
context "When Controller has module" do
|
37
|
+
|
38
|
+
before do
|
39
|
+
routes = Rails.application.routes
|
40
|
+
routes.disable_clear_and_finalize = true
|
41
|
+
routes.clear!
|
42
|
+
Rails.application.routes_reloader.paths.each { |path| load(path) }
|
43
|
+
routes.draw do
|
44
|
+
match "/users(.:format)" => "devise/registrations#destroy", :via => :DELETE
|
45
|
+
end
|
46
|
+
routes.disable_clear_and_finalize = false
|
47
|
+
routes.finalize!
|
48
|
+
|
49
|
+
@generated_javascript = ";DjrController = function(){DJR.call(this);}; DjrController.prototype.routes = {};if(!Devise) { var Devise = {}; }; Devise.RegistrationsController = function(){DJR.call(this);}; Devise.RegistrationsController.prototype.routes = {}; DjrController.prototype.routes['djr'] = {url: \"/djr(.:format)\", method: \"GET\" }; Devise.RegistrationsController.prototype.routes['destroy'] = {url: \"/users(.:format)\", method: \"DELETE\" };"
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#djr" do
|
53
|
+
|
54
|
+
it "Generate js" do
|
55
|
+
get :djr
|
56
|
+
response.body.should == @generated_javascript
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,25 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
#$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
#$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start
|
6
|
+
|
7
|
+
ENV["RAILS_ENV"] ||= 'test'
|
8
|
+
require File.expand_path("../../config/environment", __FILE__)
|
9
|
+
|
3
10
|
require 'rspec'
|
4
|
-
require '
|
11
|
+
require 'rspec/rails'
|
12
|
+
#require 'djr'
|
5
13
|
|
6
14
|
# Requires supporting files with custom matchers and macros, etc,
|
7
15
|
# in ./support/ and its subdirectories.
|
8
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
16
|
+
#Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
17
|
+
|
18
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
9
19
|
|
10
20
|
RSpec.configure do |config|
|
11
21
|
|
22
|
+
config.mock_with :rspec
|
23
|
+
config.use_transactional_fixtures = true
|
24
|
+
|
12
25
|
end
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: djr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4pre
|
5
|
+
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Christiano Milfont
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152102140 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152102140
|
25
25
|
description: DJR will generate the JavaScript code from Rails Controllers to allow
|
26
26
|
browsers to securely call into Ruby code almost as if it was running locally
|
27
27
|
email:
|
@@ -35,14 +35,44 @@ files:
|
|
35
35
|
- .rspec
|
36
36
|
- Gemfile
|
37
37
|
- MIT-LICENSE.txt
|
38
|
-
- README.
|
38
|
+
- README.md
|
39
39
|
- Rakefile
|
40
40
|
- app/controllers/djr_controller.rb
|
41
|
+
- config.ru
|
42
|
+
- config/application.rb
|
43
|
+
- config/boot.rb
|
44
|
+
- config/database.yml
|
45
|
+
- config/environment.rb
|
46
|
+
- config/environments/development.rb
|
47
|
+
- config/environments/production.rb
|
48
|
+
- config/environments/test.rb
|
49
|
+
- config/initializers/backtrace_silencers.rb
|
50
|
+
- config/initializers/inflections.rb
|
51
|
+
- config/initializers/mime_types.rb
|
52
|
+
- config/initializers/secret_token.rb
|
53
|
+
- config/initializers/session_store.rb
|
54
|
+
- config/initializers/wrap_parameters.rb
|
55
|
+
- config/locales/en.yml
|
41
56
|
- config/routes.rb
|
57
|
+
- db/development.sqlite3
|
58
|
+
- db/seeds.rb
|
59
|
+
- db/test.sqlite3
|
42
60
|
- djr.gemspec
|
61
|
+
- doc/README_FOR_APP
|
62
|
+
- lib/assets/.gitkeep
|
43
63
|
- lib/djr.rb
|
44
64
|
- lib/djr/version.rb
|
45
65
|
- lib/engine.rb
|
66
|
+
- lib/tasks/.gitkeep
|
67
|
+
- log/.gitkeep
|
68
|
+
- public/404.html
|
69
|
+
- public/422.html
|
70
|
+
- public/500.html
|
71
|
+
- public/favicon.ico
|
72
|
+
- public/index.html
|
73
|
+
- public/robots.txt
|
74
|
+
- script/rails
|
75
|
+
- spec/djr_controller_spec.rb
|
46
76
|
- spec/djr_spec.rb
|
47
77
|
- spec/spec_helper.rb
|
48
78
|
- vendor/assets/javascripts/djr.js
|
@@ -61,9 +91,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
92
|
none: false
|
63
93
|
requirements:
|
64
|
-
- - ! '
|
94
|
+
- - ! '>'
|
65
95
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
96
|
+
version: 1.3.1
|
67
97
|
requirements: []
|
68
98
|
rubyforge_project: djr
|
69
99
|
rubygems_version: 1.8.10
|
@@ -71,5 +101,6 @@ signing_key:
|
|
71
101
|
specification_version: 3
|
72
102
|
summary: Direct Jquery Remoting
|
73
103
|
test_files:
|
104
|
+
- spec/djr_controller_spec.rb
|
74
105
|
- spec/djr_spec.rb
|
75
106
|
- spec/spec_helper.rb
|
data/README.rdoc
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
= djr
|
2
|
-
|
3
|
-
DJR will generate the JavaScript code from Rails Controllers to allow browsers to securely call into Ruby code almost as if it was running locally
|
4
|
-
|
5
|
-
## Getting started
|
6
|
-
|
7
|
-
Add it to your Gemfile with:
|
8
|
-
gem 'djr'
|
9
|
-
|
10
|
-
Run the bundle command to install it.
|
11
|
-
|
12
|
-
Configure assets in app/assets/application.js file:
|
13
|
-
|
14
|
-
//= require jquery
|
15
|
-
//= require djr
|
16
|
-
//= require_tree .
|
17
|
-
|
18
|
-
Import script in your pages:
|
19
|
-
|
20
|
-
<script type="text/javascript" charset="utf-8" src="/djr"></script>
|
21
|
-
|
22
|
-
In javascript, call your Controller like:
|
23
|
-
|
24
|
-
productsController = new ProductsController
|
25
|
-
productsController.save({
|
26
|
-
name: "IPhone 4s",
|
27
|
-
value: "500.00"
|
28
|
-
}, callbackFunction);
|
29
|
-
|
30
|
-
## Conventions
|
31
|
-
|
32
|
-
controller.action( dataAsJson, callbackFunction, errorHandler );
|
33
|
-
|
34
|
-
== Contributing to djr
|
35
|
-
|
36
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
37
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
38
|
-
* Fork the project.
|
39
|
-
* Start a feature/bugfix branch.
|
40
|
-
* Commit and push until you are happy with your contribution.
|
41
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
42
|
-
* 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.
|
43
|
-
|
44
|
-
## License
|
45
|
-
|
46
|
-
MIT License. Copyright (c) 2012 Milfont Consulting. http://milfont.org
|