poke_js 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/poke_js.js +48 -0
- data/app/views/layouts/application.js.erb +7 -0
- data/lib/poke_js.rb +12 -0
- data/lib/poke_js/version.rb +3 -0
- data/lib/poke_js/view_helpers.rb +66 -0
- data/poke_js.gemspec +19 -0
- metadata +58 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 s12chung
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# PokeJs
|
2
|
+
|
3
|
+
Moves all javascript into assets js files using the [Garber-Irish Implementation](http://viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready-execution).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'poke_js'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install poke_js
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To be written
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
//http://stackoverflow.com/questions/6167805/using-rails-3-1-where-do-you-put-your-page-specific-javascript-code
|
2
|
+
POKE = {
|
3
|
+
blank: function(o) {
|
4
|
+
return typeof o === "undefined" || o === null;
|
5
|
+
},
|
6
|
+
present: function(o) {
|
7
|
+
return !POKE.blank(o);
|
8
|
+
},
|
9
|
+
get_or_create: function(namespace, o) {
|
10
|
+
if (POKE.blank(o))
|
11
|
+
o = APP;
|
12
|
+
if (POKE.blank(o[namespace]))
|
13
|
+
o[namespace] = {};
|
14
|
+
return o[namespace];
|
15
|
+
},
|
16
|
+
define: function(namespace, hash, o) {
|
17
|
+
var o_namespace = POKE.get_or_create(namespace, o);
|
18
|
+
$.extend(o_namespace, hash);
|
19
|
+
},
|
20
|
+
|
21
|
+
|
22
|
+
exec_all: function(controller, format, action) {
|
23
|
+
POKE.exec("app", format);
|
24
|
+
POKE.exec(controller, format);
|
25
|
+
POKE.exec(controller, format, action);
|
26
|
+
},
|
27
|
+
exec: function(controller, format, action) {
|
28
|
+
var ns = APP,
|
29
|
+
action = (action === undefined) ? "init" : action;
|
30
|
+
|
31
|
+
if (controller !== "" && ns[controller] &&
|
32
|
+
format !== "" && ns[controller][format]) {
|
33
|
+
var funct = ns[controller][format][action],
|
34
|
+
params = ns[controller][format][action + "_params"];
|
35
|
+
|
36
|
+
if ($.isFunction(funct))
|
37
|
+
funct(params);
|
38
|
+
}
|
39
|
+
},
|
40
|
+
init: function() {
|
41
|
+
var $body = $('body');
|
42
|
+
POKE.exec_all($body.data("controller"), "html", $body.data("action"));
|
43
|
+
}
|
44
|
+
};
|
45
|
+
|
46
|
+
if (POKE.blank(window["APP"]))
|
47
|
+
APP = {};
|
48
|
+
$(POKE.init);
|
data/lib/poke_js.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "poke_js/version"
|
2
|
+
require "poke_js/view_helpers"
|
3
|
+
|
4
|
+
module PokeJs
|
5
|
+
if defined?(Rails) && defined?(Rails::Engine)
|
6
|
+
class Engine < ::Rails::Engine
|
7
|
+
initializer "poke_js.view_helpers" do
|
8
|
+
ActionView::Base.send :include, ViewHelpers
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module PokeJs
|
2
|
+
module ViewHelpers
|
3
|
+
#http://stackoverflow.com/questions/339130/how-do-i-render-a-partial-of-a-different-format-in-rails
|
4
|
+
def with_format(format, &block)
|
5
|
+
old_formats = formats
|
6
|
+
self.formats = [format]
|
7
|
+
result = block.call
|
8
|
+
self.formats = old_formats
|
9
|
+
result
|
10
|
+
end
|
11
|
+
|
12
|
+
def poke_js_template
|
13
|
+
extract_template(@poke_js_template)
|
14
|
+
end
|
15
|
+
|
16
|
+
def with_template(template)
|
17
|
+
old_template = @poke_js_template
|
18
|
+
@poke_js_template = template
|
19
|
+
yield
|
20
|
+
@poke_js_template = old_template
|
21
|
+
end
|
22
|
+
|
23
|
+
def poke(template=@poke_js_template, format=formats.first)
|
24
|
+
controller, action = extract_template(template)
|
25
|
+
poke_lambda = -> do
|
26
|
+
if format == :html
|
27
|
+
with_format(:js) do
|
28
|
+
if lookup_context.template_exists? "#{controller}/#{action}_params"
|
29
|
+
javascript_tag do
|
30
|
+
raw %Q/
|
31
|
+
APP.#{controller}.html.#{action}_params = #{ render :template => "#{controller}/#{action}_params" };
|
32
|
+
/
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
elsif format == :js
|
37
|
+
content_for :head do
|
38
|
+
javascript_tag do
|
39
|
+
render :template => "#{controller}/#{action}", :formats => [:js], :layout => "layouts/application"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
if template != @poke_js_template
|
46
|
+
with_template(template) { poke_lambda.call }
|
47
|
+
else
|
48
|
+
poke_lambda.call
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def extract_template(template)
|
54
|
+
extracted_template = [controller_name, action_name]
|
55
|
+
if template
|
56
|
+
array = template.class == Array ? template : template.to_s.split('/')
|
57
|
+
if array.size == 1
|
58
|
+
extracted_template[1] = array.first
|
59
|
+
else
|
60
|
+
extracted_template = array
|
61
|
+
end
|
62
|
+
end
|
63
|
+
extracted_template
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/poke_js.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'poke_js/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "poke_js"
|
8
|
+
gem.version = PokeJs::VERSION
|
9
|
+
gem.authors = ["s12chung"]
|
10
|
+
gem.email = ["steve@placemarklist.com"]
|
11
|
+
gem.description = %q{ Moves all javascript into assets js files using the Garber-Irish Implementation }
|
12
|
+
gem.summary = %q{ Moves all javascript into assets js files using the Garber-Irish Implementation }
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: poke_js
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- s12chung
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-27 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! ' Moves all javascript into assets js files using the Garber-Irish
|
15
|
+
Implementation '
|
16
|
+
email:
|
17
|
+
- steve@placemarklist.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- app/assets/javascripts/poke_js.js
|
28
|
+
- app/views/layouts/application.js.erb
|
29
|
+
- lib/poke_js.rb
|
30
|
+
- lib/poke_js/version.rb
|
31
|
+
- lib/poke_js/view_helpers.rb
|
32
|
+
- poke_js.gemspec
|
33
|
+
homepage: ''
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.24
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: Moves all javascript into assets js files using the Garber-Irish Implementation
|
57
|
+
test_files: []
|
58
|
+
has_rdoc:
|