Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete trailing whitespace from files #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions asciidoc/CH01_HypermediaAReintroduction.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,8 @@ Yes, we can fix that by adding `role="button"`` and `tabindex="0"`:
[source,html]
----
<div class="bg-accent padding-4 rounded-2"
role="button"
tabindex="0"
role="button"
tabindex="0"
onclick="doStuff()">Do stuff</div>
----

Expand Down
4 changes: 2 additions & 2 deletions asciidoc/CH02_ComponentsOfAHypermediaSystem.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ In a properly structured HTML-based hypermedia system you would use an appropria
particular hypermedia control performs. For example, if a hypermedia control such as a button _deletes_ a resource,
ideally it should issue an HTTP `DELETE` request to do so.

A strange thing about HTML, though, is that the native hypermedia controls can only issue HTTP `GET` and `POST` requests.
A strange thing about HTML, though, is that the native hypermedia controls can only issue HTTP `GET` and `POST` requests.

Anchor tags always issue a `GET` request.

Expand Down Expand Up @@ -848,7 +848,7 @@ By using these elements, a page can make false promises, like `<article>` elemen
(((HTML, spec)))
The most authoritative resource for learning about HTML is the HTML specification.
The current specification lives on link:https://html.spec.whatwg.org/multipage[].footnote:[
The single-page version is too slow to load and render on most computers.
The single-page version is too slow to load and render on most computers.
There's also a developers' edition at /dev, but the standard version has nicer styling.]
There's no need to rely on hearsay to keep up with developments in HTML.

Expand Down
10 changes: 5 additions & 5 deletions asciidoc/CH03_BuildingASimpleWebApplication.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ slick features that most developers today would assume requires the use of a SPA
In order to demonstrate how web 1.0 applications work, we need to pick a server-side language and a library for
handling HTTP requests. Colloquially, this is called our "`Server-Side`" or "`Web`" stack, and there are literally hundreds
of options to choose from, many with passionate followings. You probably have a web framework that you prefer and, while
we wish we could write this book for every possible stack out there, in the interest of simplicity (and sanity) we can only pick one.
we wish we could write this book for every possible stack out there, in the interest of simplicity (and sanity) we can only pick one.

For this book we are going to use the following stack:

Expand All @@ -35,7 +35,7 @@ https://www.tiobe.com/tiobe-index/[TIOBE index], a respected measure of programm
More importantly, Python is easy to read even if you aren't familiar with it.

We chose the Flask web framework because it is simple and does not impose a lot of structure on top of the
basics of HTTP request handling.
basics of HTTP request handling.

This bare-bones approach is a good match for our needs: in other cases you might consider a more full-featured Python
framework, such as https://www.djangoproject.com/[Django], which supplies much more functionality out of the box than
Expand Down Expand Up @@ -420,7 +420,7 @@ def contacts_new_get():
Simple enough. We just render a `new.html` template with a new Contact. (`Contact()` is how you construct a new instance
of the `Contact` class in Python, if you aren't familiar with it.)

While the handler code for this route is very simple, the `new.html` template is more complicated.
While the handler code for this route is very simple, the `new.html` template is more complicated.

****
For the remaining templates we are going to omit the layout directive and the content block declaration, but you
Expand Down Expand Up @@ -571,7 +571,7 @@ We will use the PRG pattern in a few different places in this book.
****

OK, so we have our server-side logic set up to save contacts. And, believe it or not, this is about as complicated as
our handler logic will get, even when we look at adding more sophisticated htmx-driven behaviors.
our handler logic will get, even when we look at adding more sophisticated htmx-driven behaviors.

=== Viewing The Details Of A Contact

Expand Down Expand Up @@ -846,7 +846,7 @@ No need for a template in this case, the contact is gone.

=== Contact.app... Implemented!

And, well... believe it or not, that's our entire contact application!
And, well... believe it or not, that's our entire contact application!

If you've struggled with parts of the code so far, don't worry: we don't expect you to be a Python or Flask expert (we aren't!). You just need a basic understanding of how they work to benefit from the remainder of the book.

Expand Down
8 changes: 4 additions & 4 deletions asciidoc/CH04_ExtendingHTMLAsHypermedia.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Just seems wrong, doesn't it?

