CoastalResilienceNetwork / GeositeFramework

Mapping Framework powering TNC Coastal Resilience programs
http://maps.coastalresilience.org/network/
GNU General Public License v3.0
13 stars 10 forks source link

Setup templating engine and inject region.json into app #1111

Closed fungjj92 closed 5 years ago

fungjj92 commented 5 years ago

Overview

The next step in the static site conversion is that we add a templating engine that subs in data from custom JSON into templates that comprise the app. I added Jinja2 as the templating engine and process region.json for index.html as proof of concept that Jinja2 works for our needs. While we don't use Jinja2 frequently, its template syntax is familiar as it is strongly inspired by Django. Jinja2 is very lightweight as it only provides templating functionality and is very popular among pythonistas.

Connects #1086

Demo

Serving the templated index.html shows that variables are substituted.

screen shot 2018-09-18 at 11 33 52 am

Running the server looks like

screen shot 2018-09-18 at 11 40 14 am

Notes

There's a lot of context in the commit messages, check them out. The script main.py writes the jinja template to disk. This workflow works for our dev envir and build.py in the geosite-build process whereby we will return zipped static site files to the client to serve on their own.

Refreshing the browser recompiles and writes templates whoot

Testing Instructions

~Create the container, install deps, and run the server ./scripts/update ./scripts/server~

Follow the new README.md. Check that all 6 script commands work. python ./scripts/server.py python ./scripts/update.py python ./scripts/create_static.py python ./scripts/server.py -d python ./scripts/update.py -d python ./scripts/create_static.py -d

Visit http://localhost:54633 and see that variables are slotted in from region.json. The most prominent one is the text "Geosite Framework Sample" in the middle

Change the titleMain value in region.json. Refresh the browser and see that the changes are reflected.

fungjj92 commented 5 years ago

I believe all comments are addressed now.

The big picture changes were:

kellyi commented 5 years ago

Taking a look at this now.

Can we add .pyc to .gitignore?

kellyi commented 5 years ago

I followed the instructions in the README to build and run the project with the non-Docker Python scripts. Everything worked as described, with the tiny exception of having to prefix python scripts/update.py with sudo to get it to work on my machine.

Trying out the Docker versions now.

kellyi commented 5 years ago

Docker versions of these scripts work great!

I was able to run ./scripts/update.py -d and ./scripts/server.py -d and ./scripts/create_static.py -d and each of them worked.

Question: where are the static assets supposed to be after running create_static.py -d? I checked in the dist dir but don't see anything there.

I made a few comments inline about adjusting the README instruction for how to stop the service to make it more precise. Aside from that this is nearly good to go, though!

fungjj92 commented 5 years ago

@kellyi The only static file generated is index.html. I imagined that static file compilation and zipping would happen in a later card, such as #1087 or #1100

fungjj92 commented 5 years ago

Oops! I thought I had made that change but it snuck away. Thanks for the multiple speedy reviews! I will update.

fungjj92 commented 5 years ago

Updated ~

fungjj92 commented 5 years ago

Thanks so much for the thorough reviews! FYI @caseycesari I'm merging this to unblock further Task 1 work. LMK if you have any followup, we can make cards for them.