pluggable_js 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +16 -17
- data/features/support/env.rb +2 -0
- data/lib/generators/pluggable_js/pluggable_js_generator.rb +1 -1
- data/lib/generators/pluggable_js/templates/large_piece_of_code.js.coffee +5 -0
- data/lib/pluggable_js/helpers.rb +9 -0
- data/lib/pluggable_js/version.rb +1 -1
- data/pluggable_js.gemspec +1 -1
- data/test/dummy/app/assets/javascripts/pluggable/posts/new.js.coffee +3 -9
- data/test/dummy/app/assets/javascripts/posts.js.coffee +0 -2
- metadata +4 -6
- data/lib/generators/pluggable_js/templates/function_caller.js.coffee +0 -11
- data/test/dummy/app/assets/javascripts/pluggable/posts/index.js.coffee +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72eae7575c4a5d7e5e9f844695c8590ed6c2aac5
|
4
|
+
data.tar.gz: e8b110e7d310a1c60e4819e556a7e9df5054e63e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4fcc8b5881f6d09c806abc555438b91d83cd5199ba29ed2821d317412ed67bbcb024858bfa377883103eb5c8a80f27f62d628c95e8c543b0dfc72176db3e057
|
7
|
+
data.tar.gz: 50da9bbabcc78c673d66a4380a3ff5f448df812bc695677f33eec36b0c99a22a5ffb81c9d1e488d146574adf30cfa59a91a5641a2a07ce56755a5f68364c7325
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,28 +1,21 @@
|
|
1
|
-
# PluggableJs
|
2
1
|
|
3
|
-
|
2
|
+
# PluggableJs
|
4
3
|
|
5
|
-
This gem provides simple functionality of loading
|
4
|
+
This gem provides simple functionality of loading page specific javascript (for Rails >= 3.1 with asset pipeline enabled). Keep desired js code in controller related files as action based functions. They will be triggered only when matching controller and action parameters.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
3. Add `pluggable/*` to assets precompile configuration in production.rb (and staging.rb if you have one), e.g.: `config.assets.precompile += %w(pluggable/*)`
|
12
|
-
4. Be sure that `pluggable` folder is out of `require_tree` statement in application.js
|
8
|
+
* Add `gem 'pluggable_js'` to Gemfile and run `bundle` command to install it
|
9
|
+
* Add `<%= javascript_pluggable_tag %>` to application layout file after `<%= javascript_include_tag 'application' %>` line
|
13
10
|
|
14
|
-
|
11
|
+
Next steps are necessary only if you want to use generator for large pieces of js code (see usage):
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
rails generate pluggable_js Post index new
|
13
|
+
* Add `pluggable/*` to assets precompile configuration in production.rb (and staging.rb if you have one), e.g.: `config.assets.precompile += %w(pluggable/*)`
|
14
|
+
* Be sure that `pluggable` folder is out of `require_tree` statement in application.js
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
app/assets/javascripts/pluggable/posts/index.js.coffee
|
23
|
-
app/assets/javascripts/pluggable/posts/new.js.coffee
|
16
|
+
## Usage
|
24
17
|
|
25
|
-
|
18
|
+
Simply define functions in your controller related file (e.g. posts.js.coffee) like so:
|
26
19
|
|
27
20
|
```coffeescript
|
28
21
|
window.Post ||= {}
|
@@ -31,8 +24,14 @@ Post.index = () ->
|
|
31
24
|
Post.new = () ->
|
32
25
|
# and here
|
33
26
|
```
|
27
|
+
Or, in rare cases, if you have large piece of code (maybe external lib) that you don't want to define as a function, choose controller and actions you want to use and run generator, e.g.:
|
28
|
+
|
29
|
+
rails generate pluggable_js Post index new
|
34
30
|
|
35
|
-
|
31
|
+
It will create two files where you may add your code (don't forget to follow necessary installation steps):
|
32
|
+
|
33
|
+
app/assets/javascripts/pluggable/posts/index.js.coffee
|
34
|
+
app/assets/javascripts/pluggable/posts/new.js.coffee
|
36
35
|
|
37
36
|
## Config
|
38
37
|
|
data/features/support/env.rb
CHANGED
@@ -6,7 +6,7 @@ class PluggableJsGenerator < Rails::Generators::Base
|
|
6
6
|
def create_pluggable_js_files
|
7
7
|
actions.each do |action|
|
8
8
|
@action = action
|
9
|
-
template '
|
9
|
+
template 'large_piece_of_code.js.coffee', File.join('app/assets/javascripts/pluggable', controller_name, "#{action}.js.coffee")
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
data/lib/pluggable_js/helpers.rb
CHANGED
@@ -1,12 +1,21 @@
|
|
1
1
|
module PluggableJs
|
2
2
|
module Helpers
|
3
3
|
|
4
|
+
# if file exists – include it, else – call function
|
4
5
|
def javascript_pluggable_tag
|
5
6
|
controller = params[:controller]
|
6
7
|
action = define_pair_action
|
7
8
|
|
8
9
|
if File.exist?(Rails.root + "app/assets/javascripts/pluggable/#{controller}/#{action}.js.coffee")
|
9
10
|
javascript_include_tag "pluggable/#{controller}/#{action}"
|
11
|
+
else
|
12
|
+
object = controller.classify
|
13
|
+
|
14
|
+
javascript_tag "jQuery(function() {
|
15
|
+
if (typeof(#{object}) == 'object' && typeof(#{object}.#{action}) == 'function') {
|
16
|
+
return #{object}.#{action}();
|
17
|
+
}
|
18
|
+
});"
|
10
19
|
end
|
11
20
|
end
|
12
21
|
|
data/lib/pluggable_js/version.rb
CHANGED
data/pluggable_js.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = PluggableJs::VERSION
|
9
9
|
spec.authors = ['Andrey Peresleguine']
|
10
10
|
spec.email = ['peresleguine@gmail.com']
|
11
|
-
spec.description = %q{Convention of how to load
|
11
|
+
spec.description = %q{Convention of how to load page specific javascript based on controller and action parameters.}
|
12
12
|
spec.summary = %q{Pluggable javascript.}
|
13
13
|
spec.homepage = 'https://github.com/peresleguine/pluggable_js'
|
14
14
|
spec.license = 'MIT'
|
@@ -1,11 +1,5 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# window.Post ||= {}
|
4
|
-
# Post.new = () ->
|
5
|
-
# # your code goes here
|
1
|
+
# This file is used only for large piece of js code that you
|
2
|
+
# don't want to define as a function in controller related js file.
|
6
3
|
|
7
4
|
jQuery ->
|
8
|
-
|
9
|
-
# only if this filepath matches current
|
10
|
-
# controller and action parameters
|
11
|
-
Post.new()
|
5
|
+
$('.marine-quote').text('You wanna piece of me, boy?')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluggable_js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Peresleguine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coffee-rails
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
- - '>='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
-
description: Convention of how to load
|
139
|
+
description: Convention of how to load page specific javascript based on controller
|
140
140
|
and action parameters.
|
141
141
|
email:
|
142
142
|
- peresleguine@gmail.com
|
@@ -155,7 +155,7 @@ files:
|
|
155
155
|
- features/support/env.rb
|
156
156
|
- lib/generators/pluggable_js/USAGE
|
157
157
|
- lib/generators/pluggable_js/pluggable_js_generator.rb
|
158
|
-
- lib/generators/pluggable_js/templates/
|
158
|
+
- lib/generators/pluggable_js/templates/large_piece_of_code.js.coffee
|
159
159
|
- lib/pluggable_js.rb
|
160
160
|
- lib/pluggable_js/config.rb
|
161
161
|
- lib/pluggable_js/helpers.rb
|
@@ -166,7 +166,6 @@ files:
|
|
166
166
|
- test/dummy/Rakefile
|
167
167
|
- test/dummy/app/assets/images/.keep
|
168
168
|
- test/dummy/app/assets/javascripts/application.js
|
169
|
-
- test/dummy/app/assets/javascripts/pluggable/posts/index.js.coffee
|
170
169
|
- test/dummy/app/assets/javascripts/pluggable/posts/new.js.coffee
|
171
170
|
- test/dummy/app/assets/javascripts/posts.js.coffee
|
172
171
|
- test/dummy/app/assets/stylesheets/application.css
|
@@ -239,7 +238,6 @@ test_files:
|
|
239
238
|
- test/dummy/Rakefile
|
240
239
|
- test/dummy/app/assets/images/.keep
|
241
240
|
- test/dummy/app/assets/javascripts/application.js
|
242
|
-
- test/dummy/app/assets/javascripts/pluggable/posts/index.js.coffee
|
243
241
|
- test/dummy/app/assets/javascripts/pluggable/posts/new.js.coffee
|
244
242
|
- test/dummy/app/assets/javascripts/posts.js.coffee
|
245
243
|
- test/dummy/app/assets/stylesheets/application.css
|
@@ -1,11 +0,0 @@
|
|
1
|
-
# Define somewhere in your controller related js file (e.g. <%= controller_name %>.js.coffee):
|
2
|
-
#
|
3
|
-
# window.<%= model_name %> ||= {}
|
4
|
-
# <%= model_name %>.<%= @action %> = () ->
|
5
|
-
# # your code goes here
|
6
|
-
|
7
|
-
jQuery ->
|
8
|
-
# whatever you want will be triggered from here
|
9
|
-
# only if this filepath matches current
|
10
|
-
# controller and action parameters
|
11
|
-
<%= model_name %>.<%= @action %>()
|
@@ -1,11 +0,0 @@
|
|
1
|
-
# Define somewhere in your controller related js file (e.g. posts.js.coffee):
|
2
|
-
#
|
3
|
-
# window.Post ||= {}
|
4
|
-
# Post.index = () ->
|
5
|
-
# # your code goes here
|
6
|
-
|
7
|
-
jQuery ->
|
8
|
-
# whatever you want will be triggered from here
|
9
|
-
# only if this filepath matches current
|
10
|
-
# controller and action parameters
|
11
|
-
Post.index()
|