Skip to content
This repository has been archived by the owner on Nov 14, 2019. It is now read-only.

Commit

Permalink
JSPP class
Browse files Browse the repository at this point in the history
  • Loading branch information
NV committed Mar 19, 2010
1 parent 4f64e86 commit 70d1611
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lib/jspp.rb
@@ -0,0 +1,38 @@
class JSPP

INCLUDE = %r{/\*>\s*(.+?)\s*\*/}
INCLUDE_INSIDE_STRING = %r{"#{INCLUDE.source}"}

def get_file path, base_dir='.'
if path.index'http://' or path.index'https://'
require 'open-uri'
file = open(path).read
dir = File.dirname path
else
full_path = File.join base_dir, path
file = File.read full_path
dir = File.dirname full_path
end
[file, dir]
end

def parse text='', base_dir='.'
text.gsub!(INCLUDE_INSIDE_STRING) {
file, dir = get_file $1, base_dir
parsed = parse file, dir
'"' << parsed.gsub(/$/, '\\').chop << '"'
}
text.gsub!(INCLUDE) {
file, dir = get_file $1, base_dir
parse file, dir
}
text
end
end

module Kernel
def JSPP text, base_dir='.'
JSPP.new.parse text, base_dir
end
private :JSPP
end

0 comments on commit 70d1611

Please sign in to comment.