trenni-markdown 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -4
- data/examples/unit_test.md +41 -0
- data/lib/trenni/markdown/generators.rb +1 -0
- data/lib/trenni/markdown/generators/unit_test.rb +69 -0
- data/lib/trenni/markdown/parser.rb +1 -1
- data/lib/trenni/markdown/version.rb +1 -1
- data/trenni-markdown.gemspec +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80c7291285ffcd0dd7eee1a52a381007aa36c6bb
|
4
|
+
data.tar.gz: 271bb81c07044631c1ffd593e25e03975925e5fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5ca7845a950149279de439986742b331aecbcf4499bd2ff87dada9045d388bb07b2d7c1ba32df9ad432843d9bd310d9a899513ae3f9bce503042482ddebeb71
|
7
|
+
data.tar.gz: f08e25da04fb56720131cd9f1851a2365a32e3e18b44ab2e9639cfbcf329b40e4bb6e9037b39eb0a93a307549ca59320cb0bea9380cf08fc86d20dac870030ce
|
data/README.md
CHANGED
@@ -8,9 +8,15 @@ Trenni::Markdown is a light-weight (deliberately) simple Markdown parser. It doe
|
|
8
8
|
|
9
9
|
## Motivation
|
10
10
|
|
11
|
-
I've been
|
11
|
+
I've been writing a bit of C++ code lately and been thinking about how to document it in a way that is actually practically useful. Initially I started working on [ffi-clang](https://github.com/) to extract comments and symbols from C++ code. But, I found this ultimately produced unsatisfying output.
|
12
12
|
|
13
|
-
|
13
|
+
I discussed this with a friend and reviewed what I thought was good documentation. I found I tended to prefer short tangible examples, high-level use-cases that demonstrate the functionality of the library in a practical sense. He mentioned literate programming.
|
14
|
+
|
15
|
+
I started thinking about what would be the ideal documentation. In most cases, I end up copying examples from the unit tests into the main README. This is a bit tedious but I feel it gives a good high level summary of how and why you would use a library.
|
16
|
+
|
17
|
+
I stated thinking, rather than extracting the code, what about if the README could BE code. What about if the unit tests were actual markdown which could be compiled, and used to document the code in a very tangible way?
|
18
|
+
|
19
|
+
The name of this gem is a bit misleading but essentially what it does is generate code from an input markdown document according to some generator implemented in Ruby. The idea is that you could write unit tests (there is an included proof of concept for RSpec) as a readable markdown document. This would serve as the basis for the documentation and tie into the automatically generated documentation which is often hard to get a handle on in large projects. It would be the tangible entry point for high-level functionality, while the underlying symbol/comment index would be the foundation.
|
14
20
|
|
15
21
|
## Installation
|
16
22
|
|
@@ -30,7 +36,7 @@ Or install it yourself as:
|
|
30
36
|
|
31
37
|
### Command line
|
32
38
|
|
33
|
-
A command line binary is included for basic transforms:
|
39
|
+
A command line binary is included for basic transforms (using [examples/test.md](examples/test.md) in this example):
|
34
40
|
|
35
41
|
$ trenni-markdown -g RSpec examples/test.md
|
36
42
|
RSpec.describe String.new("Test") do
|
@@ -71,7 +77,7 @@ The delegate must respond to the following callbacks:
|
|
71
77
|
@delegate.paragraph(text)
|
72
78
|
@delegate.code(lines)
|
73
79
|
|
74
|
-
Keep in mind that this is not a general purpose markdown parser, but specifically for the generation of literate
|
80
|
+
Keep in mind that this is not a general purpose markdown parser, but specifically for the generation of literate code.
|
75
81
|
|
76
82
|
## Contributing
|
77
83
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#include <UnitTest/UnitTest.hpp>
|
2
|
+
#include <Dream/Events/Loop.hpp>
|
3
|
+
#include <Dream/Events/Source.hpp>
|
4
|
+
|
5
|
+
# Dream::Events
|
6
|
+
|
7
|
+
## Timer Test
|
8
|
+
|
9
|
+
### A timer is scheduled and called correctly
|
10
|
+
|
11
|
+
auto event_loop = ref(new Loop);
|
12
|
+
|
13
|
+
int ticks = 0;
|
14
|
+
|
15
|
+
event_loop->schedule_timer(new TimerSource([&](Loop *, TimerSource *, Event){
|
16
|
+
event_loop->stop();
|
17
|
+
}, 1.0));
|
18
|
+
|
19
|
+
event_loop->schedule_timer(new TimerSource([&](Loop *, TimerSource *, Event){
|
20
|
+
ticks += 1;
|
21
|
+
}, 0.01, true));
|
22
|
+
|
23
|
+
event_loop->run_forever();
|
24
|
+
|
25
|
+
examiner << "Ticker callback called correctly";
|
26
|
+
examiner.expect(ticks) == 100;
|
27
|
+
|
28
|
+
### A timer is scheduled and runs for a limited time
|
29
|
+
|
30
|
+
auto event_loop = ref(new Loop);
|
31
|
+
|
32
|
+
int ticks = 0;
|
33
|
+
|
34
|
+
event_loop->schedule_timer(new TimerSource([&](Loop *, TimerSource *, Event){
|
35
|
+
ticks += 1;
|
36
|
+
}, 0.01, true));
|
37
|
+
|
38
|
+
event_loop->run_until_timeout(0.11);
|
39
|
+
|
40
|
+
examiner << "Ticker callback called correctly within specified timeout";
|
41
|
+
examiner.expect(ticks) == 10;
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module Trenni
|
22
|
+
module Markdown
|
23
|
+
module Generators
|
24
|
+
class UnitTest < Generator
|
25
|
+
def initialize
|
26
|
+
super('// ')
|
27
|
+
end
|
28
|
+
|
29
|
+
def namespace(level, name)
|
30
|
+
# C++17 might help us avoid this mess :(
|
31
|
+
parts = name.split(/::/)
|
32
|
+
parts.collect!{|part| "namespace #{part} {"}
|
33
|
+
|
34
|
+
nest(level,
|
35
|
+
parts.join(' ') + "\n",
|
36
|
+
'}' * parts.count + "\n"
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def suite(level, name)
|
41
|
+
nest(level,
|
42
|
+
"Unit::Test #{name.gsub(/\s/, '')}Suite = {\n",
|
43
|
+
"};\n"
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test(level, name)
|
48
|
+
nest(level,
|
49
|
+
"{\"#{name}\",\n",
|
50
|
+
"},\n"
|
51
|
+
)
|
52
|
+
|
53
|
+
nest(level+1,
|
54
|
+
"[](UnitTest::Examiner & examiner) {",
|
55
|
+
"}\n"
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
def heading(level, text)
|
60
|
+
case level
|
61
|
+
when 1 then namespace(level, text)
|
62
|
+
when 2 then suite(level, text)
|
63
|
+
when 3 then test(level, text)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/trenni-markdown.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Samuel Williams"]
|
10
10
|
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
11
11
|
|
12
|
-
spec.summary = %q{A
|
12
|
+
spec.summary = %q{A markdown parser and literate programming code generator.}
|
13
13
|
spec.homepage = "https://github.com/ioquatix/trenni-markdown"
|
14
14
|
|
15
15
|
spec.files = `git ls-files`.split($/)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trenni-markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -98,11 +98,13 @@ files:
|
|
98
98
|
- bin/trenni-markdown
|
99
99
|
- examples/ruby.md
|
100
100
|
- examples/test.md
|
101
|
+
- examples/unit_test.md
|
101
102
|
- lib/trenni/markdown.rb
|
102
103
|
- lib/trenni/markdown/generator.rb
|
103
104
|
- lib/trenni/markdown/generators.rb
|
104
105
|
- lib/trenni/markdown/generators/rspec.rb
|
105
106
|
- lib/trenni/markdown/generators/ruby.rb
|
107
|
+
- lib/trenni/markdown/generators/unit_test.rb
|
106
108
|
- lib/trenni/markdown/parser.rb
|
107
109
|
- lib/trenni/markdown/version.rb
|
108
110
|
- spec/trenni/markdown/generator_spec.rb
|
@@ -130,7 +132,7 @@ rubyforge_project:
|
|
130
132
|
rubygems_version: 2.5.1
|
131
133
|
signing_key:
|
132
134
|
specification_version: 4
|
133
|
-
summary: A
|
135
|
+
summary: A markdown parser and literate programming code generator.
|
134
136
|
test_files:
|
135
137
|
- spec/trenni/markdown/generator_spec.rb
|
136
138
|
- spec/trenni/markdown/parser_spec.rb
|