Class: Hamljs::Template

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/rails-hamljs.rb

Constant Summary collapse

JS_UNESCAPES =
{
  '\\' => '\\',
  "'" => "'",
  'r' => "\r",
  'n' => "\n",
  't' => "\t",
  'u2028' => "\u2028",
  'u2029' => "\u2029"
}
JS_ESCAPES =
JS_UNESCAPES.invert
JS_UNESCAPE_PATTERN =
/\\(#{Regexp.union(JS_UNESCAPES.keys)})/
JS_ESCAPE_PATTERN =
Regexp.union(JS_ESCAPES.keys)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.engine_initialized?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/rails-hamljs.rb', line 22

def self.engine_initialized?
  true
end

Instance Method Details

#compile(source, options = {}) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rails-hamljs.rb', line 70

def compile(source, options = {})
  s = source.dup

  cmd = "haml.compileHaml({source: \"#{js_escape!(s)}\", generator: 'coffeescript'}).toString()"

  lib_sources = [
    get_coffeescript_source,
    get_hamljs_source
  ]

  context = ExecJS.compile(lib_sources.join(" "))
  result = context.eval(cmd)

  result
end

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



86
87
88
89
# File 'lib/rails-hamljs.rb', line 86

def evaluate(scope, locals, &block)
  source = data.dup
  return compile(source)
end

#get_coffeescript_sourceObject



32
33
34
# File 'lib/rails-hamljs.rb', line 32

def get_coffeescript_source
  @@coffeescript_source ||= open('http://jashkenas.github.com/coffee-script/extras/coffee-script.js').read
end

#get_creationix_hamljs_sourceObject



54
55
56
# File 'lib/rails-hamljs.rb', line 54

def get_creationix_hamljs_source
  @@creationix_hamljs_source ||= File.read(File.expand_path("../../vendor/assets/javascripts/creationix-haml-js/haml.js", __FILE__))
end

#get_hamljs_sourceObject



46
47
48
# File 'lib/rails-hamljs.rb', line 46

def get_hamljs_source
  @@hamljs_source ||= get_uglyog_hamljs_source
end

#get_jsonjs_sourceObject



50
51
52
# File 'lib/rails-hamljs.rb', line 50

def get_jsonjs_source
  @@jsonjs_source ||= File.read(File.expand_path("../../vendor/assets/javascripts/uglyog-haml-js/ext/json2.js", __FILE__))
end

#get_uglyog_hamljs_sourceObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rails-hamljs.rb', line 58

def get_uglyog_hamljs_source
  @@uglyog_hamljs_source ||= [
    get_jsonjs_source,
    get_underscore_source,
    get_underscore_string_source,
    File.read(File.expand_path("../../vendor/assets/javascripts/uglyog-haml-js/haml.min.js", __FILE__))
    #open('https://raw.github.com/uglyog/clientside-haml-js/master/lib/haml.min.js').read
  ].join(" ")

  #@@uglyog_hamljs_source ||= File.read(File.expand_path("../../vendor/assets/javascripts/uglyog-haml-js/haml.min.js", __FILE__))
end

#get_underscore_sourceObject



36
37
38
39
# File 'lib/rails-hamljs.rb', line 36

def get_underscore_source
  #@@underscore_source ||= open('http://underscorejs.org/underscore-min.js').read
  @@underscore_source ||= File.read(File.expand_path("../../vendor/assets/javascripts/uglyog-haml-js/ext/underscore.js", __FILE__))
end

#get_underscore_string_sourceObject



41
42
43
44
# File 'lib/rails-hamljs.rb', line 41

def get_underscore_string_source
  #@@underscore_string_source ||= open('http://epeli.github.com/underscore.string/dist/underscore.string.min.js').read
  @@underscore_string_source ||= File.read(File.expand_path("../../vendor/assets/javascripts/uglyog-haml-js/ext/underscore.string.js", __FILE__))
end

#initialize_engineObject



26
27
# File 'lib/rails-hamljs.rb', line 26

def initialize_engine
end

#prepareObject



29
30
# File 'lib/rails-hamljs.rb', line 29

def prepare
end