Skip to content

Commit

Permalink
Rewrite in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
rrthomas committed Nov 23, 2024
1 parent 9ae4fd9 commit 5dcff38
Show file tree
Hide file tree
Showing 137 changed files with 1,075 additions and 847 deletions.
13 changes: 0 additions & 13 deletions .depcheckrc.json

This file was deleted.

5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
indent_size = 8
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

36 changes: 0 additions & 36 deletions .eslintrc.json

This file was deleted.

1 change: 0 additions & 1 deletion .gitgrepignore

This file was deleted.

2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github: rrthomas
tidelift: npm/@sc3d/nancy
tidelift: pypi/nancy
custom: "https://rrt.sc3d.org"
100 changes: 93 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,93 @@
/coverage
/dist
/lib
/package-lock.json
/sc3d-nancy-*.tgz
node_modules
tsconfig.tsbuildinfo
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
MANIFEST
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Test outputs
tests-output

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject
4 changes: 0 additions & 4 deletions .mocharc.json

This file was deleted.

10 changes: 1 addition & 9 deletions Cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,7 @@ first for files in `source/Places/Vladivostok`, then in `source/places`, and
finally in `source`. Hence, the actual list of files used to assemble the
page is:

* `source/breadcrumb.in.html`
* `source/logo.in.html`
* `source/menu.in.html`
* `source/path-to-root.in.sh`
* `source/Places/breadcrumb.in.html`
* `source/Places/Vladivostok/breadcrumb.in.html`
* `source/Places/Vladivostok/main.in.html`
* `source/Places/Vladivostok/title.in.txt`
* `source/template.in.html`


For the site’s index page, the file `index/logo.in.html` will be used for the
logo fragment, which can refer to the larger graphic desired.
Expand Down
16 changes: 8 additions & 8 deletions Cookbook.nancy.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@ line corresponds to a page:

```
├── Home page
$paste{sh,-c,build-aux/dirtree test/cookbook-example-website-expected | sed -e 's/\.html//g' | grep -v index | grep -v \\.}
$paste{sh,-c,build-aux/dirtree tests/test-files/cookbook-example-website-expected | sed -e 's/\.html//g' | grep -v index | grep -v \\.}
```

The basic page template looks something like this:

```
$paste{cat,test/cookbook-example-website-src/template.in.html}
$paste{cat,tests/test-files/cookbook-example-website-src/template.in.html}
```

Making the menu an included file is not strictly necessary, but makes the
template easier to read. The pages will be laid out as follows:

```
$paste{build-aux/dirtree,test/cookbook-example-website-expected}
$paste{build-aux/dirtree,tests/test-files/cookbook-example-website-expected}
```

The corresponding source files are laid out as follows. This may look a
little confusing at first, but note the similarity to the HTML pages, and
hold on for the explanation!

```
$paste{build-aux/dirtree,test/cookbook-example-website-src}
$paste{build-aux/dirtree,tests/test-files/cookbook-example-website-src}
```

