2.3 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Build and Test Commands
bundle install # Install dependencies
bundle exec rake test # Run tests
bundle exec rake rubocop # Run linter
bundle exec rake # Run both tests and linter
# Run a single test file
bundle exec ruby -Ilib:test test/paragraph_test.rb
# Run a specific test by name
bundle exec ruby -Ilib:test test/paragraph_test.rb -n test_paragraph_with_text
Architecture
Notare is a Ruby gem for creating .docx files using a DSL. The gem generates valid Office Open XML (OOXML) documents.
Core Components
-
Document (
lib/notare/document.rb): Entry point viaDocument.create. Includes the Builder module and maintains a collection of nodes. -
Builder (
lib/notare/builder.rb): DSL methods (p,text,h1-h6,b,i,u,ul,ol,li,table,tr,td,image). Uses a format stack for nested formatting and target tracking for content placement. -
Nodes (
lib/notare/nodes/): Document element representations (Paragraph, Run, Image, List, ListItem, Table, TableRow, TableCell). All inherit fromNodes::Base. -
Style (
lib/notare/style.rb): Style definitions with text properties (bold, italic, color, size, font) and paragraph properties (align, indent, spacing). -
Package (
lib/notare/package.rb): Assembles the docx ZIP structure using rubyzip. Coordinates XML generation. -
XML generators (
lib/notare/xml/): Generate OOXML-compliant XML:DocumentXml: Main content with paragraphs, lists, tables, imagesStylesXml: styles.xml with built-in and custom stylesContentTypes: [Content_Types].xmlRelationships: .rels filesNumbering: numbering.xml for lists
-
ImageDimensions (
lib/notare/image_dimensions.rb): Uses fastimage gem to read image dimensions for EMU calculations.
Data Flow
- User calls DSL methods on Document
- Builder creates Node objects, pushed to Document's
@nodesarray - On save, Package creates ZIP with XML generators producing each required file
- XML generators use Nokogiri to build OOXML with proper namespaces
Testing
Tests use Minitest. NotareTestHelpers module provides helpers that create temp documents and extract XML for assertions.