Class: AngularRailsTemplates::Processor

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

Constant Summary collapse

AngularJsTemplateWrapper =
::Tilt::ERBTemplate.new "#{File.dirname __FILE__}/javascript_template.js.erb"

Constants included from CompactJavaScriptEscape

CompactJavaScriptEscape::JS_ESCAPE_MAP

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CompactJavaScriptEscape

#escape_javascript

Constructor Details

#initialize(options = {}) ⇒ Processor

Returns a new instance of Processor.



28
29
30
# File 'lib/angular-rails-templates/processor.rb', line 28

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.



22
23
24
# File 'lib/angular-rails-templates/processor.rb', line 22

def cache_key
  @cache_key
end

Class Method Details

.cache_keyObject



18
19
20
# File 'lib/angular-rails-templates/processor.rb', line 18

def self.cache_key
  instance.cache_key
end

.call(input) ⇒ Object



14
15
16
# File 'lib/angular-rails-templates/processor.rb', line 14

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

.instanceObject



10
11
12
# File 'lib/angular-rails-templates/processor.rb', line 10

def self.instance
  @instance ||= new
end

Instance Method Details

#call(input) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/angular-rails-templates/processor.rb', line 37

def call(input)
  file_path = Pathname.new(input[:filename]).relative_path_from(Rails.root).to_s

  unless config.inside_paths.any? { |folder| file_path.match(folder.to_s) }
    return input[:data]
  end

  locals = {}
  locals[:angular_template_name] = template_name(input[:name])
  locals[:angular_module] = config.module_name
  locals[:source_file] = "#{input[:filename]}".sub(/^#{Rails.root}\//,'')

  locals[:html] = escape_javascript(input[:data].chomp)

  AngularJsTemplateWrapper.render(nil, locals)
end

#configObject



24
25
26
# File 'lib/angular-rails-templates/processor.rb', line 24

def config
  Rails.configuration.angular_templates
end

#template_name(name) ⇒ Object



32
33
34
35
# File 'lib/angular-rails-templates/processor.rb', line 32

def template_name(name)
  path = name.sub(/^#{config.ignore_prefix.join('|')}/, '')
  "#{path}.#{config.extension}"
end