angular-rails-templates 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b300ab4b89e1f7085e04b70e962a8d1ff154985
4
- data.tar.gz: 0a6817faccca877d296635a144a5ecc7444fa3e7
3
+ metadata.gz: 89d964f875011e9189ab1360595c5761ab4ce256
4
+ data.tar.gz: 73ce6e9e285e9562531a7f87e22b437c132d3cb0
5
5
  SHA512:
6
- metadata.gz: a8ae17bf1b09addd325d7d2b3da68cca40210546b3e89240375d873c3dc76fd407d34b79cc7f2e1c59587062ccc621c239a3b0ab100e25eaa0c99fdd9259b171
7
- data.tar.gz: 0dec8b993230196cf3abac1667d3a03c1baded18abd3e43aaeed84ab524e28c5007fa8008752d39d99f0101e7aeb5fb843ed10f0c77f40b4137855dc69886ba0
6
+ metadata.gz: 4da72ed50555f8993d4e34af7e767db53b4cba3f606fa2ef8be8c042e972ee35dfcecd432127e42c7e8e010ffd3ab3b6fbdb3d116ae3e4467d7cf9cd7313cced
7
+ data.tar.gz: 1f938a613811dced90f9ee7c53c4f64555174c737a2995862bff80a1d3ab1d4a82c4af51b059d5e6ea6fc1b2968cca1ca45f9198581cc1f7b9514972ace41d8f
data/README.md CHANGED
@@ -1,18 +1,21 @@
1
- # Angular Rails Templates [![Build Status](https://secure.travis-ci.org/dmathieu/angular-rails-templates.png?branch=master)](http://travis-ci.org/dmathieu/angular-rails-templates)
1
+ # Angular Rails Templates [![Build Status](https://secure.travis-ci.org/pitr/angular-rails-templates.png?branch=master)](http://travis-ci.org/pitr/angular-rails-templates)
2
2
 
3
- Behind the hideous Angular Rails Templates name is hiding a template management system for rails' asset pipeline and AngularJS' template views.
3
+ Adds your HTML templates into Angular's `$templateCache` using Rails asset pipeline.
4
4
 
5
- Basically: this will precompile your templates into the template cache, to be used by your application.
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 into your Gemfile
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
- Your template files can have the extensions **.html** or **.ajs**
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
- In your application, add a dependency to the `templates` module.
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: 'path_to_your_templates/yourTemplate.html'
45
+ templateUrl: 'my_app/templates/yourTemplate.html'
39
46
  }
40
47
  ```
41
48
 
42
- ## How it works
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 2013 Damien Mathieu
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 :Version, 'angular-rails-templates/version'
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
- Sprockets.register_engine '.ajs', AngularRailsTemplates::Template
12
- Sprockets.register_engine '.html', AngularRailsTemplates::Template
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
@@ -0,0 +1,14 @@
1
+ module AngularRailsTemplates
2
+ class HamlTemplate < BaseTemplate
3
+ def initialize_engine
4
+ require_template_library 'haml'
5
+ end
6
+
7
+ protected
8
+
9
+ def engine
10
+ @engine ||= Haml::Engine.new(data)
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,14 @@
1
+ module AngularRailsTemplates
2
+ class SlimTemplate < BaseTemplate
3
+ def initialize_engine
4
+ require_template_library 'slim'
5
+ end
6
+
7
+ protected
8
+
9
+ def engine
10
+ @engine ||= Slim::Template.new(file)
11
+ end
12
+ end
13
+ end
14
+
@@ -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
- module_name = configuration.module_name
14
- logical_template_path = logical_template_path(scope)
15
-
16
- <<-EOS
17
-
18
- window.AngularRailsTemplates || (window.AngularRailsTemplates = angular.module(#{module_name.inspect}, []));
19
-
20
- window.AngularRailsTemplates.run(["$templateCache",function($templateCache) {
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
- private
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
- ext = basename.split(".")[1]
31
- "#{path}.#{ext}"
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
+
@@ -1,3 +1,3 @@
1
1
  module AngularRailsTemplates
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
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.6
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-02-12 00:00:00.000000000 Z
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/dmathieu/angular-rails-templates
72
+ homepage: https://github.com/pitr/angular-rails-templates
70
73
  licenses:
71
74
  - MIT
72
75
  metadata: {}