It turns out that we can boost the interactivity of our application and address both of these issues _without_ resorting
to the SPA approach. We can do so by using a _hypermedia-oriented_ JavaScript library, https://htmx.org[htmx]. The authors of this book built htmx specifically to extend HTML as a hypermedia and address the issues
with legacy HTML applications we mentioned above (as well as a few others.)
with legacy HTML applications we mentioned above (as well as a few others.)

Before we get into how htmx allows us to improve the UX of our Web 1.0 style application, let's revisit the
hyperlink/anchor tag from Chapter 1. Recall, a hyperlink is what is known as a _hypermedia control_, a mechanism that
Expand Down Expand Up @@ -239,7 +239,7 @@ We also mark the script as `crossorigin="anonymous"` so no credentials will be s
If you are used to modern JavaScript development, with complex build systems and large numbers of dependencies, it may
be a pleasant surprise to find that that's all it takes to install htmx.

This is in the spirit of the early web, when you could simply include a script tag and things would "`just work.`"
This is in the spirit of the early web, when you could simply include a script tag and things would "`just work.`"

If you don't want to use a CDN, you can download htmx to your local system and adjust the
script tag to point to wherever you keep your static assets. Or, you may have a build system
Expand Down Expand Up @@ -924,7 +924,7 @@ Now, the name `hx-push-url` for this attribute might sound a little obscure, but
so you are "`pushing`" new entries onto the top of the stack of history entries.

With this relatively simple, declarative mechanism, htmx allows you to integrate with the back button in a way that mimics the
"`normal`" behavior of HTML.
"`normal`" behavior of HTML.

Now, there is one additional thing we need to handle to get history "`just right`": we have "`pushed`" the `/contacts` path
into the browsers location bar successfully, and the back button works. But what if someone refreshes their browser while
Expand All @@ -941,7 +941,7 @@ more sophisticated web application than is possible in plain HTML, with minimal

Htmx aims to incrementally improve HTML as a hypermedia in a manner that is
conceptually coherent with the underlying markup language. Like any technical choice, this is not without
trade-offs: by staying so close to HTML, htmx does not give developers a lot of infrastructure that many might feel
trade-offs: by staying so close to HTML, htmx does not give developers a lot of infrastructure that many might feel
should be there "`by default`".

By staying closer to the native model of the web, htmx aims to strike a balance between simplicity and functionality,
Expand Down
8 changes: 4 additions & 4 deletions asciidoc/CH05_htmxPatterns.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Believe it or not, that's it! This simple script tag will make htmx's functiona
(((htmx patterns, boosting)))
To get our feet wet with htmx, the first feature we are going to take advantage of is known as "`boosting.`" This is
a bit of a "`magic`" feature in that we don't need to do much beyond adding a single attribute, `hx-boost`, to the
application.
application.

When you put `hx-boost` on a given element with the value `true`, it will "`boost`" all anchor and form elements within that
element. "`Boost`", here, means that htmx will convert all those anchors and forms from "`normal`" hypermedia controls
Expand Down Expand Up @@ -393,7 +393,7 @@ to send.


[source, python]
.Updated handler with `303` redirect response
.Updated handler with `303` redirect response
----
@app.route("/contacts/<contact_id>", methods=["DELETE"])
def contacts_delete(contact_id=0):
Expand Down Expand Up @@ -434,7 +434,7 @@ The fix for this is easy: add an explicit target to the button, and target the `
<1> An explicit target added to the button.

Now our button behaves as expected: clicking on the button will issue an HTTP `DELETE` to the server against the URL for
the current contact, delete the contact and redirect back to the contact list page, with a nice flash message.
the current contact, delete the contact and redirect back to the contact list page, with a nice flash message.

Is everything working smoothly now?

Expand Down Expand Up @@ -687,7 +687,7 @@ Let's make those changes to our HTML:
<2> Target the next element with the class `error` on it.

Note that in the `hx-target` attribute we are using a _relative positional_ selector, `next`. This is a feature of htmx and
an extension to normal CSS. Htmx supports prefixes that will find targets _relative_ to the current element.
an extension to normal CSS. Htmx supports prefixes that will find targets _relative_ to the current element.


.Relative Positional Expressions in Htmx
Expand Down
8 changes: 4 additions & 4 deletions asciidoc/CH06_MorehtmxPatterns.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ a _non-htmx_ request (e.g., refreshing a page) and yet the _htmx_ content is ret
in a partial page of content for the user.

The solution to this problem is to use the HTTP Response `Vary` header and call out the htmx headers that you are using
to determine what content you are returning. A full explanation of HTTP Caching is beyond the scope of this book, but the
to determine what content you are returning. A full explanation of HTTP Caching is beyond the scope of this book, but the
https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching[MDN article on the topic] is quite good, and the https://htmx.org/docs/#caching[htmx
documentation] discusses this issue as well.
****
Expand Down Expand Up @@ -437,7 +437,7 @@ location is "`pushed`" onto the stack of history elements, and when you click "`
the history stack.

