Skip to content

Commit

Permalink
Deployed 5ac2330 with MkDocs version: 1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
pelme committed Apr 10, 2024
1 parent 5a49b12 commit 39a3ef0
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 652 deletions.
22 changes: 4 additions & 18 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@



<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">


<nav class="md-nav md-nav--primary md-nav--integrated" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href="/." title="htpy - HTML in Python" class="md-nav__button md-logo" aria-label="htpy - HTML in Python" data-md-component="logo">

Expand Down Expand Up @@ -374,22 +376,6 @@
</div>



<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">


<nav class="md-nav md-nav--secondary" aria-label="Table of contents">




</nav>
</div>
</div>
</div>



<div class="md-content" data-md-component="content">
Expand Down Expand Up @@ -430,7 +416,7 @@ <h1>404 - Not found</h1>
</div>


<script id="__config" type="application/json">{"base": "/", "features": ["content.code.copy"], "search": "/assets/javascripts/workers/search.b8dbb3d2.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script>
<script id="__config" type="application/json">{"base": "/", "features": ["content.code.copy", "toc.integrate"], "search": "/assets/javascripts/workers/search.b8dbb3d2.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script>


<script src="/assets/javascripts/bundle.c8d2eff1.min.js"></script>
Expand Down
67 changes: 8 additions & 59 deletions common-patterns/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@



<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">


<nav class="md-nav md-nav--primary md-nav--integrated" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href=".." title="htpy - HTML in Python" class="md-nav__button md-logo" aria-label="htpy - HTML in Python" data-md-component="logo">

Expand Down Expand Up @@ -450,59 +452,6 @@
</div>



<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">


<nav class="md-nav md-nav--secondary" aria-label="Table of contents">






<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>

<li class="md-nav__item">
<a href="#filemodule-structure" class="md-nav__link">
<span class="md-ellipsis">
File/module structure
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#using-a-base-layout" class="md-nav__link">
<span class="md-ellipsis">
Using a base layout
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#ui-components" class="md-nav__link">
<span class="md-ellipsis">
UI components
</span>
</a>

</li>

</ul>

</nav>
</div>
</div>
</div>



<div class="md-content" data-md-component="content">
Expand All @@ -514,14 +463,14 @@



<h1 id="common-patterns">Common patterns</h1>
<h1 id="common-patterns">Common patterns<a class="headerlink" href="#common-patterns" title="Permanent link">&para;</a></h1>
<p>htpy itself is a library that does not impose any particular structure for your
code. You have the full power of Python
functions, classes and modules at your disposal.</p>
<p>General programming practices on how to structure modules, functions and classes apply to HTML generation with htpy.</p>
<p>This page describes common scenarios and patterns that may help you structure
your own project in a good way.</p>
<h2 id="filemodule-structure">File/module structure</h2>
<h2 id="filemodule-structure">File/module structure<a class="headerlink" href="#filemodule-structure" title="Permanent link">&para;</a></h2>
<p>It is generally a good idea to keep your HTML pages/components separate from HTTP request handling and "business logic".</p>
<p>In Django, this means that the view function should not directly generate the
HTML.</p>
Expand All @@ -544,7 +493,7 @@ <h2 id="filemodule-structure">File/module structure</h2>
</span><span id="__span-1-3"><a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a><span class="k">def</span> <span class="nf">greeting_page</span><span class="p">(</span><span class="o">*</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Element</span><span class="p">:</span>
</span><span id="__span-1-4"><a id="__codelineno-1-4" name="__codelineno-1-4" href="#__codelineno-1-4"></a> <span class="k">return</span> <span class="n">html</span><span class="p">[</span><span class="n">body</span><span class="p">[</span><span class="n">h1</span><span class="p">[</span><span class="sa">f</span><span class="s2">&quot;hi </span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">!&quot;</span><span class="p">]]]</span>
</span></code></pre></div>
<h2 id="using-a-base-layout">Using a base layout</h2>
<h2 id="using-a-base-layout">Using a base layout<a class="headerlink" href="#using-a-base-layout" title="Permanent link">&para;</a></h2>
<p>A common feature of template languages is to "extend" a base/parent template and specify placeholders. This can be achieved with a <code>base_layout</code> function:</p>
<div class="language-py highlight"><span class="filename">components.py</span><pre><span></span><code><span id="__span-2-1"><a id="__codelineno-2-1" name="__codelineno-2-1" href="#__codelineno-2-1"></a><span class="kn">import</span> <span class="nn">datetime</span>
</span><span id="__span-2-2"><a id="__codelineno-2-2" name="__codelineno-2-2" href="#__codelineno-2-2"></a>
Expand Down Expand Up @@ -586,7 +535,7 @@ <h2 id="using-a-base-layout">Using a base layout</h2>
</span><span id="__span-2-38"><a id="__codelineno-2-38" name="__codelineno-2-38" href="#__codelineno-2-38"></a> <span class="p">],</span>
</span><span id="__span-2-39"><a id="__codelineno-2-39" name="__codelineno-2-39" href="#__codelineno-2-39"></a> <span class="p">)</span>
</span></code></pre></div>
<h2 id="ui-components">UI components</h2>
<h2 id="ui-components">UI components<a class="headerlink" href="#ui-components" title="Permanent link">&para;</a></h2>
<p>Creating higher level wrappers for common UI components can be a good idea to reduce repetition.</p>
<p>Wrapping <a href="https://getbootstrap.com/docs/4.0/components/modal/">Bootstrap Modal</a> could be achieved with a function like this:</p>
<div class="language-py highlight"><span class="filename">Creating wrapper for Bootstrap Modal</span><pre><span></span><code><span id="__span-3-1"><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a><span class="kn">from</span> <span class="nn">markupsafe</span> <span class="kn">import</span> <span class="n">Markup</span>
Expand Down Expand Up @@ -675,7 +624,7 @@ <h2 id="ui-components">UI components</h2>
</div>


<script id="__config" type="application/json">{"base": "..", "features": ["content.code.copy"], "search": "../assets/javascripts/workers/search.b8dbb3d2.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script>
<script id="__config" type="application/json">{"base": "..", "features": ["content.code.copy", "toc.integrate"], "search": "../assets/javascripts/workers/search.b8dbb3d2.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script>


<script src="../assets/javascripts/bundle.c8d2eff1.min.js"></script>
Expand Down
78 changes: 9 additions & 69 deletions django/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@



<nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0">


<nav class="md-nav md-nav--primary md-nav--integrated" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href=".." title="htpy - HTML in Python" class="md-nav__button md-logo" aria-label="htpy - HTML in Python" data-md-component="logo">

Expand Down Expand Up @@ -459,68 +461,6 @@
</div>



<div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">


<nav class="md-nav md-nav--secondary" aria-label="Table of contents">






<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>

<li class="md-nav__item">
<a href="#returning-a-htpy-response" class="md-nav__link">
<span class="md-ellipsis">
Returning a htpy response
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#using-htpy-as-part-of-an-existing-django-template" class="md-nav__link">
<span class="md-ellipsis">
Using htpy as part of an existing Django template
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#render-a-django-form" class="md-nav__link">
<span class="md-ellipsis">
Render a Django form
</span>
</a>

</li>

<li class="md-nav__item">
<a href="#implement-custom-form-widgets-with-htpy" class="md-nav__link">
<span class="md-ellipsis">
Implement custom form widgets with htpy
</span>
</a>

</li>

</ul>

</nav>
</div>
</div>
</div>



<div class="md-content" data-md-component="content">
Expand All @@ -532,19 +472,19 @@



<h1 id="usage-with-django">Usage with Django</h1>
<h1 id="usage-with-django">Usage with Django<a class="headerlink" href="#usage-with-django" title="Permanent link">&para;</a></h1>
<p>htpy is not tied to any specific web framework. Nonetheless, htpy works great
when combined with Django. This page contains information and useful techniques
on how to combine htpy and Django.</p>
<h2 id="returning-a-htpy-response">Returning a htpy response</h2>
<h2 id="returning-a-htpy-response">Returning a htpy response<a class="headerlink" href="#returning-a-htpy-response" title="Permanent link">&para;</a></h2>
<p>htpy elements can be passed directly to <code>HttpResponse</code>:</p>
<div class="language-py highlight"><span class="filename">views.py</span><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="kn">from</span> <span class="nn">django.http</span> <span class="kn">import</span> <span class="n">HttpResponse</span>
</span><span id="__span-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><span class="kn">from</span> <span class="nn">htpy</span> <span class="kn">import</span> <span class="n">html</span><span class="p">,</span> <span class="n">body</span><span class="p">,</span> <span class="n">div</span>
</span><span id="__span-0-3"><a id="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a>
</span><span id="__span-0-4"><a id="__codelineno-0-4" name="__codelineno-0-4" href="#__codelineno-0-4"></a><span class="k">def</span> <span class="nf">my_view</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
</span><span id="__span-0-5"><a id="__codelineno-0-5" name="__codelineno-0-5" href="#__codelineno-0-5"></a> <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="n">html</span><span class="p">[</span><span class="n">body</span><span class="p">[</span><span class="n">div</span><span class="p">[</span><span class="s2">&quot;Hi Django!&quot;</span><span class="p">]]])</span>
</span></code></pre></div>
<h2 id="using-htpy-as-part-of-an-existing-django-template">Using htpy as part of an existing Django template</h2>
<h2 id="using-htpy-as-part-of-an-existing-django-template">Using htpy as part of an existing Django template<a class="headerlink" href="#using-htpy-as-part-of-an-existing-django-template" title="Permanent link">&para;</a></h2>
<p>htpy elements are marked as "safe" and can be injected directly into Django
templates. This can be useful if you want to start using htpy gradually in an
existing template based Django project:</p>
Expand All @@ -565,7 +505,7 @@ <h2 id="using-htpy-as-part-of-an-existing-django-template">Using htpy as part of
</span><span id="__span-2-8"><a id="__codelineno-2-8" name="__codelineno-2-8" href="#__codelineno-2-8"></a> <span class="s2">&quot;content&quot;</span><span class="p">:</span> <span class="n">h1</span><span class="p">[</span><span class="s2">&quot;Welcome to my site!&quot;</span><span class="p">],</span>
</span><span id="__span-2-9"><a id="__codelineno-2-9" name="__codelineno-2-9" href="#__codelineno-2-9"></a> <span class="p">})</span>
</span></code></pre></div>
<h2 id="render-a-django-form">Render a Django form</h2>
<h2 id="render-a-django-form">Render a Django form<a class="headerlink" href="#render-a-django-form" title="Permanent link">&para;</a></h2>
<p>CSRF token, form widgets and errors can be directly used within htpy elements:</p>
<div class="language-py highlight"><span class="filename">forms.py</span><pre><span></span><code><span id="__span-3-1"><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>
</span><span id="__span-3-2"><a id="__codelineno-3-2" name="__codelineno-3-2" href="#__codelineno-3-2"></a>
Expand Down Expand Up @@ -619,7 +559,7 @@ <h2 id="render-a-django-form">Render a Django form</h2>
</span><span id="__span-5-31"><a id="__codelineno-5-31" name="__codelineno-5-31" href="#__codelineno-5-31"></a> <span class="n">h1</span><span class="p">[</span><span class="s2">&quot;Success! The form was valid!&quot;</span><span class="p">],</span>
</span><span id="__span-5-32"><a id="__codelineno-5-32" name="__codelineno-5-32" href="#__codelineno-5-32"></a> <span class="p">)</span>
</span></code></pre></div>
<h2 id="implement-custom-form-widgets-with-htpy">Implement custom form widgets with htpy</h2>
<h2 id="implement-custom-form-widgets-with-htpy">Implement custom form widgets with htpy<a class="headerlink" href="#implement-custom-form-widgets-with-htpy" title="Permanent link">&para;</a></h2>
<p>You can implement a custom form widget directly with htpy like this:</p>
<div class="language-py highlight"><span class="filename">widgets.py</span><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="kn">from</span> <span class="nn">django.forms</span> <span class="kn">import</span> <span class="n">widgets</span>
</span><span id="__span-6-2"><a id="__codelineno-6-2" name="__codelineno-6-2" href="#__codelineno-6-2"></a>
Expand Down Expand Up @@ -681,7 +621,7 @@ <h2 id="implement-custom-form-widgets-with-htpy">Implement custom form widgets w
</div>


<script id="__config" type="application/json">{"base": "..", "features": ["content.code.copy"], "search": "../assets/javascripts/workers/search.b8dbb3d2.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script>
<script id="__config" type="application/json">{"base": "..", "features": ["content.code.copy", "toc.integrate"], "search": "../assets/javascripts/workers/search.b8dbb3d2.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script>


<script src="../assets/javascripts/bundle.c8d2eff1.min.js"></script>
Expand Down
Loading

0 comments on commit 39a3ef0

Please sign in to comment.