Skip to content

Commit

Permalink
Fix api doc (#1178)
Browse files Browse the repository at this point in the history
* Fixes #1177.

* Fix links.

* Remove unneeded typedoc tags.

* Redirect old API URLs.
  • Loading branch information
Arthur Evans committed Jul 16, 2020
1 parent 14fe5b3 commit f897a93
Show file tree
Hide file tree
Showing 23 changed files with 132 additions and 212 deletions.
23 changes: 0 additions & 23 deletions docs/_api/copy_api.sh

This file was deleted.

6 changes: 3 additions & 3 deletions docs/_api/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Import the main lit-html functions from the [`lit-html`](./modules/lit_html.html
import {render, html, svg} from 'lit-html';
```

- [html](./modules/lit_html.html#html)
- [svg](./modules/lit_html.html#svg)
- [render](./modules/lit_html.html#render)
- [html](./modules/_lit_html_.html#html)
- [svg](./modules/_lit_html_.html#svg)
- [render](./modules/_lit_html_.html#render)

## Directives
lit-html comes with a set of directives. You can import them as individual modules from the `lit-html/directives/` folder:
Expand Down
10 changes: 7 additions & 3 deletions docs/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ libraries:
default_expiration: "1m"

handlers:
- url: /api
static_dir: api
secure: always

- url: /css
static_dir: css
secure: always
- url: /images
static_dir: images
secure: always
- url: /api/assets
static_dir: api/assets
secure: always
- url: /api/.*
script: main.app
secure: always
- url: /.*
script: main.app
secure: always
16 changes: 8 additions & 8 deletions docs/guide/05-creating-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ html`<div>

However, instead of _returning_ a value to render, the directive controls what gets rendered to its location in the DOM.

Internally, lit-html uses the [`Part`](/api/interfaces/lit_html.part.html) interface to represent the dynamic DOM associated with a binding. A directive has access to the `Part` associated with its binding. For example, it can find the current value of the part and set a new value for the part.
Internally, lit-html uses the [`Part`](/api/interfaces/_lit_html_.part.html) interface to represent the dynamic DOM associated with a binding. A directive has access to the `Part` associated with its binding. For example, it can find the current value of the part and set a new value for the part.

To create a directive, pass a factory function to lit-html's `directive` function:

Expand All @@ -27,11 +27,11 @@ The factory function can take optional arguments for configuration and values to

The returned function is called each time the part is rendered. The `part` argument is a `Part` object with an API for directly managing the dynamic DOM associated with expressions. Each type of binding has its own specific Part object:

* [`NodePart`](/api/classes/lit_html.nodepart.html) for content bindings.
* [`AttributePart`](/api/classes/lit_html.attributepart.html) for standard attribute bindings.
* [`BooleanAttributePart`](/api/classes/lit_html.booleanattributepart.html) for boolean attribute bindings.
* [`EventPart`](/api/classes/lit_html.eventpart.html) for event bindings.
* [`PropertyPart`](/api/classes/lit_html.propertypart.html) for property bindings.
* [`NodePart`](/api/classes/_lit_html_.nodepart.html) for content bindings.
* [`AttributePart`](/api/classes/_lit_html_.attributepart.html) for standard attribute bindings.
* [`BooleanAttributePart`](/api/classes/_lit_html_.booleanattributepart.html) for boolean attribute bindings.
* [`EventPart`](/api/classes/_lit_html_.eventpart.html) for event bindings.
* [`PropertyPart`](/api/classes/_lit_html_.propertypart.html) for property bindings.

Each of these part types implement a common API:

Expand Down Expand Up @@ -166,7 +166,7 @@ const statefulDirective = directive(() => (part) => {
Sometimes you want a directive to manage multiple nested parts. For example, a directive that renders a list of items (like `repeat`) might create a nested part for each item. Keeping separate parts lets you manipulate them efficiently: for example, you can change the value of a single part without re-rendering the entire list.
To create nested parts, you construct [`NodePart`](/api/classes/lit_html.nodepart.html) instances and associate them with specific locations in the DOM. The section of DOM controlled by a given `NodePart` needs to be delimited by static nodes that serve as markers. (lit-html usually uses comment nodes for these markers.)
To create nested parts, you construct [`NodePart`](/api/classes/_lit_html_.nodepart.html) instances and associate them with specific locations in the DOM. The section of DOM controlled by a given `NodePart` needs to be delimited by static nodes that serve as markers. (lit-html usually uses comment nodes for these markers.)
<img alt="Diagram showing a tree of DOM nodes and a NodePart object. The DOM tree consists of a parent node and several child nodes, with two of the child nodes identified as 'marker nodes.' The NodePart object has a startNode property, which points to the first marker node, and an endNode property, which points to the second marker node. Child nodes between the two marker nodes are identified as 'nodes managed by NodePart.'" src="/images/guides/node-part-markers.png" style="max-width: 515px;">
Expand Down Expand Up @@ -250,4 +250,4 @@ const duplicate = directive((value) => {
});
```
The `NodePart` class provides a number of other convenience methods, including other methods for adding nested parts, and a [`clear`](/api/classes/lit_html.nodepart.html#clear) method to remove all of the DOM associated with a part. See the [NodePart API docs](/api/classes/lit_html.nodepart.html) for details.
The `NodePart` class provides a number of other convenience methods, including other methods for adding nested parts, and a [`clear`](/api/classes/_lit_html_.nodepart.html#clear) method to remove all of the DOM associated with a part. See the [NodePart API docs](/api/classes/_lit_html_.nodepart.html) for details.
2 changes: 1 addition & 1 deletion docs/guide/release-notes/1.2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ html`

`unsaveSVG` is the missing partner of [`unsafeHTML`](../template-reference#unsafehtml). It lets you render a frangment of SVG text as SVG elements rather than text. As with `unsafeHTML` this directive not safe to use with user-provided input, since if the input has `<script>` tags in it, there may be ways to get them to execute, etc.

`unsafeSVG` creates elements in the SVG namespace, so it's for use inside of `<svg>` tags or inside of lit-html [`svg`](/api/modules/lit_html.html#svg) templates. If the input contains an `<svg>` tag itself, continute to use `unsafeHTML`.
`unsafeSVG` creates elements in the SVG namespace, so it's for use inside of `<svg>` tags or inside of lit-html [`svg`](/api/modules/_lit_html_.html#svg) templates. If the input contains an `<svg>` tag itself, continute to use `unsafeHTML`.

```js
// shape is SVG partial text, with no <svg> element
Expand Down
2 changes: 2 additions & 0 deletions docs/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
indexes:
# AUTOGENERATED
34 changes: 34 additions & 0 deletions docs/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import jinja2
import webapp2

Expand All @@ -9,6 +10,11 @@
variable_end_string='}}}}',
autoescape=True)

redirects = [
(r'/api/([^/]*)/lit_html', r'/api/\1/_lit_html_'),
(r'/api/([^/]*)/shady_render', r'/api/\1/_lib_shady_render_')
]

# Match HTML pages from path; similar to behavior of Jekyll on GitHub Pages.
def find_template(path):
if path.endswith('/'):
Expand All @@ -25,6 +31,7 @@ def find_template(path):
# /try -> /try/index.html
return JINJA_ENVIRONMENT.get_template(path + '/index.html')


class MainPage(webapp2.RequestHandler):
def get(self):
try:
Expand All @@ -38,6 +45,33 @@ def get(self):
self.response.set_status(500)
self.response.write(template.render({}))

# Serve redirects for old paths, otherwise just serve static files
class ApiDoc(webapp2.RequestHandler):
def redirect_if_needed(self, path):
for redirect in redirects:
pattern = redirect[0]
replace = redirect[1]
if re.match(pattern, path):
self.redirect(re.sub(pattern, replace, path), permanent=True)
return True
return False

def get(self):
if self.redirect_if_needed(self.request.path):
return
try:
# path is always absolute starting with /api/. Slice off the leading slash
# and normalize it relative to cwd
filepath = os.path.relpath(self.request.path[1:])
page = open(filepath, 'rb').read()
self.response.write(page)
except Exception:
template = find_template('/404.html')
self.response.set_status(404)
self.response.write(template.render({}))


app = webapp2.WSGIApplication([
('/api/.*', ApiDoc),
('/.*', MainPage),
])

0 comments on commit f897a93

Please sign in to comment.