Skip to content

Commit

Permalink
Allow the global export method to handle nested namespaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobie committed Apr 29, 2010
1 parent c39fc6b commit 9e24762
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/modulr/global_export_collector.rb
Expand Up @@ -7,11 +7,26 @@ def initialize(options = {})
end

def to_js(buffer = '')
buffer << "var #{@global} = (function() {\n"
buffer << "#{define_global} = (function() {\n"
buffer << File.read(PATH_TO_MODULR_SYNC_JS)
buffer << transport
buffer << "\n return require('#{main.id}');\n"
buffer << "})();\n"
end

def define_global
if @global.include?('.')
props = @global.split('.')
str = props.shift
results = "var #{str};"
props.each do |prop|
results << "\n#{str} = #{str} || {};"
str << ".#{prop}"
end
"#{results}\n#{str}"
else
"var #{@global}"
end
end
end
end

0 comments on commit 9e24762

Please sign in to comment.