fancy 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +14 -14
- data/Rakefile +16 -4
- data/bin/fancy +3 -0
- data/bin/fspec +20 -0
- data/bin/fyi +27 -11
- data/bin/ifancy +1 -1
- data/boot/fancy_ext.rb +1 -0
- data/boot/fancy_ext/block_env.rb +1 -9
- data/boot/fancy_ext/delegator.rb +64 -0
- data/boot/fancy_ext/object.rb +4 -0
- data/boot/fancy_ext/thread.rb +4 -0
- data/boot/load.rb +5 -1
- data/boot/rbx-compiler/compiler/ast.rb +0 -1
- data/boot/rbx-compiler/compiler/ast/class_def.rb +2 -0
- data/boot/rbx-compiler/compiler/ast/method_def.rb +2 -0
- data/boot/rbx-compiler/compiler/ast/node.rb +10 -0
- data/boot/rbx-compiler/compiler/ast/ruby_args.rb +12 -0
- data/boot/rbx-compiler/compiler/ast/singleton_method_def.rb +2 -0
- data/boot/rbx-compiler/parser/fancy_parser.bundle +0 -0
- data/boot/rbx-compiler/parser/lexer.lex +5 -11
- data/boot/rbx-compiler/parser/parser.rb +16 -5
- data/boot/rbx-compiler/parser/parser.y +39 -24
- data/doc/api/fancy.css +1 -1
- data/doc/api/fancy.jsonp +1 -1
- data/doc/api/fdoc.js +22 -4
- data/doc/api/index.html +5 -6
- data/doc/api/jquery-ui.min.js +401 -0
- data/doc/api/jquery.tools.min.js +192 -0
- data/doc/api/themeswitchertool.js +250 -0
- data/doc/features.md +17 -0
- data/examples/actor_bunnies.fy +32 -0
- data/examples/actors.fy +26 -0
- data/examples/actors_primitive.fy +27 -0
- data/examples/actors_ring.fy +37 -0
- data/examples/armstrong_numbers.fy +1 -1
- data/examples/array.fy +7 -9
- data/examples/async_send.fy +1 -2
- data/examples/blocks.fy +4 -4
- data/examples/call_with_receiver.fy +1 -1
- data/examples/class.fy +1 -1
- data/examples/default_args.fy +4 -1
- data/examples/define_methods.fy +2 -2
- data/examples/echo.fy +1 -1
- data/examples/factorial.fy +1 -1
- data/examples/future_composition.fy +2 -2
- data/examples/futures.fy +0 -5
- data/examples/game_of_life.fy +1 -1
- data/examples/person.fy +1 -1
- data/lib/argv.fy +7 -2
- data/lib/array.fy +109 -42
- data/lib/block.fy +39 -14
- data/lib/boot.fy +2 -0
- data/lib/class.fy +2 -0
- data/lib/compiler/ast.fy +2 -1
- data/lib/compiler/ast/assign.fy +2 -3
- data/lib/compiler/ast/async_send.fy +1 -15
- data/lib/compiler/ast/class_def.fy +2 -1
- data/lib/compiler/ast/expression_list.fy +4 -5
- data/lib/compiler/ast/future_send.fy +1 -10
- data/lib/compiler/ast/goto.fy +46 -0
- data/lib/compiler/ast/identifier.fy +9 -7
- data/lib/compiler/ast/literals.fy +8 -1
- data/lib/compiler/ast/match.fy +14 -4
- data/lib/compiler/ast/message_send.fy +34 -6
- data/lib/compiler/ast/method_def.fy +6 -6
- data/lib/compiler/ast/node.fy +3 -3
- data/lib/compiler/ast/range.fy +1 -0
- data/lib/compiler/ast/script.fy +0 -2
- data/lib/compiler/ast/singleton_method_def.fy +2 -4
- data/lib/compiler/ast/string_interpolation.fy +17 -0
- data/lib/compiler/ast/super.fy +5 -4
- data/lib/compiler/ast/try_catch.fy +8 -6
- data/lib/compiler/ast/tuple_literal.fy +3 -2
- data/lib/compiler/command.fy +0 -1
- data/lib/compiler/compiler.fy +1 -5
- data/lib/compiler/stages.fy +6 -14
- data/lib/documentation.fy +57 -46
- data/lib/enumerable.fy +257 -23
- data/lib/enumerator.fy +122 -15
- data/lib/false_class.fy +10 -1
- data/lib/fancy_spec.fy +263 -61
- data/lib/fdoc.fy +11 -25
- data/lib/fiber.fy +11 -0
- data/lib/file.fy +8 -11
- data/lib/future.fy +84 -5
- data/lib/hash.fy +65 -14
- data/lib/integer.fy +35 -0
- data/lib/iteration.fy +54 -29
- data/lib/message.fy +6 -0
- data/lib/method.fy +0 -16
- data/lib/nil_class.fy +58 -8
- data/lib/number.fy +49 -22
- data/lib/object.fy +371 -65
- data/lib/package.fy +24 -1
- data/lib/package/installer.fy +5 -9
- data/lib/package/specification.fy +2 -2
- data/lib/parser/ext/lexer.lex +15 -11
- data/lib/parser/ext/parser.y +70 -23
- data/lib/parser/methods.fy +33 -14
- data/lib/proxy.fy +33 -3
- data/lib/range.fy +28 -0
- data/lib/rbx.fy +3 -1
- data/lib/rbx/actor.fy +53 -0
- data/lib/rbx/alpha.fy +31 -0
- data/lib/rbx/array.fy +21 -12
- data/lib/rbx/bignum.fy +6 -2
- data/lib/rbx/block.fy +23 -26
- data/lib/rbx/class.fy +54 -2
- data/lib/rbx/code_loader.fy +8 -4
- data/lib/rbx/date.fy +9 -0
- data/lib/rbx/directory.fy +18 -0
- data/lib/rbx/environment_variables.fy +1 -0
- data/lib/rbx/exception.fy +9 -2
- data/lib/rbx/fiber.fy +22 -4
- data/lib/rbx/file.fy +5 -5
- data/lib/rbx/fixnum.fy +5 -0
- data/lib/rbx/float.fy +11 -3
- data/lib/rbx/hash.fy +31 -16
- data/lib/rbx/integer.fy +1 -0
- data/lib/rbx/io.fy +17 -7
- data/lib/rbx/match_data.fy +15 -4
- data/lib/rbx/method.fy +40 -7
- data/lib/rbx/name_error.fy +4 -0
- data/lib/rbx/object.fy +92 -24
- data/lib/rbx/range.fy +20 -6
- data/lib/rbx/regexp.fy +11 -3
- data/lib/rbx/string.fy +51 -1
- data/lib/rbx/stringio.fy +17 -0
- data/lib/rbx/symbol.fy +15 -1
- data/lib/rbx/system.fy +20 -2
- data/lib/rbx/tcp_server.fy +4 -1
- data/lib/rbx/tcp_socket.fy +11 -0
- data/lib/rbx/time.fy +6 -0
- data/lib/rbx/tuple.fy +14 -5
- data/lib/set.fy +144 -29
- data/lib/stack.fy +42 -11
- data/lib/string.fy +118 -8
- data/lib/struct.fy +13 -3
- data/lib/symbol.fy +21 -2
- data/lib/thread_pool.fy +2 -1
- data/lib/true_class.fy +45 -7
- data/lib/tuple.fy +27 -9
- data/lib/version.fy +2 -2
- data/ruby_lib/fancy +43 -0
- data/ruby_lib/fdoc +23 -0
- data/ruby_lib/fspec +3 -0
- data/ruby_lib/fyi +3 -0
- data/ruby_lib/ifancy +3 -0
- data/tests/argv.fy +5 -9
- data/tests/array.fy +323 -196
- data/tests/assignment.fy +29 -29
- data/tests/block.fy +72 -59
- data/tests/class.fy +227 -138
- data/tests/control_flow.fy +83 -51
- data/tests/documentation.fy +8 -8
- data/tests/enumerable.fy +8 -0
- data/tests/enumerator.fy +47 -29
- data/tests/exception.fy +49 -32
- data/tests/file.fy +28 -28
- data/tests/fixnum.fy +170 -0
- data/tests/future.fy +24 -7
- data/tests/hash.fy +55 -38
- data/tests/method.fy +50 -43
- data/tests/nil_class.fy +37 -37
- data/tests/object.fy +152 -70
- data/tests/pattern_matching.fy +67 -31
- data/tests/range.fy +6 -6
- data/tests/set.fy +101 -4
- data/tests/stack.fy +14 -5
- data/tests/string.fy +115 -61
- data/tests/stringio.fy +18 -0
- data/tests/struct.fy +27 -0
- data/tests/symbol.fy +19 -6
- data/tests/true_class.fy +34 -34
- data/tests/tuple.fy +30 -12
- metadata +103 -81
- data/boot/rbx-compiler/compiler/ast/require.rb +0 -20
- data/examples/actor.fy +0 -37
- data/examples/curl_async.fy +0 -37
- data/lib/compiler/ast/require.fy +0 -15
- data/tests/number.fy +0 -135
- data/tests/parsing/sexp.fy +0 -50
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
class Fancy AST {
|
|
2
|
-
|
|
3
2
|
class MethodDef : Rubinius AST Define {
|
|
4
|
-
def initialize: @line name: @name args: @arguments body: @body access: @access {
|
|
3
|
+
def initialize: @line name: @name args: @arguments (MethodArgs new: @line) body: @body (ExpressionList new: @line) access: @access ('public) {
|
|
4
|
+
{ @body = ExpressionList new: @line } unless: @body
|
|
5
5
|
@name = @name method_name: nil
|
|
6
|
+
@docstring = @body shift_docstring
|
|
6
7
|
generate_ivar_assignment
|
|
7
8
|
|
|
8
9
|
if: (@body empty?) then: {
|
|
@@ -34,9 +35,8 @@ class Fancy AST {
|
|
|
34
35
|
define_method_missing: g
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
docstring = @body shift_docstring
|
|
38
38
|
bytecode(g)
|
|
39
|
-
MethodDef set: g docstring: docstring line: @line argnames: $ @arguments names()
|
|
39
|
+
MethodDef set: g docstring: @docstring line: @line argnames: $ @arguments names()
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
# Sets fancy documentation for the object currently
|
|
@@ -77,13 +77,13 @@ class Fancy AST {
|
|
|
77
77
|
ms = MessageSend new: @line \
|
|
78
78
|
message: (Identifier from: "define_forward_method_missing" line: @line) \
|
|
79
79
|
to: (Self new: @line) \
|
|
80
|
-
args: (MessageArgs new: @line
|
|
80
|
+
args: (MessageArgs new: @line)
|
|
81
81
|
ms bytecode: g
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
class MethodArgs : Rubinius AST FormalArguments {
|
|
86
|
-
def initialize: @line args: @array{
|
|
86
|
+
def initialize: @line args: @array ([]) {
|
|
87
87
|
initialize(@line, @array map() |a| { a to_sym() }, nil, nil)
|
|
88
88
|
}
|
|
89
89
|
}
|
data/lib/compiler/ast/node.fy
CHANGED
data/lib/compiler/ast/range.fy
CHANGED
data/lib/compiler/ast/script.fy
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
class Fancy AST {
|
|
2
2
|
class SingletonMethodDef : Rubinius AST DefineSingleton {
|
|
3
|
-
|
|
4
3
|
def initialize: @line name: @name args: @arguments body: @body access: @access owner: @receiver {
|
|
5
4
|
name = @name method_name: @receiver
|
|
6
5
|
@body = SingletonMethodDefScope new: @line name: name args: @arguments body: @body
|
|
@@ -13,12 +12,11 @@ class Fancy AST {
|
|
|
13
12
|
g pop()
|
|
14
13
|
bytecode(g)
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
class SingletonMethodDefScope : Rubinius AST DefineSingletonScope {
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
def initialize: @line name: @name args: @arguments body: @body {
|
|
19
|
+
}
|
|
22
20
|
|
|
23
21
|
define_method("bytecode") |g, recv| {
|
|
24
22
|
bytecode: g receiver: recv
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class Fancy AST {
|
|
2
|
+
class StringInterpolation : Node {
|
|
3
|
+
"""
|
|
4
|
+
StringInterpolation nodes need to be parsed after the overall code has been parsed
|
|
5
|
+
as the parser currently isn't re-entrant.
|
|
6
|
+
It works...
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
def initialize: @line code: @code
|
|
10
|
+
def parse_code {
|
|
11
|
+
Fancy Parser parse_code: @code file: ("<<StringInterpolation: " ++ (@code inspect) ++ ">>") line: @line
|
|
12
|
+
}
|
|
13
|
+
def bytecode: g {
|
|
14
|
+
parse_code body expressions first bytecode: g
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
data/lib/compiler/ast/super.fy
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
class Fancy AST {
|
|
2
|
-
|
|
3
2
|
class Super : Node {
|
|
4
|
-
def initialize: @line {
|
|
3
|
+
def initialize: @line {
|
|
4
|
+
}
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
class SuperSend : Node {
|
|
8
|
-
def initialize: @line message: @name args: @args {
|
|
8
|
+
def initialize: @line message: @name args: @args {
|
|
9
|
+
}
|
|
10
|
+
|
|
9
11
|
def bytecode: g {
|
|
10
12
|
pos(g)
|
|
11
13
|
@args bytecode: g
|
|
@@ -14,5 +16,4 @@ class Fancy AST {
|
|
|
14
16
|
g send_super(name, @args size)
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
|
-
|
|
18
19
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
class Fancy AST {
|
|
2
2
|
class TryCatch : Node {
|
|
3
|
-
|
|
4
3
|
def initialize: @line body: @body handlers: @handlers ensure: @ensure {
|
|
5
4
|
if: (@body empty?) then: {
|
|
6
5
|
@body unshift_expression: $ NilLiteral new: @line
|
|
@@ -12,7 +11,6 @@ class Fancy AST {
|
|
|
12
11
|
|
|
13
12
|
g push_modifiers()
|
|
14
13
|
|
|
15
|
-
|
|
16
14
|
outer_retry = g new_label()
|
|
17
15
|
this_retry = g new_label()
|
|
18
16
|
reraise = g new_label()
|
|
@@ -133,7 +131,8 @@ class Fancy AST {
|
|
|
133
131
|
}
|
|
134
132
|
|
|
135
133
|
class ExceptionHandler : Node {
|
|
136
|
-
def initialize: @line condition: @condition var: @var body: @body {
|
|
134
|
+
def initialize: @line condition: @condition var: @var body: @body {
|
|
135
|
+
}
|
|
137
136
|
|
|
138
137
|
def bytecode: g final_tag: final_tag {
|
|
139
138
|
pos(g)
|
|
@@ -161,7 +160,9 @@ class Fancy AST {
|
|
|
161
160
|
}
|
|
162
161
|
|
|
163
162
|
class CurrentException : Node {
|
|
164
|
-
def initialize: @line {
|
|
163
|
+
def initialize: @line {
|
|
164
|
+
}
|
|
165
|
+
|
|
165
166
|
def bytecode: g {
|
|
166
167
|
pos(g)
|
|
167
168
|
g push_current_exception()
|
|
@@ -169,12 +170,13 @@ class Fancy AST {
|
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
class Retry : Node {
|
|
172
|
-
def initialize: @line {
|
|
173
|
+
def initialize: @line {
|
|
174
|
+
}
|
|
175
|
+
|
|
173
176
|
def bytecode: g {
|
|
174
177
|
pos(g)
|
|
175
178
|
g pop()
|
|
176
179
|
g goto(g retry())
|
|
177
180
|
}
|
|
178
181
|
}
|
|
179
|
-
|
|
180
182
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
class Fancy AST {
|
|
2
2
|
class TupleLiteral : Node {
|
|
3
|
-
def initialize: @line entries: @elements {
|
|
3
|
+
def initialize: @line entries: @elements {
|
|
4
|
+
}
|
|
4
5
|
|
|
5
6
|
def bytecode: g {
|
|
6
7
|
pos(g)
|
|
@@ -22,7 +23,7 @@ class Fancy AST {
|
|
|
22
23
|
ary = [FixnumLiteral new: @line value: i, e]
|
|
23
24
|
|
|
24
25
|
ms = MessageSend new: @line \
|
|
25
|
-
message: (Identifier from: "
|
|
26
|
+
message: (Identifier from: "[]:" line: @line) \
|
|
26
27
|
to: (Nothing new: @line) \
|
|
27
28
|
args: (MessageArgs new: @line args: ary)
|
|
28
29
|
|
data/lib/compiler/command.fy
CHANGED
data/lib/compiler/compiler.fy
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
class Fancy {
|
|
2
|
-
|
|
3
2
|
class Compiler : Rubinius Compiler {
|
|
4
|
-
|
|
5
|
-
read_write_slots: ['parser, 'generator, 'packager, 'writer]
|
|
3
|
+
read_write_slots: [ 'parser, 'generator, 'packager, 'writer ]
|
|
6
4
|
|
|
7
5
|
def self compiled_name: file {
|
|
8
6
|
"""
|
|
@@ -69,7 +67,5 @@ class Fancy {
|
|
|
69
67
|
compiler_error("Error trying to compile " ++ file, e)
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
|
-
|
|
73
70
|
}
|
|
74
|
-
|
|
75
71
|
}
|
data/lib/compiler/stages.fy
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
class Fancy Compiler Stages {
|
|
2
|
-
|
|
3
2
|
class Stage : Rubinius Compiler Stage {
|
|
4
|
-
|
|
5
3
|
initialize = |compiler, last| {
|
|
6
4
|
sup = Rubinius Compiler Stage instance_method('initialize)
|
|
7
5
|
sup bind(self) call(compiler, last)
|
|
@@ -16,14 +14,11 @@ class Fancy Compiler Stages {
|
|
|
16
14
|
|
|
17
15
|
run = { self run; run_next() }
|
|
18
16
|
define_method('run, &run)
|
|
19
|
-
|
|
20
17
|
}
|
|
21
18
|
|
|
22
19
|
class FancyGenerator : Stage {
|
|
23
|
-
|
|
24
20
|
stage: 'fancy_bytecode next: Rubinius Compiler Encoder
|
|
25
|
-
|
|
26
|
-
read_write_slots: ['variable_scope]
|
|
21
|
+
read_write_slot: 'variable_scope
|
|
27
22
|
|
|
28
23
|
def initialize: compiler last: last {
|
|
29
24
|
@variable_scope = nil
|
|
@@ -36,7 +31,6 @@ class Fancy Compiler Stages {
|
|
|
36
31
|
@input bytecode(@output)
|
|
37
32
|
@output close()
|
|
38
33
|
}
|
|
39
|
-
|
|
40
34
|
}
|
|
41
35
|
|
|
42
36
|
class FancyCodeParser : Stage {
|
|
@@ -47,7 +41,8 @@ class Fancy Compiler Stages {
|
|
|
47
41
|
compiler parser: self
|
|
48
42
|
}
|
|
49
43
|
|
|
50
|
-
def input: @code file: @filename line: @line (1) {
|
|
44
|
+
def input: @code file: @filename line: @line (1) {
|
|
45
|
+
}
|
|
51
46
|
|
|
52
47
|
def run {
|
|
53
48
|
ast = Fancy Parser parse_code: @code file: @filename line: @line
|
|
@@ -58,7 +53,6 @@ class Fancy Compiler Stages {
|
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
class FancyFileParser : Stage {
|
|
61
|
-
|
|
62
56
|
stage: 'fancy_file next: FancyGenerator
|
|
63
57
|
read_write_slots: ['root, 'print]
|
|
64
58
|
|
|
@@ -66,7 +60,8 @@ class Fancy Compiler Stages {
|
|
|
66
60
|
compiler parser: self
|
|
67
61
|
}
|
|
68
62
|
|
|
69
|
-
def input: @filename line: @line (1) {
|
|
63
|
+
def input: @filename line: @line (1) {
|
|
64
|
+
}
|
|
70
65
|
|
|
71
66
|
def run {
|
|
72
67
|
ast = Fancy Parser parse_file: @filename line: @line
|
|
@@ -74,8 +69,5 @@ class Fancy Compiler Stages {
|
|
|
74
69
|
@output = @root new(ast)
|
|
75
70
|
@output file=(@filename)
|
|
76
71
|
}
|
|
77
|
-
|
|
78
72
|
}
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
73
|
+
}
|
data/lib/documentation.fy
CHANGED
|
@@ -1,57 +1,60 @@
|
|
|
1
1
|
class Fancy Documentation {
|
|
2
|
-
|
|
3
2
|
"""
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
A Fancy Documentation object is a holder for docstrings and specs.
|
|
4
|
+
Keeps a registry of documentation for anything Fancy.
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
Provides methods for searching and formatting an Object's docstrings.
|
|
7
|
+
This can be be handy for users of the interactive Fancy REPL,
|
|
8
|
+
document generators, instrospection tools, IDEs, anything!
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
This object can be converted to just anything by using its format:
|
|
11
|
+
method. Formatters can be registered with Fancy Documentation#formatter:is:
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
By default two formatters are defined:
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
'fancy => Returns the Fancy::Documentation object
|
|
16
|
+
'string => Returns the docs string representation
|
|
18
17
|
"""
|
|
18
|
+
|
|
19
19
|
read_write_slots: ['object, 'docs, 'specs]
|
|
20
20
|
|
|
21
21
|
instance_method: 'docs . executable() . documentation: """
|
|
22
|
-
|
|
22
|
+
An array of docstrings for the object beind documented.
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
We have an array of docstrings because in Fancy, some
|
|
25
|
+
things like classes can be re-openned and the user may
|
|
26
|
+
specify new documentation for it each time. Thus we dont
|
|
27
|
+
want to loose the previous documentation but rather build
|
|
28
|
+
upon it. That is, fancy supports incremental documentation.
|
|
29
29
|
"""
|
|
30
30
|
|
|
31
31
|
instance_method: 'specs . documentation: """
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
An array of associated Fancy specs for the object
|
|
33
|
+
being documented.
|
|
34
|
+
|
|
35
|
+
Its a lot better to keep the associated specs in
|
|
36
|
+
Fancy Documentation objects instead of just having them
|
|
37
|
+
in method instances. This allows us to associate any object
|
|
38
|
+
with an spec example.
|
|
39
|
+
|
|
40
|
+
This way you can have a single Fancy spec example that
|
|
41
|
+
is related to many objects (methods, constants, classes)
|
|
42
|
+
that are being specified. Later in documentation, we can
|
|
43
|
+
provide links to all specs where an object is being exercised.
|
|
44
44
|
"""
|
|
45
45
|
|
|
46
|
-
def to_s {
|
|
46
|
+
def to_s {
|
|
47
|
+
@docs join: "\n" . skip_leading_indentation
|
|
48
|
+
}
|
|
47
49
|
|
|
48
50
|
def format: format {
|
|
49
51
|
"""
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
If format is specified, the documentation string will be
|
|
53
|
+
converted using the corresponding formatter. This allows
|
|
54
|
+
you to extend Fancy documentation system, and produce
|
|
55
|
+
html documents, man pages, or anything you can imagine.
|
|
54
56
|
"""
|
|
57
|
+
|
|
55
58
|
formatter = Fancy Documentation formatter: format
|
|
56
59
|
{ "No such documentation format: " ++ format . raise! } unless: formatter
|
|
57
60
|
formatter call: [self]
|
|
@@ -59,9 +62,10 @@ class Fancy Documentation {
|
|
|
59
62
|
|
|
60
63
|
def self for: obj append: docstring {
|
|
61
64
|
"""
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
Append docstring to the documentation for obj.
|
|
66
|
+
If obj has no documentation, one is created for it.
|
|
64
67
|
"""
|
|
68
|
+
|
|
65
69
|
doc = for: obj
|
|
66
70
|
if: doc then: {
|
|
67
71
|
doc docs << docstring
|
|
@@ -72,17 +76,26 @@ class Fancy Documentation {
|
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
def self formatter: name {
|
|
75
|
-
"
|
|
79
|
+
"""
|
|
80
|
+
Obtains a formatter by a given name. Returns a callable object.
|
|
81
|
+
"""
|
|
82
|
+
|
|
76
83
|
formatters at: name
|
|
77
84
|
}
|
|
78
85
|
|
|
79
86
|
def self formatter: name is: callable {
|
|
80
|
-
"
|
|
81
|
-
|
|
87
|
+
"""
|
|
88
|
+
Registers a callable object as formatter under name.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
formatters[name]: callable
|
|
82
92
|
}
|
|
83
93
|
|
|
84
94
|
def self formatters {
|
|
85
|
-
"
|
|
95
|
+
"""
|
|
96
|
+
Obtain the hash of known documentation formatters.
|
|
97
|
+
"""
|
|
98
|
+
|
|
86
99
|
unless: @formatters do: { @formatters = <[]> }
|
|
87
100
|
@formatters
|
|
88
101
|
}
|
|
@@ -92,12 +105,13 @@ class Fancy Documentation {
|
|
|
92
105
|
|
|
93
106
|
# TODO: implement. Plain is just like string but including spec names.
|
|
94
107
|
self formatter: 'plain is: |doc| { doc to_s }
|
|
95
|
-
|
|
96
108
|
}
|
|
97
109
|
|
|
98
110
|
class Fancy Documentation RDiscount {
|
|
111
|
+
"""
|
|
112
|
+
A documentation formatter using ruby's RDiscount markdown
|
|
113
|
+
"""
|
|
99
114
|
|
|
100
|
-
"A documentation formatter using ruby's RDiscount markdown"
|
|
101
115
|
Fancy Documentation formatter: 'rdiscount is: |d| { rdiscount: d }
|
|
102
116
|
|
|
103
117
|
# Register as default markdown formatter.
|
|
@@ -109,7 +123,4 @@ class Fancy Documentation RDiscount {
|
|
|
109
123
|
require("rdiscount")
|
|
110
124
|
RDiscount.new(doc to_s).to_html()
|
|
111
125
|
}
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
126
|
+
}
|