Sha256: d7ea99831f61f74f9c6d25cfce76458206bc4b8cb4a2ced6f4b6a9fe70145d3b
Contents?: true
Size: 813 Bytes
Versions: 1
Compression:
Stored size: 813 Bytes
Contents
class JSPreprocessor def initialize @defines = [] end def process(cwd, main_file) main = File.open(cwd + main_file).read.split "\n" compiled_file = recurse_files(cwd, main).join "\n" replace_defines compiled_file end def recurse_files(cwd, file) file.each_with_index do |line, index| if line.include? '#include' to_include = cwd + line[10..-2] + '.js' next_wd = Pathname.new(to_include).dirname.to_s + '/' file[index] = recurse_files next_wd, File.open(to_include).read.split("\n") elsif line.include? '#define' @defines << line[8..-1].split(' ') file.delete_at index end end end def replace_defines(file) @defines.each do |definition| file.gsub! definition[0], definition[1] end file end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jspreprocessor-0.0.2 | lib/JSPreprocessor.rb |