class NeptuneCoffee::JavascriptGenerator
Attributes
generators[RW]
class_files[RW]
dir[RW]
root[RW]
subdirs[RW]
Public Class Methods
load_erb()
click to toggle source
# File lib/neptune_coffee/javascript_generator.rb, line 8 def load_erb generator_root = Pathname.new(__FILE__).parent + "generators" @generators = {} generator_root.children(false).each do |erb_file| name = erb_file.to_s.split(/\.erb$/)[0] path = generator_root + erb_file @generators[name] = ERB.new path.read, nil, "<>-" @generators[name].filename = erb_file end end
new(root, dir)
click to toggle source
# File lib/neptune_coffee/javascript_generator.rb, line 22 def initialize root, dir @root = root @dir = dir end
Public Instance Methods
define_js(relative_file_paths, local_names) { || ... }
click to toggle source
# File lib/neptune_coffee/javascript_generator.rb, line 31 def define_js relative_file_paths, local_names files_js = if relative_file_paths.length == 0 then "" else "\n " + relative_file_paths.map{|f| "'./#{f}'"}.join(",\n ") + "\n" end old_buffer, @output_buffer = @output_buffer, '' begin content = yield ensure @output_buffer = old_buffer end @output_buffer << "define([#{files_js}], function(#{local_names.join ', '}) {#{content}});" end
files_relative_to(files, relative_to_path)
click to toggle source
# File lib/neptune_coffee/javascript_generator.rb, line 27 def files_relative_to files, relative_to_path files.map {|f| f.relative_path_from relative_to_path} end
module(subdirs, class_files)
click to toggle source
# File lib/neptune_coffee/javascript_generator.rb, line 47 def module subdirs, class_files @output_buffer = "" @subdirs = subdirs @class_files = class_files JavascriptGenerator.generators["module.js"].result(binding) @output_buffer end
namespace(subdirs)
click to toggle source
# File lib/neptune_coffee/javascript_generator.rb, line 59 def namespace subdirs @output_buffer = "" @subdirs = subdirs JavascriptGenerator.generators["namespace.js"].result(binding) @output_buffer end
namespace_name()
click to toggle source
# File lib/neptune_coffee/javascript_generator.rb, line 55 def namespace_name @namespace_name ||= (dir == root ? "Neptune" : dir.basename.to_s.camel_case) end