Skip to content

Commit

Permalink
Merge pull request #37 from davidomarf/v0.8.0
Browse files Browse the repository at this point in the history
V0.8.0
  • Loading branch information
davidomarf committed Nov 3, 2019
2 parents a5cad15 + 5a0b0f3 commit 0cf6e0e
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 135 deletions.
73 changes: 50 additions & 23 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/source/conf.py
Expand Up @@ -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 ---------------------------------------------------
Expand Down
6 changes: 0 additions & 6 deletions forceBuild.sh

This file was deleted.

3 changes: 2 additions & 1 deletion ginpar/__init__.py
@@ -1,4 +1,5 @@
from ginpar.cli import cli


def main():
cli()
cli()
52 changes: 31 additions & 21 deletions ginpar/build.py
Expand Up @@ -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]:
Expand All @@ -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,
}


Expand Down Expand Up @@ -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 = "<form>\n" + content + "\n</form>", site=site
sketch=unkebab(sketch["name"]),
form="<form>\n" + content + "\n</form>",
site=site,
)
)
sketch_index.close()
Expand All @@ -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()
Expand Down Expand Up @@ -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"]

Expand All @@ -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)}`")
Expand All @@ -386,14 +394,16 @@ 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")

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.")
6 changes: 3 additions & 3 deletions ginpar/cli.py
Expand Up @@ -34,7 +34,7 @@ def cli():
"The PATH where the site will be built. [ <config.build_path>, public ] "
"This path is relative to the current directory. When no option is provided "
"Ginpar will read the <config.build_path> from the configuration file."
),
),
)
def build(path):
"""Build the project content into PATH.
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions ginpar/generators.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion ginpar/init.py
Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions ginpar/new.py
Expand Up @@ -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")
echo(f"\nYour new sketch {path} is ready.\n")
3 changes: 2 additions & 1 deletion ginpar/quickstart.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
raise click.Abort()
4 changes: 2 additions & 2 deletions ginpar/serve.py
Expand Up @@ -51,5 +51,5 @@ def serve(port):

server = Server()

server.watch(site["content_path"], 'ginpar build')
server.serve(port=port, root=site["build_path"])
server.watch(site["content_path"], "ginpar build")
server.serve(port=port, root=site["build_path"])
2 changes: 1 addition & 1 deletion ginpar/templates/input.html
Expand Up @@ -2,5 +2,5 @@
<label for="{{ id }}">
{{ name }}
</label>
<input name="{{ id }}" id = "{{ id }}" {{ attrs | getattrs }} onchange="updateVars(); setup(); draw();">
<input name="{{ id }}" id = "{{ id }}" {{ attrs | getattrs }} onchange="ginpar_updateVars(); setup(); draw();">
</div>

0 comments on commit 0cf6e0e

Please sign in to comment.