Skip to content

Template Processor - AI-Assisted Development Study

File Generator

Template Processor & AI Development Study - A practical Rust CLI application for processing templates with variable substitution, developed as a case study in AI-assisted development workflows.

Overview

The Template Processor is a practical Rust CLI application that processes Markdown templates with variable substitution. While the core functionality is straightforward template processing, the project serves as a comprehensive case study in AI-assisted development, having been built using AI assistance (specifically Ollama with qwen2.5-coder:14b via Avante in Neovim).

The project explores:

  • AI-assisted code generation and development workflows
  • Template processing with variable substitution
  • Practical AI tool evaluation in real development scenarios
  • Modern Rust development patterns and best practices

Core Functionality

Template Processing

The application processes Markdown templates with variable substitution:

Terminal window
# Generate a document from template
cargo run -- \
-o output.md \
-t templates/default.md \
-v title="My Document" \
-v introduction="This is an example document."

Template Format

Templates use simple variable substitution syntax:

# {{title}}
{{introduction}}
## Details
This document was generated on {{date}}.

AI Development Process

How This Project Was Built with AI

This project was developed using Ollama with qwen2.5-coder:14b via the Avante plugin in Neovim. The AI assisted with:

Initial Project Structure

// AI-generated: Basic CLI application structure
#[derive(Parser)]
#[command(name = "file-generator")]
#[command(about = "Generate files from templates with variable substitution")]
struct Args {
/// Output file path
#[arg(short, long)]
output: PathBuf,
/// Template file path
#[arg(short, long)]
template: PathBuf,
/// Variable assignments (key=value)
#[arg(short = 'v', long, value_parser = parse_key_value)]
variables: Vec<(String, String)>,
}

Template Processing Logic

// AI-generated: Core template processing function
fn process_template(content: &str, variables: &HashMap<String, String>) -> Result<String, anyhow::Error> {
let mut result = content.to_string();
for (key, value) in variables {
let placeholder = format!("{{{{{}}}}}", key);
result = result.replace(&placeholder, value);
}
Ok(result)
}

AI Development Outcomes

  • ✅ Successful: Generated functional Rust code with proper error handling
  • ⚠️ Required Fixes: AI initially missed serde_json dependency and used deprecated error handling
  • ✅ Quick Iteration: AI adapted to feedback and corrected issues promptly
  • ✅ Production Ready: Final code follows Rust best practices and conventions

Concrete Examples from This Session

Here are specific instances where AI assistance was used in developing this documentation site:

1. Sidebar Navigation Generation

// AI helped generate this sidebar structure
{
label: 'Repositories',
items: [
{ label: 'Overview', slug: 'repositories' },
{ label: 'Fretsome', slug: 'repositories/fretsome' },
{ label: 'Robot Arm', slug: 'repositories/robot-arm' },
// ... additional items
]
}

2. Error Handling Patterns

// AI suggested this error handling approach
fn process_template(content: &str, variables: &HashMap<String, String>) -> Result<String, anyhow::Error> {
// Implementation with proper error propagation
}

3. Documentation Structure

AI assisted in creating consistent documentation patterns across all repository pages, including:

  • Standardized frontmatter
  • Consistent card layouts
  • Technical implementation sections
  • Cross-references and navigation

AI Development Learnings

Effective AI Prompting

Clear, specific prompts yield better results. The AI responded well to detailed requirements about template processing and CLI interfaces.

Iterative Refinement

AI-generated code often needs human review and iteration. Dependencies and deprecated patterns required manual fixes.

Quality Validation

AI can produce functional code quickly, but human oversight ensures correctness, security, and best practices.

Workflow Integration

Tools like Avante make AI assistance seamless within existing development environments like Neovim.

Technical Implementation

Dependencies

[dependencies]
clap = { version = "4.0", features = ["derive"] } # CLI argument parsing
serde_json = "1.0" # JSON handling
anyhow = "1.0" # Error handling

Key Components

CLI Interface

#[derive(Parser)]
#[command(author, version, about)]
struct Args {
/// Output file path
#[arg(short, long)]
output: PathBuf,
/// Template file path
#[arg(short, long)]
template: PathBuf,
/// Variable assignments (key=value)
#[arg(short = 'v', long, value_parser = parse_key_value)]
variables: Vec<(String, String)>,
}

Template Processing

fn process_template(template: &str, variables: &HashMap<String, String>) -> String {
let mut result = template.to_string();
for (key, value) in variables {
let placeholder = format!("{{{{{}}}}}", key);
result = result.replace(&placeholder, value);
}
result
}

Development Workflow

AI-Assisted Development Steps

  1. Initial Prompting

    Create a Rust CLI application that processes templates with variable substitution
  2. Iterative Refinement

    • Fix missing dependencies
    • Update deprecated error handling
    • Add proper CLI argument parsing
    • Implement file I/O operations
  3. Testing & Validation

    • Manual testing with sample templates
    • Error handling verification
    • Code review and cleanup

Tools Evaluated

Ollama Integration

  • Model: qwen2.5-coder:14b
  • Interface: Avante (Neovim plugin)
  • Performance: Good for straightforward tasks
  • Limitations: Context awareness, complex multi-step reasoning

Development Environment

  • Editor: Neovim with AI plugins
  • Language: Rust 2021 edition
  • Build System: Cargo
  • Version Control: Git

Project Structure

file-generator/
├── src/
│ └── main.rs # CLI application logic
├── templates/
│ └── default.md # Sample template
├── Cargo.toml # Project dependencies
├── Cargo.lock # Dependency lock file
└── README.md # Usage documentation

Future Enhancements

Planned Features

  • Interactive Mode: Guided template creation
  • Template Discovery: Automatic template detection
  • Validation: Template syntax checking
  • Multiple Formats: Support for JSON, YAML, TOML templates
  • Plugin System: Extensible template processors

AI Integration Improvements

  • Better Prompting: More specific instructions
  • Context Awareness: Include project structure in prompts
  • Review Process: Systematic AI-generated code review
  • Testing: AI-assisted test generation

Learning Outcomes

AI-Assisted Development

  • Prompt Engineering: Crafting effective instructions for AI
  • Code Review: Evaluating AI-generated code quality
  • Iterative Development: Working with AI through multiple iterations
  • Tool Integration: Combining AI tools with development workflows

Rust Development

  • CLI Applications: Building command-line tools with Clap
  • File Operations: Reading/writing files in Rust
  • Error Handling: Modern error handling with anyhow
  • Template Processing: String manipulation and substitution

Usage Examples

Basic Document Generation

Terminal window
# Create a blog post
cargo run -- \
-o blog-post.md \
-t templates/blog.md \
-v title="My First Post" \
-v author="Ryan Parsley" \
-v date="2025-01-15"

Configuration File Generation

Terminal window
# Generate a config file
cargo run -- \
-o config.json \
-t templates/config.json \
-v app_name="my-app" \
-v port="8080" \
-v debug="true"

Contributing

This project welcomes contributions in:

  • AI Tool Evaluation: Testing different LLMs and interfaces
  • Template Formats: Adding support for new template types
  • User Experience: Improving CLI ergonomics
  • Documentation: Better examples and tutorials

View on Codeberg | AI Development Notes