diff --git a/Pipfile.lock b/Pipfile.lock index 70d8121..559e4b3 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -136,11 +136,11 @@ }, "black": { "hashes": [ - "sha256:09a9dcb7c46ed496a9850b76e4e825d6049ecd38b611f1224857a79bd985a8cf", - "sha256:68950ffd4d9169716bcb8719a56c07a2f4485354fec061cdd5910aa07369731c" + "sha256:1b30e59be925fafc1ee4565e5e08abef6b03fe455102883820fe5ee2e4734e0b", + "sha256:c2edb73a08e9e0e6f65a0e6af18b059b8b1cdd5bef997d7a0b181df93dc81539" ], "index": "pypi", - "version": "==19.3b0" + "version": "==19.10b0" }, "click": { "hashes": [ @@ -159,26 +159,29 @@ }, "lazy-object-proxy": { "hashes": [ - "sha256:02b260c8deb80db09325b99edf62ae344ce9bc64d68b7a634410b8e9a568edbf", - "sha256:18f9c401083a4ba6e162355873f906315332ea7035803d0fd8166051e3d402e3", - "sha256:1f2c6209a8917c525c1e2b55a716135ca4658a3042b5122d4e3413a4030c26ce", - "sha256:2f06d97f0ca0f414f6b707c974aaf8829c2292c1c497642f63824119d770226f", - "sha256:616c94f8176808f4018b39f9638080ed86f96b55370b5a9463b2ee5c926f6c5f", - "sha256:63b91e30ef47ef68a30f0c3c278fbfe9822319c15f34b7538a829515b84ca2a0", - "sha256:77b454f03860b844f758c5d5c6e5f18d27de899a3db367f4af06bec2e6013a8e", - "sha256:83fe27ba321e4cfac466178606147d3c0aa18e8087507caec78ed5a966a64905", - "sha256:84742532d39f72df959d237912344d8a1764c2d03fe58beba96a87bfa11a76d8", - "sha256:874ebf3caaf55a020aeb08acead813baf5a305927a71ce88c9377970fe7ad3c2", - "sha256:9f5caf2c7436d44f3cec97c2fa7791f8a675170badbfa86e1992ca1b84c37009", - "sha256:a0c8758d01fcdfe7ae8e4b4017b13552efa7f1197dd7358dc9da0576f9d0328a", - "sha256:a4def978d9d28cda2d960c279318d46b327632686d82b4917516c36d4c274512", - "sha256:ad4f4be843dace866af5fc142509e9b9817ca0c59342fdb176ab6ad552c927f5", - "sha256:ae33dd198f772f714420c5ab698ff05ff900150486c648d29951e9c70694338e", - "sha256:b4a2b782b8a8c5522ad35c93e04d60e2ba7f7dcb9271ec8e8c3e08239be6c7b4", - "sha256:c462eb33f6abca3b34cdedbe84d761f31a60b814e173b98ede3c81bb48967c4f", - "sha256:fd135b8d35dfdcdb984828c84d695937e58cc5f49e1c854eb311c4d6aa03f4f1" - ], - "version": "==1.4.2" + "sha256:0c4b206227a8097f05c4dbdd323c50edf81f15db3b8dc064d08c62d37e1a504d", + "sha256:194d092e6f246b906e8f70884e620e459fc54db3259e60cf69a4d66c3fda3449", + "sha256:1be7e4c9f96948003609aa6c974ae59830a6baecc5376c25c92d7d697e684c08", + "sha256:4677f594e474c91da97f489fea5b7daa17b5517190899cf213697e48d3902f5a", + "sha256:48dab84ebd4831077b150572aec802f303117c8cc5c871e182447281ebf3ac50", + "sha256:5541cada25cd173702dbd99f8e22434105456314462326f06dba3e180f203dfd", + "sha256:59f79fef100b09564bc2df42ea2d8d21a64fdcda64979c0fa3db7bdaabaf6239", + "sha256:8d859b89baf8ef7f8bc6b00aa20316483d67f0b1cbf422f5b4dc56701c8f2ffb", + "sha256:9254f4358b9b541e3441b007a0ea0764b9d056afdeafc1a5569eee1cc6c1b9ea", + "sha256:9651375199045a358eb6741df3e02a651e0330be090b3bc79f6d0de31a80ec3e", + "sha256:97bb5884f6f1cdce0099f86b907aa41c970c3c672ac8b9c8352789e103cf3156", + "sha256:9b15f3f4c0f35727d3a0fba4b770b3c4ebbb1fa907dbcc046a1d2799f3edd142", + "sha256:a2238e9d1bb71a56cd710611a1614d1194dc10a175c1e08d75e1a7bcc250d442", + "sha256:a6ae12d08c0bf9909ce12385803a543bfe99b95fe01e752536a60af2b7797c62", + "sha256:ca0a928a3ddbc5725be2dd1cf895ec0a254798915fb3a36af0964a0a4149e3db", + "sha256:cb2c7c57005a6804ab66f106ceb8482da55f5314b7fcb06551db1edae4ad1531", + "sha256:d74bb8693bf9cf75ac3b47a54d716bbb1a92648d5f781fc799347cfc95952383", + "sha256:d945239a5639b3ff35b70a88c5f2f491913eb94871780ebfabb2568bd58afc5a", + "sha256:eba7011090323c1dadf18b3b689845fd96a61ba0a1dfbd7f24b921398affc357", + "sha256:efa1909120ce98bbb3777e8b6f92237f5d5c8ea6758efea36a473e1d38f7d3e4", + "sha256:f3900e8a5de27447acbf900b4750b0ddfd7ec1ea7fbaf11dfa911141bc522af0" + ], + "version": "==1.4.3" }, "mccabe": { "hashes": [ @@ -187,6 +190,12 @@ ], "version": "==0.6.1" }, + "pathspec": { + "hashes": [ + "sha256:e285ccc8b0785beadd4c18e5708b12bb8fcf529a1e61215b3feff1d1e559ea5c" + ], + "version": "==0.6.0" + }, "pylint": { "hashes": [ "sha256:7b76045426c650d2b0f02fc47c14d7934d17898779da95288a74c2a7ec440702", @@ -195,6 +204,24 @@ "index": "pypi", "version": "==2.4.3" }, + "regex": { + "hashes": [ + "sha256:15454b37c5a278f46f7aa2d9339bda450c300617ca2fca6558d05d870245edc7", + "sha256:1ad40708c255943a227e778b022c6497c129ad614bb7a2a2f916e12e8a359ee7", + "sha256:5e00f65cc507d13ab4dfa92c1232d004fa202c1d43a32a13940ab8a5afe2fb96", + "sha256:604dc563a02a74d70ae1f55208ddc9bfb6d9f470f6d1a5054c4bd5ae58744ab1", + "sha256:720e34a539a76a1fedcebe4397290604cc2bdf6f81eca44adb9fb2ea071c0c69", + "sha256:7caf47e4a9ac6ef08cabd3442cc4ca3386db141fb3c8b2a7e202d0470028e910", + "sha256:7faf534c1841c09d8fefa60ccde7b9903c9b528853ecf41628689793290ca143", + "sha256:b4e0406d822aa4993ac45072a584d57aa4931cf8288b5455bbf30c1d59dbad59", + "sha256:c31eaf28c6fe75ea329add0022efeed249e37861c19681960f99bbc7db981fb2", + "sha256:c7393597191fc2043c744db021643549061e12abe0b3ff5c429d806de7b93b66", + "sha256:d2b302f8cdd82c8f48e9de749d1d17f85ce9a0f082880b9a4859f66b07037dc6", + "sha256:e3d8dd0ec0ea280cf89026b0898971f5750a7bd92cb62c51af5a52abd020054a", + "sha256:ec032cbfed59bd5a4b8eab943c310acfaaa81394e14f44454ad5c9eba4f24a74" + ], + "version": "==2019.11.1" + }, "six": { "hashes": [ "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", diff --git a/docs/source/conf.py b/docs/source/conf.py index bc16c91..dd3ff4c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -23,7 +23,7 @@ author = 'David Omar Flores Chavez' # The full version, including alpha/beta/rc tags -release = 'v0.7.4' +release = 'v0.8.0' # -- General configuration --------------------------------------------------- diff --git a/forceBuild.sh b/forceBuild.sh deleted file mode 100755 index 24e64b6..0000000 --- a/forceBuild.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -# Install the package, force a quickstart, and build the site - -sudo python setup.py install -ginpar-quickstart --force -ginpar \ No newline at end of file diff --git a/ginpar/__init__.py b/ginpar/__init__.py index e49a2e5..6e9be47 100644 --- a/ginpar/__init__.py +++ b/ginpar/__init__.py @@ -1,4 +1,5 @@ from ginpar.cli import cli + def main(): - cli() \ No newline at end of file + cli() diff --git a/ginpar/build.py b/ginpar/build.py index 358b66e..6d89d73 100644 --- a/ginpar/build.py +++ b/ginpar/build.py @@ -230,11 +230,10 @@ def render_index(build_path, sketches, site, page_template): index = open(os.path.join(build_path, "index.html"), "w") # Write the contents of the rendered template into the index file - index.write( - page_template.render(sketches=sketches, site=site) - ) + index.write(page_template.render(sketches=sketches, site=site)) index.close() + def param_to_dict(param): param_var = list(param)[0] if "name" in param[param_var]: @@ -245,7 +244,7 @@ def param_to_dict(param): "var": param_var, "id": param_var.lower(), "attrs": param[param_var]["attrs"], - "name": name + "name": name, } @@ -283,21 +282,26 @@ def render_sketch_page(build_path, sketch, site, page_template, input_templates) ## Create a directory with the sketch title os.mkdir(os.path.join(build_path, sketch["name"])) params = list(map(param_to_dict, sketch["data"]["params"])) - default_input = next((x for x in input_templates if x.name.endswith("default.html"))) + default_input = next( + (x for x in input_templates if x.name.endswith("default.html")) + ) content = "" for param in params: input_type = param["attrs"]["type"] template = next( (x for x in input_templates if x.name.endswith(input_type + ".html")), - default_input) - content = content + template.render(param = param) + default_input, + ) + content = content + template.render(param=param) ## Create index.html sketch_index = open(f"public/{sketch['name']}/index.html", "w+") sketch_index.write( page_template.render( - sketch=unkebab(sketch["name"]), form = "
\n" + content + "\n
", site=site + sketch=unkebab(sketch["name"]), + form="
\n" + content + "\n
", + site=site, ) ) sketch_index.close() @@ -308,8 +312,12 @@ def render_sketch_page(build_path, sketch, site, page_template, input_templates) ## Copy all the content from original sketches/{title}.js to sketch.js sf = open(sketch["script"], "r") - - sketch_script.write(gg.makeValueGetter(list(params))) + sketch_script.write( + gg.makeValueGetter( + ("global_seed" in sketch["data"] and sketch["data"]["global_seed"]), + list(params), + ) + ) for x in sf.readlines(): sketch_script.write(x) sf.close() @@ -354,7 +362,7 @@ def build(path): _THEME = _SITE["theme"].split("/")[1] _THEME_PATH = os.path.join("themes", _THEME) - + _TEMPLATES_PATH = os.path.join(_THEME_PATH, "templates") _SKETCHES_PATH = _SITE["content_path"] @@ -363,19 +371,19 @@ def build(path): _jinja_env.filters["unkebab"] = unkebab _jinja_env.filters["getattrs"] = dict_to_attrs - - if not os.path.isdir(_THEME_PATH): clone_repo(_SITE["theme"], _THEME_PATH) delete_git_files(_THEME_PATH) - input_templates = list(map( - lambda t : _jinja_env.get_template(t), - filter( - lambda t : t.startswith(os.path.join("form", "inputs")), - _jinja_env.list_templates() + input_templates = list( + map( + lambda t: _jinja_env.get_template(t), + filter( + lambda t: t.startswith(os.path.join("form", "inputs")), + _jinja_env.list_templates(), + ), ) - )) + ) create_publishing_directory(path) echo(f"Building in `{os.path.abspath(path)}`") @@ -386,7 +394,7 @@ def build(path): ## Create the sketches list sketches = list(get_sketches(_SKETCHES_PATH)) echo(f"Found {len(sketches)} sketch(es)") - sketches.sort(key=lambda a : a["data"]["date"], reverse=True) + sketches.sort(key=lambda a: a["data"]["date"], reverse=True) render_index(path, sketches, _SITE, _jinja_env.get_template("index.html")) echo("Building main page") @@ -394,6 +402,8 @@ def build(path): echo("Building sketches:") for sketch in sketches: echo(f" Building {sketch['name']}") - render_sketch_page(path, sketch, _SITE, _jinja_env.get_template("sketch.html"), input_templates) + render_sketch_page( + path, sketch, _SITE, _jinja_env.get_template("sketch.html"), input_templates + ) success("Success.") diff --git a/ginpar/cli.py b/ginpar/cli.py index d69dfeb..f00e252 100644 --- a/ginpar/cli.py +++ b/ginpar/cli.py @@ -34,7 +34,7 @@ def cli(): "The PATH where the site will be built. [ , public ] " "This path is relative to the current directory. When no option is provided " "Ginpar will read the from the configuration file." - ), + ), ) def build(path): """Build the project content into PATH. @@ -63,7 +63,7 @@ def build(path): "If Ginpar finds an existing directory with the same name of the " "project being initialized, it'll force its removal. " "Only do this if you're completely sure you want to do it." - ), + ), ) @click.option( "--quick", @@ -118,7 +118,7 @@ def new(sketch): "If Ginpar finds an existing directory with the same name of the sample content, " "it'll force its removal. " "Only do this if you're completely sure you want to do it." - ), + ), ) def quickstart(force): """Import a working sample project. diff --git a/ginpar/generators.py b/ginpar/generators.py index 5da46dc..7c5c18b 100644 --- a/ginpar/generators.py +++ b/ginpar/generators.py @@ -35,10 +35,9 @@ def dict_to_attrs(d): _jinja_env.filters["getattrs"] = dict_to_attrs -def makeValueGetter(attrs): +def makeValueGetter(global_seed, attrs): _TEMPLATE = _jinja_env.get_template("retrieve.js") - - return _TEMPLATE.render(params=attrs) + return _TEMPLATE.render(global_seed=global_seed, params=attrs) def sketch_to_dict(s): diff --git a/ginpar/init.py b/ginpar/init.py index 6131846..f16ae4a 100644 --- a/ginpar/init.py +++ b/ginpar/init.py @@ -102,7 +102,7 @@ def init(force, quick): config_yaml = os.path.join(path, "config.yaml") echo("\n---\n") - + if force: echo("\n---\n") try_remove(path) diff --git a/ginpar/new.py b/ginpar/new.py index d75f414..0d19c98 100644 --- a/ginpar/new.py +++ b/ginpar/new.py @@ -70,14 +70,15 @@ def new(sketch): error(f"Failure.") echo(f"{path} already exists.") raise click.Abort() - + create_folder(path) sketch_template = _jinja_env.get_template("sketch.js") data_template = _jinja_env.get_template("data.yaml") create_file(os.path.join(path, "sketch.js"), sketch_template.render()) - create_file(os.path.join(path, "data.yaml"), data_template.render( - today = date.today().strftime("%Y-%m-%d") - )) + create_file( + os.path.join(path, "data.yaml"), + data_template.render(today=date.today().strftime("%Y-%m-%d")), + ) - echo(f"\nYour new sketch {path} is ready.\n") \ No newline at end of file + echo(f"\nYour new sketch {path} is ready.\n") diff --git a/ginpar/quickstart.py b/ginpar/quickstart.py index 4e27ff3..cebbc23 100644 --- a/ginpar/quickstart.py +++ b/ginpar/quickstart.py @@ -32,6 +32,7 @@ from ginpar.utils.files import try_remove from ginpar.utils.git import clone_repo, delete_git_files + def quickstart(force): """Main function of the module. This is what `ginpar quickstart` calls. @@ -60,4 +61,4 @@ def quickstart(force): echo("Run `cd quickstart` to move to the project directory.") echo("Then run `ginpar build` or `ginpar serve` to see it working.") else: - raise click.Abort() \ No newline at end of file + raise click.Abort() diff --git a/ginpar/serve.py b/ginpar/serve.py index 0312051..14e937d 100644 --- a/ginpar/serve.py +++ b/ginpar/serve.py @@ -51,5 +51,5 @@ def serve(port): server = Server() - server.watch(site["content_path"], 'ginpar build') - server.serve(port=port, root=site["build_path"]) \ No newline at end of file + server.watch(site["content_path"], "ginpar build") + server.serve(port=port, root=site["build_path"]) diff --git a/ginpar/templates/input.html b/ginpar/templates/input.html index 0161755..54e7950 100644 --- a/ginpar/templates/input.html +++ b/ginpar/templates/input.html @@ -2,5 +2,5 @@ - + \ No newline at end of file diff --git a/ginpar/templates/retrieve.js b/ginpar/templates/retrieve.js index ee0faf7..a801dce 100644 --- a/ginpar/templates/retrieve.js +++ b/ginpar/templates/retrieve.js @@ -1,28 +1,40 @@ -function newRandomSeeds(){ - RANDOM_S = Math.random() * 100000000 - NOISE_S = Math.random() * 10000000 +var RANDOM_SEED = Math.round(Math.random() * 100000000) +var NOISE_SEED = Math.round(Math.random() * 100000000) + +{% if global_seed -%} +function ginpar_newRandomSeeds(){ + RANDOM_SEED = Math.round(Math.random() * 100000000) + NOISE_SEED = Math.round(Math.random() * 100000000) } +{%- endif %} + -function resetDraw(){ - updateVars(); setup(); draw(); +function ginpar_resetDraw(){ + ginpar_updateVars(); draw(); } -function updateVars(){ +function ginpar_updateVars(){ {% for param in params -%} - {% if param["attrs"]['type'] == 'dimensions' -%} + {%- if param["attrs"]['type'] == 'dimensions' -%} {{ param.var }} = [ - document.getElementById("{{ param.id }}-0").value, - document.getElementById("{{ param.id }}-1").value + Number(document.getElementById("{{ param.id }}-0").value), + Number(document.getElementById("{{ param.id }}-1").value) ]; {% else %} - {{ param.var }} = document.getElementById("{{param.id}}").value; - + {{ param.var }} = + {%- if param.attrs.type == "number" -%} Number{%- endif -%} + (document.getElementById("{{param.id}}").value); {%- endif %} {%- endfor %} } -updateVars() + +function ginpar_save(){ + save(`${RANDOM_SEED}-${NOISE_SEED}`) +} + +ginpar_updateVars() {{'\n'}} \ No newline at end of file diff --git a/ginpar/utils/git.py b/ginpar/utils/git.py index 1ba95a5..0eb1e5c 100644 --- a/ginpar/utils/git.py +++ b/ginpar/utils/git.py @@ -6,6 +6,7 @@ from ginpar.utils.echo import success, echo, error from ginpar.utils.files import try_remove + def clone_repo(repo, path): """Clone the contents of a repository in a custom path @@ -31,6 +32,7 @@ def clone_repo(repo, path): success(f"Successfully cloned {repo}.\n") return 0 + def delete_git_files(path): """Delete the git files to only keep the relevant files diff --git a/ginpar/utils/strings.py b/ginpar/utils/strings.py index 835e3fa..2e98530 100644 --- a/ginpar/utils/strings.py +++ b/ginpar/utils/strings.py @@ -7,4 +7,4 @@ def space_to_kebab(s): def camel_to_space(s): - return " ".join(s.split("_")) \ No newline at end of file + return " ".join(s.split("_")) diff --git a/requirements.txt b/requirements.txt index 7b3dbd5..42b056c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,56 +1,8 @@ -alabaster==0.7.12 -appdirs==1.4.3 -argh==0.26.2 -astroid==2.3.2 -attrs==19.3.0 -Babel==2.7.0 -black==19.3b0 -certifi==2019.9.11 -chardet==3.0.4 -Click==7.0 -doc8==0.8.0 -docutils==0.15.2 -idna==2.8 -imagesize==1.1.0 -importlib-metadata==0.23 -isort==4.3.21 -Jinja2==2.10.3 -lazy-object-proxy==1.4.2 +-i https://pypi.org/simple +click==7.0 +jinja2==2.10.3 livereload==2.6.1 -MarkupSafe==1.1.1 -mccabe==0.6.1 -more-itertools==7.2.0 -packaging==19.2 -Pallets-Sphinx-Themes==1.2.2 -pathtools==0.1.2 -pbr==5.4.3 -port-for==0.3.1 -Pygments==2.4.2 -pylint==2.4.3 -pyparsing==2.4.2 -pytz==2019.3 -PyYAML==5.1.2 -requests==2.22.0 -restructuredtext-lint==1.3.0 +markupsafe==1.1.1 +pyyaml==5.1.2 six==1.12.0 -snowballstemmer==2.0.0 -Sphinx==2.1.2 -sphinx-autobuild==0.7.1 -sphinx-click==2.3.0 -sphinx-prompt==1.1.0 -sphinxcontrib-applehelp==1.0.1 -sphinxcontrib-devhelp==1.0.1 -sphinxcontrib-htmlhelp==1.0.2 -sphinxcontrib-jsmath==1.0.1 -sphinxcontrib-programoutput==0.15 -sphinxcontrib-qthelp==1.0.2 -sphinxcontrib-serializinghtml==1.1.3 -stevedore==1.31.0 -toml==0.10.0 tornado==6.0.3 -typed-ast==1.4.0 -urllib3==1.25.6 -virtualenv==16.7.6 -watchdog==0.9.0 -wrapt==1.11.2 -zipp==0.6.0 diff --git a/setup.py b/setup.py index c378e74..4294549 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ import setuptools -version = '0.7.4' +version = '0.8.0' requires = ['jinja2 >= 2.7', 'pyyaml', 'click']