documentize 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/Guardfile +32 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +3 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/documentize.gemspec +38 -0
- data/lib/documentize.rb +42 -0
- data/lib/documentize/collector.rb +104 -0
- data/lib/documentize/generator.rb +4 -0
- data/lib/documentize/version.rb +3 -0
- data/tasks/rspec.rake +3 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab38f8045075ee564fe9b48cb2e69bc2fec8a478
|
4
|
+
data.tar.gz: b82635f46ad6f81f7d512c81ecabdbadbf062bf3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8cb432194f5ee2611f7a5191fe30a38acc37539d5785625b3d25261c25fa8a53789d3af3114b5f2dfd8e5fcc4b6ae0bd5e1464c792d4135ce2eab88655a681f9
|
7
|
+
data.tar.gz: 3548c0f2037a5d3e59d4f41fb02f3cbedc79f085012721970a33217f92b29bc567213b093bc3feada716a008c010c5fd0f6a6ba04e583dc0873d7efe4477ad55
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
guard 'rake', :task => 'spec' do
|
19
|
+
watch(%r{^lib/(.+).rb$}) do |m|
|
20
|
+
"spec/#{m[1]}_spec.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
watch(%r{^lib/gameboard/(.+).rb$}) do |m|
|
24
|
+
"spec/#{m[1]}_spec.rb"
|
25
|
+
end
|
26
|
+
|
27
|
+
# watch /spec/ files
|
28
|
+
watch(%r{^spec/(.+).rb$}) do |m|
|
29
|
+
"spec/#{m[1]}.rb"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Sampson Crowley
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Documentize
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/documentize`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'documentize'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install documentize
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake true` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/documentize.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "documentize"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/documentize.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'documentize/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "documentize"
|
8
|
+
spec.version = Documentize::VERSION
|
9
|
+
spec.authors = ["Sampson Crowley"]
|
10
|
+
spec.email = ["sampsonsprojects@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Generates a ruby file with a TomDoc skeletons from existing ruby files}
|
13
|
+
spec.description = %q{Pass in a cluttered, or just undocumented ruby file and get back a well-spaced file with a TomDoc Skeleton for easy doc writing}
|
14
|
+
spec.homepage = "https://github.com/SampsonCrowley/documentize"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.5.0"
|
36
|
+
spec.add_development_dependency "guard", "~> 2.14"
|
37
|
+
spec.add_development_dependency "guard-rake"
|
38
|
+
end
|
data/lib/documentize.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "documentize/version"
|
2
|
+
require "documentize/collector"
|
3
|
+
require "documentize/generator"
|
4
|
+
|
5
|
+
|
6
|
+
module Documentize
|
7
|
+
class Documentize
|
8
|
+
REGEX = {
|
9
|
+
ext: /\.rb$|\.ru$/,
|
10
|
+
shbang: /^#!.*?ruby$/
|
11
|
+
}
|
12
|
+
|
13
|
+
attr_reader :collector, :file, :header, :tree
|
14
|
+
|
15
|
+
def initialize(file_name)
|
16
|
+
@file = load_file(file_name)
|
17
|
+
@collector = Collector.new
|
18
|
+
@generator = Generator.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def load_file(file_name)
|
22
|
+
file = File.readlines(file_name).map {|line| line.strip} - [""]
|
23
|
+
raise ArgumentError unless valid?(file_name, file[0])
|
24
|
+
file
|
25
|
+
end
|
26
|
+
|
27
|
+
def run
|
28
|
+
@tree, @header = collector.run(@file)
|
29
|
+
# generator.gen_docs(tree)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def valid?(file_name, shebang)
|
35
|
+
if file_name =~ REGEX[:ext] || shebang =~ REGEX[:shbang]
|
36
|
+
true
|
37
|
+
else
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Documentize
|
2
|
+
class Collector
|
3
|
+
|
4
|
+
REGEX = {
|
5
|
+
args: /(.*?)[\(|\s](.*?)\)/,
|
6
|
+
header: /^require/,
|
7
|
+
block: /\sdo[\s\|.*]/,
|
8
|
+
inline_do: /\sdo.*?end/,
|
9
|
+
is_class: /^class/,
|
10
|
+
is_method: /^def/,
|
11
|
+
is_module: /^module/,
|
12
|
+
comment: /^#/
|
13
|
+
}
|
14
|
+
|
15
|
+
def run(lines)
|
16
|
+
queue, header = remove_headers(lines)
|
17
|
+
[build(queue), header]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def build(queue)
|
23
|
+
content = []
|
24
|
+
skips = 0
|
25
|
+
until queue.length == 0
|
26
|
+
|
27
|
+
item = queue.shift
|
28
|
+
|
29
|
+
if item =~ REGEX[:is_class] ||
|
30
|
+
item =~ REGEX[:is_method] ||
|
31
|
+
item =~ REGEX[:is_module]
|
32
|
+
|
33
|
+
item = parse_command(item)
|
34
|
+
|
35
|
+
item[:content], queue = build(queue)
|
36
|
+
|
37
|
+
elsif item =~ REGEX[:block]
|
38
|
+
|
39
|
+
skips += 1 unless item =~ REGEX[:inline_do]
|
40
|
+
|
41
|
+
elsif item =~ /end/
|
42
|
+
|
43
|
+
return content, queue if skips <= 0
|
44
|
+
skips -= 1
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
content << item
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
content
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_args(cmd)
|
57
|
+
if cmd !~ REGEX[:args]
|
58
|
+
[cmd, nil]
|
59
|
+
else
|
60
|
+
matches = cmd.match(REGEX[:args])
|
61
|
+
[matches[1], parse_args(matches[2])]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse_args(arg_list)
|
66
|
+
breakup = arg_list.split(",").map{|arg| arg.strip}
|
67
|
+
breakup.map do |arg|
|
68
|
+
items = arg.split("=").map{ |item| item.strip }
|
69
|
+
{
|
70
|
+
name: items[0],
|
71
|
+
default: items[1]
|
72
|
+
}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def parse_command(cmd)
|
77
|
+
breakup = cmd.split(" ", 2)
|
78
|
+
if breakup[0] == "def"
|
79
|
+
type = "method"
|
80
|
+
cmd, args = get_args(breakup[1])
|
81
|
+
else
|
82
|
+
type = breakup[0]
|
83
|
+
cmd = breakup[1]
|
84
|
+
end
|
85
|
+
{
|
86
|
+
type: type,
|
87
|
+
name: cmd,
|
88
|
+
args: args,
|
89
|
+
content: [],
|
90
|
+
doc: nil
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
def remove_headers(file)
|
95
|
+
header = ""
|
96
|
+
until file[0] !~ REGEX[:header] && file[0] !~ REGEX[:comment]
|
97
|
+
header << "#{file.shift}\n"
|
98
|
+
end
|
99
|
+
header = header.length == 0 ? nil : header.strip
|
100
|
+
[file, header]
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
data/tasks/rspec.rake
ADDED
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: documentize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sampson Crowley
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.5.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.5.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Pass in a cluttered, or just undocumented ruby file and get back a well-spaced
|
84
|
+
file with a TomDoc Skeleton for easy doc writing
|
85
|
+
email:
|
86
|
+
- sampsonsprojects@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- Guardfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- documentize.gemspec
|
102
|
+
- lib/documentize.rb
|
103
|
+
- lib/documentize/collector.rb
|
104
|
+
- lib/documentize/generator.rb
|
105
|
+
- lib/documentize/version.rb
|
106
|
+
- tasks/rspec.rake
|
107
|
+
homepage: https://github.com/SampsonCrowley/documentize
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata:
|
111
|
+
allowed_push_host: https://rubygems.org
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.5.1
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Generates a ruby file with a TomDoc skeletons from existing ruby files
|
132
|
+
test_files: []
|