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

Change directive syntax. #4

Merged
merged 2 commits into from
Nov 8, 2014
Merged
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
63 changes: 40 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ to make working with long Fountain documents more palatable._

Mountain makes use of two **directives**:

- `#include`
- `#reference` (and its companion, `/reference`)
- `include:`
- `reference:` (and its companion, `/reference`)

A directive is metadata that is encoded inside of a Fountain note. (Fountain
does not currently have first-class support for metadata.)

`#include` enables a Fountain document to reference another Fountain document.
`include:` enables a Fountain document to reference another Fountain document.

`#reference ... /reference` is used to wrap a document that has been inline
`#include`'d.
`reference: ... /reference` is used to wrap a document that has been inline
`include:`'d.

(Examples are available in the tutorial, below.)

Expand Down Expand Up @@ -92,21 +92,21 @@ _manifest.fountain_:

= Meet the **Hero**.

[[#include intro.fountain]]
[[include: intro.fountain]]

# ACT II

# ACT III

## Finale

[[#include the-end.fountain]]
[[include: the-end.fountain]]
```

This file probably looks similar to how most Fountain screenplays start out,
with the exception of the two notes that begin with `#include`.
with the exception of the two notes that begin with `include:`.

Here, `#include` is a directive that points to another file that should be
Here, `include:` is a directive that points to another file that should be
included in its place.

_intro.fountain_:
Expand Down Expand Up @@ -139,7 +139,7 @@ _screenplay.fountain_:

= Meet the **Hero**.

[[#reference intro.fountain]]
[[reference: intro.fountain]]

FADE IN:

Expand All @@ -151,7 +151,7 @@ FADE IN:

## Finale

[[#reference the-end.fountain]]
[[reference: the-end.fountain]]

> FADE OUT.

Expand All @@ -162,7 +162,7 @@ FADE IN:

This new document is a combination of _manifest.fountain_ and each of the files
referenced in the manifest (_intro.fountain_, _the-end.fountain_). These
referenced files are included in-line and wrapped in the `#reference ...
referenced files are included in-line and wrapped in the `reference: ...
/reference` directives.

Mountain works in both directions. To see this in action, edit the combined
Expand All @@ -177,7 +177,7 @@ _screenplay.fountain_:

## The World

[[#reference intro.fountain]]
[[reference: intro.fountain]]

FADE IN:

Expand All @@ -191,7 +191,7 @@ A green, open field, stretching for miles in all directions.

## Finale

[[#reference the-end.fountain]]
[[reference: the-end.fountain]]

> FADE OUT.

Expand Down Expand Up @@ -230,15 +230,15 @@ _manifest.fountain_:

## The World

[[#include intro.fountain]]
[[include: intro.fountain]]

# ACT II

# ACT III

## Finale

[[#include the-end.fountain]]
[[include: the-end.fountain]]
```

_intro.fountain_:
Expand All @@ -257,25 +257,25 @@ be frequently jumping back and forth between these two modes.

### Additional Notes

- Use a relative file path in an `#include` directive (relative to the
- Use a relative file path in an `include:` directive (relative to the
directory that the manifest file is located in). For example, if you write
`[[#include a.fountain]]`, then _a.fountain_ should be in the same folder as
`[[include: a.fountain]]`, then _a.fountain_ should be in the same folder as
the manifest file.

- Referenced files can be in different folders. For example,
`[[#include act iii/the-end.fountain]]` is legal (_the-end.fountain_ should
`[[include: act iii/the-end.fountain]]` is legal (_the-end.fountain_ should
be located within a folder called _act iii_, relative to
_manifest.fountain_'s directory).

- Mountain works with any file extension, not just _.fountain_.

- If a file that does not exist is referenced in an `#include` directive, and
the `mountain join` command is executed, then the `#include` directive will
- If a file that does not exist is referenced in an `include:` directive, and
the `mountain join` command is executed, then the `include:` directive will
remain in the resultant combined document. (It will not be converted to
`#reference ... \reference`, and an error will not be thrown.)
`reference: ... \reference`, and an error will not be thrown.)

- Mountain does not support recursive includes (i.e., a file that is included
via `#include` can't itself include another file via `#include`).
via `include:` can't itself include another file via `include:`).

## Development

Expand Down Expand Up @@ -303,6 +303,23 @@ python setup.py test

The tests use fixtures located at `./test/fixtures/`.

## Changelog

### pending

- Change directive syntax. `#include` is now `include:`, and `#reference` is
now `reference:`. [#2](https://github.com/mjrusso/mountain/pull/2),
[#4](https://github.com/mjrusso/mountain/pull/4)

### v0.2.1

- Prevent crash when processing directives that expect arguments but do not
include non-whitespace characters. [#1](https://github.com/mjrusso/mountain/pull/1)

### v0.2.0

- Initial release.

## Copyright

Copyright (c) 2014 [Michael Russo](http://mjrusso.com). See LICENSE for details.
6 changes: 3 additions & 3 deletions mountain/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def expand_manifest(manifest_path, combined_document_path):
# All referenced files in the manifest are relative to this base path.
base_path = os.path.dirname(manifest_path)

referenced_file_names = (re.compile("\[\[\s*#include\s+(\S.*?)\s*\]\]")
referenced_file_names = (re.compile("\[\[\s*include:\s+(\S.*?)\s*\]\]")
.findall(manifest))

for file_name in referenced_file_names:
Expand All @@ -34,9 +34,9 @@ def expand_manifest(manifest_path, combined_document_path):
referenced_file = f.read()

manifest = re.sub(
"\[\[\s*#include\s*?%s\s*\]\]" % re.escape(file_name),
"\[\[\s*include:\s*?%s\s*\]\]" % re.escape(file_name),
"".join([
"[[#reference %s]]" % file_name,
"[[reference: %s]]" % file_name,
"\n" if referenced_file.startswith("\n") else "\n\n",
referenced_file,
"\n" if referenced_file.endswith("\n") else "\n\n",
Expand Down
4 changes: 2 additions & 2 deletions mountain/mountain.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def help():
overwritten if it already exists.

The files referenced from <manifest-path> must be referenced with the
[[#include file-path]] directive.
[[include: file-path]] directive.

$ mountain split <manifest-path> <combined-document-path>

Expand All @@ -39,7 +39,7 @@ def help():
files will be overwritten if they already exist.

All included files in <combined-document-path> must be indicated with the
[[#reference file-path]] ... [[/reference]] directive.
[[reference: file-path]] ... [[/reference]] directive.

$ mountain --version

Expand Down
6 changes: 3 additions & 3 deletions mountain/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def split_combined_document(manifest_path, combined_document_path):
base_path = os.path.dirname(manifest_path)

references = re.findall(
"\[\[#reference\s+(\S.*?)\]\](.*?)\[\[/reference\]\]",
"\[\[reference:\s+(\S.*?)\]\](.*?)\[\[/reference\]\]",
combined_document,
re.DOTALL)

Expand All @@ -39,8 +39,8 @@ def split_combined_document(manifest_path, combined_document_path):
queue_file_write(write_queue, file_path, file_contents)

manifest = re.sub(
"\[\[#reference\s+%s\]\].*?\[\[/reference\]\]" % re.escape(file_name),
"[[#include %s]]" % file_name,
"\[\[reference:\s+%s\]\].*?\[\[/reference\]\]" % re.escape(file_name),
"[[include: %s]]" % file_name,
manifest,
0,
re.DOTALL
Expand Down
52 changes: 26 additions & 26 deletions test/fixtures/complex/manifest.fountain
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@

# 1

[[#include one.fountain]]
[[include: one.fountain]]

## 1.1

[[#include one-one.fountain]]
[[include: one-one.fountain]]

# 2

[[#include two.fountain]]
[[include: two.fountain]]

## 2.1

[[ #include part ii/one-a.fountain ]]
[[ include: part ii/one-a.fountain ]]

[[ #include part ii/one-b.fountain]]
[[ include: part ii/one-b.fountain]]

[[#include part ii/one-c.fountain ]]
[[include: part ii/one-c.fountain ]]

[[ #include part ii/one-d.fountain ]]
[[ include: part ii/one-d.fountain ]]

## 2.2

[[#include part ii/two.txt]]
[[include: part ii/two.txt]]

## 2.3

[[#include part ii/subpart iii/a.md]]
[[include: part ii/subpart iii/a.md]]

[[#include part ii/subpart iii/b.txt]]
[[include: part ii/subpart iii/b.txt]]

### 2.3.1

[[#include part ii/subpart iii/1.fountain]]
[[include: part ii/subpart iii/1.fountain]]

### 2.3.2

[[#include part ii/subpart iii/2.md]]
[[include: part ii/subpart iii/2.md]]

### 2.3.3

[[#include part ii/subpart iii/3.txt]]
[[include: part ii/subpart iii/3.txt]]

### 2.3.4

[[#include part ii/subpart iii/4.fountain]]
[[include: part ii/subpart iii/4.fountain]]

## 2.4

[[#include part ii/four.txt]]
[[include: part ii/four.txt]]

# 3

[[#include three.fountain]]
[[include: three.fountain]]

## 3.1

[[#include this-file-does-not-exist]]
[[include: this-file-does-not-exist]]

[[#include]]
[[include:]]

[[#include ]]
[[include: ]]

[[#include ]]
[[include: ]]

[[#include ]]
[[include: ]]

## 3.2

[[#include three-two-a.fountain]]
[[include: three-two-a.fountain]]

[[#include three-two-b.fountain]]
[[include: three-two-b.fountain]]

[[#include three-two-c.fountain]]
[[include: three-two-c.fountain]]

[[#include three-two-d.fountain]]
[[include: three-two-d.fountain]]

[[#include three-two-e.fountain]]
[[include: three-two-e.fountain]]
Loading