scripts/gen_require.rb in webruby-0.2.1 vs scripts/gen_require.rb in webruby-0.2.2

- old
+ new

@@ -70,10 +70,11 @@ RUBY_SOURCE_PATH = "#{OUTPUT_PATH}.tmp" File.open(RUBY_SOURCE_PATH, "w") do |f| f.puts <<END module Kernel + @@REQUIRED_PATH = "" @@REQUIRED_MODULES = { END files.each_with_index do |file_name, index| f.puts " #{file_name.inspect} => #{index},\n" @@ -82,12 +83,29 @@ f.puts <<END } def require(name) return false unless @@REQUIRED_MODULES.include?(name) + @@REQUIRED_PATH = name[0, name.rindex('/') || 0] require_internal(@@REQUIRED_MODULES[name]) @@REQUIRED_MODULES.delete(name) true + end + + def require_relative(path) + current_path = @@REQUIRED_PATH + path.split('/').each do |fragment| + case fragment + when '.' + # Doing nothing, current path + when '..' + current_path = current_path[0, current_path.rindex('/') || 0] + else + current_path = current_path.empty? ? fragment : + "\#{current_path}/\#{fragment}" + end + end + require(current_path) end end END end