Finish Python script that switches the release script tags in svg-editor.html. Updated Makefile
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1930 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
af0599d632
commit
8379711c3e
8
Makefile
8
Makefile
|
@ -40,8 +40,8 @@ build/$(PACKAGE): $(COMPILED_JS)
|
|||
# Remove all hidden .svn directories
|
||||
-find build/$(PACKAGE) -name .svn -type d | xargs rm -rf {} \;
|
||||
|
||||
# Remove all JS files that were compiled
|
||||
rm $(JS_BUILD_FILES)
|
||||
# Create the release version of the main HTML file.
|
||||
build/tools/ship.py --i=editor/svg-editor.html --on=svg_edit_release > build/$(PACKAGE)/svg-editor.html
|
||||
|
||||
# codedread: NOTE: Some files are not ready for the Closure compiler: (jquery)
|
||||
$(COMPILED_JS):
|
||||
|
@ -75,4 +75,8 @@ clean:
|
|||
rm -rf build/$(PACKAGE)
|
||||
rm -rf build/firefox
|
||||
rm -rf build/opera
|
||||
rm -rf build/$(PACKAGE).zip
|
||||
rm -rf build/$(PACKAGE)-src.tar.gz
|
||||
rm -rf build/$(PACKAGE).xpi
|
||||
rm -rf build/$(PACKAGE).wgt
|
||||
rm -rf $(COMPILED_JS)
|
||||
|
|
|
@ -4,16 +4,19 @@
|
|||
# ship.py
|
||||
#
|
||||
# Licensed under the Apache 2 License as is the rest of the project
|
||||
#
|
||||
# Copyright (c) 2011 Jeff Schiller
|
||||
#
|
||||
# This script has very little real-world application. It is only used in our pure-client web
|
||||
# app served on GoogleCode so we can have one HTML file, run a build script and generate a 'release'
|
||||
# version without having to maintain two separate HTML files.
|
||||
#
|
||||
# This script takes the following inputs:
|
||||
#
|
||||
# * a HTML file
|
||||
# * a series of flag names
|
||||
# * a HTML file (--i=in.html)
|
||||
# * a series of flag names (--on=Foo --on=Bar)
|
||||
#
|
||||
# It parses, the HTML file, enables/disables sections of the makrup based
|
||||
# on conditional comments and flag values, then outputs a new HTML file.
|
||||
# It parses, the HTML file, enables/disables sections of the markup based
|
||||
# on if-else comments and flag values, then outputs a new HTML file.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
|
@ -24,7 +27,7 @@
|
|||
# BAR!
|
||||
# <!--{endif}-->
|
||||
#
|
||||
# $ ship.py --i in.html --o test-out.html --enable foo
|
||||
# $ ship.py --i in.html --on foo
|
||||
#
|
||||
# out.html:
|
||||
# <!--{if foo}-->
|
||||
|
@ -33,30 +36,117 @@
|
|||
# BAR!
|
||||
# <!{endif}-->
|
||||
#
|
||||
# Only if-else-endif are currently supported. All conditional comment expressions must
|
||||
# be on one line with no other non-whitespace characters.
|
||||
# It has the following limitations:
|
||||
#
|
||||
# 1) Only if-else-endif are currently supported.
|
||||
# 2) All processing comments must be on one line with no other non-whitespace characters.
|
||||
# 3) Comments cannot be nested.
|
||||
|
||||
import optparse
|
||||
import os
|
||||
|
||||
inside_if = False
|
||||
last_if_true = False
|
||||
|
||||
_options_parser = optparse.OptionParser(
|
||||
usage="%prog --i input.svg --o output.svg [--enable flag1]",
|
||||
description=("Hello world!"))
|
||||
_options_parser.add_option("--i",
|
||||
action="store", dest="input_html_file", help="Input HTML filename")
|
||||
_options_parser.add_option("--o",
|
||||
action="store", dest="output_html_file", help="Output HTML filename")
|
||||
_options_parser.add_option("--on",
|
||||
action="append", type="string", dest="enabled_flags",
|
||||
help="name of flag to enable")
|
||||
usage='%prog --i input.html [--on flag1]',
|
||||
description=('Rewrites an HTML file based on conditional comments and flags'))
|
||||
_options_parser.add_option('--i',
|
||||
action='store', dest='input_html_file', help='Input HTML filename')
|
||||
_options_parser.add_option('--on',
|
||||
action='append', type='string', dest='enabled_flags',
|
||||
help='name of flag to enable')
|
||||
|
||||
def parse_args(args=None):
|
||||
options, rargs = _options_parser.parse_args(args)
|
||||
print options
|
||||
|
||||
if rargs:
|
||||
_options_parser.error("Additional arguments not handled: %r, see --help" % rargs)
|
||||
|
||||
return options, (None, None)
|
||||
|
||||
def parseComment(line, line_num, enabled_flags):
|
||||
global inside_if
|
||||
global last_if_true
|
||||
|
||||
start = line.find('{')
|
||||
end = line.find('}')
|
||||
statement = line[start+1:end].strip()
|
||||
if statement.startswith('if '):
|
||||
if inside_if == True:
|
||||
print 'Fatal Error: Nested {if} found on line ' + str(line_num)
|
||||
print line
|
||||
quit()
|
||||
|
||||
# Evaluate whether the expression is true/false.
|
||||
# only one variable name allowed for now
|
||||
variable_name = statement[3:].strip()
|
||||
if variable_name in enabled_flags:
|
||||
last_if_true = True
|
||||
line = '<!--{if ' + variable_name + '}-->'
|
||||
else:
|
||||
last_if_true = False
|
||||
line = '<!--{if ' + variable_name + '}>'
|
||||
|
||||
inside_if = True
|
||||
|
||||
elif statement == 'else':
|
||||
if inside_if == False:
|
||||
print 'Fatal Error: {else} found without {if} on line ' + str(line_num)
|
||||
print line
|
||||
quit()
|
||||
|
||||
if last_if_true:
|
||||
line = '<!--{else}>'
|
||||
else:
|
||||
line = '<!{else}-->'
|
||||
|
||||
# invert the logic so the endif clause is closed properly
|
||||
last_if_true = not last_if_true
|
||||
|
||||
elif statement == 'endif':
|
||||
if inside_if == False:
|
||||
print 'Fatal Error: {endif} found without {if} on line ' + str(line_num)
|
||||
print line
|
||||
quit()
|
||||
|
||||
if last_if_true:
|
||||
line = '<!--{endif}-->'
|
||||
else:
|
||||
line = '<!{endif}-->'
|
||||
|
||||
inside_if = False
|
||||
|
||||
return line
|
||||
|
||||
|
||||
def ship(inFileName, enabled_flags):
|
||||
# read in HTML file
|
||||
in_file = file(inFileName, 'r')
|
||||
|
||||
i = 0
|
||||
lines = in_file.readlines()
|
||||
|
||||
out_lines = []
|
||||
|
||||
# loop for each line of markup
|
||||
for line in lines:
|
||||
strline = line.strip()
|
||||
# if we find a comment, process it and print out
|
||||
if strline.startswith('<!--{') or strline.startswith('<!{'):
|
||||
# using the same indentation as the previous line
|
||||
start = line.find('<')
|
||||
out_lines.append(line[:start] \
|
||||
+ parseComment(strline, i, enabled_flags) \
|
||||
+ os.linesep)
|
||||
else: # else append line to the output list
|
||||
out_lines.append(line)
|
||||
i += 1
|
||||
|
||||
return ''.join(out_lines)
|
||||
|
||||
if __name__ == '__main__':
|
||||
options, (input, output) = parse_args()
|
||||
|
||||
if options.input_html_file != None:
|
||||
enabled_flags = []
|
||||
if options.enabled_flags != None:
|
||||
enabled_flags.extend(options.enabled_flags)
|
||||
out_file = ship(options.input_html_file, enabled_flags)
|
||||
print out_file
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
<!--{if svg_edit_release}>
|
||||
<script type="text/javascript" src="svgedit.compiled.js"></script>
|
||||
<{else}-->
|
||||
<!{else}-->
|
||||
<script type="text/javascript" src="browser.js"></script>
|
||||
<script type="text/javascript" src="svgtransformlist.js"></script>
|
||||
<script type="text/javascript" src="math.js"></script>
|
||||
|
|
Loading…
Reference in New Issue