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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6817aa80ad45a4ecc1698a6810bc46c37b60cfd0
4
- data.tar.gz: 329eb1d15fb3a57f487322ee15040b113eabe7a4
3
+ metadata.gz: 72eae7575c4a5d7e5e9f844695c8590ed6c2aac5
4
+ data.tar.gz: e8b110e7d310a1c60e4819e556a7e9df5054e63e
5
5
  SHA512:
6
- metadata.gz: ffd735361c98f0a9b6122c9b642efa680011f35349001aed3633267e63115b18e28b6dd649f2315aa05c6502464a08c3981531f2807629e14197f4ce93a21175
7
- data.tar.gz: 93473f70466749116f88366280ab4b6793b03c226abd5ae42ccd9819fe2841a716e992b3eb948d31c7b2686cde684087236ece42bbc09e03292380243178ac8a
6
+ metadata.gz: a4fcc8b5881f6d09c806abc555438b91d83cd5199ba29ed2821d317412ed67bbcb024858bfa377883103eb5c8a80f27f62d628c95e8c543b0dfc72176db3e057
7
+ data.tar.gz: 50da9bbabcc78c673d66a4380a3ff5f448df812bc695677f33eec36b0c99a22a5ffb81c9d1e488d146574adf30cfa59a91a5641a2a07ce56755a5f68364c7325
data/CHANGELOG.md CHANGED
@@ -20,4 +20,8 @@
20
20
 
21
21
  ## v0.0.4
22
22
 
23
- * added necessary folders to gitignore for dummy app
23
+ * added necessary folders to gitignore for dummy app
24
+
25
+ ## v0.0.5
26
+
27
+ * improved function call, left generator only for large js files
data/README.md CHANGED
@@ -1,28 +1,21 @@
1
- # PluggableJs
2
1
 
3
- Sometimes you need to use javascript only in specific pages, but you don't want to change DOM or write code in a view. Maybe you have one container with the same class in different templates, but part of bound logic is needed only in one. Or maybe some javascript causes exceptions in other views.
2
+ # PluggableJs
4
3
 
5
- This gem provides simple functionality of loading javascript only in certain pages based on controller and action parameters. Keep your js code in controller related files as action based functions (still in asset pipeline). It will be triggered only if needed.
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
- 1. Add `gem 'pluggable_js'` to Gemfile and run `bundle` command to install it
10
- 2. Add `<%= javascript_pluggable_tag %>` to application layout file after `<%= javascript_include_tag 'application' %>` line
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
- ## Usage
11
+ Next steps are necessary only if you want to use generator for large pieces of js code (see usage):
15
12
 
16
- Choose controller and actions you want to use for pluggable js and run generator, e.g.:
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
- It will create two files (just function callers):
21
-
22
- app/assets/javascripts/pluggable/posts/index.js.coffee
23
- app/assets/javascripts/pluggable/posts/new.js.coffee
16
+ ## Usage
24
17
 
25
- Now you simply have to define `Post.index` and `Post.new` functions in posts.js.coffee:
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
- They will be triggered only when matching controller and action parameters.
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
 
@@ -1,4 +1,6 @@
1
1
  require 'bundler'
2
+ require 'coffee_script'
3
+
2
4
  begin
3
5
  Bundler.setup(:default, :development)
4
6
  rescue Bundler::BundlerError => e
@@ -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 'function_caller.js.coffee', File.join('app/assets/javascripts/pluggable', controller_name, "#{action}.js.coffee")
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
 
@@ -0,0 +1,5 @@
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.
3
+
4
+ # jQuery ->
5
+ # # your code goes here
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module PluggableJs
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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 javascript only in certain pages based on controller and action parameters.}
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
- # Define somewhere in your controller related js file (e.g. posts.js.coffee):
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
- # whatever you want will be triggered from here
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?')
@@ -1,5 +1,3 @@
1
1
  window.Post ||= {}
2
2
  Post.index = () ->
3
3
  $('.zealot-quote').text('My life for aiur!')
4
- 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
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-05 00:00:00.000000000 Z
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 javascript only in certain pages based on controller
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/function_caller.js.coffee
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()