Skip to content

Commit

Permalink
Merge pull request #144 from glyph/plating-doc-cleanups
Browse files Browse the repository at this point in the history
documentation cleanups for Plating
  • Loading branch information
wsanchez authored Dec 10, 2016
2 parents 967b809 + eed6a59 commit f3686e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
14 changes: 7 additions & 7 deletions docs/introduction/1-gettingstarted.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ appear. That'll look something like this:
.. literalinclude:: codeexamples/html.py
:lines: 13-24

Notice that we have defined a ``"title"`` slot in the template - individual
Notice that we have defined a ``"pageTitle"`` slot in the template - individual
pages must each provide a value for the title themselves in order to use the
``style`` frame. Nothing's special about "title", by the way; you may define
whatever slots you want in your page template.
``myStyle`` frame. Nothing's special about ``"pageTitle"``, by the way; you
may define whatever slots you want in your page template.

You can also specify a dictionary of default values to fill slots with.

Next, you want to create a route that is plated with that ``Plating``, by using
the ``Plating.routed`` decorator. ``@style.routed`` takes a route from the
the ``Plating.routed`` decorator. ``@myStyle.routed`` takes a route from the
Klein instance, in this case ``app``, and then a template for the content
portion (the ``Plating.CONTENT`` slot) of the page. The decorated function
must then return a dictionary of the values to populate the slots in the
Expand All @@ -151,7 +151,7 @@ the content slot.
This page generates some links to various sub-pages which we'll get to in a
moment. But first, if you load ``http://localhost:8080/``, you'll see that the
template specified for ``root`` is inserted at the point in the template for
``style`` specified the content should go.
``myStyle`` specified the content should go.

Next, we should actually try injecting some data.

Expand All @@ -162,7 +162,7 @@ Here you can see the ``/foods/...`` route for showing information about a food.
In the content template, we've got slots for ``"name"``, ``"rating"``, and
``"carbohydrates"``, the three primary properties which define a food. The
decorated function then returns a dictionary that returns values for each of
those slots, as well as a value for "title".
those slots, as well as a value for ``"pageTitle"``.

Each of these slots is only filled with a single item, though. What if you
need to put multiple items into the template? The route for ``/places/...``
Expand Down Expand Up @@ -196,7 +196,7 @@ result like this:
"latitude": -32.610538480748815,
"longitude": -9.38433633489143,
"name": "chicago",
"title": "Place: chicago"
"pageTitle": "Place: chicago"
}
Any route decorated by ``@routed`` will similarly give you structured data if
Expand Down
20 changes: 11 additions & 9 deletions docs/introduction/codeexamples/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ def random_from_string(string):
from klein import Klein, Plating
app = Klein()

style = Plating(
myStyle = Plating(
tags=tags.html(
tags.head(tags.title(slot("title"))),
tags.body(tags.h1(slot("title"), Class="title"),
tags.head(tags.title(slot("pageTitle"))),
tags.body(tags.h1(slot("pageTitle"), Class="titleHeading"),
tags.div(slot(Plating.CONTENT)))
),
defaults={"title": "Places & Foods"}
defaults={"pageTitle": "Places & Foods"}
)

@style.routed(
@myStyle.routed(
app.route("/"),
tags.div(
tags.h2("Sample Places:"),
Expand All @@ -36,7 +36,7 @@ def random_from_string(string):
def root(request):
return {}

@style.routed(app.route("/foods/<food>"),
@myStyle.routed(app.route("/foods/<food>"),
tags.table(border="2", style="color: blue")(
tags.tr(tags.td("Name:"), tags.td(slot("name"))),
tags.tr(tags.td("Deliciousness:"),
Expand All @@ -45,11 +45,12 @@ def root(request):
tags.td(slot("carbohydrates")))))
def one_food(request, food):
random = random_from_string(food)
return {"name": food, "title": "Food: {}".format(food),
return {"name": food,
"pageTitle": "Food: {}".format(food),
"rating": random.randint(1, 5),
"carbohydrates": random.randint(0, 100)}

@style.routed(
@myStyle.routed(
app.route("/places/<place>"),
tags.div(style="color: green")(
tags.h1("Place: ", slot("name")),
Expand All @@ -62,7 +63,8 @@ def one_place(request, place):
possible_foods = ["hamburgers", "cheeseburgers", "hot dogs", "pizza",
"叉烧", "皮蛋", "foie gras"]
random.shuffle(possible_foods)
return {"name": place, "title": "Place: {}".format(place),
return {"name": place,
"pageTitle": "Place: {}".format(place),
"latitude": random.uniform(-90, 90),
"longitude": random.uniform(-180, 180),
"foods": possible_foods[:3]}
Expand Down

0 comments on commit f3686e3

Please sign in to comment.