Skip to content
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
5 changes: 5 additions & 0 deletions .rdoc_options
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ title: rdoc Documentation
main_page: README.md
autolink_excluded_words:
- RDoc

exclude:
- AGENTS.md
- CLAUDE.md
- lib/rdoc/markdown.kpeg
223 changes: 223 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
# RDoc Project Guide for AI Agents

## Project Overview

**RDoc** is Ruby's default documentation generation tool that produces HTML and command-line documentation for Ruby projects. It parses Ruby source code, C extensions, and markup files to generate documentation.

- **Repository:** https://github.com/ruby/rdoc
- **Homepage:** https://ruby.github.io/rdoc
- **Required Ruby:** See the version specified in gemspec
- **Main Executables:** `rdoc` and `ri`

## Key Development Commands

### Testing

```bash
# Run all tests (default task)
bundle exec rake

# Run unit tests only (excludes RubyGems integration)
bundle exec rake normal_test

# Run RubyGems integration tests only
bundle exec rake rubygems_test

# Verify generated parser files are current (CI check)
bundle exec rake verify_generated
```

**Test Framework:** Test::Unit with `test-unit` gem
**Test Location:** `test/` directory
**Test Helper:** `test/lib/helper.rb`

### Linting

#### RuboCop (Ruby Linting)

```bash
# Check Ruby code style
bundle exec rubocop

# Auto-fix style issues
bundle exec rubocop -A
```

**Configuration:** `.rubocop.yml`

- Target Ruby: 3.0
- Minimal cop set (opt-in approach)
- Excludes generated parser files

#### Herb Linter (ERB/RHTML Files)

```bash
# Lint ERB template files
npx @herb-tools/linter "**/*.rhtml"

# Lint specific directory
npx @herb-tools/linter "lib/**/*.rhtml"
```

**Template Location:** `lib/rdoc/generator/template/**/*.rhtml`
**CI Workflow:** `.github/workflows/lint.yml`

### Documentation Generation

```bash
# Generate documentation (creates _site directory)
bundle exec rake rdoc

# Force regenerate documentation
bundle exec rake rerdoc

# Show documentation coverage
bundle exec rake rdoc:coverage
bundle exec rake coverage
```

**Output Directory:** `_site/` (GitHub Pages compatible)
**Configuration:** `.rdoc_options`

### Parser Generation

RDoc uses generated parsers for Markdown and RD formats:

```bash
# Generate all parser files from sources
bundle exec rake generate

# Remove generated parser files
bundle exec rake clean
```

**Generated Files:**

- `lib/rdoc/rd/block_parser.rb` (from `.ry` via racc)
- `lib/rdoc/rd/inline_parser.rb` (from `.ry` via racc)
- `lib/rdoc/markdown.rb` (from `.kpeg` via kpeg)
- `lib/rdoc/markdown/literals.rb` (from `.kpeg` via kpeg)

**Note:** These files are auto-generated and should not be edited manually. Always regenerate after modifying source `.ry` or `.kpeg` files.

### Building and Releasing

```bash
# Build gem package
bundle exec rake build

# Install gem locally
bundle exec rake install

# Create tag and push to rubygems.org
bundle exec rake release
```

## Project Structure

```sh
lib/rdoc/
├── rdoc.rb # Main entry point (RDoc::RDoc class)
├── version.rb # Version constant
├── task.rb # Rake task integration
├── parser/ # Source code parsers (Ruby, C, Markdown, RD)
│ ├── ruby.rb # Ruby code parser
│ ├── c.rb # C extension parser
│ ├── prism_ruby.rb # Prism-based Ruby parser
│ └── ...
├── generator/ # Documentation generators
│ ├── darkfish.rb # HTML generator (default theme)
│ ├── markup.rb # Markup format generator
│ ├── ri.rb # RI command generator
│ └── template/darkfish/ # ERB templates (.rhtml files)
├── markup/ # Markup parsing and formatting
├── code_object/ # AST objects for documented items
├── markdown/ # Markdown parsing
├── rd/ # RD format parsing
└── ri/ # RI (Ruby Info) tool

test/ # 79 test files
├── lib/helper.rb # Test helpers
└── rdoc/ # Main test directory

exe/
├── rdoc # rdoc command executable
└── ri # ri command executable
```

## Important Files

### Configuration

- `.rubocop.yml` - RuboCop configuration (main)
- `.generated_files_rubocop.yml` - RuboCop config for generated files
- `.rdoc_options` - RDoc generation options
- `.document` - File list for documentation
- `Rakefile` - Task definitions
- `lib/rdoc/task.rb` - Task definitions provided by RDoc
- `rdoc.gemspec` - Gem specification
- `Gemfile` - Development dependencies

### CI/CD

- `.github/workflows/test.yml` - Test execution across Ruby versions/platforms
- `.github/workflows/lint.yml` - Linting (RuboCop + Herb)
- `.github/workflows/push_gem.yml` - Gem publishing

### Documentation

- `README.md` - Basic usage guide
- `ExampleRDoc.rdoc` - RDoc markup examples
- `doc/rdoc/markup_reference.rb` - RDoc markup references
- `ExampleMarkdown.md` - Markdown examples

## Architecture Notes

### Pluggable System

- **Parsers:** Ruby, C, Markdown, RD, Prism-based Ruby (experimental)
- **Generators:** HTML/Darkfish, RI, POT (gettext), JSON, Markup

