angular-rails4-templates 0.3.0 → 0.4.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 +5 -4
- data/lib/angular-rails4-templates.rb +1 -0
- data/lib/angular-rails4-templates/engine.rb +7 -26
- data/lib/angular-rails4-templates/haml_processor.rb +1 -1
- data/lib/angular-rails4-templates/processor.rb +1 -1
- data/lib/angular-rails4-templates/slim_processor.rb +15 -0
- data/lib/angular-rails4-templates/template.rb +1 -2
- data/lib/angular-rails4-templates/version.rb +1 -1
- metadata +3 -9
- data/lib/angular-rails-templates/compact_javascript_escape.rb +0 -29
- data/lib/angular-rails-templates/engine.rb +0 -78
- data/lib/angular-rails-templates/haml_processor.rb +0 -19
- data/lib/angular-rails-templates/javascript_template.js.erb +0 -6
- data/lib/angular-rails-templates/processor.rb +0 -51
- data/lib/angular-rails-templates/template.rb +0 -53
- data/lib/angular-rails-templates/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7030f28e3d73640f9b2c8e192d5bd0cc4bb82f44
|
4
|
+
data.tar.gz: 6b172e47e0de5f36fc941c1a982c64915530e4e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28d2c9112ce23c385f019fea283a9364c834f82aec9ebff7a2aa6a1550cb4c19c76fde4fa681de44524124f391da98e9d9e7386162c447e2ab86f7f0964302eb
|
7
|
+
data.tar.gz: b37e21fb5cde280dc3e36f11b123757e5aee18a69b2d188dbeb04eb07b11ff0c47eebcf01f971ec807b4da230292447fcb42072767ab8d0579b175cec3ea7917
|
data/README.md
CHANGED
@@ -17,12 +17,12 @@ gem 'angular-rails4-templates'
|
|
17
17
|
|
18
18
|
### 2. Include Templates in Rails Asset Pipeline
|
19
19
|
|
20
|
-
Then, in your `application.js` file, require `angular-
|
20
|
+
Then, in your `application.js` file, require `angular-rails4-templates` and your templates:
|
21
21
|
|
22
22
|
```javascript
|
23
23
|
//= require angularjs
|
24
24
|
// ...
|
25
|
-
//= require angular-
|
25
|
+
//= require angular-rails4-templates
|
26
26
|
//
|
27
27
|
// Templates in app/assets/javascript/templates
|
28
28
|
//= require_tree ./templates
|
@@ -31,7 +31,7 @@ Then, in your `application.js` file, require `angular-rails-templates` and your
|
|
31
31
|
//= require_tree ../templates
|
32
32
|
```
|
33
33
|
|
34
|
-
Make sure to `require angular-
|
34
|
+
Make sure to `require angular-rails4-templates` **before** you require your templates.
|
35
35
|
|
36
36
|
You'll need to use specific extensions to run the right preprocessor and load the resulting
|
37
37
|
compiled template into the angular template cache.
|
@@ -112,7 +112,7 @@ It is used to generate javascript like:
|
|
112
112
|
angular.module("<%= module_name %>")...
|
113
113
|
```
|
114
114
|
|
115
|
-
Although it is not recommended, you can set `module_name` to the name of your main application module and remove `require angular-
|
115
|
+
Although it is not recommended, you can set `module_name` to the name of your main application module and remove `require angular-rails4-templates` from your javascript manifest to have your templates directly injected into your app.
|
116
116
|
|
117
117
|
### Configuration Option: `ignore_prefix`
|
118
118
|
|
@@ -217,3 +217,4 @@ MIT License. Copyright 2014 Pitr
|
|
217
217
|
* Damien Mathieu <42@dmathieu.com>
|
218
218
|
* pitr <pitr.vern@gmail.com>
|
219
219
|
* Jeremy Ebler <jebler@gmail.com>
|
220
|
+
* Chris Nelson <chris@teamgaslight.com>
|
@@ -2,6 +2,7 @@ require 'angular-rails4-templates/engine'
|
|
2
2
|
|
3
3
|
module AngularRails4Templates
|
4
4
|
autoload :HamlProcessor, 'angular-rails4-templates/haml_processor'
|
5
|
+
autoload :SlimProcessor, 'angular-rails4-templates/slim_processor'
|
5
6
|
autoload :Processor, 'angular-rails4-templates/processor'
|
6
7
|
autoload :VERSION, 'angular-rails4-templates/version'
|
7
8
|
end
|
@@ -27,35 +27,16 @@ module AngularRails4Templates
|
|
27
27
|
|
28
28
|
|
29
29
|
initializer 'angular-rails-templates', group: :all do |app|
|
30
|
-
|
30
|
+
app.config.assets.configure do |env|
|
31
31
|
require 'sprockets'
|
32
32
|
require 'sprockets/engines' # load sprockets for Rails 3
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
#
|
41
|
-
# # These engines render markup as HTML
|
42
|
-
# app.config.angular_templates.markups.each do |ext|
|
43
|
-
# # Processed haml/slim templates have a mime-type of text/html.
|
44
|
-
# # If sprockets sees a `foo.html.haml` it will process the haml
|
45
|
-
# # and stop, because the haml output is html. Our html engine won't get run.
|
46
|
-
# mimeless_engine = Class.new(Tilt[ext]) do
|
47
|
-
# def self.default_mime_type
|
48
|
-
# nil
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
# app.assets.register_engine ".#{ext}", mimeless_engine
|
53
|
-
# end
|
54
|
-
|
55
|
-
app.assets.register_mime_type 'text/ng-html', extensions: ['.nghtml']
|
56
|
-
app.assets.register_mime_type 'text/ng-haml', extensions: ['.nghaml']
|
57
|
-
app.assets.register_transformer 'text/ng-haml', 'application/javascript', AngularRails4Templates::HamlProcessor
|
58
|
-
app.assets.register_transformer 'text/ng-html', 'application/javascript', AngularRails4Templates::Processor
|
34
|
+
env.register_mime_type 'text/ng-html', extensions: ['.nghtml']
|
35
|
+
env.register_mime_type 'text/ng-haml', extensions: ['.nghaml']
|
36
|
+
env.register_mime_type 'text/ng-slim', extensions: ['.ngslim']
|
37
|
+
env.register_transformer 'text/ng-slim', 'application/javascript', AngularRails4Templates::SlimProcessor
|
38
|
+
env.register_transformer 'text/ng-haml', 'application/javascript', AngularRails4Templates::HamlProcessor
|
39
|
+
env.register_transformer 'text/ng-html', 'application/javascript', AngularRails4Templates::Processor
|
59
40
|
end
|
60
41
|
|
61
42
|
# Sprockets Cache Busting
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'angular-rails4-templates/compact_javascript_escape'
|
2
|
+
require 'slim'
|
3
|
+
|
4
|
+
module AngularRails4Templates
|
5
|
+
class SlimProcessor < Processor
|
6
|
+
|
7
|
+
include CompactJavaScriptEscape
|
8
|
+
|
9
|
+
def render_html(input)
|
10
|
+
template = input[:data]
|
11
|
+
output = Slim::Template.new { template }.render
|
12
|
+
escape_javascript output
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'angular-
|
1
|
+
require 'angular-rails4-templates/compact_javascript_escape'
|
2
2
|
|
3
3
|
module AngularRails4Templates
|
4
4
|
class Template < ::Tilt::Template
|
@@ -51,4 +51,3 @@ module AngularRails4Templates
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angular-rails4-templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Mathieu
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-12-
|
14
|
+
date: 2015-12-29 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: railties
|
@@ -106,19 +106,13 @@ extra_rdoc_files: []
|
|
106
106
|
files:
|
107
107
|
- LICENSE
|
108
108
|
- README.md
|
109
|
-
- lib/angular-rails-templates/compact_javascript_escape.rb
|
110
|
-
- lib/angular-rails-templates/engine.rb
|
111
|
-
- lib/angular-rails-templates/haml_processor.rb
|
112
|
-
- lib/angular-rails-templates/javascript_template.js.erb
|
113
|
-
- lib/angular-rails-templates/processor.rb
|
114
|
-
- lib/angular-rails-templates/template.rb
|
115
|
-
- lib/angular-rails-templates/version.rb
|
116
109
|
- lib/angular-rails4-templates.rb
|
117
110
|
- lib/angular-rails4-templates/compact_javascript_escape.rb
|
118
111
|
- lib/angular-rails4-templates/engine.rb
|
119
112
|
- lib/angular-rails4-templates/haml_processor.rb
|
120
113
|
- lib/angular-rails4-templates/javascript_template.js.erb
|
121
114
|
- lib/angular-rails4-templates/processor.rb
|
115
|
+
- lib/angular-rails4-templates/slim_processor.rb
|
122
116
|
- lib/angular-rails4-templates/template.rb
|
123
117
|
- lib/angular-rails4-templates/version.rb
|
124
118
|
- vendor/assets/javascripts/angular-rails4-templates.js.erb
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module AngularRails4Templates
|
2
|
-
module CompactJavaScriptEscape
|
3
|
-
# inspired by Rails' action_view/helpers/javascript_helper.rb
|
4
|
-
JS_ESCAPE_MAP = {
|
5
|
-
'\\' => '\\\\',
|
6
|
-
"\r\n" => '\n',
|
7
|
-
"\n" => '\n',
|
8
|
-
"\r" => '\n',
|
9
|
-
'"' => '\\"',
|
10
|
-
"'" => "\\'"
|
11
|
-
}
|
12
|
-
|
13
|
-
# We want to deliver the shortist valid javascript escaped string
|
14
|
-
# Count the number of " vs '
|
15
|
-
# If more ', escape "
|
16
|
-
# If more ", escape '
|
17
|
-
# If equal, prefer to escape "
|
18
|
-
|
19
|
-
def escape_javascript(raw)
|
20
|
-
if raw
|
21
|
-
quote = raw.count(%{'}) >= raw.count(%{"}) ? %{"} : %{'}
|
22
|
-
escaped = raw.gsub(/(\\|\r\n|[\n\r#{quote}])/u) {|match| JS_ESCAPE_MAP[match] }
|
23
|
-
"#{quote}#{escaped}#{quote}"
|
24
|
-
else
|
25
|
-
'""'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'tilt'
|
2
|
-
|
3
|
-
module AngularRails4Templates
|
4
|
-
class Engine < ::Rails::Engine
|
5
|
-
config.angular_templates = ActiveSupport::OrderedOptions.new
|
6
|
-
config.angular_templates.module_name = 'templates'
|
7
|
-
config.angular_templates.ignore_prefix = ['templates/']
|
8
|
-
config.angular_templates.inside_paths = [] # defined in before_configuration
|
9
|
-
config.angular_templates.markups = []
|
10
|
-
config.angular_templates.htmlcompressor = false
|
11
|
-
|
12
|
-
config.before_configuration do |app|
|
13
|
-
config.angular_templates.inside_paths = [Rails.root.join('app', 'assets')]
|
14
|
-
|
15
|
-
# try loading common markups
|
16
|
-
%w(erb haml liquid md radius slim str textile wiki).
|
17
|
-
each do |ext|
|
18
|
-
begin
|
19
|
-
silence_warnings do
|
20
|
-
config.angular_templates.markups << ext if Tilt[ext]
|
21
|
-
end
|
22
|
-
rescue LoadError
|
23
|
-
# They don't have the required library required. Oh well.
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
initializer 'angular-rails-templates', group: :all do |app|
|
30
|
-
if app.config.assets
|
31
|
-
require 'sprockets'
|
32
|
-
require 'sprockets/engines' # load sprockets for Rails 3
|
33
|
-
|
34
|
-
# if app.config.angular_templates.htmlcompressor
|
35
|
-
# require 'htmlcompressor/compressor'
|
36
|
-
# unless app.config.angular_templates.htmlcompressor.is_a? Hash
|
37
|
-
# app.config.angular_templates.htmlcompressor = {remove_intertag_spaces: true}
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
# # These engines render markup as HTML
|
42
|
-
# app.config.angular_templates.markups.each do |ext|
|
43
|
-
# # Processed haml/slim templates have a mime-type of text/html.
|
44
|
-
# # If sprockets sees a `foo.html.haml` it will process the haml
|
45
|
-
# # and stop, because the haml output is html. Our html engine won't get run.
|
46
|
-
# mimeless_engine = Class.new(Tilt[ext]) do
|
47
|
-
# def self.default_mime_type
|
48
|
-
# nil
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
# app.assets.register_engine ".#{ext}", mimeless_engine
|
53
|
-
# end
|
54
|
-
|
55
|
-
app.assets.register_mime_type 'text/ng-html', extensions: ['.nghtml']
|
56
|
-
app.assets.register_mime_type 'text/ng-haml', extensions: ['.nghaml']
|
57
|
-
app.assets.register_transformer 'text/ng-haml', 'application/javascript', AngularRails4Templates::HamlProcessor
|
58
|
-
app.assets.register_transformer 'text/ng-html', 'application/javascript', AngularRails4Templates::Processor
|
59
|
-
end
|
60
|
-
|
61
|
-
# Sprockets Cache Busting
|
62
|
-
# If ART's version or settings change, expire and recompile all assets
|
63
|
-
app.config.assets.version = [
|
64
|
-
app.config.assets.version,
|
65
|
-
'ART',
|
66
|
-
Digest::MD5.hexdigest("#{VERSION}-#{app.config.angular_templates}")
|
67
|
-
].join '-'
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
config.after_initialize do |app|
|
72
|
-
# Ensure ignore_prefix can be passed as a String or Array
|
73
|
-
if app.config.angular_templates.ignore_prefix.is_a? String
|
74
|
-
app.config.angular_templates.ignore_prefix = Array(app.config.angular_templates.ignore_prefix)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'angular-rails-templates/compact_javascript_escape'
|
2
|
-
require 'haml'
|
3
|
-
|
4
|
-
module AngularRails4Templates
|
5
|
-
class HamlProcessor < Processor
|
6
|
-
|
7
|
-
include CompactJavaScriptEscape
|
8
|
-
|
9
|
-
def render_html(input)
|
10
|
-
template = input[:data]
|
11
|
-
haml_engine = Haml::Engine.new(template)
|
12
|
-
output = haml_engine.render
|
13
|
-
escape_javascript output
|
14
|
-
rescue Haml::SyntaxError => ex
|
15
|
-
raise Haml::SyntaxError.new("#{input[:filename]} #{ex.message}", ex.line)
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'angular-rails-templates/compact_javascript_escape'
|
2
|
-
|
3
|
-
module AngularRails4Templates
|
4
|
-
class Processor
|
5
|
-
|
6
|
-
include CompactJavaScriptEscape
|
7
|
-
|
8
|
-
def self.instance
|
9
|
-
@instance ||= new
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.call(input)
|
13
|
-
instance.call(input)
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.cache_key
|
17
|
-
instance.cache_key
|
18
|
-
end
|
19
|
-
|
20
|
-
attr_reader :cache_key, :config
|
21
|
-
|
22
|
-
def config
|
23
|
-
Rails.configuration.angular_templates
|
24
|
-
end
|
25
|
-
|
26
|
-
def initialize(options = {})
|
27
|
-
@cache_key = [self.class.name, VERSION, options].freeze
|
28
|
-
end
|
29
|
-
|
30
|
-
def render_html(input)
|
31
|
-
escape_javascript input[:data].chomp
|
32
|
-
end
|
33
|
-
|
34
|
-
def template_name(name)
|
35
|
-
path = name.sub /^(#{config.ignore_prefix.join('|')})/, ''
|
36
|
-
"#{path}.html"
|
37
|
-
end
|
38
|
-
|
39
|
-
def call(input)
|
40
|
-
angular_template_name = template_name(input[:name])
|
41
|
-
angular_module = config.module_name
|
42
|
-
html = render_html(input)
|
43
|
-
source_file = "#{input[:filename]}".sub(/^#{Rails.root}\//,'')
|
44
|
-
erb = ERB.new(File.read("#{File.dirname __FILE__}/javascript_template.js.erb"))
|
45
|
-
|
46
|
-
result = erb.result binding
|
47
|
-
|
48
|
-
result
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'angular-rails-templates/compact_javascript_escape'
|
2
|
-
|
3
|
-
module AngularRails4Templates
|
4
|
-
class Template < ::Tilt::Template
|
5
|
-
include CompactJavaScriptEscape
|
6
|
-
AngularJsTemplateWrapper = Tilt::ERBTemplate.new "#{File.dirname __FILE__}/javascript_template.js.erb"
|
7
|
-
@@compressor = nil
|
8
|
-
|
9
|
-
def self.default_mime_type
|
10
|
-
'application/javascript'
|
11
|
-
end
|
12
|
-
|
13
|
-
def prepare
|
14
|
-
# we only want to process html assets inside those specified in configuration.inside_paths
|
15
|
-
@asset_should_be_processed = configuration.inside_paths.any? { |folder| file.match(folder.to_s) }
|
16
|
-
|
17
|
-
if configuration.htmlcompressor and @asset_should_be_processed
|
18
|
-
@data = compress data
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def evaluate(scope, locals, &block)
|
23
|
-
locals[:html] = escape_javascript data.chomp
|
24
|
-
locals[:angular_template_name] = logical_template_path(scope)
|
25
|
-
locals[:source_file] = "#{scope.pathname}".sub(/^#{Rails.root}\//,'')
|
26
|
-
locals[:angular_module] = configuration.module_name
|
27
|
-
|
28
|
-
if @asset_should_be_processed
|
29
|
-
AngularJsTemplateWrapper.render(scope, locals)
|
30
|
-
else
|
31
|
-
data
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def logical_template_path(scope)
|
38
|
-
path = scope.logical_path.sub /^(#{configuration.ignore_prefix.join('|')})/, ''
|
39
|
-
"#{path}.html"
|
40
|
-
end
|
41
|
-
|
42
|
-
def configuration
|
43
|
-
::Rails.configuration.angular_templates
|
44
|
-
end
|
45
|
-
|
46
|
-
def compress html
|
47
|
-
unless @@compressor
|
48
|
-
@@compressor = HtmlCompressor::Compressor.new configuration.htmlcompressor
|
49
|
-
end
|
50
|
-
@@compressor.compress(html)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|