So, to get proper history support for our Active Search, all we need to do is to set the `hx-push-url` attribute to
`true`.
`true`.

.Updating the URL during active search
[source, html]
Expand Down Expand Up @@ -499,7 +499,7 @@ the element from view, while at the same time not disrupting the layout of the p
When an htmx request is triggered that points to this indicator, another class, `htmx-request` is added to the indicator
which transitions its opacity to 1. So you can use just about anything as an indicator, and it will be hidden by default. Then, when a request is in flight, it will be shown. This is all done via standard CSS classes, allowing you to control
the transitions and even the mechanism by which the indicator is shown (e.g., you might use `display` rather than
`opacity`).
`opacity`).

.Use Request Indicators!
****
Expand Down Expand Up @@ -1187,7 +1187,7 @@ From the link:https://www.w3.org/WAI/ARIA/apg/patterns/tabs/[ARIA Authoring Prac

* ARIA roles, states, and properties

** "`[The element that contains the tabs] has role `tablist`.`"
** "`[The element that contains the tabs] has role `tablist`.`"

** "`Each [tab] has role `tab` [...]`"

Expand Down
10 changes: 5 additions & 5 deletions asciidoc/CH07_ADynamicArchiveUIWithhtmx.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def start_archive():
=== Conditionally Rendering A Progress UI

((("conditional rendering")))
Now let's turn our attention to updating our archiving UI by setting `archive_ui.html` to conditionally render different content depending on the state of the archive process.
Now let's turn our attention to updating our archiving UI by setting `archive_ui.html` to conditionally render different content depending on the state of the archive process.

Recall that the archiver has a `status()` method. When we pass the archiver through
as a variable to the template, we can consult this `status()` method to see
Expand Down Expand Up @@ -538,7 +538,7 @@ def archive_content():

Perfect. Now we have an archive UI that is very slick. You click the "`Download Contacts Archive`" button and a progress
bar appears. When the progress bar reaches 100%, it disappears and a link to download the archive file appears. The user
can then click on that link and download their archive.
can then click on that link and download their archive.

We're offering a user experience that is much more user-friendly than the common
click-and-wait experience of many websites.
Expand Down Expand Up @@ -596,9 +596,9 @@ are restored.

=== Our Smoothing Solution

So, we arrive at our fix.
So, we arrive at our fix.

All we need to do is add a stable ID to our `progress-bar` element.
All we need to do is add a stable ID to our `progress-bar` element.

.Smoothing things out
[source, html]
Expand All @@ -615,7 +615,7 @@ Despite the complicated mechanics going on behind the scenes in htmx, the soluti
`id` attribute to the element we want to animate.

Now, rather than jumping on every update, the progress bar should smoothly move across the screen as it is updating, using the CSS transition
defined in our style sheet. The htmx swapping model allows us to achieve this even though we are replacing the content with new HTML.
defined in our style sheet. The htmx swapping model allows us to achieve this even though we are replacing the content with new HTML.

And voila: we have a nice, smoothly animated progress bar for our contact archiving feature. The result has the look and
feel of a JavaScript-based solution, but we did it with the simplicity of an HTML-based approach.
Expand Down
10 changes: 5 additions & 5 deletions asciidoc/CH08_TricksOfThehtmxMasters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@ before it was removed from the DOM.
In addition to these, `hx-swap` offers further control with the following modifiers:

`settle`::
(((hx-swap, settle)))
(((hx-swap, settle)))
Like `swap`, this allows you to apply a specific delay between when the content has been swapped into the DOM and when
its attributes are "`settled`", that is, updated from their old values (if any) to their new values. This can give you
fine-grained control over CSS transitions.

`show`::
(((hx-swap, show)))
(((hx-swap, show)))
Allows you to specify an element that should be shown -- that is, scrolled into the viewport of the browser if
necessary -- when a request is completed.

`scroll`::
(((hx-swap, scroll)))
(((hx-swap, scroll)))
Allows you to specify a scrollable element (that is, an element with scrollbars), that should be scrolled to the top or
bottom when a request is completed.


