Skip to content

Remove sqlite and use csv instead #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
#bundler-cache: true
- run: bundle config unset deployment
- run: bundle install
- name: Run tests
run: bundle exec rake test
- name: syntax_tree
if: ${{ !cancelled() }}
run: |
set -E
bundle exec stree check Gemfile $(git ls-files '*.rb') $(git ls-files '*.rake')
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4.1"
#bundler-cache: true
- run: bundle config unset deployment
- run: bundle install
- name: Run tests
run: bundle exec rake test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
.DS_Store
example/created.rid
.vscode/
example_ruby/*
source_ruby/*

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "source_ruby"]
path = source_ruby
url = https://github.com/ruby/ruby
10 changes: 0 additions & 10 deletions .standard.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .streerc

This file was deleted.

2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ gemspec
gem "rake", "~> 13.0"

gem "minitest", "~> 5.0"
gem "syntax_tree"
gem "syntax_tree-disable_ternary"
75 changes: 44 additions & 31 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,66 @@ PATH
remote: .
specs:
rdoc-markdown (0.4.2)
erb (~> 2.0)
extralite-bundle (~> 1.0)
rdoc (~> 6.0)
reverse_markdown (~> 2.0)
unindent (~> 1.0)
csv
erb
rdoc
reverse_markdown
unindent

GEM
remote: https://rubygems.org/
specs:
cgi (0.3.3)
erb (2.2.3)
cgi
extralite-bundle (1.17)
mini_portile2 (2.8.4)
minitest (5.16.3)
nokogiri (1.13.9)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
prettier_print (1.2.1)
psych (4.0.6)
cgi (0.4.1)
csv (3.3.2)
date (3.4.1)
erb (4.0.4)
cgi (>= 0.3.3)
minitest (5.25.4)
nokogiri (1.18.0-aarch64-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.0-aarch64-linux-musl)
racc (~> 1.4)
nokogiri (1.18.0-arm-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.0-arm-linux-musl)
racc (~> 1.4)
nokogiri (1.18.0-arm64-darwin)
racc (~> 1.4)
nokogiri (1.18.0-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.18.0-x86_64-linux-gnu)
racc (~> 1.4)
nokogiri (1.18.0-x86_64-linux-musl)
racc (~> 1.4)
psych (5.2.2)
date
stringio
racc (1.6.0)
rake (13.0.6)
rdiscount (2.2.7)
rdoc (6.4.0)
racc (1.8.1)
rake (13.2.1)
rdiscount (2.2.7.3)
rdoc (6.10.0)
psych (>= 4.0.0)
reverse_markdown (2.1.1)
reverse_markdown (3.0.0)
nokogiri
stringio (3.0.2)
syntax_tree (6.1.1)
prettier_print (>= 1.2.0)
syntax_tree-disable_ternary (1.0.0)
stringio (3.1.2)
unindent (1.0)

PLATFORMS
arm64-darwin-21
arm64-darwin-22
x86_64-linux
aarch64-linux-gnu
aarch64-linux-musl
arm-linux-gnu
arm-linux-musl
arm64-darwin
x86_64-darwin
x86_64-linux-gnu
x86_64-linux-musl

DEPENDENCIES
bundler (~> 2.0)
minitest (~> 5.0)
rake (~> 13.0)
rdiscount (~> 2.0)
rdoc-markdown!
syntax_tree
syntax_tree-disable_ternary

BUNDLED WITH
2.4.19
2.6.1
6 changes: 5 additions & 1 deletion bin/generate.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/sh


rm -r example/
# convert example code into a markdown documentation.
bundle exec rdoc --format=markdown -o example/ --root=test/data/ -D

rm -r example_ruby/
## convert ruby source into a markdown documentation.
bundle exec rdoc --format=markdown -o example_ruby/ --root=source_ruby/ -D --force-output
2 changes: 0 additions & 2 deletions example/RDoc.md

This file was deleted.

2 changes: 0 additions & 2 deletions example/RDoc/Generator.md

This file was deleted.

30 changes: 0 additions & 30 deletions example/RDoc/Generator/Markdown.md

This file was deleted.

6 changes: 0 additions & 6 deletions example/RDoc/Markdown.md

This file was deleted.

10 changes: 0 additions & 10 deletions example/TestGenerator.md

This file was deleted.

16 changes: 16 additions & 0 deletions example/index.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name,type,path
Bird,Class,Bird.md
Bird.speak,Method,Bird.md#method-i-speak
Bird.fly,Method,Bird.md#method-i-fly
Duck,Class,Duck.md
Duck.speak,Method,Duck.md#method-i-speak
Duck.rubber_ducks,Method,Duck.md#method-c-rubber_ducks
Duck.new,Method,Duck.md#method-c-new
Duck.useful?,Method,Duck.md#method-i-useful-3F
Duck.MAX_VELOCITY,Constant,Duck.md#MAX_VELOCITY
Duck.domestic,Attribute,Duck.md#attribute-i-domestic
Duck.rubber,Attribute,Duck.md#attribute-i-rubber
Object,Class,Object.md
Object.DEFAULT_DUCK_VELOCITY,Constant,Object.md#DEFAULT_DUCK_VELOCITY
Waterfowl,Module,Waterfowl.md
Waterfowl.swim,Method,Waterfowl.md#method-i-swim
Binary file removed example/index.db
Binary file not shown.
102 changes: 45 additions & 57 deletions lib/rdoc/generator/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
require "pathname"
require "erb"
require "reverse_markdown"
require "extralite"
require "unindent"
require "csv"

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

def generate
# TODO: Make sure to set --markup parameter to 'markdown'.

debug("Setting things up #{@output_dir}")

setup
Expand All @@ -70,9 +68,9 @@ def generate

emit_classfiles

debug("Generate search index in #{output_dir}/index.db")
debug("Generate index file in #{@output_dir}")

emit_sqlite
emit_csv_index
end

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

def emit_sqlite(name = "index.db")
db = Extralite::Database.new("#{output_dir}/#{name}")

db.execute <<-SQL
create table contentIndex (
id INTEGER PRIMARY KEY,
name TEXT,
type TEXT,
path TEXT
);
SQL

result = []

@classes.map do |klass|
result << {
name: klass.full_name,
type: klass.type.capitalize,
path: turn_to_path(klass.full_name),
}

klass.method_list.each do |method|
next if method.visibility.to_s.eql?("private")

result << {
name: "#{klass.full_name}.#{method.name}",
type: "Method",
path: "#{turn_to_path(klass.full_name)}##{method.aref}",
}
end
def emit_csv_index(name = "index.csv")
filepath = "#{output_dir}/#{name}"

klass
.constants
.sort_by { |x| x.name }
.each do |const|
result << {
name: "#{klass.full_name}.#{const.name}",
type: "Constant",
path: "#{turn_to_path(klass.full_name)}##{const.name}",
}
end
CSV.open(filepath, "wb") do |csv|
csv << %w[name type path]

@classes.map do |klass|
csv << [
klass.full_name,
klass.type.capitalize,
turn_to_path(klass.full_name),
]

klass
.attributes
.sort_by { |x| x.name }
.each do |attr|
result << {
name: "#{klass.full_name}.#{attr.name}",
type: "Attribute",
path: "#{turn_to_path(klass.full_name)}##{attr.aref}",
}
klass.method_list.each do |method|
next if method.visibility.to_s.eql?("private")
next if method.visibility.to_s.eql?("protected")

csv << [
"#{klass.full_name}.#{method.name}",
"Method",
"#{turn_to_path(klass.full_name)}##{method.aref}",
]
end
end

result.each do |rec|
db.execute "insert into contentIndex (name, type, path) values (:name, :type, :path)", rec
klass
.constants
.sort_by { |x| x.name }
.each do |const|
csv << [
"#{klass.full_name}.#{const.name}",
"Constant",
"#{turn_to_path(klass.full_name)}##{const.name}",
]
end

klass
.attributes
.sort_by { |x| x.name }
.each do |attr|
csv << [
"#{klass.full_name}.#{attr.name}",
"Attribute",
"#{turn_to_path(klass.full_name)}##{attr.aref}",
]
end
end
end
end

Expand Down
10 changes: 5 additions & 5 deletions rdoc-markdown.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "rdoc", "~> 6.0"
spec.add_dependency "erb", "~> 2.0"
spec.add_dependency "reverse_markdown", "~> 2.0"
spec.add_dependency "extralite-bundle", "~> 1.0"
spec.add_dependency "unindent", "~> 1.0"
spec.add_dependency "rdoc"
spec.add_dependency "erb"
spec.add_dependency "reverse_markdown"
spec.add_dependency "unindent"
spec.add_dependency "csv"

spec.add_development_dependency "minitest", "~> 5.0"
spec.add_development_dependency "rake", "~> 13.0"
Expand Down
Loading
Loading