Class: AngularRailsTemplates::Transformer

Inherits:
Object
  • Object
show all
Defined in:
lib/angular-rails-templates/transformer.rb

Overview

Temporary wrapper, old one is deprecated by Sprockets 4.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Transformer

Returns a new instance of Transformer.



8
9
10
# File 'lib/angular-rails-templates/transformer.rb', line 8

def initialize(options = {})
  @cache_key = [self.class.name, VERSION, options].freeze
end

Instance Attribute Details

#cache_keyObject (readonly)

Returns the value of attribute cache_key.



6
7
8
# File 'lib/angular-rails-templates/transformer.rb', line 6

def cache_key
  @cache_key
end

Class Method Details

.cache_keyObject



48
49
50
# File 'lib/angular-rails-templates/transformer.rb', line 48

def cache_key
  instance.cache_key
end

.call(input) ⇒ Object



52
53
54
# File 'lib/angular-rails-templates/transformer.rb', line 52

def call(input)
  instance.call(input)
end

.configObject



56
57
58
# File 'lib/angular-rails-templates/transformer.rb', line 56

def config
  Rails.configuration.angular_templates
end

.instanceObject



44
45
46
# File 'lib/angular-rails-templates/transformer.rb', line 44

def instance
  @instance ||= new
end

.register(env, ext) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/angular-rails-templates/transformer.rb', line 60

def register(env, ext)
  if ::Sprockets::VERSION.to_i < 4
    env.register_engine ".#{ext}", ::Tilt[ext] # Legacy Sprockets
  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

Instance Method Details

#add_template(ext, template) ⇒ Object



12
13
14
# File 'lib/angular-rails-templates/transformer.rb', line 12

def add_template(ext, template)
  templates[ext] ||= template
end

#call(input) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# 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