Skip to content

Commit 15f82a5

Browse files
committed
up
1 parent 374b15c commit 15f82a5

File tree

6 files changed

+189
-0
lines changed

6 files changed

+189
-0
lines changed

natspec/.gitignore

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
*.gem
2+
*.rbc
3+
/.config
4+
/coverage/
5+
/InstalledFiles
6+
/pkg/
7+
/spec/reports/
8+
/test/tmp/
9+
/test/version_tmp/
10+
/tmp/
11+
12+
## Specific to RubyMotion:
13+
.dat*
14+
.repl_history
15+
build/
16+
17+
## Documentation cache and generated files:
18+
/.yardoc/
19+
/_yardoc/
20+
/doc/
21+
/rdoc/
22+
23+
## Environment normalisation:
24+
/.bundle/
25+
/vendor/bundle
26+
/lib/bundler/man/
27+
28+
# for a library or gem, you might want to ignore these files since the code is
29+
# intended to run in multiple environments; otherwise, check them in:
30+
# Gemfile.lock
31+
.ruby-version
32+
.ruby-gemset
33+
34+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35+
.rvmrc
36+
37+
# Gladiator (Glimmer Editor)
38+
.gladiator
39+
.DS_Store
40+
41+
42+
43+
####
44+
# exclude all tmp & tmp2 and o directory (in all levels)
45+
tmp/
46+
tmp2/
47+
o/
48+
49+
########
50+
# exclude all dbs e.g. artbase.db etc.
51+
*.db
52+
53+
######
54+
# exclude all zips (in /dl)
55+
*.zip
56+
57+
58+

natspec/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### 0.0.1 / 2023-01-13
2+
3+
* Everything is new. First release

natspec/Manifest.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CHANGELOG.md
2+
Manifest.txt
3+
README.md
4+
Rakefile
5+
lib/natspec.rb

natspec/README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Natspec - Natural Spec(ification) Documentation Parser
2+
3+
natspec - natural specification (comments) parser / machinery; document application binary interfaces (abis) for Ethereum & Co. (blockchain) contracts
4+
5+
6+
7+
* home :: [github.com/rubycocos/blockchain](https://github.com/rubycocos/blockchain)
8+
* bugs :: [github.com/rubycocos/blockchain/issues](https://github.com/rubycocos/blockchain/issues)
9+
* gem :: [rubygems.org/gems/natspec](https://rubygems.org/gems/natspec)
10+
* rdoc :: [rubydoc.info/gems/natspec](http://rubydoc.info/gems/natspec)
11+
12+
13+
14+
## Usage
15+
16+
To be done
17+
18+
19+
20+
21+
## License
22+
23+
The scripts are dedicated to the public domain.
24+
Use it as you please with no restrictions whatsoever.
25+
26+
27+
## Questions? Comments?
28+
29+
30+
Post them on the [D.I.Y. Punk (Pixel) Art reddit](https://old.reddit.com/r/DIYPunkArt). Thanks.
31+
32+

natspec/Rakefile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'hoe'
2+
3+
4+
Hoe.spec 'natspec' do
5+
6+
self.version = '0.0.1'
7+
8+
self.summary = "natspec - natural specification (comments) parser / machinery; document application binary interfaces (abis) for Ethereum & Co. (blockchain) contracts"
9+
self.description = summary
10+
11+
self.urls = { home: 'https://github.com/rubycocos/blockchain' }
12+
13+
self.author = 'Gerald Bauer'
14+
self.email = '[email protected]'
15+
16+
# switch extension to .markdown for gihub formatting
17+
self.readme_file = 'README.md'
18+
self.history_file = 'CHANGELOG.md'
19+
20+
self.extra_deps = [
21+
]
22+
23+
self.licenses = ['Public Domain']
24+
25+
self.spec_extras = {
26+
required_ruby_version: '>= 2.3'
27+
}
28+
29+
end
30+

natspec/lib/natspec.rb

+61
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,71 @@ def parse
6767

6868
sections << section if section
6969

70+
71+
## pre-process sections
72+
## remove trailing empty lines
73+
_strip_empty_leading_lines( head )
74+
_strip_empty_trailing_lines( head )
75+
_indent_code_block( head )
76+
77+
sections.each do |heading, lines|
78+
_strip_empty_leading_lines( lines )
79+
_strip_empty_trailing_lines( lines )
80+
_strip_code_block( lines )
81+
end
82+
83+
7084
Document.new( head, sections )
7185
end
86+
87+
88+
def _strip_code_block( sect )
89+
sect.reject! { |line| line.start_with?( '```' ) }
90+
end
91+
92+
def _indent_code_block( sect )
93+
## step 1: indent code blocks
94+
inside_block = false
95+
sect.each_with_index do |line,i|
96+
if line.start_with?( '```' )
97+
inside_block = !inside_block
98+
elsif inside_block
99+
sect[i] = (' '*4) + sect[i]
100+
else
101+
## regular line; keep going
102+
end
103+
end
104+
## step 2: remove all code block lines
105+
_strip_code_block( sect )
106+
end
107+
108+
109+
def _strip_empty_trailing_lines( sect )
110+
loop do
111+
line = sect[-1]
112+
if line && line.empty?
113+
sect.pop
114+
else
115+
break
116+
end
117+
end
118+
sect
119+
end
120+
121+
def _strip_empty_leading_lines( sect )
122+
loop do
123+
line = sect[0]
124+
if line && line.empty?
125+
sect.shift
126+
else
127+
break
128+
end
129+
end
130+
sect
131+
end
72132
end # class Parser
73133

134+
74135
def self.read( path )
75136
Parser.new( read_text( path ) ).parse
76137
end

0 commit comments

Comments
 (0)