Class: Apotomo::JavascriptGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/apotomo/javascript_generator.rb

Defined Under Namespace

Modules: Jquery, Prototype, Right

Constant Summary

JS_ESCAPE_MAP =

Copied from ActionView::Helpers::JavascriptHelper.

{
'\\'    => '\\\\',
'</'    => '<\/',
"\r\n"  => '\n',
"\n"    => '\n',
"\r"    => '\n',
'"'     => '\\"',
"'"     => "\\'" }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(framework) ⇒ JavascriptGenerator

Returns a new instance of JavascriptGenerator



3
4
5
6
# File 'lib/apotomo/javascript_generator.rb', line 3

def initialize(framework)
  raise "No JS framework specified" if framework.blank?
  extend "apotomo/javascript_generator/#{framework}".camelize.constantize
end

Class Method Details

.escape(javascript) ⇒ Object

Escape carrier returns and single and double quotes for JavaScript segments.



23
24
25
26
27
# File 'lib/apotomo/javascript_generator.rb', line 23

def self.escape(javascript)
  return javascript.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { JS_ESCAPE_MAP[$1] } if javascript
  
  ''
end

Instance Method Details

#<<(javascript) ⇒ Object



8
9
10
# File 'lib/apotomo/javascript_generator.rb', line 8

def <<(javascript)
  "#{javascript}"
end

#escape(javascript) ⇒ Object



29
30
31
# File 'lib/apotomo/javascript_generator.rb', line 29

def escape(javascript)
  self.class.escape(javascript)
end