angular-rails-templates 0.3.0 → 1.0.0.beta1

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: 44d240dc6f8c691a6243c5595d3a460781ae0606
4
- data.tar.gz: 369f4eef0998ac3d46e466331132c31acc16767e
3
+ metadata.gz: 9fb45cac6296e091c98d1a3d48afb136d320f074
4
+ data.tar.gz: 4df7de01e2ff66162c323393b968e291d5e281ff
5
5
  SHA512:
6
- metadata.gz: b471e6cc6362f41b3b1811287d4856dc177a36e24dcf0a564fcf1affd8e43388a9ff041d9f57760e9994aacfb3fd642b0c1437466b66dfd512f9e03c2fa25e74
7
- data.tar.gz: bd8f42bce871649cb42def0fa3aa64342a675adac268f7f34e078e4122c47f30791551d5ce3deec0d9833e0939b0b74c57c7b853346745a13d0c12e6893f15fb
6
+ metadata.gz: 76656192c87de937514ae8708ac1a2b45ec4062b4cf8c21dd04823e6f6b38e5552ca994151b71ccb89f408ce0e42cb09306d93634742619c9e177e8ec5cb5d66
7
+ data.tar.gz: b8c956f2e4dd71889e1fa6f4b93b64446386a553d61dfbe95d127385254fe6fb435b261781e41e2712b48b499b18753c18ccf78a40096dab0db0de1228f9d76e
data/README.md CHANGED
@@ -43,7 +43,7 @@ foo.html.haml
43
43
  foo.html.slim
44
44
  ```
45
45
 
46
- Caution: *`.ngslim` and `.nghaml` are no longer supported!*
46
+ Caution: *`.ngslim` is no longer supported!*
47
47
 
48
48
  Angular Rails Templates will try to load support for the following markups if their gems are present:
49
49
 
@@ -80,7 +80,7 @@ modals/dialog.html.slim.erb.str => modals/dialog.html # don't do this
80
80
  The templates can then be accessed via `templateUrl` as expected:
81
81
 
82
82
  ```javascript
83
- // Template: app/assets/templates/yourTemplate.html.haml
83
+ // Template: app/assets/templates/yourTemplate.html.nghaml
84
84
  {
85
85
  templateUrl: 'yourTemplate.html'
86
86
  }
@@ -107,7 +107,6 @@ config.angular_templates.module_name = 'templates'
107
107
  config.angular_templates.ignore_prefix = %w(templates/)
108
108
  config.angular_templates.inside_paths = [Rails.root.join('app', 'assets')]
109
109
  config.angular_templates.markups = %w(erb str haml slim md)
110
- config.angular_templates.htmlcompressor = false
111
110
  ```
112
111
 
113
112
  ### Configuration Option: `module_name`
@@ -188,39 +187,13 @@ config.angular_templates.markups.push 'nghaml'
188
187
  ```
189
188
  Note: You would still need to use `foo`**`.html`**`.nghaml`
190
189
 
