From af0599d63204f36c875bf32013b5b27b7e135baa Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Mon, 17 Jan 2011 22:11:35 +0000 Subject: [PATCH] Changes to Makefile so things build better. Start on a python script for releasing the HTML file git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1929 eee81c28-f429-11dd-99c0-75d572ba1ddd --- Makefile | 62 ++++++++++++++++++++++++----------------- build/tools/ship.py | 62 +++++++++++++++++++++++++++++++++++++++++ editor/locale/locale.js | 10 ++++--- editor/svg-editor.html | 57 ++++++++++++++++++------------------- editor/svgcanvas.js | 58 +++++++++++++++++++------------------- 5 files changed, 161 insertions(+), 88 deletions(-) create mode 100755 build/tools/ship.py diff --git a/Makefile b/Makefile index cd67f0b5..2d0ac51f 100644 --- a/Makefile +++ b/Makefile @@ -3,48 +3,57 @@ VERSION=2.6 PACKAGE=$(NAME)-$(VERSION) MAKEDOCS=naturaldocs/NaturalDocs CLOSURE=build/tools/closure-compiler.jar -YUICOMPRESS=build/tools/yuicompressor.jar ZIP=zip +# All files that will be compiled by the Closure compiler. +JS_FILES=\ + browser.js \ + svgtransformlist.js \ + math.js \ + units.js \ + svgutils.js \ + sanitize.js \ + history.js \ + select.js \ + draw.js \ + svgcanvas.js \ + svg-editor.js \ + locale/locale.js + +JS_INPUT_FILES=$(addprefix editor/, $(JS_FILES)) +JS_BUILD_FILES=$(addprefix build/$(PACKAGE)/, $(JS_FILES)) +CLOSURE_JS_ARGS=$(addprefix --js , $(JS_INPUT_FILES)) +COMPILED_JS=editor/svgedit.compiled.js + all: release firefox opera -build/$(PACKAGE): +# The build directory relies on the JS being compiled. +build/$(PACKAGE): $(COMPILED_JS) rm -rf config mkdir config if [ -x $(MAKEDOCS) ] ; then $(MAKEDOCS) -i editor/ -o html docs/ -p config/ -oft -r ; fi + + # Make build directory and copy all editor contents into it mkdir -p build/$(PACKAGE) cp -r editor/* build/$(PACKAGE) - -find build/$(PACKAGE) -name .svn -type d -exec rm -rf {} \; -# minify spin button - java -jar $(YUICOMPRESS) build/$(PACKAGE)/spinbtn/JQuerySpinBtn.js > build/$(PACKAGE)/spinbtn/JQuerySpinBtn.min.js -# minify SVG-edit files - java -jar $(YUICOMPRESS) build/$(PACKAGE)/svg-editor.js > build/$(PACKAGE)/svg-editor.min.js - java -jar $(YUICOMPRESS) build/$(PACKAGE)/svgcanvas.js > build/$(PACKAGE)/svgcanvas.min.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) # codedread: NOTE: Some files are not ready for the Closure compiler: (jquery) +$(COMPILED_JS): java -jar $(CLOSURE) \ - --js browser.js \ - --js svgtransformlist.js \ - --js math.js \ - --js units.js \ - --js svgutils.js \ - --js sanitize.js \ - --js history.js \ - --js select.js \ - --js draw.js \ - --js svgcanvas.js \ - --js svg-editor.js \ - --js locale/locale.js \ - --js_output_file svgedit.compiled.js - -# CSS files do not work remotely -# java -jar $(YUICOMPRESS) build/$(PACKAGE)/spinbtn/JQuerySpinBtn.css > build/$(PACKAGE)/spinbtn/JQuerySpinBtn.min.css -# java -jar $(YUICOMPRESS) build/$(PACKAGE)/svg-editor.css > build/$(PACKAGE)/svg-editor.min.css + --compilation_level WHITESPACE_ONLY \ + $(CLOSURE_JS_ARGS) \ + --js_output_file $(COMPILED_JS) release: build/$(PACKAGE) cd build ; $(ZIP) $(PACKAGE).zip -r $(PACKAGE) ; cd .. tar -z -c -f build/$(PACKAGE)-src.tar.gz \ - --exclude-vcs \ + --exclude='\.svn' \ --exclude='build/*' \ . @@ -66,3 +75,4 @@ clean: rm -rf build/$(PACKAGE) rm -rf build/firefox rm -rf build/opera + rm -rf $(COMPILED_JS) diff --git a/build/tools/ship.py b/build/tools/ship.py new file mode 100755 index 00000000..55f5d87f --- /dev/null +++ b/build/tools/ship.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# ship.py +# +# Licensed under the Apache 2 License as is the rest of the project +# +# Copyright (c) 2011 Jeff Schiller +# +# This script takes the following inputs: +# +# * a HTML file +# * a series of flag names +# +# It parses, the HTML file, enables/disables sections of the makrup based +# on conditional comments and flag values, then outputs a new HTML file. +# +# Example: +# +# in.html: +# +# BAR! +# +# +# $ ship.py --i in.html --o test-out.html --enable foo +# +# out.html: +# +# FOO! +# +# +# Only if-else-endif are currently supported. All conditional comment expressions must +# be on one line with no other non-whitespace characters. + +import optparse + +_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") + +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) + +if __name__ == '__main__': + options, (input, output) = parse_args() diff --git a/editor/locale/locale.js b/editor/locale/locale.js index a8333582..e480a2ae 100644 --- a/editor/locale/locale.js +++ b/editor/locale/locale.js @@ -8,6 +8,11 @@ * */ +// Dependencies +// 1) jQuery +// 2) svgcanvas.js +// 3) svg-editor.js + var svgEditor = (function($, Editor) { var lang_param; @@ -47,7 +52,6 @@ var svgEditor = (function($, Editor) { } } - Editor.readLang = function(langData) { var more = Editor.canvas.runExtensions("addlangData", lang_param, true); $.each(more, function(i, m) { @@ -133,9 +137,7 @@ var svgEditor = (function($, Editor) { svginfo_grid_settings: config.grid, svginfo_snap_onoff: config.snapping_onoff, - svginfo_snap_step: config.snapping_stepsize, - - + svginfo_snap_step: config.snapping_stepsize }, true); // Shape categories diff --git a/editor/svg-editor.html b/editor/svg-editor.html index acd15d9a..0b0888ec 100644 --- a/editor/svg-editor.html +++ b/editor/svg-editor.html @@ -9,38 +9,39 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - ---> + + + + + + + + + + + + + + + + + + + diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index af1d9c1d..10dae628 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -262,7 +262,7 @@ if (svgedit.browser.supportsSelectors()) { }; } canvas.getElem = getElem; - + // Function: assignAttributes // Assigns multiple attributes to an element. // @@ -2827,9 +2827,6 @@ var getMouseTarget = this.getMouseTarget = function(evt) { // in this function we do not record any state changes yet (but we do update // any elements that are still being created, moved or resized on the canvas) - // TODO: svgcanvas should just retain a reference to the image being dragged instead - // of the getId() and getElementById() funkiness - this will help us customize the ids - // a little bit for squares and paths var mouseMove = function(evt) { if (!started) return; @@ -2839,7 +2836,6 @@ var getMouseTarget = this.getMouseTarget = function(evt) { mouse_x = pt.x * current_zoom, mouse_y = pt.y * current_zoom, shape = getElem(getId()); - // IE9 gives the wrong root_sctm // TODO: Use non-browser sniffing way to make this work if($.browser.msie) { @@ -3567,8 +3563,10 @@ var getMouseTarget = this.getMouseTarget = function(evt) { return false; }; - $(container).mousedown(mouseDown).mousemove(mouseMove).click(handleLinkInCanvas).dblclick(dblClick); - $(window).mouseup(mouseUp); + // Added mouseup to the container here. + // TODO(codedread): Figure out why after the Closure compiler, the window mouseup is ignored. + $(container).mousedown(mouseDown).mousemove(mouseMove).click(handleLinkInCanvas).dblclick(dblClick).mouseup(mouseUp); +// $(window).mouseup(mouseUp); $(container).bind("mousewheel DOMMouseScroll", function(e){ if(!e.shiftKey) return; @@ -7016,7 +7014,7 @@ this.cloneLayer = function(name) { // Deletes the current layer from the drawing and then clears the selection. This function // then calls the 'changed' handler. This is an undoable action. this.deleteCurrentLayer = function() { - if (current_layer && current_drawing.all_layers.length > 1) { + if (current_layer && current_drawing.getNumLayers() > 1) { var batchCmd = new BatchCommand("Delete Layer"); // actually delete from the DOM and store in our Undo History var parent = current_layer.parentNode; @@ -7026,7 +7024,7 @@ this.deleteCurrentLayer = function() { addCommandToHistory(batchCmd); clearSelection(); identifyLayers(); - canvas.setCurrentLayer(current_drawing.all_layers[current_drawing.all_layers.length-1][0]); + canvas.setCurrentLayer(current_drawing.getLayer(current_drawing.getNumLayers())); call("changed", [svgcontent]); return true; } @@ -7042,7 +7040,7 @@ this.deleteCurrentLayer = function() { this.getCurrentLayer = function() { for (var i = 0; i < current_drawing.getNumLayers(); ++i) { if (current_drawing.all_layers[i][1] == current_layer) { - return current_drawing.all_layers[i][0]; + return current_drawing.getLayer(i); } } return ""; @@ -7059,8 +7057,8 @@ this.getCurrentLayer = function() { // true if the current layer was switched, otherwise false this.setCurrentLayer = function(name) { name = svgedit.utilities.toXml(name); - for (var i = 0; i < current_drawing.all_layers.length; ++i) { - if (name == current_drawing.all_layers[i][0]) { + for (var i = 0; i < current_drawing.getNumLayers(); ++i) { + if (name == current_drawing.getLayer(i)) { if (current_layer != current_drawing.all_layers[i][1]) { clearSelection(); current_layer.setAttribute("style", "pointer-events:none"); @@ -7090,10 +7088,10 @@ this.renameCurrentLayer = function(newname) { if (!canvas.setCurrentLayer(newname)) { var batchCmd = new BatchCommand("Rename Layer"); // find the index of the layer - for (var i = 0; i < current_drawing.all_layers.length; ++i) { + for (var i = 0; i < current_drawing.getNumLayers(); ++i) { if (current_drawing.all_layers[i][1] == oldLayer) break; } - var oldname = current_drawing.all_layers[i][0]; + var oldname = current_drawing.getLayer(i); current_drawing.all_layers[i][0] = svgedit.utilities.toXml(newname); // now change the underlying title element contents @@ -7130,19 +7128,19 @@ this.renameCurrentLayer = function(newname) { // Returns: // true if the current layer position was changed, false otherwise. this.setCurrentLayerPosition = function(newpos) { - if (current_layer && newpos >= 0 && newpos < current_drawing.all_layers.length) { - for (var oldpos = 0; oldpos < current_drawing.all_layers.length; ++oldpos) { + if (current_layer && newpos >= 0 && newpos < current_drawing.getNumLayers()) { + for (var oldpos = 0; oldpos < current_drawing.getNumLayers(); ++oldpos) { if (current_drawing.all_layers[oldpos][1] == current_layer) break; } // some unknown error condition (current_layer not in all_layers) - if (oldpos == current_drawing.all_layers.length) { return false; } + if (oldpos == current_drawing.getNumLayers()) { return false; } if (oldpos != newpos) { // if our new position is below us, we need to insert before the node after newpos var refLayer = null; var oldNextSibling = current_layer.nextSibling; if (newpos > oldpos ) { - if (newpos < current_drawing.all_layers.length-1) { + if (newpos < current_drawing.getNumLayers()-1) { refLayer = current_drawing.all_layers[newpos+1][1]; } } @@ -7154,7 +7152,7 @@ this.setCurrentLayerPosition = function(newpos) { addCommandToHistory(new MoveElementCommand(current_layer, oldNextSibling, svgcontent)); identifyLayers(); - canvas.setCurrentLayer(current_drawing.all_layers[newpos][0]); + canvas.setCurrentLayer(current_drawing.getLayer(newpos)); return true; } @@ -7175,8 +7173,8 @@ this.setCurrentLayerPosition = function(newpos) { this.getLayerVisibility = function(layername) { // find the layer var layer = null; - for (var i = 0; i < current_drawing.all_layers.length; ++i) { - if (current_drawing.all_layers[i][0] == layername) { + for (var i = 0; i < current_drawing.getNumLayers(); ++i) { + if (current_drawing.getLayer(i) == layername) { layer = current_drawing.all_layers[i][1]; break; } @@ -7198,8 +7196,8 @@ this.getLayerVisibility = function(layername) { this.setLayerVisibility = function(layername, bVisible) { // find the layer var layer = null; - for (var i = 0; i < current_drawing.all_layers.length; ++i) { - if (current_drawing.all_layers[i][0] == layername) { + for (var i = 0; i < current_drawing.getNumLayers(); ++i) { + if (current_drawing.getLayer(i) == layername) { layer = current_drawing.all_layers[i][1]; break; } @@ -7232,8 +7230,8 @@ this.setLayerVisibility = function(layername, bVisible) { this.moveSelectedToLayer = function(layername) { // find the layer var layer = null; - for (var i = 0; i < current_drawing.all_layers.length; ++i) { - if (current_drawing.all_layers[i][0] == layername) { + for (var i = 0; i < current_drawing.getNumLayers(); ++i) { + if (current_drawing.getLayer(i) == layername) { layer = current_drawing.all_layers[i][1]; break; } @@ -7300,7 +7298,7 @@ this.mergeLayer = function(skipHistory) { this.mergeAllLayers = function() { var batchCmd = new BatchCommand("Merge all Layers"); - current_layer = current_drawing.all_layers[current_drawing.all_layers.length-1][1]; + current_layer = current_drawing.all_layers[current_drawing.getNumLayers()-1][1]; while($(svgcontent).children('g').length > 1) { batchCmd.addSubCommand(canvas.mergeLayer(true)); } @@ -7321,8 +7319,8 @@ this.mergeAllLayers = function() { // The opacity value of the given layer. This will be a value between 0.0 and 1.0, or null // if layername is not a valid layer this.getLayerOpacity = function(layername) { - for (var i = 0; i < current_drawing.all_layers.length; ++i) { - if (current_drawing.all_layers[i][0] == layername) { + for (var i = 0; i < current_drawing.getNumLayers(); ++i) { + if (current_drawing.getLayer(i) == layername) { var g = current_drawing.all_layers[i][1]; var opacity = g.getAttribute("opacity"); if (!opacity) { @@ -7347,8 +7345,8 @@ this.getLayerOpacity = function(layername) { // opacity - a float value in the range 0.0-1.0 this.setLayerOpacity = function(layername, opacity) { if (opacity < 0.0 || opacity > 1.0) return; - for (var i = 0; i < current_drawing.all_layers.length; ++i) { - if (current_drawing.all_layers[i][0] == layername) { + for (var i = 0; i < current_drawing.getNumLayers(); ++i) { + if (current_drawing.getLayer(i) == layername) { var g = current_drawing.all_layers[i][1]; g.setAttribute("opacity", opacity); break;