Permalink
Browse files

Change command syntax to #!

Add support for require statements
  • Loading branch information...
1 parent c5eba84 commit 6a1d3d11fce358202f9b417d49e9f0e6c03e7082 @apcomplete apcomplete committed Mar 6, 2012
Showing with 9 additions and 5 deletions.
  1. +2 −2 jswatchr/config.py
  2. +7 −3 jswatchr/parse.py
View
4 jswatchr/config.py
@@ -3,9 +3,9 @@
source_ext = 'xjs'
exts = ['js', source_ext]
# TODO: support ignoring pre-minified and output files
-#ignore_exts = ['min.js']
sources = {}
source_dir = None
dest_dir = None
-import_regex = '(?P<command>@import|@require) (?P<script>\S+(.\S+)(?!.min)(.xjs|.js))'
+import_regex = '(#!(?P<command>import|require)) (?P<script>\S+(.\S+)(.xjs|.js))'
file_regex = '([a-zA-Z/]*.(?!min)(xjs|js))'
+stack = []
View
10 jswatchr/parse.py
@@ -9,6 +9,8 @@ def parse_file(src):
"""
find file in config and output to dest dir
"""
+ #clear the stack between parses
+ config.stack = []
for parent in src.parents:
if config.dest_dir == None:
dest = parent.dir
@@ -30,9 +32,11 @@ def get_output(src):
for line in lines:
m = re.match(config.import_regex,line)
if m:
- # TODO: handle user adding a new import line to dependency
- src_file = config.sources[os.path.abspath(src.dir + '/' + m.group('script'))]
- output += get_output(src_file)
+ include_file = config.sources[os.path.abspath(src.dir + '/' + m.group('script'))]
+ #require statements dont include if the file has already been included
+ if include_file not in config.stack or m.group('command') == 'import':
+ config.stack.append(include_file)
+ output += get_output(include_file)
else:
output += line
return output

0 comments on commit 6a1d3d1

Please sign in to comment.