`focus-scroll`::
(((hx-swap, focus-scroll)))
(((hx-swap, focus-scroll)))
Allows you to specify that htmx should scroll to the focused element when a request completes. The default for this
modifier is "`false.`"

Expand Down Expand Up @@ -136,7 +136,7 @@ able to take advantage of all the power they offer. We will discuss events in m
Here are the other modifiers available on `hx-trigger`:

`once`::
(((hx-trigger, once)))
(((hx-trigger, once)))
The given event will only trigger a request once.

`throttle`::
Expand Down
12 changes: 6 additions & 6 deletions asciidoc/CH09_ScriptingInAHypermediaApplication.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ Let's implement a feature in Contact.app using the RSJS/vanilla JavaScript appro
Our homepage has "`Edit`", "`View`" and "`Delete`" links for every contact in our table. This uses a lot of space and creates
visual clutter. Let's fix that by placing these actions inside a drop-down menu with a button to open it.

If you're less familiar with JavaScript and the code here starts to feel too complicated, don't worry; the Alpine.js and +_hyperscript+ examples -- which we'll look at next -- are easier to follow.
If you're less familiar with JavaScript and the code here starts to feel too complicated, don't worry; the Alpine.js and +_hyperscript+ examples -- which we'll look at next -- are easier to follow.

Let's begin by sketching the markup we want for our dropdown menu. First, we need an element, we'll use a `<div>`, to enclose the
entire widget and mark it as a menu component. Within this div, we will have a standard `<button>` that will function
Expand Down Expand Up @@ -856,7 +856,7 @@ to see if there are any selected contacts, quite easily:
<div class="box info tool-bar">
<slot x-text="selected.length"></slot>
contacts selected

<button type="button" class="bad bg color border">Delete</button> <2>
<hr aria-orientation="vertical">
<button type="button">Cancel</button>
Expand Down Expand Up @@ -889,7 +889,7 @@ With this code written, we can make the toolbar appear and disappear, based on w

Very slick.

Before we move on, you may have noticed our code here includes some "`class=`" references. These are for css styling, and are not part of Alpine.js. We've included them only as a reminder that the menu bar we're building will require css to work well. The classes in the code above refer to a minimal css library called Missing.css. If you use other css libraries, such as Bootstrap, Tailwind, Bulma, Pico.css, etc., your styling code will be different.
Before we move on, you may have noticed our code here includes some "`class=`" references. These are for css styling, and are not part of Alpine.js. We've included them only as a reminder that the menu bar we're building will require css to work well. The classes in the code above refer to a minimal css library called Missing.css. If you use other css libraries, such as Bootstrap, Tailwind, Bulma, Pico.css, etc., your styling code will be different.

==== Implementing actions

Expand Down Expand Up @@ -949,14 +949,14 @@ visual clutter and the toolbar can be extended with more options without creatin

((("_hyperscript")))
The final scripting technology we are going to look at is a bit further afield: https://hyperscript.org[+_hyperscript+]. The authors of this book initially created +_hyperscript+ as a sibling project to htmx. We felt that JavaScript wasn't
event-oriented enough, which made adding small scripting enhancements to htmx applications cumbersome.
event-oriented enough, which made adding small scripting enhancements to htmx applications cumbersome.

While the previous two examples are JavaScript-oriented, +_hyperscript+ has a completely different syntax than JavaScript, based on an older language called HyperTalk.
HyperTalk was the scripting language for a technology called HyperCard, an old hypermedia system available on early
Macintosh Computers.

The most noticeable thing about +_hyperscript+ is that it resembles English prose more than it resembles other programming
languages.
languages.

Like Alpine,
+_hyperscript+ is a modern jQuery replacement. Also like Alpine, +_hyperscript+ allows you to write your scripting inline, in HTML.
Expand Down Expand Up @@ -1103,7 +1103,7 @@ at some level, you are right: JavaScript is a decent scripting language, is very
in web development. On the other hand, by creating an entirely new front end scripting language, we had the freedom
to address some problems that we saw generating ugly and verbose code in JavaScript:

Async transparency::
Async transparency::
((("_hyperscript", "async transparency")))
In +_hyperscript+, asynchronous functions (i.e., functions that return `Promise` instances) can be
invoked _as if they were synchronous_. Changing a function from sync to async does not break any +_hyperscript+ code that
Expand Down
Loading