diff --git a/Makefile b/Makefile index 1ee342534..515fe6c5f 100644 --- a/Makefile +++ b/Makefile @@ -41,16 +41,27 @@ server: test: pdfjs shell-test browser-test +# +# Create production output (pdf.js, and corresponding changes to web files) +# +production: | bundle + @echo "Preparing production viewer..."; \ + cd web; \ + sed '/PDFJSSCRIPT_REMOVE/d' viewer.html > viewer-1.tmp; \ + sed '/PDFJSSCRIPT_INCLUDE_BUILD/ r viewer-snippet.html' viewer-1.tmp > viewer-production.html; \ + rm -f *.tmp; \ + cd .. + # # Bundle pdf.js # -pdfjs: - @echo "Bundling source files..." +bundle: + @echo "Bundling source files into pdf.js..." @mkdir -p $(BUILD_DIR) @cd src; \ cat $(PDF_JS_FILES) > all_files.tmp; \ - sed '/INSERT_POINT/ r all_files.tmp' pdf.js > ../$(PDFJS_TARGET); \ - rm -f all_files.tmp; \ + sed '/PDFJSSCRIPT_INCLUDE_ALL/ r all_files.tmp' pdf.js > ../$(PDFJS_TARGET); \ + rm -f *.tmp; \ cd .. # make browser-test @@ -127,13 +138,14 @@ lint: # TODO: Use the Closure compiler to optimize the pdf.js files. # GH_PAGES = $(BUILD_DIR)/gh-pages -web: | pdfjs extension compiler pages-repo \ +web: | production extension compiler pages-repo \ $(addprefix $(GH_PAGES)/, $(PDFJS_TARGET)) \ $(addprefix $(GH_PAGES)/, $(wildcard web/*.*)) \ $(addprefix $(GH_PAGES)/, $(wildcard web/images/*.*)) \ $(addprefix $(GH_PAGES)/, $(wildcard $(EXTENSION_SRC)/*.xpi)) @cp $(GH_PAGES)/web/index.html.template $(GH_PAGES)/index.html; + @mv -f $(GH_PAGES)/web/viewer-production.html $(GH_PAGES)/web/viewer.html; @cd $(GH_PAGES); git add -A; @echo @echo "Website built in $(GH_PAGES)." @@ -191,15 +203,16 @@ PDF_WEB_FILES = \ web/compatibility.js \ web/viewer.css \ web/viewer.js \ - web/viewer.html \ + web/viewer-production.html \ $(NULL) -extension: | pdfjs +extension: | production # Copy a standalone version of pdf.js inside the content directory @rm -Rf $(EXTENSION_SRC)/$(CONTENT_DIR)/ @mkdir -p $(EXTENSION_SRC)/$(CONTENT_DIR)/$(BUILD_DIR) @mkdir -p $(EXTENSION_SRC)/$(CONTENT_DIR)/web @cp $(PDFJS_TARGET) $(EXTENSION_SRC)/$(CONTENT_DIR)/$(BUILD_DIR) @cp -r $(PDF_WEB_FILES) $(EXTENSION_SRC)/$(CONTENT_DIR)/web/ + @mv -f $(EXTENSION_SRC)/$(CONTENT_DIR)/web/viewer-production.html $(EXTENSION_SRC)/$(CONTENT_DIR)/web/viewer.html # Create the xpi @cd $(EXTENSION_SRC); zip -r $(EXTENSION_NAME) * @@ -219,12 +232,5 @@ clean: help: @echo "Read the comments in the Makefile for guidance."; -# -# Watch for file changes, regenerate pdf.js if change found -# -watch: - @echo "Watching for file changes in src/" - @python watch.py src/*.js - 'make pdfjs' - -.PHONY:: all pdfjs watch test browser-test font-test shell-test \ +.PHONY:: production watch test browser-test font-test shell-test \ shell-msg lint clean web compiler help server diff --git a/examples/helloworld/index.html b/examples/helloworld/index.html index 169161959..b10e9eaeb 100644 --- a/examples/helloworld/index.html +++ b/examples/helloworld/index.html @@ -2,8 +2,26 @@ - - + + + + + + + + + + + + + + + + + + + + diff --git a/src/core.js b/src/core.js index 1c4f56aab..55525c788 100644 --- a/src/core.js +++ b/src/core.js @@ -10,7 +10,7 @@ var useWorker = false; // In production, it will be declared outside a global wrapper // In development, it will be declared here if (typeof PDF === 'undefined') { - var PDF = {}; + PDF = {}; } // getPdf() diff --git a/src/pdf.js b/src/pdf.js index 94ea074da..427526f65 100644 --- a/src/pdf.js +++ b/src/pdf.js @@ -4,9 +4,11 @@ var PDF = {}; (function() { + // Use strict in our context only - users might not want it 'use strict'; // Files are inserted below - see Makefile - /* INSERT_POINT */ + /* PDFJSSCRIPT_INCLUDE_ALL */ + })(); diff --git a/watch.py b/watch.py deleted file mode 100644 index 1a94f8953..000000000 --- a/watch.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python -# Python port of Ian Piumarta's watch.c -# BSD Licensed - http://eschew.org/txt/bsd.txt - -import re -import os -import sys -import time -import string -import subprocess - -maxfiles = 64 - -def usage(): - return """usage: %(watch)s - - is/are the file/s to be monitored - is/are the commands to execute (quote if args required) - Note: occurrences of '${file}' in command strings will be replaced - with updated filename before execution. - e.g.: %(watch)s *.txt - 'echo ${file}' -""" % { 'watch': sys.argv[0] } - -def try_get_mtime(path): - try: - buf = os.stat(path) - except OSError: - time.sleep(1) - try: - buf = os.stat(path) - except OSError: - print "%(watch)s: %(file)s: file not found" - sys.exit(1) - return buf.st_mtime - -def execute_commands(commands, filename): - for command in commands: - cmd = string.Template(command).safe_substitute(file=filename) - cmd_pieces = re.split('\s+', cmd) - subprocess.Popen(cmd_pieces) - -def main(): - files = [] - commands = [] - seeing_paths = True - for part in sys.argv[1:]: - if part == '-': - seeing_paths = False - elif seeing_paths: - files.append(part) - else: - commands.append(part) - - if len(commands) == 0: - print usage() - sys.exit(1) - - if len(files) > maxfiles: - print "%(watch)s: too many files to watch" % sys.argv[0] - - mtimes = dict([(f, try_get_mtime(f)) for f in files]) - done = False - while not done: - for f in files: - old_mtime = mtimes[f] - new_mtime = try_get_mtime(f) - if new_mtime != old_mtime: - mtimes[f] = new_mtime - execute_commands(commands, f) - time.sleep(1) - -if __name__ == '__main__': - try: - main() - except KeyboardInterrupt: - sys.exit(0) - - diff --git a/web/.gitignore b/web/.gitignore new file mode 100644 index 000000000..2c0f5df71 --- /dev/null +++ b/web/.gitignore @@ -0,0 +1 @@ +viewer-production.html diff --git a/web/viewer-snippet.html b/web/viewer-snippet.html new file mode 100644 index 000000000..c99897a44 --- /dev/null +++ b/web/viewer-snippet.html @@ -0,0 +1,2 @@ + + diff --git a/web/viewer.html b/web/viewer.html index 6d119152d..f7a5378ed 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -4,24 +4,26 @@ Simple pdf.js page viewer - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + +