angular-rails-templates 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -5
- data/lib/angular-rails-templates.rb +1 -0
- data/lib/angular-rails-templates/engine.rb +1 -1
- data/lib/angular-rails-templates/processor.rb +3 -3
- data/lib/angular-rails-templates/transformer.rb +72 -0
- data/lib/angular-rails-templates/version.rb +1 -1
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ab1b13e51cdc6b7f3e7a3f6159f0479f67c374a
|
4
|
+
data.tar.gz: f8561c7c81112d0cf75446bb5a1adcfb9276cfc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d95c383e517ebe42216c61eb19f841290f782c141600c24e35fb7d8f4cc3548c218f1591a26860fda2842ae94afd20ae6f9c966c45e799593cd8be08053d1cdb
|
7
|
+
data.tar.gz: bd7f560bef3a1c9cb0aaf27111f14b2a1193ab3e608619d28a3d3428309eee0d78710a83f08343aa0c470937ff64fe0eb53c200f9879a0b12b76d953a2392264
|
data/README.md
CHANGED
@@ -1,9 +1,21 @@
|
|
1
|
-
# Angular Rails Templates
|
1
|
+
# Angular Rails Templates
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/angular-rails-templates.png)](http://badge.fury.io/rb/angular-rails-templates)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/pitr/angular-rails-templates/badge.svg?branch=master)](https://coveralls.io/github/pitr/angular-rails-templates?branch=master)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/pitr/angular-rails-templates/badges/gpa.svg)](https://codeclimate.com/github/pitr/angular-rails-templates)
|
6
|
+
[![Issue Stats](http://issuestats.com/github/pitr/angular-rails-templates/badge/pr)](http://issuestats.com/github/pitr/angular-rails-templates)
|
7
|
+
[![Issue Stats](http://issuestats.com/github/pitr/angular-rails-templates/badge/issue)](http://issuestats.com/github/pitr/angular-rails-templates)
|
8
|
+
[![Stories in Ready](https://badge.waffle.io/pitr/angular-rails-templates.png?label=ready&title=Ready)](https://waffle.io/pitr/angular-rails-templates)
|
2
9
|
|
3
10
|
Adds your HTML templates into Angular's `$templateCache` using Rails asset pipeline.
|
4
11
|
|
5
12
|
**IMPORTANT**: for Rails 4.2+ use version 1.0+ of this gem. For Rails 3 - 4.1 use version 0.x
|
6
13
|
|
14
|
+
Branch | Build Status
|
15
|
+
------------|---------
|
16
|
+
master | [![Build Status](https://travis-ci.org/pitr/angular-rails-templates.png?branch=master)](https://travis-ci.org/pitr/angular-rails-templates)
|
17
|
+
0-x-stable | [![Build Status](https://travis-ci.org/pitr/angular-rails-templates.png?branch=0-x-stable)](https://travis-ci.org/pitr/angular-rails-templates)
|
18
|
+
|
7
19
|
It removes the need for AJAX calls to retrieve the templates (or for you to manually set them into the DOM).
|
8
20
|
|
9
21
|
## Usage
|
@@ -43,8 +55,6 @@ foo.html.haml
|
|
43
55
|
foo.html.slim
|
44
56
|
```
|
45
57
|
|
46
|
-
Caution: *`.ngslim` is no longer supported!*
|
47
|
-
|
48
58
|
Angular Rails Templates will try to load support for the following markups if their gems are present:
|
49
59
|
|
50
60
|
| Extension | Required gem |
|
@@ -80,7 +90,7 @@ modals/dialog.html.slim.erb.str => modals/dialog.html # don't do this
|
|
80
90
|
The templates can then be accessed via `templateUrl` as expected:
|
81
91
|
|
82
92
|
```javascript
|
83
|
-
// Template: app/assets/templates/yourTemplate.html.
|
93
|
+
// Template: app/assets/templates/yourTemplate.html.haml
|
84
94
|
{
|
85
95
|
templateUrl: 'yourTemplate.html'
|
86
96
|
}
|
@@ -194,7 +204,7 @@ By default this gem looks only at templates with `.html` suffix, eg. `foo.html`
|
|
194
204
|
|
195
205
|
## License
|
196
206
|
|
197
|
-
MIT License. Copyright
|
207
|
+
MIT License. Copyright 2016 pitr
|
198
208
|
|
199
209
|
## Authors & contributors
|
200
210
|
|
@@ -3,7 +3,7 @@ require 'angular-rails-templates/compact_javascript_escape'
|
|
3
3
|
module AngularRailsTemplates
|
4
4
|
class Processor
|
5
5
|
|
6
|
-
AngularJsTemplateWrapper = Tilt::ERBTemplate.new "#{File.dirname __FILE__}/javascript_template.js.erb"
|
6
|
+
AngularJsTemplateWrapper = ::Tilt::ERBTemplate.new "#{File.dirname __FILE__}/javascript_template.js.erb"
|
7
7
|
|
8
8
|
include CompactJavaScriptEscape
|
9
9
|
|
@@ -19,7 +19,7 @@ module AngularRailsTemplates
|
|
19
19
|
instance.cache_key
|
20
20
|
end
|
21
21
|
|
22
|
-
attr_reader :cache_key
|
22
|
+
attr_reader :cache_key
|
23
23
|
|
24
24
|
def config
|
25
25
|
Rails.configuration.angular_templates
|
@@ -30,7 +30,7 @@ module AngularRailsTemplates
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def template_name(name)
|
33
|
-
path = name.sub
|
33
|
+
path = name.sub(/^#{config.ignore_prefix.join('|')}/, '')
|
34
34
|
"#{path}.#{config.extension}"
|
35
35
|
end
|
36
36
|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module AngularRailsTemplates
|
2
|
+
#
|
3
|
+
# Temporary wrapper, old one is deprecated by Sprockets 4.
|
4
|
+
#
|
5
|
+
class Transformer
|
6
|
+
attr_reader :cache_key
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@cache_key = [self.class.name, VERSION, options].freeze
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_template(ext, template)
|
13
|
+
templates[ext] ||= template
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(input)
|
17
|
+
filename = input[:filename]
|
18
|
+
ext = File.extname(filename).split('.').last
|
19
|
+
|
20
|
+
return input unless has?(ext)
|
21
|
+
|
22
|
+
data = input[:data]
|
23
|
+
context = input[:environment].context_class.new(input)
|
24
|
+
|
25
|
+
process(filename, data, context, ext)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def templates
|
31
|
+
@templates ||= Hash.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def has?(ext)
|
35
|
+
templates.has_key?(ext)
|
36
|
+
end
|
37
|
+
|
38
|
+
def process(filename, data, context, ext)
|
39
|
+
data = templates[ext].new(filename) { data }.render(context, {})
|
40
|
+
context.metadata.merge(data: data.to_str)
|
41
|
+
end
|
42
|
+
|
43
|
+
class << self
|
44
|
+
def instance
|
45
|
+
@instance ||= new
|
46
|
+
end
|
47
|
+
|
48
|
+
def cache_key
|
49
|
+
instance.cache_key
|
50
|
+
end
|
51
|
+
|
52
|
+
def call(input)
|
53
|
+
instance.call(input)
|
54
|
+
end
|
55
|
+
|
56
|
+
def config
|
57
|
+
Rails.configuration.angular_templates
|
58
|
+
end
|
59
|
+
|
60
|
+
def register(env, ext)
|
61
|
+
if ::Sprockets::VERSION.to_i < 4
|
62
|
+
env.register_engine ".#{ext}", ::Tilt[ext] # Legacy Sprockets
|
63
|
+
else
|
64
|
+
instance.add_template(ext, ::Tilt[ext])
|
65
|
+
|
66
|
+
env.register_mime_type "text/ng-#{ext}", extensions: [".#{config.extension}.#{ext}"]
|
67
|
+
env.register_transformer "text/ng-#{ext}", 'text/ng-html', AngularRailsTemplates::Transformer
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
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: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Mathieu
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-02
|
13
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|
@@ -36,16 +36,22 @@ dependencies:
|
|
36
36
|
name: sprockets
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '3.0'
|
42
|
+
- - "<"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '5'
|
42
45
|
type: :runtime
|
43
46
|
prerelease: false
|
44
47
|
version_requirements: !ruby/object:Gem::Requirement
|
45
48
|
requirements:
|
46
|
-
- - "
|
49
|
+
- - ">="
|
47
50
|
- !ruby/object:Gem::Version
|
48
51
|
version: '3.0'
|
52
|
+
- - "<"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5'
|
49
55
|
- !ruby/object:Gem::Dependency
|
50
56
|
name: tilt
|
51
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,6 +122,7 @@ files:
|
|
116
122
|
- lib/angular-rails-templates/engine.rb
|
117
123
|
- lib/angular-rails-templates/javascript_template.js.erb
|
118
124
|
- lib/angular-rails-templates/processor.rb
|
125
|
+
- lib/angular-rails-templates/transformer.rb
|
119
126
|
- lib/angular-rails-templates/version.rb
|
120
127
|
- vendor/assets/javascripts/angular-rails-templates.js.erb
|
121
128
|
homepage: https://github.com/pitr/angular-rails-templates
|