rails_script 0.2.0 → 0.3.0
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/README.md +4 -0
 - data/include_rails_script.js.coffee +2 -33
 - data/lib/generators/rails_script/class/templates/javascript.js.coffee +0 -1
 - data/lib/generators/rails_script/element/templates/javascript.js.coffee +1 -1
 - data/lib/generators/rails_script/install/templates/base.js.coffee +23 -1
 - data/lib/generators/rails_script/utility/templates/javascript.js.coffee +0 -1
 - data/lib/rails_script/loader_helper.rb +10 -2
 - data/lib/rails_script/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 2d9958511d98ea471627dc977879e6d035c35898
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 25902692ba8bb9c73879b978090a30cc26440668
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 3bae329972b4ade7e5f3ec70ec9a681b9b06f3c1d3a86c9d39bde356af002715e4a919f973a36c0f089aed29ed19ba1646cf3ec201b5078cec956f3186d483d9
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 26a1d353e5466280a883128165935bd41f7baa25b322625d548a71531d171f70309ceb0faf77533359b357feec44846adfc02b2db52f9716f6237f23e8706159
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -280,6 +280,10 @@ class App.MyClassName 
     | 
|
| 
       280 
280 
     | 
    
         | 
| 
       281 
281 
     | 
    
         
             
            ```
         
     | 
| 
       282 
282 
     | 
    
         | 
| 
      
 283 
     | 
    
         
            +
            ### Passing Rails Variables
         
     | 
| 
      
 284 
     | 
    
         
            +
             
     | 
| 
      
 285 
     | 
    
         
            +
            To pass data from Rails to JavaScript, just define ```@to_javascript```.  This is then converted to a JSON object with ```@to_javascript.to_json``` and can be accessed with ```Utility.RailsVars```.
         
     | 
| 
      
 286 
     | 
    
         
            +
             
     | 
| 
       283 
287 
     | 
    
         | 
| 
       284 
288 
     | 
    
         
             
            ### Events
         
     | 
| 
       285 
289 
     | 
    
         | 
| 
         @@ -1,40 +1,9 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            window.Utility || (window.Utility = {});
         
     | 
| 
       2 
2 
     | 
    
         
             
            Utility.RailsVars = #{@to_javascript.nil? ? '{}' : @to_javascript.to_json};
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
            function() {
         
     | 
| 
       5 
5 
     | 
    
         
             
              window.$this = new (App.#{ controller_path.split(/\/|_/).map(&:capitalize).join('') } || App.Base)();
         
     | 
| 
       6 
6 
     | 
    
         
             
              if (typeof $this.#{ action_name } === 'function') {
         
     | 
| 
       7 
7 
     | 
    
         
             
                return $this.#{ action_name }.call();
         
     | 
| 
       8 
8 
     | 
    
         
             
              }
         
     | 
| 
       9 
     | 
    
         
            -
            } 
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            jQuery(document).on('page:before-change', function() {
         
     | 
| 
       12 
     | 
    
         
            -
              var element, handler, handlers, type, _i, _len, _ref, _results;
         
     | 
| 
       13 
     | 
    
         
            -
              _ref = [window, document];
         
     | 
| 
       14 
     | 
    
         
            -
              _results = [];
         
     | 
| 
       15 
     | 
    
         
            -
              for (_i = 0, _len = _ref.length; _i < _len; _i++) {
         
     | 
| 
       16 
     | 
    
         
            -
                element = _ref[_i];
         
     | 
| 
       17 
     | 
    
         
            -
                _results.push((function() {
         
     | 
| 
       18 
     | 
    
         
            -
                  var _ref2, _results2;
         
     | 
| 
       19 
     | 
    
         
            -
                  _ref2 = jQuery._data(element, 'events');
         
     | 
| 
       20 
     | 
    
         
            -
                  _results2 = [];
         
     | 
| 
       21 
     | 
    
         
            -
                  for (type in _ref2) {
         
     | 
| 
       22 
     | 
    
         
            -
                    handlers = _ref2[type];
         
     | 
| 
       23 
     | 
    
         
            -
                    _results2.push((function() {
         
     | 
| 
       24 
     | 
    
         
            -
                      var _j, _len2, _results3;
         
     | 
| 
       25 
     | 
    
         
            -
                      _results3 = [];
         
     | 
| 
       26 
     | 
    
         
            -
                      for (_j = 0, _len2 = handlers.length; _j < _len2; _j++) {
         
     | 
| 
       27 
     | 
    
         
            -
                        handler = handlers[_j];
         
     | 
| 
       28 
     | 
    
         
            -
                        if (handler == null) {
         
     | 
| 
       29 
     | 
    
         
            -
                          continue;
         
     | 
| 
       30 
     | 
    
         
            -
                        }
         
     | 
| 
       31 
     | 
    
         
            -
                        _results3.push(handler.namespace === '' ? $(element).off(type, handler.handler) : void 0);
         
     | 
| 
       32 
     | 
    
         
            -
                      }
         
     | 
| 
       33 
     | 
    
         
            -
                      return _results3;
         
     | 
| 
       34 
     | 
    
         
            -
                    })());
         
     | 
| 
       35 
     | 
    
         
            -
                  }
         
     | 
| 
       36 
     | 
    
         
            -
                  return _results2;
         
     | 
| 
       37 
     | 
    
         
            -
                })());
         
     | 
| 
       38 
     | 
    
         
            -
              }
         
     | 
| 
       39 
     | 
    
         
            -
              return _results;
         
     | 
| 
       40 
     | 
    
         
            -
            });
         
     | 
| 
      
 9 
     | 
    
         
            +
            };
         
     | 
| 
         @@ -2,14 +2,36 @@ window.App ||= {} 
     | 
|
| 
       2 
2 
     | 
    
         
             
            class App.Base
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
              constructor: ->
         
     | 
| 
      
 5 
     | 
    
         
            +
                if (window.jQuery) then @setClearEventHandlers() # clearing application event handlers only possible with jQuery
         
     | 
| 
       5 
6 
     | 
    
         
             
                return this
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
8 
     | 
    
         | 
| 
      
 9 
     | 
    
         
            +
              ###
         
     | 
| 
      
 10 
     | 
    
         
            +
              Run the new action for the create action.  Generally the create action will 'render :new' if there was a problem.
         
     | 
| 
      
 11 
     | 
    
         
            +
              This prevents doubling the code for each action.
         
     | 
| 
      
 12 
     | 
    
         
            +
              ###
         
     | 
| 
       8 
13 
     | 
    
         
             
              create: ->
         
     | 
| 
       9 
14 
     | 
    
         
             
                if typeof $this.new == 'function'
         
     | 
| 
       10 
15 
     | 
    
         
             
                  return $this.new()
         
     | 
| 
       11 
16 
     | 
    
         | 
| 
       12 
17 
     | 
    
         | 
| 
      
 18 
     | 
    
         
            +
              ###
         
     | 
| 
      
 19 
     | 
    
         
            +
              Run the edit action for the update action.  Generally the update action will 'render :edit' if there was a problem.
         
     | 
| 
      
 20 
     | 
    
         
            +
              This prevents doubling the code for each action.
         
     | 
| 
      
 21 
     | 
    
         
            +
              ###
         
     | 
| 
       13 
22 
     | 
    
         
             
              update: ->
         
     | 
| 
       14 
23 
     | 
    
         
             
                if typeof $this.edit == 'function'
         
     | 
| 
       15 
     | 
    
         
            -
                  return $this.edit()
         
     | 
| 
      
 24 
     | 
    
         
            +
                  return $this.edit()
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              ###
         
     | 
| 
      
 28 
     | 
    
         
            +
              Clear event handlers with a blank namespace.  This will prevent window and document event handlers from stacking
         
     | 
| 
      
 29 
     | 
    
         
            +
              when each new page is fetched.  Adding a namespace to your events will prevent them from being removed between page
         
     | 
| 
      
 30 
     | 
    
         
            +
              loads, i.e. "$(window).on 'scroll.app', myHandler"
         
     | 
| 
      
 31 
     | 
    
         
            +
              ###
         
     | 
| 
      
 32 
     | 
    
         
            +
              clearEventHandlers: ->
         
     | 
| 
      
 33 
     | 
    
         
            +
                jQuery(document).on 'page:before-change', ->
         
     | 
| 
      
 34 
     | 
    
         
            +
                  for element in [window, document]
         
     | 
| 
      
 35 
     | 
    
         
            +
                    for event, handlers in jQuery._data(element, 'events')
         
     | 
| 
      
 36 
     | 
    
         
            +
                      for handler in handlers
         
     | 
| 
      
 37 
     | 
    
         
            +
                        if handler.namespace == '' then $(element).off event, handler.handler
         
     | 
| 
         @@ -3,8 +3,16 @@ module RailsScript 
     | 
|
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
                def include_rails_script
         
     | 
| 
       5 
5 
     | 
    
         
             
                  javascript_tag <<-RUBY
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
            window.Utility || (window.Utility = {});
         
     | 
| 
      
 7 
     | 
    
         
            +
            Utility.RailsVars = #{@to_javascript.nil? ? '{}' : @to_javascript.to_json};
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            (function() {
         
     | 
| 
      
 10 
     | 
    
         
            +
              window.$this = new (App.#{ controller_path.split(/\/|_/).map(&:capitalize).join('') } || App.Base)();
         
     | 
| 
      
 11 
     | 
    
         
            +
              if (typeof $this.#{ action_name } === 'function') {
         
     | 
| 
      
 12 
     | 
    
         
            +
                return $this.#{ action_name }.call();
         
     | 
| 
      
 13 
     | 
    
         
            +
              }
         
     | 
| 
      
 14 
     | 
    
         
            +
            })();
         
     | 
| 
      
 15 
     | 
    
         
            +
            RUBY
         
     | 
| 
       8 
16 
     | 
    
         
             
                end
         
     | 
| 
       9 
17 
     | 
    
         | 
| 
       10 
18 
     | 
    
         
             
              end
         
     | 
    
        data/lib/rails_script/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: rails_script
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Kevin Pheasey
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2014-10- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-10-08 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |