Class: Sprockets::SafetyColons

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/sprockets/safety_colons.rb

Overview

For JS developers who are colonfobic, concatenating JS files using the module pattern usually leads to syntax errors.

The `SafetyColons` processor will insert missing semicolons to the end of the file.

This behavior can be disabled with:

environment.unregister_postprocessor 'application/javascript', Sprockets::SafetyColons

Instance Method Summary collapse

Instance Method Details

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



18
19
20
21
22
23
24
25
26
# File 'lib/sprockets/safety_colons.rb', line 18

def evaluate(context, locals, &block)
  # If the file is blank or ends in a semicolon, leave it as is
  if data =~ /\A\s*\Z/m || data =~ /;\s*\Z/m
    data
  else
    # Otherwise, append a semicolon and newline
    "#{data};\n"
  end
end

#prepareObject



15
16
# File 'lib/sprockets/safety_colons.rb', line 15

def prepare
end