Class: AngularRailsTemplates::Transformer
- Inherits:
-
Object
- Object
- AngularRailsTemplates::Transformer
- Defined in:
- lib/angular-rails-templates/transformer.rb
Overview
Temporary wrapper, old one is deprecated by Sprockets 4.
Instance Attribute Summary collapse
-
#cache_key ⇒ Object
readonly
Returns the value of attribute cache_key.
Class Method Summary collapse
- .cache_key ⇒ Object
- .call(input) ⇒ Object
- .config ⇒ Object
- .instance ⇒ Object
- .register(env, ext) ⇒ Object
Instance Method Summary collapse
- #add_template(ext, template) ⇒ Object
- #call(input) ⇒ Object
-
#initialize(options = {}) ⇒ Transformer
constructor
A new instance of Transformer.
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( = {}) @cache_key = [self.class.name, VERSION, ].freeze end |
Instance Attribute Details
#cache_key ⇒ Object (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_key ⇒ Object
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 |
.config ⇒ Object
56 57 58 |
# File 'lib/angular-rails-templates/transformer.rb', line 56 def config Rails.configuration.angular_templates end |
.instance ⇒ Object
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 70 71 72 73 |
# 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 |
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 |