Class: AngularRailsTemplates::Template

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

Constant Summary collapse

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

Constants included from CompactJavaScriptEscape

CompactJavaScriptEscape::JS_ESCAPE_MAP

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CompactJavaScriptEscape

#escape_javascript

Class Method Details

.default_mime_typeObject



9
10
11
# File 'lib/angular-rails-templates/template.rb', line 9

def self.default_mime_type
  'application/javascript'
end

Instance Method Details

#evaluate(scope, locals, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/angular-rails-templates/template.rb', line 22

def evaluate(scope, locals, &block)
  locals[:html] = escape_javascript data.chomp
  locals[:angular_template_name] = logical_template_path(scope)
  locals[:source_file] = "#{scope.pathname}".sub(/^#{Rails.root}\//,'')
  locals[:angular_module] = configuration.module_name

  if @asset_should_be_processed
    AngularJsTemplateWrapper.render(scope, locals)
  else
    data
  end
end

#prepareObject



13
14
15
16
17
18
19
20
# File 'lib/angular-rails-templates/template.rb', line 13

def prepare
  # we only want to process html assets inside those specified in configuration.inside_paths
  @asset_should_be_processed = configuration.inside_paths.any? { |folder| file.match(folder.to_s) }

  if configuration.htmlcompressor and @asset_should_be_processed
    @data = compress data
  end
end