Note that there is only one menu fragment (the main menu is the same for
Expand All @@ -51,13 +51,13 @@ Now consider how Nancy builds the page whose URL is
`Places/Vladivostok/index.html`. Assume the source files are in the
directory `source`. This page is built from
`source/Places/Vladivostok/index.nancy.html`, whose contents is
`$paste{cat,test/cookbook-example-website-src/Places/Vladivostok/index.nancy.html}`. According to the rules given in the
`$paste{cat,tests/test-files/cookbook-example-website-src/Places/Vladivostok/index.nancy.html}`. According to the rules given in the
[Operation](README.md#operation) section of the manual, Nancy will look
first for files in `source/Places/Vladivostok`, then in `source/places`, and
finally in `source`. Hence, the actual list of files used to assemble the
page is:

$paste{env,NANCY_TMPDIR=/tmp/cookbook-dest.$$,sh,-c,rm -rf ${NANCY_TMPDIR} && DEBUG="*" ./bin/run.js --path Places/Vladivostok test/cookbook-example-website-src ${NANCY_TMPDIR} 2>&1 | grep Found | cut -d " " -f 4 | sort | uniq | sed -e 's|^'\''test/cookbook-example-website-src\(.*\)'\''$|* `source\1`|' && rm -rf ${NANCY_TMPDIR}}
$paste{env,NANCY_TMPDIR=/tmp/cookbook-dest.$$,sh,-c,rm -rf ${NANCY_TMPDIR} && DEBUG="*" PYTHONPATH=. python -m nancy --path Places/Vladivostok tests/test-files/cookbook-example-website-src ${NANCY_TMPDIR} 2>&1 | grep Found | cut -d " " -f 4 | sort | uniq | sed -e 's|^'\''tests/test-files/cookbook-example-website-src\(.*\)'\''$|* `source\1`|' && rm -rf ${NANCY_TMPDIR}}

For the site’s index page, the file `index/logo.in.html` will be used for the
logo fragment, which can refer to the larger graphic desired.
Expand Down Expand Up @@ -94,13 +94,13 @@ Given a simple page template, a datestamp can be added by using the `date`
command with `\$paste`:

```
$paste{sh,-c,sed -e 's|\,--date=2016/10/12||' < test/page-template-with-date-src/Page.nancy.md}
$paste{sh,-c,sed -e 's|\,--date=2016/10/12||' < tests/test-files/page-template-with-date-src/Page.nancy.md}
```

This gives a result looking something like:

```
$include{cat,test/page-template-with-date-src/Page.nancy.md}
$include{cat,tests/test-files/page-template-with-date-src/Page.nancy.md}
```

## Adding code examples to Markdown
Expand Down
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Makefile for maintainer tasks

build:
python -m build

docs:
PYTHONPATH=. python -m nancy README.nancy.md README.md && \
PYTHONPATH=. python -m nancy Cookbook.nancy.md Cookbook.md

dist:
git diff --exit-code && \
rm -rf ./dist && \
mkdir dist && \
$(MAKE) build

test:
tox

release:
make test
make dist
twine upload dist/* && \
git tag v$$(grep version pyproject.toml | grep -o "[0-9.]\+") && \
git push --tags

loc:
cloc nancy tests/*.py

example:
python -c "import webbrowser; webbrowser.open(\"file://`pwd`/tests/test-files/cookbook-example-website-expected/index/index.html\")"

.PHONY: dist
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![logo](logo/nancy-small.png) _logo by Silvia Polverini_

© 2002–2023 Reuben Thomas <[email protected]>
© 2002–2024 Reuben Thomas <[email protected]>
https://github.com/rrthomas/nancy

Nancy is a simple macro processor that copies a file or directory, filling
Expand All @@ -27,10 +27,10 @@ report them on the project’s web page (see above for addresses).

## Installation

Install Nancy with npm (part of [Node](https://nodejs.org)):
Install Nancy with pip (part of [Python](https://python.org)):

```
$ npm install -g @sc3d/nancy
$ pip install nancy
```

## Invocation
Expand All @@ -44,7 +44,7 @@ positional arguments:
INPUT-PATH list of input directories, or a single file
OUTPUT output directory, or file ('-' for stdout)
optional arguments:
options:
-h, --help show this help message and exit
--path PATH path to build relative to input tree [default: '']
--version show program's version number and exit
Expand Down Expand Up @@ -216,15 +216,14 @@ Now I can talk about $paste.

## Development

Check out the git repository and download dependencies with:
Check out the git repository with:

```
git clone https://github.com/rrthomas/nancy
npm install
```

To run the tests:

```
npm test
make test
```
15 changes: 8 additions & 7 deletions README.nancy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![logo](logo/nancy-small.png) _logo by Silvia Polverini_

$paste{/bin/sh,-c,./bin/run.js --version | tail +2 | head -2 | sed -e 's/$/ /'}
$paste{/bin/sh,-c,PYTHONPATH=. python -m nancy --version | tail +2 | head -2 | sed -e 's/$/ /'}

Nancy is a simple macro processor that copies a file or directory, filling
in templates as it goes. It has just one non-trivial construct:
Expand All @@ -26,16 +26,16 @@ report them on the project’s web page (see above for addresses).

## Installation

Install Nancy with npm (part of [Node](https://nodejs.org)):
Install Nancy with pip (part of [Python](https://python.org)):

```
$ npm install -g @sc3d/nancy
$ pip install nancy
```

## Invocation

```
$paste{/bin/sh,-c,./bin/run.js --help | sed -e 's/usage: run.js/nancy/'}
$paste{/bin/sh,-c,PYTHONPATH=. python -m nancy --help | sed -e 's/usage: nancy/nancy/'}
```

## Operation <a name="operation"></a>
Expand Down Expand Up @@ -199,15 +199,16 @@ Now I can talk about \$paste.

## Development

Check out the git repository and download dependencies with:
Check out the git repository with:

```
git clone https://github.com/rrthomas/nancy
npm install
```

To run the tests:

```
npm test
make test
```

You will need the `tree` utility to build the documentation.
Loading

0 comments on commit 5dcff38

Please sign in to comment.