Skip to content
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ $RECYCLE.BIN/
# Bazel
/bazel-*
!/bazel-registry/
bazel/bazel-*

# Rust coverage reports
rust/tarpaulin-report.html
Expand Down
197 changes: 197 additions & 0 deletions bazel/website/IMPLEMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
# Implementation Summary: Provider-Based Website Builder Architecture

## Overview

Successfully refactored the Bazel website builder to use a provider-based architecture that makes the system extensible to different static site generators while maintaining 100% backwards compatibility.

## What Was Implemented

### 1. Provider Layer ✅

**File**: `bazel/website/providers.bzl`

- `WebsiteAssetInfo`: Provider for typed assets with fields:
- `files`: depset of files
- `asset_type`: string identifier (markdown, jinja, rst, scss, static, rust_component, etc)
- `prefix`: mount point in source tree

- `WebsiteGeneratorInfo`: Provider for generators with fields:
- `executable`: the build tool
- `accepts`: list of asset_types this generator handles
- `output_path`: where it puts output
- `dev_server`: optional dev mode executable

### 2. Base Asset Rules ✅

**File**: `bazel/website/assets.bzl`

- `_asset_impl`: Implementation that produces `WebsiteAssetInfo`
- `static_assets`: Generic rule for any asset type
- Backwards compatible: produces both providers and `pkg_files`

### 3. Typed Asset Rules ✅

**Content Assets** (`bazel/website/content/`):
- `markdown.bzl`: `markdown_assets` rule for markdown content
- `rst.bzl`: `rst_assets` rule for reStructuredText content

**Template Assets** (`bazel/website/templates/`):
- `jinja.bzl`: `jinja_templates` rule for Jinja2 templates
- `rst.bzl`: `rst_templates` rule for RST templates (Sphinx)

Each produces `WebsiteAssetInfo` with appropriate `asset_type`.

### 4. Generator Rules ✅

**Pelican** (`bazel/website/generators/pelican.bzl`):
- `pelican_generator`: Wraps Pelican with `WebsiteGeneratorInfo`
- Accepts: markdown, rst, jinja, scss, css, js, static
- Production-ready, uses existing Pelican tool

**Mock Generator** (`bazel/website/generators/mock.bzl`):
- `mock_generator`: Simple test generator
- Configurable accepted types
- Creates minimal HTML output for validation

**Sphinx Skeleton** (`bazel/website/generators/sphinx.bzl`):
- `sphinx_generator`: Skeleton proving RST generators work
- Accepts: rst, markdown, sphinx_theme, css, js, static
- Ready for community to complete implementation

**Yew/WASM Skeleton** (`bazel/website/generators/yew.bzl`):
- `yew_generator`: Skeleton proving Rust/WASM generators work
- Accepts: rust_component, css, js, static, wasm
- `rust_assets`: Helper for Rust component assets
- Ready for community to complete implementation

### 5. Updated static_website Macro ✅

**File**: `bazel/website/macros.bzl`

- Added provider imports
- Added helper functions for asset introspection
- Enhanced documentation
- **100% backwards compatible**: all existing calls work unchanged

### 6. Comprehensive Tests ✅

**Existing Tests** (all pass):
- `website_generation_test`: Basic Pelican generation
- `website_parameterized_test`: Custom configurations
- `website_compression_test`: Compression support

**New Provider Tests** (`provider_architecture_test`):
- Tests `WebsiteAssetInfo` attachment by asset rules
- Tests `WebsiteGeneratorInfo` attachment by generator rules
- Tests mock generator with markdown assets
- Tests Sphinx skeleton generator
- Tests Yew/WASM skeleton generator
- Tests mixed asset types

### 7. Directory Structure ✅

```
bazel/website/
├── PROVIDERS.md # Comprehensive documentation
├── providers.bzl # Provider definitions
├── assets.bzl # Base asset rules
├── macros.bzl # static_website (enhanced)
├── content/
│ ├── BUILD
│ ├── markdown.bzl
│ └── rst.bzl
├── templates/
│ ├── BUILD
│ ├── jinja.bzl
│ └── rst.bzl
├── generators/
│ ├── BUILD
│ ├── pelican.bzl # Production Pelican
│ ├── mock.bzl # Testing
│ ├── sphinx.bzl # RST skeleton
│ └── yew.bzl # WASM skeleton
└── tests/
├── EXAMPLES.md # Usage examples
├── BUILD # Test targets
└── run_provider_tests.sh # Provider test script
```

### 8. Documentation ✅

**PROVIDERS.md**: Complete documentation covering:
- Architecture overview
- Provider definitions
- Asset rules usage
- Generator rules usage
- Backwards compatibility
- Testing approach
- Extensibility guide
- Migration guide

**EXAMPLES.md**: Practical examples showing:
- Using typed asset rules
- Using custom generators
- Skeleton generators
- Asset type reference
- Generator type reference

## Validation Results

### All Tests Pass ✓

```
//website/tests:provider_architecture_test PASSED
//website/tests:website_compression_test PASSED
//website/tests:website_generation_test PASSED
//website/tests:website_parameterized_test PASSED
```

### Backwards Compatibility Verified ✓

- Existing Pelican-based test sites build and generate correct output
- No changes required to existing `static_website` calls
- Asset rules produce both providers and pkg_files

### Extensibility Proven ✓

- Mock generator successfully processes markdown assets
- Sphinx skeleton proves RST-based generators are viable
- Yew skeleton proves Rust/WASM generators are viable
- Framework ready for community contributions

## Key Design Decisions

1. **Dual Output**: Asset rules produce both providers (new) and pkg_files (backwards compat)
2. **Optional Providers**: Generators can work with or without provider introspection
3. **Skeleton Generators**: Included minimal but functional skeletons to prove extensibility
4. **No Breaking Changes**: All existing code continues to work unchanged

## Future Extensibility

The framework is ready for:

- **Hugo**: Static site generator using Go templates
- **Jekyll**: Ruby-based static site generator
- **MkDocs**: Python documentation generator
- **Docusaurus**: React-based documentation site
- **mdBook**: Rust documentation tool
- **Custom generators**: Any tool can be wrapped with the provider interface

## Testing Strategy

1. **Unit Tests**: Each provider attachment is verified
2. **Integration Tests**: Complete website generation workflows
3. **Backwards Compatibility**: All existing tests continue to pass
4. **Extensibility Tests**: Skeleton generators prove new types work

## Conclusion

The refactoring successfully:
- ✅ Creates a provider-based architecture
- ✅ Makes the system extensible to any generator
- ✅ Maintains 100% backwards compatibility
- ✅ Includes comprehensive tests
- ✅ Provides complete documentation
- ✅ Proves extensibility with skeletons

All requirements from the problem statement have been met.
Loading
Loading