## Common Workflows

Do NOT commit anything. Ask the developer to review the changes after tasks are finished.

NEVER pushes code to any repositories.

### Making Code Changes

Use Red, Green, Refactor approach:

1. **Ensure Ruby version**: Verify you're using Ruby 3.3.0+ (prepend `chruby <ruby version>` if needed)
2. **Red - Write failing tests**: Add tests that fail for the new behavior
3. **Verify failure**: Run `bundle exec rake` to confirm tests fail as expected
4. **Green - Make it work**: Implement the minimum code to make tests pass
5. **Refactor - Make it right**: Improve code quality while keeping tests green
- Run `bundle exec rake` after each refactor to ensure tests still pass
- Iterate on steps 4-5 as needed
6. **Lint your changes**:
- Ruby code: `bundle exec rubocop -A` (auto-fix when possible)
- ERB templates: `npx @herb-tools/linter "**/*.rhtml"` (if modified)

### Modifying Parsers

1. Edit source files (`.ry` or `.kpeg`)
2. Regenerate: `bundle exec rake generate`
3. Verify: `bundle exec rake verify_generated`
4. Run tests: `bundle exec rake`

### Updating Documentation

1. Modify documentation comments in source
2. Regenerate: `bundle exec rake rerdoc`
3. Check output in `_site/` directory
4. Check coverage: `bundle exec rake coverage`

## Notes for AI Agents

1. **Always run tests** after making changes: `bundle exec rake`
2. **Check both RuboCop and Herb** for linting
3. **Regenerate parsers** if you modify `.ry` or `.kpeg` files
4. **Use `rake rerdoc`** to regenerate documentation (not just `rdoc`)
5. **Verify generated files** with `rake verify_generated`
6. **Don't edit generated files** directly (in `lib/rdoc/markdown/` and `lib/rdoc/rd/`)
12 changes: 12 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Claude Code Instructions for RDoc

Please refer to `AGENTS.md` for comprehensive project documentation, including:

- Rake tasks and workflows
- Testing setup
- Linting configuration
- Project structure
- Development commands
- CI/CD information

All project-specific instructions and guidelines are maintained in `AGENTS.md`.
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ gem 'rubocop', '>= 1.31.0'
gem 'gettext'
gem 'prism', '>= 0.30.0'
gem 'webrick'

platforms :ruby do
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.2')
gem 'mini_racer' # For testing the searcher.js file
end
end
43 changes: 38 additions & 5 deletions lib/rdoc/generator/template/json_index/js/searcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Searcher.prototype = new function() {

var results =
performSearch(_this.data, regexps, queries, highlighters, state);
var hasMore = (state.limit > 0 && state.pass < 4);
var hasMore = (state.limit > 0 && state.pass < 6);

triggerResults.call(_this, results, !hasMore);
if (hasMore) {
Expand Down Expand Up @@ -85,6 +85,30 @@ Searcher.prototype = new function() {

/* ----- Mathchers ------ */

/*
* This record matches if both the index and longIndex exactly equal queries[0]
* and the record matches all of the regexps. This ensures top-level exact matches
* like "String" are prioritized over nested classes like "Gem::Module::String".
*/
function matchPassExact(index, longIndex, queries) {
return index == queries[0] && longIndex == queries[0];
}

/*
* This record matches if the index without "()" exactly equals queries[0].
* This prioritizes methods like "attribute()" when searching for "attribute".
*/
function matchPassExactMethod(index, longIndex, queries, regexps) {
var indexWithoutParens = index.replace(/\(\)$/, '');
if (indexWithoutParens != queries[0]) return false;
if (index === indexWithoutParens) return false; // Not a method (no parens to remove)
for (var i=1, l = regexps.length; i < l; i++) {
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
return false;
};
return true;
}

/*
* This record matches if the index starts with queries[0] and the record
* matches all of the regexps
Expand Down Expand Up @@ -192,17 +216,26 @@ Searcher.prototype = new function() {
var togo = CHUNK_SIZE;
var matchFunc, hltFunc;

while (state.pass < 4 && state.limit > 0 && togo > 0) {
var isLowercaseQuery = queries[0] === queries[0].toLowerCase();

while (state.pass < 6 && state.limit > 0 && togo > 0) {
// When query is lowercase, prioritize methods over classes
if (state.pass == 0) {
matchFunc = matchPassBeginning;
matchFunc = isLowercaseQuery ? matchPassExactMethod : matchPassExact;
hltFunc = highlightQuery;
} else if (state.pass == 1) {
matchFunc = matchPassLongIndex;
matchFunc = isLowercaseQuery ? matchPassExact : matchPassExactMethod;
hltFunc = highlightQuery;
} else if (state.pass == 2) {
matchFunc = matchPassContains;
matchFunc = matchPassBeginning;
hltFunc = highlightQuery;
} else if (state.pass == 3) {
matchFunc = matchPassLongIndex;
hltFunc = highlightQuery;
} else if (state.pass == 4) {
matchFunc = matchPassContains;
hltFunc = highlightQuery;
} else if (state.pass == 5) {
matchFunc = matchPassRegexp;
hltFunc = highlightRegexp;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module RDoc
##
# RDoc version you are using

VERSION = '6.15.0'
VERSION = '6.15.1'

end
Loading
Loading