Class: Red::DefinitionNode::Module

Inherits:
Red::DefinitionNode show all
Defined in:
lib/red/nodes/definition_nodes.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from String

#%, #*, #+, #<<, #<=>, #==, #=~, #[], #[]=, #capitalize, #capitalize!, #casecmp, #center, #chomp, #chomp!, #chop, #chop!, #concat, #count, #crypt, #delete, #delete!, #downcase, #downcase!, #each, #each_byte, #each_line, #empty?, #eql?, #gsub, #gsub!, #hash, #hex, #include?, #index, #insert, #inspect, #intern, #length, #ljust, #lstrip, #lstrip!, #match, #next, #next!, #oct, #replace, #reverse, #reverse!, #rindex, #rjust, #rstrip, #rstrip!, #scan, #size, #slice, #slice!, #split, #squeeze, #strip, #strip!, #strip_scripts, #sub, #sub!, #succ, #succ!, #sum, #swapcase, #swapcase!, #to_f, #to_i, #to_s, #to_str, #to_sym, #tr, #tr!, #tr_s, #tr_s!, #upcase, #upcase!, #upto

Constructor Details

#initialize(module_name_sexp, scope_sexp, options) ⇒ Module

:module, :Foo, [:scope, (expression | :block)]


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/red/nodes/definition_nodes.rb', line 44

def initialize(module_name_sexp, scope_sexp, options)
  module_name = "%s" % module_name_sexp.red!
  
  if module_name_sexp.is_sexp?(:colon3)
    old_namespace_stack = @@namespace_stack
    namespaced_module   = module_name
    @@namespace_stack   = [namespaced_module]
  elsif module_name_sexp.is_sexp?(:colon2)
    namespaced_module   = module_name
    module_name         = module_name_sexp.last.red!
    @@namespace_stack.push(module_name)
  else
    module_name = "c$%s" % module_name_sexp.red!
    @@namespace_stack.push(module_name)
    namespaced_module   = @@namespace_stack.join(".")
  end
  @@red_constants |= [namespaced_module]
  
  scope = scope_sexp.red!(:as_class_eval => true)
  
  self << "\n\nRed._module('%s',function(){ var _=%s.prototype;\n  %s;\n})" % [namespaced_module.gsub("c$",""), namespaced_module, scope]
  
  @@namespace_stack.pop
end