class AngularRailsTemplates::Transformer
Temporary wrapper, old one is deprecated by Sprockets 4.
Attributes
cache_key[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/angular-rails-templates/transformer.rb, line 8 def initialize(options = {}) @cache_key = [self.class.name, VERSION, options].freeze end
Private Class Methods
cache_key()
click to toggle source
# File lib/angular-rails-templates/transformer.rb, line 48 def cache_key instance.cache_key end
call(input)
click to toggle source
# File lib/angular-rails-templates/transformer.rb, line 52 def call(input) instance.call(input) end
config()
click to toggle source
# File lib/angular-rails-templates/transformer.rb, line 56 def config Rails.configuration.angular_templates end
instance()
click to toggle source
# File lib/angular-rails-templates/transformer.rb, line 44 def instance @instance ||= new end
register(env, ext)
click to toggle source
# File lib/angular-rails-templates/transformer.rb, line 60 def register(env, ext) if ::Sprockets::VERSION.to_i < 4 # Legacy Sprockets args = [".#{ext}", ::Tilt[ext]] if ::Sprockets::VERSION.to_i == 3 args << { mime_type: "text/ng-#{ext}", silence_deprecation: true } end env.register_engine(*args) else instance.add_template(ext, ::Tilt[ext]) env.register_mime_type "text/ng-#{ext}", extensions: [".#{config.extension}.#{ext}"] env.register_transformer "text/ng-#{ext}", 'text/ng-html', AngularRailsTemplates::Transformer end end
Public Instance Methods
add_template(ext, template)
click to toggle source
# File lib/angular-rails-templates/transformer.rb, line 12 def add_template(ext, template) templates[ext] ||= template end
call(input)
click to toggle source
# File lib/angular-rails-templates/transformer.rb, line 16 def call(input) filename = input[:filename] ext = File.extname(filename).split('.').last return input unless has?(ext) data = input[:data] context = input[:environment].context_class.new(input) process(filename, data, context, ext) end
Private Instance Methods
has?(ext)
click to toggle source
# File lib/angular-rails-templates/transformer.rb, line 34 def has?(ext) templates.has_key?(ext) end
process(filename, data, context, ext)
click to toggle source
# File lib/angular-rails-templates/transformer.rb, line 38 def process(filename, data, context, ext) data = templates[ext].new(filename) { data }.render(context, {}) context.metadata.merge(data: data.to_str) end
templates()
click to toggle source
# File lib/angular-rails-templates/transformer.rb, line 30 def templates @templates ||= Hash.new end