// Package templates provides output formatting templates and customization options. package templates import ( "time" "github.com/ivuorinen/gibidify/shared" ) // OutputTemplate represents a customizable output template. type OutputTemplate struct { Name string `json:"name" yaml:"name"` Description string `json:"description" yaml:"description"` Format string `json:"format" yaml:"format"` // markdown, json, yaml Header string `json:"header" yaml:"header"` Footer string `json:"footer" yaml:"footer"` FileHeader string `json:"file_header" yaml:"file_header"` FileFooter string `json:"file_footer" yaml:"file_footer"` Metadata MetadataOptions `json:"metadata" yaml:"metadata"` Markdown MarkdownOptions `json:"markdown" yaml:"markdown"` Variables map[string]string `json:"variables" yaml:"variables"` } // MetadataOptions controls what metadata to include in the output. type MetadataOptions struct { IncludeStats bool `json:"include_stats" yaml:"include_stats"` IncludeTimestamp bool `json:"include_timestamp" yaml:"include_timestamp"` IncludeFileCount bool `json:"include_file_count" yaml:"include_file_count"` IncludeSourcePath bool `json:"include_source_path" yaml:"include_source_path"` IncludeFileTypes bool `json:"include_file_types" yaml:"include_file_types"` IncludeProcessingTime bool `json:"include_processing_time" yaml:"include_processing_time"` IncludeTotalSize bool `json:"include_total_size" yaml:"include_total_size"` IncludeMetrics bool `json:"include_metrics" yaml:"include_metrics"` } // MarkdownOptions controls markdown-specific formatting. type MarkdownOptions struct { UseCodeBlocks bool `json:"use_code_blocks" yaml:"use_code_blocks"` IncludeLanguage bool `json:"include_language" yaml:"include_language"` HeaderLevel int `json:"header_level" yaml:"header_level"` // 1-6 for # levels TableOfContents bool `json:"table_of_contents" yaml:"table_of_contents"` UseCollapsible bool `json:"use_collapsible" yaml:"use_collapsible"` SyntaxHighlighting bool `json:"syntax_highlighting" yaml:"syntax_highlighting"` LineNumbers bool `json:"line_numbers" yaml:"line_numbers"` FoldLongFiles bool `json:"fold_long_files" yaml:"fold_long_files"` MaxLineLength int `json:"max_line_length" yaml:"max_line_length"` CustomCSS string `json:"custom_css" yaml:"custom_css"` } // TemplateContext provides data available for template substitution. type TemplateContext struct { // Basic information Timestamp time.Time `json:"timestamp"` SourcePath string `json:"source_path"` Format string `json:"format"` // File statistics TotalFiles int `json:"total_files"` ProcessedFiles int `json:"processed_files"` SkippedFiles int `json:"skipped_files"` ErrorFiles int `json:"error_files"` TotalSize int64 `json:"total_size"` // Processing metrics ProcessingTime string `json:"processing_time"` FilesPerSecond float64 `json:"files_per_second"` BytesPerSecond float64 `json:"bytes_per_second"` FileTypes map[string]int `json:"file_types"` // Custom variables Variables map[string]string `json:"variables"` } // FileContext provides data for individual file formatting. type FileContext struct { Path string `json:"path"` RelativePath string `json:"relative_path"` Name string `json:"name"` Extension string `json:"extension"` Language string `json:"language"` Size int64 `json:"size"` ModTime time.Time `json:"mod_time"` Content string `json:"content"` LineCount int `json:"line_count"` IsLarge bool `json:"is_large"` Truncated bool `json:"truncated"` } // BuiltinTemplates contains predefined templates. var BuiltinTemplates = map[string]OutputTemplate{ "default": { Name: "Default", Description: "Standard output template", Format: shared.FormatMarkdown, Header: "# {{.SourcePath}}\n\nGenerated on {{.Timestamp.Format \"2006-01-02 15:04:05\"}}\n", Footer: "\n---\nGenerated by gibidify\n", FileHeader: "## {{.Path}}\n\n```{{.Language}}\n", FileFooter: "```\n\n", Metadata: MetadataOptions{ IncludeStats: true, IncludeTimestamp: true, IncludeFileCount: true, IncludeSourcePath: true, }, Markdown: MarkdownOptions{ UseCodeBlocks: true, IncludeLanguage: true, HeaderLevel: 2, SyntaxHighlighting: true, }, }, "minimal": { Name: "Minimal", Description: "Minimal output with just file contents", Format: shared.FormatMarkdown, Header: "", Footer: "", FileHeader: "\n", FileFooter: "\n", Metadata: MetadataOptions{ IncludeStats: false, IncludeTimestamp: false, IncludeFileCount: false, IncludeSourcePath: false, }, Markdown: MarkdownOptions{ UseCodeBlocks: false, IncludeLanguage: false, }, }, "detailed": { Name: "Detailed", Description: "Comprehensive output with full metadata", Format: shared.FormatMarkdown, Header: `# Project Analysis: {{.SourcePath}} Generated on {{.Timestamp.Format "January 2, 2006 at 3:04 PM"}} ## Summary - **Total Files**: {{.TotalFiles}} - **Processed Files**: {{.ProcessedFiles}} - **Total Size**: {{.TotalSize}} bytes - **Processing Time**: {{.ProcessingTime}} - **Rate**: {{.FilesPerSecond}} files/sec `, Footer: "\n---\n*Generated by gibidify*\n", FileHeader: "### {{.RelativePath}}\n\n**Language**: {{.Language}} \n" + "**Size**: {{.Size}} bytes \n**Lines**: {{.LineCount}} \n\n```{{.Language}}\n", FileFooter: "```\n\n", Metadata: MetadataOptions{ IncludeStats: true, IncludeTimestamp: true, IncludeFileCount: true, IncludeSourcePath: true, IncludeFileTypes: true, IncludeProcessingTime: true, IncludeTotalSize: true, IncludeMetrics: true, }, Markdown: MarkdownOptions{ UseCodeBlocks: true, IncludeLanguage: true, HeaderLevel: 3, TableOfContents: true, SyntaxHighlighting: true, LineNumbers: false, }, }, "compact": { Name: "Compact", Description: "Space-efficient output with collapsible sections", Format: shared.FormatMarkdown, Header: "# {{.SourcePath}}\n\n
📊 Stats ({{.TotalFiles}} files)\n\n" + "- Processed: {{.ProcessedFiles}}\n- Size: {{.TotalSize}} bytes\n" + "- Time: {{.ProcessingTime}}\n\n
\n\n", Footer: "\n---\n*Compressed with gibidify*\n", FileHeader: "
📄 {{.RelativePath}} ({{.Size}} bytes)\n\n```{{.Language}}\n", FileFooter: "```\n\n
\n\n", Metadata: MetadataOptions{ IncludeStats: true, IncludeFileCount: true, IncludeTotalSize: true, }, Markdown: MarkdownOptions{ UseCodeBlocks: true, IncludeLanguage: true, UseCollapsible: true, SyntaxHighlighting: true, }, }, } // DefaultMetadataOptions returns the default metadata options. func DefaultMetadataOptions() MetadataOptions { return MetadataOptions{ IncludeStats: true, IncludeTimestamp: true, IncludeFileCount: true, IncludeSourcePath: true, IncludeFileTypes: false, IncludeProcessingTime: false, IncludeTotalSize: false, IncludeMetrics: false, } } // DefaultMarkdownOptions returns the default markdown options. func DefaultMarkdownOptions() MarkdownOptions { return MarkdownOptions{ UseCodeBlocks: true, IncludeLanguage: true, HeaderLevel: 2, TableOfContents: false, UseCollapsible: false, SyntaxHighlighting: true, LineNumbers: false, FoldLongFiles: false, MaxLineLength: 120, } }