Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Update README.md to instruct how to use IntelliJ file watcher functionality #74

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
71 changes: 67 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ becomes...

## Usage

There are two different ways to use this library.

### Option 1: Template loaders
There are three different ways to use this library.
(click to expand)

<details>
<summary><b>1. Djano template loaders</b></summary>
<p>

These are Django template loaders which will convert any templates with `.haml` or `.hamlpy` extensions to regular
Django templates whenever they are requested by a Django view. To use them, add them to the list of template loaders in
your Django settings, e.g.
Expand Down Expand Up @@ -137,8 +140,15 @@ You can configure the Haml compiler with the following Django settings:
* `HAMLPY_DJANGO_INLINE_STYLE` -- Whether to support `={...}` syntax for inline variables in addition to `#{...}`.
Defaults to `False`.

### Option 2: Watcher
</p>
</details>



<details>
<summary><b>2. File watcher CLI</b></summary>
<p>

The library can also be used as a stand-alone program. There is a watcher script which will monitor Haml files in a
given directory and convert them to HTML as they are edited.

Expand Down Expand Up @@ -188,8 +198,61 @@ Then just include your Haml templates along with all the other files which conta

```bash
python manage.py makemessages --extension haml,html,py,txt
```
</p>
</details>


<details>
<summary><b>3. PyCharm file watcher</b></summary>
<p>

This will configure your IDE to automatically compile files as-you-type.

Save this script @ `<myproject>/scripts/compile_haml.py`

```python
import sys

from hamlpy.compiler import Compiler


with open(sys.argv[1], "r") as f:
print(Compiler().process(f.read()))
```

Save this as `watcher.xml`, and click import button at file watcher settings.

```xml
<TaskOptions>
<TaskOptions>
<option name="arguments" value="$ProjectFileDir$/scripts/compile_haml.py $FileName$" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="haml" />
<option name="immediateSync" value="true" />
<option name="name" value="Haml" />
<option name="output" value="$FileNameWithoutExtension$.html" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="true" />
<option name="program" value="$PyInterpreterDirectory$/python" />
<option name="runOnExternalChanges" value="true" />
<option name="scopeName" value="Project Files" />
<option name="trackOnlyRoot" value="true" />
<option name="workingDir" value="$FileDir$" />
<envs />
</TaskOptions>
</TaskOptions>
```

</p>
</details>



## Reference

Check out the [reference](http://github.com/nyaruka/django-hamlpy/blob/master/REFERENCE.md) file for the complete syntax
Expand Down