angular-rails-templates 0.0.6 → 0.0.7
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 +17 -12
 - data/lib/angular-rails-templates.rb +7 -2
 - data/lib/angular-rails-templates/base_template.rb +29 -0
 - data/lib/angular-rails-templates/engine.rb +5 -2
 - data/lib/angular-rails-templates/haml_template.rb +14 -0
 - data/lib/angular-rails-templates/slim_template.rb +14 -0
 - data/lib/angular-rails-templates/template.rb +28 -15
 - data/lib/angular-rails-templates/version.rb +1 -1
 - metadata +6 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 89d964f875011e9189ab1360595c5761ab4ce256
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 73ce6e9e285e9562531a7f87e22b437c132d3cb0
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 4da72ed50555f8993d4e34af7e767db53b4cba3f606fa2ef8be8c042e972ee35dfcecd432127e42c7e8e010ffd3ab3b6fbdb3d116ae3e4467d7cf9cd7313cced
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 1f938a613811dced90f9ee7c53c4f64555174c737a2995862bff80a1d3ab1d4a82c4af51b059d5e6ea6fc1b2968cca1ca45f9198581cc1f7b9514972ace41d8f
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,18 +1,21 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # Angular Rails Templates [](http://travis-ci.org/pitr/angular-rails-templates)
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            Adds your HTML templates into Angular's `$templateCache` using Rails asset pipeline.
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            It removes the need for ajax calls to get the templates (or for you to manually set them into the dom).
         
     | 
| 
      
 5 
     | 
    
         
            +
            It removes the need for AJAX calls to retrieve the templates (or for you to manually set them into the DOM).
         
     | 
| 
       7 
6 
     | 
    
         | 
| 
       8 
7 
     | 
    
         
             
            ## Usage
         
     | 
| 
       9 
8 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
            Add the gem 
     | 
| 
      
 9 
     | 
    
         
            +
            ### 1. Add the gem
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            In Gemfile
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
            ```ruby
         
     | 
| 
       13 
14 
     | 
    
         
             
            gem 'angular-rails-templates'
         
     | 
| 
       14 
15 
     | 
    
         
             
            ```
         
     | 
| 
       15 
16 
     | 
    
         | 
| 
      
 17 
     | 
    
         
            +
            ### 2. Include templates in JS
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       16 
19 
     | 
    
         
             
            Then, in your `application.js` file, require your templates and the internal javascript file:
         
     | 
| 
       17 
20 
     | 
    
         | 
| 
       18 
21 
     | 
    
         
             
            ```javascript
         
     | 
| 
         @@ -20,9 +23,13 @@ Then, in your `application.js` file, require your templates and the internal jav 
     | 
|
| 
       20 
23 
     | 
    
         
             
            //= require_tree ./path_to_your_templates
         
     | 
| 
       21 
24 
     | 
    
         
             
            ```
         
     | 
| 
       22 
25 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
      
 26 
     | 
    
         
            +
            `path_to_your_templates` is relative to `application.js`.  For example, your templates are under `app/assets/javascripts/my_app/templates` and you then `require_tree ./my_app/templates`
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            Extensions supported are **.html**, **.ajs**, **.nghaml**, **.ngslim**. Last two do additional preprocessing and require `haml` and `slim` gems in your Gemfile.
         
     | 
| 
       24 
29 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
            ### 3. Add a dependency in Angular module
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            Your Angular module needs to have `templates` as a dependency (configurable with `config.angular_templates.module_name`)
         
     | 
| 
       26 
33 
     | 
    
         | 
| 
       27 
34 
     | 
    
         
             
            ```javascript
         
     | 
| 
       28 
35 
     | 
    
         
             
            var application = angular.module('myApplication', ['templates']);
         
     | 
| 
         @@ -35,17 +42,15 @@ The templates can then be accessed via `templateUrl` as expected: 
     | 
|
| 
       35 
42 
     | 
    
         | 
| 
       36 
43 
     | 
    
         
             
            ``` javascript
         
     | 
| 
       37 
44 
     | 
    
         
             
            {
         
     | 
| 
       38 
     | 
    
         
            -
              templateUrl: ' 
     | 
| 
      
 45 
     | 
    
         
            +
              templateUrl: 'my_app/templates/yourTemplate.html'
         
     | 
| 
       39 
46 
     | 
    
         
             
            }
         
     | 
| 
       40 
