Class: NeptuneCoffee::JavascriptGenerator
- Inherits:
-
Object
- Object
- NeptuneCoffee::JavascriptGenerator
- Defined in:
- lib/neptune_coffee/javascript_generator.rb
Class Attribute Summary collapse
-
.generators ⇒ Object
Returns the value of attribute generators.
Instance Attribute Summary collapse
-
#class_files ⇒ Object
Returns the value of attribute class_files.
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#root ⇒ Object
Returns the value of attribute root.
-
#subdirs ⇒ Object
Returns the value of attribute subdirs.
Class Method Summary collapse
Instance Method Summary collapse
- #define_js(relative_file_paths, local_names) ⇒ Object
- #files_relative_to(files, relative_to_path) ⇒ Object
-
#initialize(root, dir) ⇒ JavascriptGenerator
constructor
A new instance of JavascriptGenerator.
- #module(subdirs, class_files) ⇒ Object
- #namespace(subdirs) ⇒ Object
- #namespace_name ⇒ Object
Constructor Details
#initialize(root, dir) ⇒ JavascriptGenerator
Returns a new instance of JavascriptGenerator.
22 23 24 25 |
# File 'lib/neptune_coffee/javascript_generator.rb', line 22 def initialize root, dir @root = root @dir = dir end |
Class Attribute Details
.generators ⇒ Object
Returns the value of attribute generators.
7 8 9 |
# File 'lib/neptune_coffee/javascript_generator.rb', line 7 def generators @generators end |
Instance Attribute Details
#class_files ⇒ Object
Returns the value of attribute class_files.
21 22 23 |
# File 'lib/neptune_coffee/javascript_generator.rb', line 21 def class_files @class_files end |
#dir ⇒ Object
Returns the value of attribute dir.
21 22 23 |
# File 'lib/neptune_coffee/javascript_generator.rb', line 21 def dir @dir end |
#root ⇒ Object
Returns the value of attribute root.
21 22 23 |
# File 'lib/neptune_coffee/javascript_generator.rb', line 21 def root @root end |
#subdirs ⇒ Object
Returns the value of attribute subdirs.
21 22 23 |
# File 'lib/neptune_coffee/javascript_generator.rb', line 21 def subdirs @subdirs end |
Class Method Details
.load_erb ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# 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 |
Instance Method Details
#define_js(relative_file_paths, local_names) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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) ⇒ Object
27 28 29 |
# 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) ⇒ Object
47 48 49 50 51 52 53 |
# 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) ⇒ Object
59 60 61 62 63 64 |
# 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 ⇒ Object
55 56 57 |
# File 'lib/neptune_coffee/javascript_generator.rb', line 55 def namespace_name @namespace_name ||= (dir == root ? "Neptune" : dir.basename.to_s.camel_case) end |