Skip to content

feat(slides): add create-from-template command with text replacement#273

Closed
penguinco wants to merge 1 commit intoopenclaw:mainfrom
penguinco:feat/slides-create-from-template
Closed

feat(slides): add create-from-template command with text replacement#273
penguinco wants to merge 1 commit intoopenclaw:mainfrom
penguinco:feat/slides-create-from-template

Conversation

@penguinco
Copy link
Copy Markdown
Contributor

Summary

This PR adds a new gog slides create-from-template command that creates Google Slides presentations from templates with automatic placeholder text replacement using the Slides API's ReplaceAllText feature.

Features

Core Functionality

  • Create presentations from existing templates
  • Automatic text replacement throughout the presentation
  • Support for {{key}} placeholder format (auto-wrapped)
  • Multiple input sources: command-line flags and JSON files

Replacement Options

  • --replace "key=value" — Command-line replacements (repeatable)
  • --replacements file.json — JSON file with multiple replacements
  • Both can be combined (flags override file values)
  • --exact — Match exact strings without {{}} wrapping

Additional Features

  • Type conversion from JSON (numbers, booleans → strings)
  • Replacement statistics in output (occurrences per key)
  • JSON and text output modes
  • --parent flag to organize in specific folder

Usage Examples

# Basic usage with command-line flags
gog slides create-from-template <templateId> "Q1 Report" \
  --replace "quarter=Q1 2026" \
  --replace "revenue=$1.2M" \
  --replace "growth=15%"

# Using JSON file for many replacements
cat > data.json <<JSON
{
  "name": "John Doe",
  "title": "Sales Manager",
  "date": "2026-02-15",
  "sales": 125,
  "target": 100
}
JSON

gog slides create-from-template <templateId> "Monthly Report" \
  --replacements data.json

# Combining both (flags override file)
gog slides create-from-template <templateId> "Report" \
  --replacements base-data.json \
  --replace "date=2026-02-15"

# Exact string matching (no {{}} wrapping)
gog slides create-from-template <templateId> "Report" \
  --replace "OLD_TEXT=NEW_TEXT" \
  --exact

Output

Text Output

Created presentation from template
id              1new456presentation
name            Q1 Report
link            https://docs.google.com/presentation/d/1new456presentation/edit

Replacements:
  quarter       3 occurrences
  revenue       2 occurrences
  growth        1 occurrences

JSON Output

{
  "presentationId": "1new456presentation",
  "name": "Q1 Report",
  "link": "https://docs.google.com/...",
  "replacements": {
    "quarter": 3,
    "revenue": 2,
    "growth": 1
  }
}

Technical Implementation

  1. Template Copy: Uses Drive API Files.Copy to duplicate the template
  2. Text Replacement: Uses Slides API ReplaceAllText in batch for all placeholders
  3. Type Conversion: Handles JSON values (numbers, booleans, null) → strings
  4. Error Handling: Validates inputs, reports API errors, shows warnings on partial failure

Files Changed

File Changes Description
internal/cmd/slides_create_from_template.go +240 lines Main command implementation
internal/cmd/slides_create_from_template_test.go +590 lines Comprehensive test suite
internal/cmd/slides.go Modified Added command registration
docs/slides-template-replacement.md +200 lines User documentation
README.md Modified Added usage examples

Testing

All tests pass ✅ (7/7):

  • ✅ Basic text replacement
  • ✅ JSON file loading with type conversion
  • ✅ Exact mode (no {{}} wrapping)
  • ✅ Empty replacements error
  • ✅ Invalid format error
  • ✅ Invalid JSON error
  • ✅ Combining file and flags (flag precedence)
PASS: TestSlidesCreateFromTemplate_Basic
PASS: TestSlidesCreateFromTemplate_JSONFile
PASS: TestSlidesCreateFromTemplate_ExactMode
PASS: TestSlidesCreateFromTemplate_EmptyReplacements
PASS: TestSlidesCreateFromTemplate_InvalidReplaceFormat
PASS: TestSlidesCreateFromTemplate_InvalidJSON
PASS: TestSlidesCreateFromTemplate_CombineFileAndFlags

Use Cases

  • Report Generation: Monthly/quarterly reports with dynamic data
  • Presentations: Team presentations with personalized content
  • Bulk Creation: Generate multiple presentations from same template
  • Automation: Script-friendly for CI/CD pipelines

Documentation

See docs/slides-template-replacement.md for:

  • Detailed usage guide
  • JSON file format examples
  • Batch generation scripts
  • Troubleshooting tips

Related: Similar to gog docs find-replace but for Slides and template-based

Made with Cursor

Adds `gog slides create-from-template` command to create presentations
from templates with automatic placeholder text replacement.

Features:
- {{key}} placeholder format (auto-wrapped)
- Multiple replacement sources: --replace flags and --replacements JSON file
- Type conversion for JSON (numbers, booleans → strings)
- --exact flag for arbitrary string replacement
- Replacement statistics in output
- JSON/text output modes

Implementation:
- Copy template via Drive API
- Batch text replacement via Slides API ReplaceAllText
- Comprehensive error handling and validation
- 7 test cases covering all features and edge cases

Usage: gog slides create-from-template <templateId> <title> \
    --replace "key=value" \
    --replacements data.json
Co-authored-by: Cursor <cursoragent@cursor.com>
@steipete
Copy link
Copy Markdown
Collaborator

steipete commented Mar 8, 2026

Closing after direct land on main in 922c1fb + 12e5037 + 4a69ebb; PR head repo is no longer available for a normal merge update.

@steipete
Copy link
Copy Markdown
Collaborator

steipete commented Mar 8, 2026

Landed directly on main from a current-main rebase.

  • Gate: make ci
  • Land commits: 922c1fb0f96dcf7f3e19818f72631078806f4e77, 12e50378aa9124aa1d7dcfbd603ca81d88099039, 4a69ebbc63dbe3cd2132ea8a6724fd3a2a68823b
  • Note: PR head repo is no longer available, so the rebased branch could not be pushed back for a normal PR merge.

Thanks @penguinco!

@steipete steipete closed this Mar 8, 2026
@penguinco penguinco deleted the feat/slides-create-from-template branch March 9, 2026 11:10
klodr pushed a commit to klodr/gogcli that referenced this pull request Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants