Module: Jsus::Util::CodeGenerator

Defined in:
lib/jsus/util/code_generator.rb

Overview

Code generation routines.

Class Method Summary collapse

Class Method Details

.generate_includes(paths) ⇒ String

Returns javascript for includes for a list of given paths.

Parameters:

  • paths (Array)

    list of paths

Returns:

  • (String)

    javascript for includes for a list of given paths



9
10
11
12
13
14
15
16
17
18
# File 'lib/jsus/util/code_generator.rb', line 9

def generate_includes(paths)
  script = %{
  (function(prefix, loader) {
    var sources = %sources%;
    if (!loader) loader = function(path) {
      document.write('<scr' + 'ipt src="' + (prefix || '') + path + '"></script>');
    }
    for (var i = 0, j = sources.length; i < j; i++) loader(sources[i]);
  })(window.prefix, window.loader);}.sub("%sources%", JSON.pretty_generate(paths))
end