191
-
192
- ### Configuration Option: `htmlcompressor`
193
-
194
- The [htmlcompressor gem](https://github.com/paolochiodi/htmlcompressor) is in alpha, not activly maintained, and has several known bugs. Beware if you are using windows. The `simple_boolean_attributes` option is known to mangle angular templates. It depends on a three-year-old version of yui-compressor. However, it does a good job of compressing html!
195
-
196
- If you would like to use htmlcompressor add it to your Gemfile and Enable the configuration option.
197
-
198
- ```ruby
199
- # Gemfile
200
- gem 'htmlcompressor'
201
- ```
202
-
203
- ```ruby
204
- # config/application.rb
205
- config.angular_templates.htmlcompressor = true
206
- ```
207
-
208
- You can also pass an options hash to `htmlcompressor` that will be directly passed to ```HtmlCompressor::Compressor.new```. See the [ruby project](https://github.com/paolochiodi/htmlcompressor#usage) or the [java project](https://code.google.com/p/htmlcompressor/#Compressing_HTML_and_XML_files_from_a_command_line) for descriptions of the options.
209
-
210
- ```ruby
211
- # config/application.rb
212
- config.angular_templates.htmlcompressor = {
213
- :remove_quotes => true
214
- }
215
- ```
216
-
217
-
218
190
  ## License
219
191
 
220
- MIT License. Copyright 2017 pitr
192
+ MIT License. Copyright 2015 pitr
221
193
 
222
194
  ## Authors & contributors
223
195
 
224
196
  * Damien Mathieu <42@dmathieu.com>
225
197
  * pitr <pitr.vern@gmail.com>
226
198
  * Jeremy Ebler <jebler@gmail.com>
199
+ * Chris Nelson <chris@teamgaslight.com>
@@ -1,6 +1,7 @@
1
+ require 'angular-rails-templates/compact_javascript_escape'
2
+ require 'angular-rails-templates/processor'
1
3
  require 'angular-rails-templates/engine'
2
4
 
3
5
  module AngularRailsTemplates
4
- autoload :Template, 'angular-rails-templates/template'
5
6
  autoload :VERSION, 'angular-rails-templates/version'
6
7
  end
@@ -7,7 +7,6 @@ module AngularRailsTemplates
7
7
  config.angular_templates.ignore_prefix = ['templates/']
8
8
  config.angular_templates.inside_paths = [] # defined in before_configuration
9
9
  config.angular_templates.markups = []
10
- config.angular_templates.htmlcompressor = false
11
10
 
12
11
  config.before_configuration do |app|
13
12
  config.angular_templates.inside_paths = [Rails.root.join('app', 'assets')]
@@ -31,29 +30,16 @@ module AngularRailsTemplates
31
30
  require 'sprockets'
32
31
  require 'sprockets/engines' # load sprockets for Rails 3
33
32
 
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
33
+ config.assets.configure do |env|
34
+ # byebug
35
+ env.register_mime_type 'text/ng-html', extensions: ['.html']
36
+ env.register_transformer 'text/ng-html', 'application/javascript', AngularRailsTemplates::Processor
40
37
 
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
38
+ # These engines render markup as HTML
39
+ app.config.angular_templates.markups.each do |ext|
40
+ env.register_engine ".#{ext}", Tilt[ext]
50
41
  end
51
-
52
- app.assets.register_engine ".#{ext}", mimeless_engine
53
42
  end
54
-
55
- # This engine wraps the HTML into JS
56
- app.assets.register_engine '.html', AngularRailsTemplates::Template
57
43
  end
58
44
 
59
45
  # Sprockets Cache Busting
@@ -0,0 +1,52 @@
1
+ require 'angular-rails-templates/compact_javascript_escape'
2
+
3
+ module AngularRailsTemplates
4
+ class Processor
5
+
6
+ AngularJsTemplateWrapper = Tilt::ERBTemplate.new "#{File.dirname __FILE__}/javascript_template.js.erb"
7
+
8
+ include CompactJavaScriptEscape
9
+
10
+ def self.instance
11
+ @instance ||= new
12
+ end
13
+
14
+ def self.call(input)
15
+ instance.call(input)
16
+ end
17
+
18
+ def self.cache_key
19
+ instance.cache_key
20
+ end
21
+
22
+ attr_reader :cache_key, :config
23
+
24
+ def config
25
+ Rails.configuration.angular_templates
26
+ end
27
+
28
+ def initialize(options = {})
29
+ @cache_key = [self.class.name, VERSION, options].freeze
30
+ end
31
+
32
+ def template_name(name)
33
+ path = name.sub /^(#{config.ignore_prefix.join('|')})/, ''
34
+ "#{path}.html"
35
+ end
36
+
37
+ def call(input)
38
+ locals = {}
39
+ locals[:angular_template_name] = template_name(input[:name])
40
+ locals[:angular_module] = config.module_name
41
+ locals[:source_file] = "#{input[:filename]}".sub(/^#{Rails.root}\//,'')
42
+
43
+ locals[:html] = escape_javascript(input[:data].chomp)
44
+
45
+ if config.inside_paths.any? { |folder| input[:filename].match(folder.to_s) }
46
+ AngularJsTemplateWrapper.render(nil, locals)
47
+ else
48
+ input[:data]
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,3 +1,3 @@
1
1
  module AngularRailsTemplates
2
- VERSION = '0.3.0'
2
+ VERSION = '1.0.0.beta1'
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.3.0
4
+ version: 1.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Mathieu
@@ -10,50 +10,36 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-01-18 00:00:00.000000000 Z
13
+ date: 2016-02-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ">="
19
+ - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '3.1'
21
+ version: '4.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ">="
26
+ - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '3.1'
28
+ version: '4.2'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: sprockets
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '2.0'
35
+ version: '3.0'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '2.0'
43
- - !ruby/object:Gem::Dependency
44
- name: tilt
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: '0'
50
- type: :runtime
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: '0'
42
+ version: '3.0'
57
43
  - !ruby/object:Gem::Dependency
58
44
  name: minitest
59
45
  requirement: !ruby/object:Gem::Requirement
@@ -82,20 +68,6 @@ dependencies:
82
68
  - - ">="
83
69
  - !ruby/object:Gem::Version
84
70
  version: '0'
85
- - !ruby/object:Gem::Dependency
86
- name: mime-types
87
- requirement: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - "<"
90
- - !ruby/object:Gem::Version
91
- version: '3'
92
- type: :development
93
- prerelease: false
94
- version_requirements: !ruby/object:Gem::Requirement
95
- requirements:
96
- - - "<"
97
- - !ruby/object:Gem::Version
98
- version: '3'
99
71
  - !ruby/object:Gem::Dependency
100
72
  name: uglifier
101
73
  requirement: !ruby/object:Gem::Requirement
@@ -123,7 +95,7 @@ files:
123
95
  - lib/angular-rails-templates/compact_javascript_escape.rb
124
96
  - lib/angular-rails-templates/engine.rb
125
97
  - lib/angular-rails-templates/javascript_template.js.erb
126
- - lib/angular-rails-templates/template.rb
98
+ - lib/angular-rails-templates/processor.rb
127
99
  - lib/angular-rails-templates/version.rb
128
100
  - vendor/assets/javascripts/angular-rails-templates.js.erb
129
101
  homepage: https://github.com/pitr/angular-rails-templates
@@ -141,12 +113,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
113
  version: '0'
142
114
  required_rubygems_version: !ruby/object:Gem::Requirement
143
115
  requirements:
144
- - - ">="
116
+ - - ">"
145
117
  - !ruby/object:Gem::Version
146
- version: '0'
118
+ version: 1.3.1
147
119
  requirements: []
148
120
  rubyforge_project:
149
- rubygems_version: 2.5.1
121
+ rubygems_version: 2.2.2
150
122
  signing_key:
151
123
  specification_version: 4
152
124
  summary: Use your angular templates with rails' asset pipeline
@@ -1,58 +0,0 @@
1
- require 'angular-rails-templates/compact_javascript_escape'
2
-
3
- module AngularRailsTemplates
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
- unless @asset_should_be_processed
18
- @data = nil
19
- return
20
- end
21
-
22
- if configuration.htmlcompressor and @asset_should_be_processed
23
- @data = compress data
24
- end
25
- end
26
-
27
- def evaluate(scope, locals, &block)
28
- if @asset_should_be_processed
29
- locals[:html] = escape_javascript data.chomp
30
- locals[:angular_template_name] = logical_template_path(scope)
31
- locals[:source_file] = "#{scope.pathname}".sub(/^#{Rails.root}\//,'')
32
- locals[:angular_module] = configuration.module_name
33
- AngularJsTemplateWrapper.render(scope, locals)
34
- else
35
- data
36
- end
37
- end
38
-
39
- private
40
-
41
- def logical_template_path(scope)
42
- path = scope.logical_path.sub /^(#{configuration.ignore_prefix.join('|')})/, ''
43
- "#{path}.html"
44
- end
45
-
46
- def configuration
47
- ::Rails.configuration.angular_templates
48
- end
49
-
50
- def compress html
51
- unless @@compressor
52
- @@compressor = HtmlCompressor::Compressor.new configuration.htmlcompressor
53
- end
54
- @@compressor.compress(html)
55
- end
56
- end
57
- end
58
-