Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldb committed Jan 13, 2023
1 parent 374b15c commit 15f82a5
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 0 deletions.
58 changes: 58 additions & 0 deletions natspec/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/test/tmp/
/test/version_tmp/
/tmp/

## Specific to RubyMotion:
.dat*
.repl_history
build/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/

## Environment normalisation:
/.bundle/
/vendor/bundle
/lib/bundler/man/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
.ruby-version
.ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc

# Gladiator (Glimmer Editor)
.gladiator
.DS_Store



####
# exclude all tmp & tmp2 and o directory (in all levels)
tmp/
tmp2/
o/

########
# exclude all dbs e.g. artbase.db etc.
*.db

######
# exclude all zips (in /dl)
*.zip



3 changes: 3 additions & 0 deletions natspec/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### 0.0.1 / 2023-01-13

* Everything is new. First release
5 changes: 5 additions & 0 deletions natspec/Manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CHANGELOG.md
Manifest.txt
README.md
Rakefile
lib/natspec.rb
32 changes: 32 additions & 0 deletions natspec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Natspec - Natural Spec(ification) Documentation Parser

natspec - natural specification (comments) parser / machinery; document application binary interfaces (abis) for Ethereum & Co. (blockchain) contracts



* home :: [github.com/rubycocos/blockchain](https://github.com/rubycocos/blockchain)
* bugs :: [github.com/rubycocos/blockchain/issues](https://github.com/rubycocos/blockchain/issues)
* gem :: [rubygems.org/gems/natspec](https://rubygems.org/gems/natspec)
* rdoc :: [rubydoc.info/gems/natspec](http://rubydoc.info/gems/natspec)



## Usage

To be done




## License

The scripts are dedicated to the public domain.
Use it as you please with no restrictions whatsoever.


## Questions? Comments?


Post them on the [D.I.Y. Punk (Pixel) Art reddit](https://old.reddit.com/r/DIYPunkArt). Thanks.


30 changes: 30 additions & 0 deletions natspec/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'hoe'


Hoe.spec 'natspec' do

self.version = '0.0.1'

self.summary = "natspec - natural specification (comments) parser / machinery; document application binary interfaces (abis) for Ethereum & Co. (blockchain) contracts"
self.description = summary

self.urls = { home: 'https://github.com/rubycocos/blockchain' }

self.author = 'Gerald Bauer'
self.email = '[email protected]'

# switch extension to .markdown for gihub formatting
self.readme_file = 'README.md'
self.history_file = 'CHANGELOG.md'

self.extra_deps = [
]

self.licenses = ['Public Domain']

self.spec_extras = {
required_ruby_version: '>= 2.3'
}

end

61 changes: 61 additions & 0 deletions natspec/lib/natspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,71 @@ def parse

sections << section if section


## pre-process sections
## remove trailing empty lines
_strip_empty_leading_lines( head )
_strip_empty_trailing_lines( head )
_indent_code_block( head )

sections.each do |heading, lines|
_strip_empty_leading_lines( lines )
_strip_empty_trailing_lines( lines )
_strip_code_block( lines )
end


Document.new( head, sections )
end


def _strip_code_block( sect )
sect.reject! { |line| line.start_with?( '```' ) }
end

def _indent_code_block( sect )
## step 1: indent code blocks
inside_block = false
sect.each_with_index do |line,i|
if line.start_with?( '```' )
inside_block = !inside_block
elsif inside_block
sect[i] = (' '*4) + sect[i]
else
## regular line; keep going
end
end
## step 2: remove all code block lines
_strip_code_block( sect )
end


def _strip_empty_trailing_lines( sect )
loop do
line = sect[-1]
if line && line.empty?
sect.pop
else
break
end
end
sect
end

def _strip_empty_leading_lines( sect )
loop do
line = sect[0]
if line && line.empty?
sect.shift
else
break
end
end
sect
end
end # class Parser


def self.read( path )
Parser.new( read_text( path ) ).parse
end
Expand Down

0 comments on commit 15f82a5

Please sign in to comment.