Skip to content

Commit 9882b98

Browse files
Stanislav (Stas) KatkovStanislav (Stas) Katkov
Stanislav (Stas) Katkov
and
Stanislav (Stas) Katkov
authored
Remove sqlite and use csv instead (#42)
* Remove sqlite * Generate example documentation for ruby source code * remove example_ruby/ folder before generating documentation * fixing ci: provide proper ruby v, remove syntax tree * modify tests * emit csv file as an index * remove styling gems * explicitly adding csv gem * rewrite test, but instead use .csv file --------- Co-authored-by: Stanislav (Stas) Katkov <github@skatkov.com>
1 parent 6445213 commit 9882b98

19 files changed

+144
-179
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,13 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v3
16-
- name: Set up Ruby
17-
uses: ruby/setup-ruby@v1
18-
with:
19-
ruby-version: '3.0'
20-
#bundler-cache: true
21-
- run: bundle config unset deployment
22-
- run: bundle install
23-
- name: Run tests
24-
run: bundle exec rake test
25-
- name: syntax_tree
26-
if: ${{ !cancelled() }}
27-
run: |
28-
set -E
29-
bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake')
15+
- uses: actions/checkout@v4
16+
- name: Set up Ruby
17+
uses: ruby/setup-ruby@v1
18+
with:
19+
ruby-version: "3.4.1"
20+
#bundler-cache: true
21+
- run: bundle config unset deployment
22+
- run: bundle install
23+
- name: Run tests
24+
run: bundle exec rake test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
.DS_Store
1111
example/created.rid
1212
.vscode/
13+
example_ruby/*
14+
source_ruby/*
15+

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "source_ruby"]
2+
path = source_ruby
3+
url = https://github.com/ruby/ruby

.standard.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.streerc

Lines changed: 0 additions & 2 deletions
This file was deleted.

Gemfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,3 @@ gemspec
88
gem "rake", "~> 13.0"
99

1010
gem "minitest", "~> 5.0"
11-
gem "syntax_tree"
12-
gem "syntax_tree-disable_ternary"

Gemfile.lock

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,66 @@ PATH
22
remote: .
33
specs:
44
rdoc-markdown (0.4.2)
5-
erb (~> 2.0)
6-
extralite-bundle (~> 1.0)
7-
rdoc (~> 6.0)
8-
reverse_markdown (~> 2.0)
9-
unindent (~> 1.0)
5+
csv
6+
erb
7+
rdoc
8+
reverse_markdown
9+
unindent
1010

1111
GEM
1212
remote: https://rubygems.org/
1313
specs:
14-
cgi (0.3.3)
15-
erb (2.2.3)
16-
cgi
17-
extralite-bundle (1.17)
18-
mini_portile2 (2.8.4)
19-
minitest (5.16.3)
20-
nokogiri (1.13.9)
21-
mini_portile2 (~> 2.8.0)
22-
racc (~> 1.4)
23-
prettier_print (1.2.1)
24-
psych (4.0.6)
14+
cgi (0.4.1)
15+
csv (3.3.2)
16+
date (3.4.1)
17+
erb (4.0.4)
18+
cgi (>= 0.3.3)
19+
minitest (5.25.4)
20+
nokogiri (1.18.0-aarch64-linux-gnu)
21+
racc (~> 1.4)
22+
nokogiri (1.18.0-aarch64-linux-musl)
23+
racc (~> 1.4)
24+
nokogiri (1.18.0-arm-linux-gnu)
25+
racc (~> 1.4)
26+
nokogiri (1.18.0-arm-linux-musl)
27+
racc (~> 1.4)
28+
nokogiri (1.18.0-arm64-darwin)
29+
racc (~> 1.4)
30+
nokogiri (1.18.0-x86_64-darwin)
31+
racc (~> 1.4)
32+
nokogiri (1.18.0-x86_64-linux-gnu)
33+
racc (~> 1.4)
34+
nokogiri (1.18.0-x86_64-linux-musl)
35+
racc (~> 1.4)
36+
psych (5.2.2)
37+
date
2538
stringio
26-
racc (1.6.0)
27-
rake (13.0.6)
28-
rdiscount (2.2.7)
29-
rdoc (6.4.0)
39+
racc (1.8.1)
40+
rake (13.2.1)
41+
rdiscount (2.2.7.3)
42+
rdoc (6.10.0)
3043
psych (>= 4.0.0)
31-
reverse_markdown (2.1.1)
44+
reverse_markdown (3.0.0)
3245
nokogiri
33-
stringio (3.0.2)
34-
syntax_tree (6.1.1)
35-
prettier_print (>= 1.2.0)
36-
syntax_tree-disable_ternary (1.0.0)
46+
stringio (3.1.2)
3747
unindent (1.0)
3848

3949
PLATFORMS
40-
arm64-darwin-21
41-
arm64-darwin-22
42-
x86_64-linux
50+
aarch64-linux-gnu
51+
aarch64-linux-musl
52+
arm-linux-gnu
53+
arm-linux-musl
54+
arm64-darwin
55+
x86_64-darwin
56+
x86_64-linux-gnu
57+
x86_64-linux-musl
4358

4459
DEPENDENCIES
4560
bundler (~> 2.0)
4661
minitest (~> 5.0)
4762
rake (~> 13.0)
4863
rdiscount (~> 2.0)
4964
rdoc-markdown!
50-
syntax_tree
51-
syntax_tree-disable_ternary
5265

5366
BUNDLED WITH
54-
2.4.19
67+
2.6.1

bin/generate.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/sh
22

3-
43
rm -r example/
4+
# convert example code into a markdown documentation.
55
bundle exec rdoc --format=markdown -o example/ --root=test/data/ -D
6+
7+
rm -r example_ruby/
8+
## convert ruby source into a markdown documentation.
9+
bundle exec rdoc --format=markdown -o example_ruby/ --root=source_ruby/ -D --force-output

example/RDoc.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

example/RDoc/Generator.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

example/RDoc/Generator/Markdown.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

example/RDoc/Markdown.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

example/TestGenerator.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

example/index.csv

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name,type,path
2+
Bird,Class,Bird.md
3+
Bird.speak,Method,Bird.md#method-i-speak
4+
Bird.fly,Method,Bird.md#method-i-fly
5+
Duck,Class,Duck.md
6+
Duck.speak,Method,Duck.md#method-i-speak
7+
Duck.rubber_ducks,Method,Duck.md#method-c-rubber_ducks
8+
Duck.new,Method,Duck.md#method-c-new
9+
Duck.useful?,Method,Duck.md#method-i-useful-3F
10+
Duck.MAX_VELOCITY,Constant,Duck.md#MAX_VELOCITY
11+
Duck.domestic,Attribute,Duck.md#attribute-i-domestic
12+
Duck.rubber,Attribute,Duck.md#attribute-i-rubber
13+
Object,Class,Object.md
14+
Object.DEFAULT_DUCK_VELOCITY,Constant,Object.md#DEFAULT_DUCK_VELOCITY
15+
Waterfowl,Module,Waterfowl.md
16+
Waterfowl.swim,Method,Waterfowl.md#method-i-swim

example/index.db

-8 KB
Binary file not shown.

lib/rdoc/generator/markdown.rb

Lines changed: 45 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
require "pathname"
66
require "erb"
77
require "reverse_markdown"
8-
require "extralite"
98
require "unindent"
9+
require "csv"
1010

1111
class RDoc::Generator::Markdown
1212
RDoc::RDoc.add_generator self
@@ -60,8 +60,6 @@ def initialize(store, options)
6060
# Generates markdown files and search index file
6161

6262
def generate
63-
# TODO: Make sure to set --markup parameter to 'markdown'.
64-
6563
debug("Setting things up #{@output_dir}")
6664

6765
setup
@@ -70,9 +68,9 @@ def generate
7068

7169
emit_classfiles
7270

73-
debug("Generate search index in #{output_dir}/index.db")
71+
debug("Generate index file in #{@output_dir}")
7472

75-
emit_sqlite
73+
emit_csv_index
7674
end
7775

7876
private
@@ -94,62 +92,52 @@ def debug(str = nil)
9492
# This class emits a search index for generated documentation as sqlite database
9593
#
9694

97-
def emit_sqlite(name = "index.db")
98-
db = Extralite::Database.new("#{output_dir}/#{name}")
99-
100-
db.execute <<-SQL
101-
create table contentIndex (
102-
id INTEGER PRIMARY KEY,
103-
name TEXT,
104-
type TEXT,
105-
path TEXT
106-
);
107-
SQL
108-
109-
result = []
110-
111-
@classes.map do |klass|
112-
result << {
113-
name: klass.full_name,
114-
type: klass.type.capitalize,
115-
path: turn_to_path(klass.full_name),
116-
}
117-
118-
klass.method_list.each do |method|
119-
next if method.visibility.to_s.eql?("private")
120-
121-
result << {
122-
name: "#{klass.full_name}.#{method.name}",
123-
type: "Method",
124-
path: "#{turn_to_path(klass.full_name)}##{method.aref}",
125-
}
126-
end
95+
def emit_csv_index(name = "index.csv")
96+
filepath = "#{output_dir}/#{name}"
12797

128-
klass
129-
.constants
130-
.sort_by { |x| x.name }
131-
.each do |const|
132-
result << {
133-
name: "#{klass.full_name}.#{const.name}",
134-
type: "Constant",
135-
path: "#{turn_to_path(klass.full_name)}##{const.name}",
136-
}
137-
end
98+
CSV.open(filepath, "wb") do |csv|
99+
csv << %w[name type path]
100+
101+
@classes.map do |klass|
102+
csv << [
103+
klass.full_name,
104+
klass.type.capitalize,
105+
turn_to_path(klass.full_name),
106+
]
138107

139-
klass
140-
.attributes
141-
.sort_by { |x| x.name }
142-
.each do |attr|
143-
result << {
144-
name: "#{klass.full_name}.#{attr.name}",
145-
type: "Attribute",
146-
path: "#{turn_to_path(klass.full_name)}##{attr.aref}",
147-
}
108+
klass.method_list.each do |method|
109+
next if method.visibility.to_s.eql?("private")
110+
next if method.visibility.to_s.eql?("protected")
111+
112+
csv << [
113+
"#{klass.full_name}.#{method.name}",
114+
"Method",
115+
"#{turn_to_path(klass.full_name)}##{method.aref}",
116+
]
148117
end
149-
end
150118

151-
result.each do |rec|
152-
db.execute "insert into contentIndex (name, type, path) values (:name, :type, :path)", rec
119+
klass
120+
.constants
121+
.sort_by { |x| x.name }
122+
.each do |const|
123+
csv << [
124+
"#{klass.full_name}.#{const.name}",
125+
"Constant",
126+
"#{turn_to_path(klass.full_name)}##{const.name}",
127+
]
128+
end
129+
130+
klass
131+
.attributes
132+
.sort_by { |x| x.name }
133+
.each do |attr|
134+
csv << [
135+
"#{klass.full_name}.#{attr.name}",
136+
"Attribute",
137+
"#{turn_to_path(klass.full_name)}##{attr.aref}",
138+
]
139+
end
140+
end
153141
end
154142
end
155143

rdoc-markdown.gemspec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ Gem::Specification.new do |spec|
3131
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
3232
spec.require_paths = ["lib"]
3333

34-
spec.add_dependency "rdoc", "~> 6.0"
35-
spec.add_dependency "erb", "~> 2.0"
36-
spec.add_dependency "reverse_markdown", "~> 2.0"
37-
spec.add_dependency "extralite-bundle", "~> 1.0"
38-
spec.add_dependency "unindent", "~> 1.0"
34+
spec.add_dependency "rdoc"
35+
spec.add_dependency "erb"
36+
spec.add_dependency "reverse_markdown"
37+
spec.add_dependency "unindent"
38+
spec.add_dependency "csv"
3939

4040
spec.add_development_dependency "minitest", "~> 5.0"
4141
spec.add_development_dependency "rake", "~> 13.0"

0 commit comments

Comments
 (0)