1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,3 +9,4 @@
|
||||
/build/src
|
||||
/examples/*.json
|
||||
/examples/*.combined.js
|
||||
/examples/index.html
|
||||
|
||||
8
Makefile
8
Makefile
@@ -11,7 +11,7 @@ EXTERNAL_SRC = \
|
||||
build/src/external/externs/types.js \
|
||||
build/src/external/src/exports.js \
|
||||
build/src/external/src/types.js
|
||||
EXAMPLES = $(shell find examples -maxdepth 1 -name \*.html)
|
||||
EXAMPLES = $(filter-out examples/index.html,$(shell find examples -maxdepth 1 -name \*.html))
|
||||
comma := ,
|
||||
empty :=
|
||||
space := $(empty) $(empty)
|
||||
@@ -63,7 +63,10 @@ build/src/internal/src/types.js: bin/generate-exports src/ol/exports.txt
|
||||
build-examples: examples $(subst .html,.combined.js,$(EXAMPLES))
|
||||
|
||||
.PHONY: examples
|
||||
examples: $(subst .html,.json,$(EXAMPLES))
|
||||
examples: examples/index.html $(subst .html,.json,$(EXAMPLES))
|
||||
|
||||
examples/index.html: bin/generate-examples-index $(EXAMPLES)
|
||||
bin/generate-examples-index -o $@ -s examples/index.js $(EXAMPLES)
|
||||
|
||||
examples/%.json: Makefile base.json
|
||||
echo "{\"id\": \"$(basename $(notdir $@))\", \"inherits\": \"../base.json\", \"inputs\": [\"$(subst .json,.js,$@)\", \"build/src/internal/src/types.js\"]}" > $@
|
||||
@@ -116,6 +119,7 @@ hostexamples: build examples
|
||||
cp $(EXAMPLES) $(subst .html,.js,$(EXAMPLES)) examples/style.css build/gh-pages/$(BRANCH)/examples/
|
||||
cp build/loader_hosted_examples.js build/gh-pages/$(BRANCH)/examples/loader.js
|
||||
cp build/ol.js build/ol.css build/gh-pages/$(BRANCH)/build/
|
||||
cp examples/index.html examples/index.js build/gh-pages/$(BRANCH)/examples
|
||||
|
||||
.PHONY: test
|
||||
test: $(INTERNAL_SRC)
|
||||
|
||||
65
bin/generate-examples-index
Executable file
65
bin/generate-examples-index
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from contextlib import contextmanager
|
||||
from optparse import OptionParser
|
||||
import os
|
||||
import sys
|
||||
import xml.etree.cElementTree as ElementTree
|
||||
|
||||
|
||||
@contextmanager
|
||||
def tag(tb, name, attrs=None):
|
||||
tb.start(name, attrs)
|
||||
yield tb
|
||||
tb.end(name)
|
||||
|
||||
|
||||
def main(argv):
|
||||
|
||||
option_parser = OptionParser()
|
||||
option_parser.add_option('--output', '-o', metavar='FILENAME')
|
||||
option_parser.add_option('--script', '-s', action='append', default=[],
|
||||
dest='scripts', metavar='SCRIPT')
|
||||
options, args = option_parser.parse_args(argv[1:])
|
||||
if options.output:
|
||||
outputdir = os.path.dirname(options.output)
|
||||
else:
|
||||
outputdir = os.curdir()
|
||||
|
||||
tb = ElementTree.TreeBuilder()
|
||||
with tag(tb, 'html'):
|
||||
with tag(tb, 'head'):
|
||||
with tag(tb, 'meta', {'content': 'text/html; charset=utf-8',
|
||||
'http-equiv': 'Content-Type'}):
|
||||
pass
|
||||
with tag(tb, 'link', {'href': 'style.css',
|
||||
'rel': 'stylesheet',
|
||||
'type': 'text/css'}):
|
||||
pass
|
||||
with tag(tb, 'title'):
|
||||
tb.data('ol3 examples')
|
||||
with tag(tb, 'body'):
|
||||
with tag(tb, 'h1'):
|
||||
tb.data('ol3 examples')
|
||||
with tag(tb, 'ul'):
|
||||
for arg in sorted(args):
|
||||
with tag(tb, 'li'):
|
||||
href = os.path.relpath(arg, outputdir)
|
||||
with tag(tb, 'a', {'href': href}):
|
||||
tb.data(os.path.splitext(os.path.basename(arg))[0]
|
||||
.replace('-', ' '))
|
||||
for script in sorted(options.scripts):
|
||||
src = os.path.relpath(script, outputdir)
|
||||
with tag(tb, 'script', {'src': src, 'type': 'text/javascript'}):
|
||||
tb.data('')
|
||||
|
||||
if options.output:
|
||||
output = open(options.output, 'w')
|
||||
else:
|
||||
output = sys.stdout
|
||||
output.write('<!doctype html>')
|
||||
output.write(ElementTree.tostring(tb.close(), 'utf-8', 'html'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
16
examples/index.js
Normal file
16
examples/index.js
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
|
||||
/**
|
||||
* Loader to append the query string to every A element in the document.
|
||||
*
|
||||
* This is so that (for example) visiting
|
||||
* /examples/index.html?mode=RAW&Debug=true
|
||||
* will cause all links to automatically include the ?mode=RAW&Debug=true.
|
||||
*/
|
||||
(function() {
|
||||
var as = document.getElementsByTagName('a');
|
||||
var i, n = as.length;
|
||||
for (i = 0; i < n; ++i) {
|
||||
as[i].href += window.location.search;
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user