-
Notifications
You must be signed in to change notification settings - Fork 169
/
engine.rb
56 lines (49 loc) · 2.02 KB
/
engine.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module AngularRailsTemplates
class Engine < ::Rails::Engine
config.angular_templates = ActiveSupport::OrderedOptions.new
config.angular_templates.module_name = 'templates'
config.angular_templates.ignore_prefix = ['templates/']
config.angular_templates.inside_paths = ['app/assets']
config.angular_templates.markups = []
config.angular_templates.extension = 'html'
config.before_configuration do |app|
# try loading common markups
%w(erb haml liquid md radius slim str textile wiki).
each do |ext|
begin
silence_warnings do
config.angular_templates.markups << ext if Tilt[ext]
end
rescue LoadError
# They don't have the required library required. Oh well.
end
end
end
initializer 'angular-rails-templates', group: :all do |app|
if defined?(Sprockets::Railtie)
config.assets.configure do |env|
env.register_mime_type 'text/ng-html', extensions: [".#{app.config.angular_templates.extension}"]
env.register_transformer 'text/ng-html', 'application/javascript', AngularRailsTemplates::Processor
# These engines render markup as HTML
app.config.angular_templates.markups.each do |ext|
AngularRailsTemplates::Transformer.register(env, ext)
end
end
end
# Sprockets Cache Busting
# If ART's version or settings change, expire and recompile all assets
hash_digest = defined?(ActiveSupport::Digest) ? ActiveSupport::Digest : Digest::MD5
app.config.assets.version = [
app.config.assets.version,
'ART',
hash_digest.hexdigest("#{VERSION}-#{app.config.angular_templates}")
].join '-'
end
config.after_initialize do |app|
# Ensure ignore_prefix can be passed as a String or Array
if app.config.angular_templates.ignore_prefix.is_a? String
app.config.angular_templates.ignore_prefix = Array(app.config.angular_templates.ignore_prefix)
end
end
end
end