djr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "rails", "~> 3.2.0"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "rspec", "~> 2.8.0"
12
+ gem "rdoc", "3.12"
13
+ gem "bundler", "1.0.21"
14
+ # gem "jeweler", "~> 1.8.3"
15
+ gem "rcov", ">= 0"
16
+ end
data/MIT-LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ MIT License. Copyright (c) 2012 Milfont Consulting. http://milfont.org
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,17 @@
1
+ = djr
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to djr
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
+ ## License
16
+
17
+ MIT License. Copyright (c) 2012 Milfont Consulting. http://milfont.org
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ class DjrController < ApplicationController
2
+
3
+ def djr
4
+
5
+ routeSet = Rails.application.routes
6
+ routes = routeSet.routes
7
+
8
+ js = ""
9
+
10
+ js << routes.map { |route| route.defaults[:controller]}.uniq.compact.map { |route|
11
+ route_str = ""
12
+ controller_name = "#{route.camelize.gsub(/\:\:/, '.')}Controller"
13
+ if m = controller_name.match(/\./)
14
+ route_str << "if(!#{m.pre_match}) { var #{m.pre_match} = {}; }; "
15
+ end
16
+ route_str << "#{controller_name} = function(){DJR.call(this);}; #{controller_name}.prototype.routes = {};"
17
+ }.compact.join
18
+
19
+ js << routes.map { |route|
20
+ method = route.conditions[:request_method].present? ? route.conditions[:request_method].source[1..-2] : "GET"
21
+ controller_name = "#{route.defaults[:controller].camelize.gsub(/\:\:/, '.')}Controller"
22
+ " #{controller_name}.prototype.routes['#{route.defaults[:action]}'] = {url: \"#{route.path}\", method: \"#{method}\" };"
23
+ }.compact.join
24
+
25
+ render :text => js.to_s
26
+
27
+ end
28
+
29
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+
3
+ get "djr" => "djr#djr"
4
+ #match '/djr' => 'djr#djr', :via => :get
5
+
6
+ end
data/djr.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "djr/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "djr"
7
+ s.version = Djr::VERSION
8
+ s.authors = ["Christiano Milfont"]
9
+ s.email = ["cmilfont@gmail.com"]
10
+ s.homepage = "https://github.com/milfont/djr"
11
+ s.summary = %q{Direct Jquery Remoting}
12
+ s.description = %q{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}
13
+
14
+ s.rubyforge_project = "djr"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency('railties', '>= 3.1.0')
22
+
23
+ # specify any dependencies here; for example:
24
+ # s.add_development_dependency "rspec"
25
+ # s.add_runtime_dependency "rest-client"
26
+ end
@@ -0,0 +1,3 @@
1
+ module Djr
2
+ VERSION = "0.0.1"
3
+ end
data/lib/djr.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "djr/version"
2
+
3
+ module Djr
4
+ require 'engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
5
+ end
data/lib/engine.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'rails'
2
+
3
+ module Djr
4
+ class Engine < Rails::Engine
5
+
6
+
7
+ # Load rake tasks
8
+ #rake_tasks do
9
+ # load File.join(File.dirname(__FILE__), 'rails/railties/tasks.rake')
10
+ #end
11
+
12
+ # Check the gem config
13
+ #initializer "check config" do |app|
14
+ # make sure mount_at ends with trailing slash
15
+ # config.mount_at += '/' unless config.mount_at.last == '/'
16
+ #end
17
+
18
+ #initializer "static assets" do |app|
19
+ # app.middleware.use ::ActionDispatch::Static, "#{root}/public"
20
+ #end
21
+
22
+ end
23
+ end
data/spec/djr_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Djr" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'djr'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,76 @@
1
+ function toMap(object) {
2
+ var arr = [];
3
+ for(var item in object)
4
+ arr[arr.length] = {key: item, value: object[item]};
5
+ return arr;
6
+ };
7
+
8
+ var DJR = function() {
9
+ this.data = "";
10
+ this.error = {};
11
+ this.format = ".json";
12
+
13
+ this.formatURL = function(url, params) {
14
+ toMap(params).forEach( function(param) {
15
+ url = url.replace((new RegExp(param.key)).source, param.value);
16
+ });
17
+ return url;
18
+ };
19
+ this.callbackDefault = function(data) {
20
+ this.data = data;
21
+ };
22
+ this.errorDefault = function(error) {
23
+ this.error = error;
24
+ };
25
+ this.ajax = function(object, callback, error, method, url, params) {
26
+ var self = this;
27
+ var params = params || [];
28
+ params["\(.:format\)"] = this.format;
29
+
30
+ if(method === "")
31
+ method = "GET";
32
+
33
+ toMap(object).forEach( function(param) {
34
+ params[":" + param.key] = param.value;
35
+ });
36
+ if(method !== "GET") {
37
+ object = JSON.stringify(object);
38
+ if (object && object.length === 2)
39
+ object = null;
40
+ }
41
+ if(method === "DELETE") object = null;
42
+
43
+ jQuery.ajax({
44
+ context : self,
45
+ data : object,
46
+ cache : false,
47
+ dataType : 'json',
48
+ error : error,
49
+ success : callback,
50
+ contentType : "application/json",
51
+ headers : {"Content-Type":"application/json", "Accept":"application/json"},
52
+ type : method,
53
+ url : this.formatURL(url, params) + "?authenticity_token=" + $("meta[name='csrf-token']").attr("content")
54
+ });
55
+ };
56
+ for (var action in this.routes) {
57
+ this[action] = function(act) {
58
+ return function(object, callback, error) {
59
+ if(typeof object === "function") {
60
+ callback = object;
61
+ error = callback;
62
+ object = {};
63
+ }
64
+ var localCallback = callback || this.callbackDefault;
65
+ var localErrorHandler = error || this.errorDefault;
66
+ this.ajax(object,
67
+ localCallback,
68
+ localErrorHandler,
69
+ this.routes[act].method,
70
+ this.routes[act].url);
71
+ return this;
72
+ }
73
+ }(action);
74
+ }
75
+
76
+ };
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: djr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christiano Milfont
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-20 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: &2152632480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2152632480
25
+ description: DJR will generate the JavaScript code from Rails Controllers to allow
26
+ browsers to securely call into Ruby code almost as if it was running locally
27
+ email:
28
+ - cmilfont@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .document
34
+ - .gitignore
35
+ - .rspec
36
+ - Gemfile
37
+ - MIT-LICENSE.txt
38
+ - README.rdoc
39
+ - Rakefile
40
+ - app/controllers/djr_controller.rb
41
+ - config/routes.rb
42
+ - djr.gemspec
43
+ - lib/djr.rb
44
+ - lib/djr/version.rb
45
+ - lib/engine.rb
46
+ - spec/djr_spec.rb
47
+ - spec/spec_helper.rb
48
+ - vendor/assets/javascripts/djr.js
49
+ homepage: https://github.com/milfont/djr
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project: djr
69
+ rubygems_version: 1.8.10
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Direct Jquery Remoting
73
+ test_files:
74
+ - spec/djr_spec.rb
75
+ - spec/spec_helper.rb