anatomy 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +201 -0
- data/bin/anatomy +5 -0
- data/lib/anatomy/atomy.ay +202 -0
- data/lib/anatomy/base.ay +151 -0
- data/lib/anatomy/cmd.ay +60 -0
- data/lib/anatomy/data.ay +147 -0
- data/lib/anatomy/html.ay +73 -0
- data/lib/anatomy/language/parser.ay +130 -0
- data/lib/anatomy/processor.ay +35 -0
- data/lib/anatomy/renderers/html.ay +306 -0
- data/lib/anatomy/ruby.ay +178 -0
- data/lib/anatomy/server.ay +80 -0
- data/lib/anatomy/slides.ay +48 -0
- data/lib/anatomy/stages/collect.ay +35 -0
- data/lib/anatomy/stages/meta.ay +100 -0
- data/lib/anatomy/stages/resolve.ay +55 -0
- data/lib/anatomy/stages/traverse.ay +34 -0
- data/lib/anatomy.ay +4 -0
- data/public/anatomy.css +427 -0
- data/public/highlight.css +60 -0
- data/public/jquery.hotkeys.js +99 -0
- data/public/jquery.js +16 -0
- data/public/main.js +237 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 547b0c69a5d69834407e72746658ae60ba8aef42
|
4
|
+
data.tar.gz: 4937b2321af83a9ea71d9ec66f4ff55c31cdd005
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44eee7a43b3c6421ab8d56445b4df1b814889742015be3a453fe7eabf0a2973172147aafed0ab1001379733207a045d7f011b3e66a47f58025d6dd792e143d0f
|
7
|
+
data.tar.gz: 29b12c49804886a3fe1ee069e9c57d91e9e04b388841517490f3613483681b5133f07cfd5605b2305db619e75ab1aa116abcad297c6a6be816c267e9e856c8ed
|
data/LICENSE.md
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/bin/anatomy
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
use(require("atomy"))
|
2
|
+
io = require("io")
|
3
|
+
pretty = require("pretty")
|
4
|
+
|
5
|
+
require("stringio")
|
6
|
+
|
7
|
+
hl = require("hl")
|
8
|
+
token = require("hl/token")
|
9
|
+
atomy = hl load("atomy")
|
10
|
+
|
11
|
+
use(require("anatomy/html"))
|
12
|
+
base = require("anatomy/base")
|
13
|
+
data = require("anatomy/data")
|
14
|
+
|
15
|
+
require("atomy/message_structure")
|
16
|
+
|
17
|
+
fn(format-inline(tokens, link-only = nil)):
|
18
|
+
tokens collect [t]:
|
19
|
+
data Element new(
|
20
|
+
-- constants, identifiers, and operators
|
21
|
+
if((link-only && link-only include?(t contents)) ||
|
22
|
+
(!link-only && ["no", "n", "o"] include?(t type tag)))
|
23
|
+
then:
|
24
|
+
data ResolveElement new(
|
25
|
+
[part]:
|
26
|
+
tag = part find-tag(t contents)
|
27
|
+
if(tag)
|
28
|
+
then: data Reference new(tag, t contents)
|
29
|
+
else: t contents)
|
30
|
+
else: t contents
|
31
|
+
.class(t type tag))
|
32
|
+
|
33
|
+
fn(format-block(tokens, link-only = nil)):
|
34
|
+
data Block new(
|
35
|
+
base verbatim(format-inline(tokens, link-only))
|
36
|
+
.class("highlight"))
|
37
|
+
|
38
|
+
-- redirect ALL stdout/stderr for interaction
|
39
|
+
fn(with-all-output-to(out, err) &action):
|
40
|
+
before-out = io OutputPort instance-variable-get(."@default")
|
41
|
+
before-err = io ErrorPort instance-variable-get(."@default")
|
42
|
+
|
43
|
+
{ io OutputPort instance-variable-set(."@default", out)
|
44
|
+
io ErrorPort instance-variable-set(."@default", err)
|
45
|
+
|
46
|
+
io with-output-to(out):
|
47
|
+
io with-error-to(err):
|
48
|
+
action call
|
49
|
+
} ensuring:
|
50
|
+
io OutputPort instance-variable-set(."@default", before-out)
|
51
|
+
io ErrorPort instance-variable-set(."@default", before-err)
|
52
|
+
|
53
|
+
fn(interactive-line(mod, input, line, context)):
|
54
|
+
out = StringIO new
|
55
|
+
err = StringIO new
|
56
|
+
|
57
|
+
output-tokens =
|
58
|
+
with-restarts(use-tokens(ts): ts) {
|
59
|
+
res =
|
60
|
+
with-all-output-to(out, err):
|
61
|
+
mod eval(input, line)
|
62
|
+
|
63
|
+
-- shorten the long-form inspections that show the ivars
|
64
|
+
atomy lex(pretty show(res) sub(r"#<([^\s]+)\s+@.*$", "#<\\1>"))
|
65
|
+
} bind:
|
66
|
+
(e & Error):
|
67
|
+
restart(
|
68
|
+
.use-tokens
|
69
|
+
[ token Token new(
|
70
|
+
token Tagged new(.gr)
|
71
|
+
i"#{e name}: #{e message}")
|
72
|
+
])
|
73
|
+
|
74
|
+
[ format-inline(
|
75
|
+
token Token new(token Tagged new(.caret), "> ") .
|
76
|
+
atomy lex(input))
|
77
|
+
"\n"
|
78
|
+
out string
|
79
|
+
unless(err string empty?):
|
80
|
+
data Element new(err string, .class("gr"))
|
81
|
+
format-inline(output-tokens)
|
82
|
+
"\n"
|
83
|
+
]
|
84
|
+
|
85
|
+
|
86
|
+
def(hl(x)): base code(format-inline(atomy new(x) run))
|
87
|
+
def(atomy(x)): format-block(atomy new(x) run)
|
88
|
+
|
89
|
+
fn(new-interaction-env(where = nil)):
|
90
|
+
Atomy Module new(where || "interaction") tap [mod]:
|
91
|
+
mod use("atomy")
|
92
|
+
|
93
|
+
environments = #{}
|
94
|
+
def(interaction(x, where = nil)):
|
95
|
+
mod =
|
96
|
+
if(where)
|
97
|
+
then:
|
98
|
+
environments[where] ||= new-interaction-env(where)
|
99
|
+
else:
|
100
|
+
new-interaction-env(where)
|
101
|
+
|
102
|
+
data Block new(
|
103
|
+
data Block new(
|
104
|
+
x split("\n") collect with-index [input, line]:
|
105
|
+
interactive-line(mod, input, line + 1, where)
|
106
|
+
.tt)
|
107
|
+
.class("interaction"))
|
108
|
+
|
109
|
+
def(example(x, where = nil)):
|
110
|
+
data Block new(
|
111
|
+
[ data Paragraph new([data Element new("Example:", .italic)])
|
112
|
+
interaction(x, where)
|
113
|
+
]
|
114
|
+
.class("example"))
|
115
|
+
|
116
|
+
def(example-segment(x)):
|
117
|
+
data Block new(
|
118
|
+
[ data Paragraph new([data Element new("Example:", .italic)])
|
119
|
+
format-block(atomy new(x) run)
|
120
|
+
]
|
121
|
+
.class("example"))
|
122
|
+
|
123
|
+
|
124
|
+
def(define(what, *rules, returns, body)):
|
125
|
+
thumb = Atomy Parser parse-string(what)
|
126
|
+
|
127
|
+
structure = Atomy MessageStructure new(thumb nodes first)
|
128
|
+
message-name = structure name to-s
|
129
|
+
tag-name =
|
130
|
+
if(message-name =~ r"^[\p{Ll}_]")
|
131
|
+
then: message-name tr("_", "-")
|
132
|
+
else: message-name
|
133
|
+
|
134
|
+
display = format-inline(atomy lex(what), [tag-name])
|
135
|
+
data Block new(
|
136
|
+
[ base target-element(tag-name)
|
137
|
+
data Block new(
|
138
|
+
[ data Block new(
|
139
|
+
[ display
|
140
|
+
data Element new(
|
141
|
+
" => "
|
142
|
+
.class("definition_result_arrow"))
|
143
|
+
format-inline(atomy lex(returns))
|
144
|
+
rules collect [rule]:
|
145
|
+
["\n | ", format-inline(atomy lex(rule))]
|
146
|
+
]
|
147
|
+
.tt)
|
148
|
+
]
|
149
|
+
.class("thumb"))
|
150
|
+
body
|
151
|
+
]
|
152
|
+
.class("definition"))
|
153
|
+
|
154
|
+
def(assign(name, to, body)):
|
155
|
+
display = format-inline(atomy lex(name), [name])
|
156
|
+
data Block new(
|
157
|
+
[ base target-element(name)
|
158
|
+
data Block new(
|
159
|
+
[ data Block new(
|
160
|
+
[ display
|
161
|
+
data Element new(
|
162
|
+
" = "
|
163
|
+
.class("definition_result_arrow"))
|
164
|
+
format-inline(atomy lex(to))
|
165
|
+
]
|
166
|
+
.tt)
|
167
|
+
]
|
168
|
+
.class("thumb"))
|
169
|
+
body
|
170
|
+
]
|
171
|
+
.class("definition", "assign"))
|
172
|
+
|
173
|
+
fn(find-tags(tags, c & Atomy Grammar AST Constant)): tags << c name to-s
|
174
|
+
fn(find-tags(tags, `((~what)(~*_)))): find-tags(tags, what)
|
175
|
+
fn(find-tags(tags, `(~what: ~*childs))):
|
176
|
+
find-tags(tags, what)
|
177
|
+
|
178
|
+
childs each [c]:
|
179
|
+
find-tags(tags, c)
|
180
|
+
|
181
|
+
def(data(tree, body)):
|
182
|
+
tree-ast = Atomy Parser parse-string(tree) nodes first
|
183
|
+
|
184
|
+
tag-names = []
|
185
|
+
find-tags(tag-names, tree-ast)
|
186
|
+
|
187
|
+
display = format-inline(atomy lex(tree), tag-names)
|
188
|
+
data Block new(
|
189
|
+
[ tag-names collect [name]: base target-element(name)
|
190
|
+
data Block new([base verbatim(display)], .class("thumb"))
|
191
|
+
body
|
192
|
+
]
|
193
|
+
.class("definition", "data"))
|
194
|
+
|
195
|
+
def(macro(pattern, *tag-names, result, body)):
|
196
|
+
display = format-inline(atomy lex(pattern), tag-names)
|
197
|
+
data Block new(
|
198
|
+
[ tag-names collect [name]: base target-element(name)
|
199
|
+
data Block new([data Block new([display], .tt)], .class("thumb"))
|
200
|
+
body
|
201
|
+
]
|
202
|
+
.class("definition", "macro"))
|
data/lib/anatomy/base.ay
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
use(require("atomy"))
|
2
|
+
|
3
|
+
require("atomy/codeloader")
|
4
|
+
|
5
|
+
data = require("anatomy/data")
|
6
|
+
meta = require("anatomy/stages/meta")
|
7
|
+
traverse = require("anatomy/stages/traverse")
|
8
|
+
collect = require("anatomy/stages/collect")
|
9
|
+
|
10
|
+
hl = require("hl")
|
11
|
+
|
12
|
+
def(title(content, tag-name = data sanitize(content), *extra-tag-names)):
|
13
|
+
data MetaBlock new(
|
14
|
+
[part]:
|
15
|
+
part title = content
|
16
|
+
|
17
|
+
part tag = part set-tag(tag-name, .self, content)
|
18
|
+
|
19
|
+
extra-tag-names each [t]:
|
20
|
+
part set-tag(t))
|
21
|
+
|
22
|
+
def(table-of-contents):
|
23
|
+
data MetaBlock new(
|
24
|
+
[part]:
|
25
|
+
part style properties << .toc)
|
26
|
+
|
27
|
+
def(omit-children-from-table-of-contents):
|
28
|
+
data ResolveElement new(
|
29
|
+
[part]:
|
30
|
+
part omit-children-from-table-of-contents? = true
|
31
|
+
"")
|
32
|
+
|
33
|
+
def(section(title, *tag-names, content)):
|
34
|
+
decode(title(title, *tag-names), content)
|
35
|
+
|
36
|
+
def(include-section(path)):
|
37
|
+
Atomy CodeLoader require(path) doc
|
38
|
+
|
39
|
+
def(include-sections(path)):
|
40
|
+
Dir glob(path) collect [s]:
|
41
|
+
Atomy CodeLoader require(s) doc
|
42
|
+
|
43
|
+
def(target-element(tag-name, display = nil)):
|
44
|
+
data CollectElement new(
|
45
|
+
[part]:
|
46
|
+
part set-tag(tag-name, .anchor(tag-name), display)
|
47
|
+
data Target new(tag-name))
|
48
|
+
|
49
|
+
def(verbatim(content)):
|
50
|
+
data Block new(content, .verbatim)
|
51
|
+
|
52
|
+
def(hyperlink(url, content)):
|
53
|
+
data Element new(content, .hyperlink(url))
|
54
|
+
|
55
|
+
def(reference(tag-name, content = nil)):
|
56
|
+
data ResolveElement new(
|
57
|
+
[part]:
|
58
|
+
tag = part find-tag(tag-name)
|
59
|
+
unless(tag):
|
60
|
+
warning(.undefined(tag-name))
|
61
|
+
|
62
|
+
data Reference new(
|
63
|
+
tag
|
64
|
+
content || ((tag && tag display) || tag-name)))
|
65
|
+
|
66
|
+
def(centered(content)):
|
67
|
+
data Block new(content, .centered)
|
68
|
+
|
69
|
+
def(image(asset-path, alt-text = "")):
|
70
|
+
data ResolveElement new(
|
71
|
+
[part]:
|
72
|
+
part assets << File expand-path(asset-path)
|
73
|
+
|
74
|
+
data Element new(
|
75
|
+
alt-text
|
76
|
+
.image(File basename(asset-path))))
|
77
|
+
|
78
|
+
def(definitions(content)):
|
79
|
+
defs = []
|
80
|
+
Array(content) select [x]:
|
81
|
+
x match:
|
82
|
+
.item(name, val):
|
83
|
+
defs << [name, val]
|
84
|
+
|
85
|
+
data Itemization new(defs)
|
86
|
+
|
87
|
+
def(item(name, content)): .item(name, content)
|
88
|
+
|
89
|
+
def(italic(content)): data Element new(content, .italic)
|
90
|
+
|
91
|
+
def(strike(content)): data Element new(content, .strike)
|
92
|
+
|
93
|
+
def(list(*elements)): data List new(elements)
|
94
|
+
|
95
|
+
def(ordered-list(*elements)): data OrderedList new(elements)
|
96
|
+
|
97
|
+
def(bold(content)): data Element new(content, .bold)
|
98
|
+
|
99
|
+
def(smaller(content)): data Element new(content, .smaller)
|
100
|
+
|
101
|
+
def(larger(content)): data Element new(content, .larger)
|
102
|
+
|
103
|
+
def(superscript(content)): data Element new(content, .superscript)
|
104
|
+
|
105
|
+
def(subscript(content)): data Element new(content, .subscript)
|
106
|
+
|
107
|
+
def(code(content)): data Element new(content, .tt)
|
108
|
+
|
109
|
+
def(margin-note(content)): data Block new(content, .margin-note)
|
110
|
+
|
111
|
+
def(aux(content)): data Element new(content, .aux)
|
112
|
+
|
113
|
+
def(inset(content)): data Block new(content, .inset)
|
114
|
+
|
115
|
+
fn(format-inline(tokens, link-only = nil)):
|
116
|
+
tokens collect [t]:
|
117
|
+
data Element new(
|
118
|
+
-- constants, identifiers, and operators
|
119
|
+
if((link-only && link-only include?(t contents)) ||
|
120
|
+
(!link-only && ["no", "n", "o"] include?(t type tag)))
|
121
|
+
then:
|
122
|
+
data ResolveElement new(
|
123
|
+
[part]:
|
124
|
+
tag = part find-tag(t contents)
|
125
|
+
if(tag)
|
126
|
+
then: data Reference new(tag, t contents)
|
127
|
+
else: t contents)
|
128
|
+
else: t contents
|
129
|
+
.class(t type tag))
|
130
|
+
|
131
|
+
fn(format-block(tokens, link-only = nil)):
|
132
|
+
data Block new(
|
133
|
+
verbatim(format-inline(tokens, link-only))
|
134
|
+
.class("highlight"))
|
135
|
+
|
136
|
+
def(codeblock(language, content)):
|
137
|
+
format-block(hl load(language) new(content) run) rescue:
|
138
|
+
LoadError:
|
139
|
+
warning(.unknown-language(language))
|
140
|
+
verbatim(content)
|
141
|
+
|
142
|
+
def(newline): data Element new("", .newline)
|
143
|
+
|
144
|
+
def(no-break(content)): data Element new(content, .no-break)
|
145
|
+
|
146
|
+
def(decode(*cs)):
|
147
|
+
part = data Part new
|
148
|
+
|
149
|
+
meta over(cs, part)
|
150
|
+
|
151
|
+
part
|
data/lib/anatomy/cmd.ay
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
use(require("atomy"))
|
2
|
+
|
3
|
+
require("optparse")
|
4
|
+
|
5
|
+
$LOAD_PATH unshift(File expand-path("../../lib", __FILE__))
|
6
|
+
|
7
|
+
processor = require("anatomy/processor")
|
8
|
+
|
9
|
+
ARGV shift
|
10
|
+
|
11
|
+
options = #{
|
12
|
+
.input -> ARGV[0]
|
13
|
+
.output -> "."
|
14
|
+
.renderer -> "html"
|
15
|
+
.serve -> nil
|
16
|
+
}
|
17
|
+
|
18
|
+
op = OptionParser new [o]:
|
19
|
+
o banner = "usage: anatomy [file] [options]"
|
20
|
+
|
21
|
+
o on("-s", "--serve PORT", "serve the rendered documents on the given port") [v]:
|
22
|
+
options[.serve] = v to-i
|
23
|
+
|
24
|
+
o on("-i", "--input FILE", "anatomy document") [v]:
|
25
|
+
options[.input] = v
|
26
|
+
|
27
|
+
o on("-o", "--output DIRECTORY",
|
28
|
+
"where to place output documents and files") [v]:
|
29
|
+
options[.output] = v
|
30
|
+
|
31
|
+
o on("-r", "--renderer NAME",
|
32
|
+
"which renderer to use (e.g. html)") [v]:
|
33
|
+
options[.renderer] = v
|
34
|
+
|
35
|
+
op parse!
|
36
|
+
|
37
|
+
input = options[.input]
|
38
|
+
output = options[.output]
|
39
|
+
renderer = options[.renderer]
|
40
|
+
|
41
|
+
unless(input):
|
42
|
+
puts(op help)
|
43
|
+
exit(1)
|
44
|
+
|
45
|
+
-- a / in the renderer name implies it's external
|
46
|
+
unless(renderer include?("/")):
|
47
|
+
renderer = i"anatomy/renderers/#{renderer}"
|
48
|
+
|
49
|
+
if(options[.serve])
|
50
|
+
then:
|
51
|
+
server = require("anatomy/server") Server new(
|
52
|
+
options[.input]
|
53
|
+
options[.output]
|
54
|
+
processor
|
55
|
+
require(renderer)
|
56
|
+
)
|
57
|
+
|
58
|
+
server serve(options[.serve])
|
59
|
+
else:
|
60
|
+
processor process(input, require(renderer), output)
|