47 
     | 
    
         
             
            ```
         
     | 
| 
       41 
48 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
            We create the `templates` module (configurable through `config.angular_templates.module_name` in your application.rb), which populates Angular's `$templateCache` with all your templates when the module is included in your app.
         
     | 
| 
      
 49 
     | 
    
         
            +
            You can set `config.angular_templates.ignore_prefix` to remove part of the path to your templates. For example, set it to `my_app/templates/` so you can refer to your templates by simply `yourTemplate.html`. Default is `templates/`.
         
     | 
| 
       45 
50 
     | 
    
         | 
| 
       46 
51 
     | 
    
         
             
            ## License
         
     | 
| 
       47 
52 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
            MIT License. Copyright  
     | 
| 
      
 53 
     | 
    
         
            +
            MIT License. Copyright 2014 Pitr
         
     | 
| 
       49 
54 
     | 
    
         | 
| 
       50 
55 
     | 
    
         
             
            ## Authors & contributors
         
     | 
| 
       51 
56 
     | 
    
         | 
| 
         @@ -1,7 +1,12 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module AngularRailsTemplates
         
     | 
| 
      
 2 
     | 
    
         
            +
              HAML_EXT = '.nghaml'
         
     | 
| 
      
 3 
     | 
    
         
            +
              SLIM_EXT = '.ngslim'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
              autoload :Template, 'angular-rails-templates/template'
         
     | 
| 
       4 
     | 
    
         
            -
              autoload : 
     | 
| 
      
 5 
     | 
    
         
            +
              autoload :Template        , 'angular-rails-templates/template'
         
     | 
| 
      
 6 
     | 
    
         
            +
              autoload :BaseTemplate    , 'angular-rails-templates/base_template'
         
     | 
| 
      
 7 
     | 
    
         
            +
              autoload :SlimTemplate    , 'angular-rails-templates/slim_template'
         
     | 
| 
      
 8 
     | 
    
         
            +
              autoload :HamlTemplate    , 'angular-rails-templates/haml_template'
         
     | 
| 
      
 9 
     | 
    
         
            +
              autoload :Version         , 'angular-rails-templates/version'
         
     | 
| 
       5 
10 
     | 
    
         
             
            end
         
     | 
| 
       6 
11 
     | 
    
         | 
| 
       7 
12 
     | 
    
         
             
            require 'angular-rails-templates/engine'
         
     | 
| 
         @@ -0,0 +1,29 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'forwardable'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module AngularRailsTemplates
         
     | 
| 
      
 4 
     | 
    
         
            +
              BaseTemplate = Struct.new(:context) do
         
     | 
| 
      
 5 
     | 
    
         
            +
                extend Forwardable
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                def_delegators :context, :file, :data, :require_template_library
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                def initialize_engine ; end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                def render
         
     | 
| 
      
 12 
     | 
    
         
            +
                  initialize_engine
         
     | 
| 
      
 13 
     | 
    
         
            +
                  engine.render
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                protected
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                NoEngine = Struct.new(:data) do
         
     | 
| 
      
 19 
     | 
    
         
            +
                  def render
         
     | 
| 
      
 20 
     | 
    
         
            +
                    data
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                def engine
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @engine ||= NoEngine.new(data)
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
         @@ -8,8 +8,11 @@ module AngularRailsTemplates 
     | 
|
| 
       8 
8 
     | 
    
         
             
                  if app.config.assets
         
     | 
| 
       9 
9 
     | 
    
         
             
                    require 'sprockets'
         
     | 
| 
       10 
10 
     | 
    
         
             
                    Sprockets::Engines #force autoloading
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                    Sprockets.register_engine  
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                    Sprockets.register_engine SLIM_EXT , AngularRailsTemplates::Template
         
     | 
| 
      
 13 
     | 
    
         
            +
                    Sprockets.register_engine HAML_EXT , AngularRailsTemplates::Template
         
     | 
| 
      
 14 
     | 
    
         
            +
                    Sprockets.register_engine '.ajs'   , AngularRailsTemplates::Template
         
     | 
| 
      
 15 
     | 
    
         
            +
                    Sprockets.register_engine '.html'  , AngularRailsTemplates::Template
         
     | 
| 
       13 
16 
     | 
    
         
             
                  end
         
     | 
| 
       14 
17 
     | 
    
         
             
                end
         
     | 
| 
       15 
18 
     | 
    
         
             
              end
         
     | 
| 
         @@ -7,32 +7,45 @@ module AngularRailsTemplates 
     | 
|
| 
       7 
7 
     | 
    
         
             
                  'application/javascript'
         
     | 
| 
       8 
8 
     | 
    
         
             
                end
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
                def prepare; end
         
     | 
| 
      
 10 
     | 
    
         
            +
                def prepare ; end
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
                def evaluate(scope, locals, &block)
         
     | 
| 
       13 
     | 
    
         
            -
                   
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
              $templateCache.put(#{logical_template_path.inspect}, #{data.to_json});
         
     | 
| 
       22 
     | 
    
         
            -
            }]);
         
     | 
| 
       23 
     | 
    
         
            -
                  EOS
         
     | 
| 
      
 13 
     | 
    
         
            +
                  template = case File.extname(file)
         
     | 
| 
      
 14 
     | 
    
         
            +
                           when HAML_EXT then HamlTemplate.new(self)
         
     | 
| 
      
 15 
     | 
    
         
            +
                           when SLIM_EXT then SlimTemplate.new(self)
         
     | 
| 
      
 16 
     | 
    
         
            +
                           else
         
     | 
| 
      
 17 
     | 
    
         
            +
                             BaseTemplate.new(self)
         
     | 
| 
      
 18 
     | 
    
         
            +
                           end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  render_script_template(logical_template_path(scope), template.render)
         
     | 
| 
       24 
21 
     | 
    
         
             
                end
         
     | 
| 
       25 
22 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                 
     | 
| 
      
 23 
     | 
    
         
            +
                protected
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
       27 
25 
     | 
    
         
             
                def logical_template_path(scope)
         
     | 
| 
       28 
26 
     | 
    
         
             
                  path = scope.logical_path
         
     | 
| 
       29 
27 
     | 
    
         
             
                  path.gsub!(Regexp.new("^#{configuration.ignore_prefix}"), "")
         
     | 
| 
       30 
     | 
    
         
            -
                   
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
                  "#{path}.html"
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                def module_name
         
     | 
| 
      
 32 
     | 
    
         
            +
                  configuration.module_name.inspect
         
     | 
| 
       32 
33 
     | 
    
         
             
                end
         
     | 
| 
       33 
34 
     | 
    
         | 
| 
       34 
35 
     | 
    
         
             
                def configuration
         
     | 
| 
       35 
36 
     | 
    
         
             
                  ::Rails.configuration.angular_templates
         
     | 
| 
       36 
37 
     | 
    
         
             
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                def render_script_template(path, data)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  %Q{
         
     | 
| 
      
 41 
     | 
    
         
            +
            window.AngularRailsTemplates || (window.AngularRailsTemplates = angular.module(#{module_name}, []));
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            window.AngularRailsTemplates.run(["$templateCache",function($templateCache) {
         
     | 
| 
      
 44 
     | 
    
         
            +
              $templateCache.put(#{path.inspect}, #{data.to_json});
         
     | 
| 
      
 45 
     | 
    
         
            +
            }]);
         
     | 
| 
      
 46 
     | 
    
         
            +
                  }
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
       37 
49 
     | 
    
         
             
              end
         
     | 
| 
       38 
50 
     | 
    
         
             
            end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: angular-rails-templates
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.7
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Damien Mathieu
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2014- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2014-03-03 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: railties
         
     | 
| 
         @@ -63,10 +63,13 @@ files: 
     | 
|
| 
       63 
63 
     | 
    
         
             
            - LICENSE
         
     | 
| 
       64 
64 
     | 
    
         
             
            - README.md
         
     | 
| 
       65 
65 
     | 
    
         
             
            - lib/angular-rails-templates.rb
         
     | 
| 
      
 66 
     | 
    
         
            +
            - lib/angular-rails-templates/base_template.rb
         
     | 
| 
       66 
67 
     | 
    
         
             
            - lib/angular-rails-templates/engine.rb
         
     | 
| 
      
 68 
     | 
    
         
            +
            - lib/angular-rails-templates/haml_template.rb
         
     | 
| 
      
 69 
     | 
    
         
            +
            - lib/angular-rails-templates/slim_template.rb
         
     | 
| 
       67 
70 
     | 
    
         
             
            - lib/angular-rails-templates/template.rb
         
     | 
| 
       68 
71 
     | 
    
         
             
            - lib/angular-rails-templates/version.rb
         
     | 
| 
       69 
     | 
    
         
            -
            homepage: https://github.com/ 
     | 
| 
      
 72 
     | 
    
         
            +
            homepage: https://github.com/pitr/angular-rails-templates
         
     | 
| 
       70 
73 
     | 
    
         
             
            licenses:
         
     | 
| 
       71 
74 
     | 
    
         
             
            - MIT
         
     | 
| 
       72 
75 
     | 
    
         
             
            metadata: {}
         
     |