Class: JSPP
- Inherits:
-
Object
- Object
- JSPP
- Defined in:
- lib/jspp.rb
Constant Summary collapse
- INCLUDE =
%r{/\*>\s*(.+?)\s*\*/}- INCLUDE_INSIDE_STRING =
%r{"#{INCLUDE.source}"}
Instance Method Summary collapse
Instance Method Details
#get_file(path, base_dir = '.') ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/jspp.rb', line 19 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 |
#parse(text = '', base_dir = '.') ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/jspp.rb', line 6 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 |