4 Commits

Author SHA1 Message Date
dec346254c Project rename
All checks were successful
CI Pipeline / build (push) Successful in 12s
2025-12-02 13:21:13 +01:00
29ebb9a8d1 Merge pull request 'Fix issue where Word Online wasn't properly able to render our tables' (#5) from bug/tables-word-online into main
All checks were successful
CI Pipeline / build (push) Successful in 12s
Reviewed-on: Kaukus/ezdoc#5
2025-12-02 12:12:39 +00:00
6cbc9e4d98 Fix issue where Word Online wasn't properly able to render our tables
All checks were successful
CI Pipeline / build (pull_request) Successful in 12s
2025-12-02 12:26:40 +01:00
c7020140f4 Merge pull request 'Fix bug with heading styles' (#4) from bug/heading-styles into main
All checks were successful
CI Pipeline / build (push) Successful in 11s
Reviewed-on: Kaukus/ezdoc#4
2025-12-02 11:14:04 +00:00
36 changed files with 131 additions and 120 deletions

View File

@@ -19,28 +19,28 @@ bundle exec ruby -Ilib:test test/paragraph_test.rb -n test_paragraph_with_text
## Architecture ## Architecture
Ezdoc is a Ruby gem for creating .docx files using a DSL. The gem generates valid Office Open XML (OOXML) documents. Notare is a Ruby gem for creating .docx files using a DSL. The gem generates valid Office Open XML (OOXML) documents.
### Core Components ### Core Components
- **Document** (`lib/ezdoc/document.rb`): Entry point via `Document.create`. Includes the Builder module and maintains a collection of nodes. - **Document** (`lib/notare/document.rb`): Entry point via `Document.create`. Includes the Builder module and maintains a collection of nodes.
- **Builder** (`lib/ezdoc/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. - **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/ezdoc/nodes/`): Document element representations (Paragraph, Run, Image, List, ListItem, Table, TableRow, TableCell). All inherit from `Nodes::Base`. - **Nodes** (`lib/notare/nodes/`): Document element representations (Paragraph, Run, Image, List, ListItem, Table, TableRow, TableCell). All inherit from `Nodes::Base`.
- **Style** (`lib/ezdoc/style.rb`): Style definitions with text properties (bold, italic, color, size, font) and paragraph properties (align, indent, spacing). - **Style** (`lib/notare/style.rb`): Style definitions with text properties (bold, italic, color, size, font) and paragraph properties (align, indent, spacing).
- **Package** (`lib/ezdoc/package.rb`): Assembles the docx ZIP structure using rubyzip. Coordinates XML generation. - **Package** (`lib/notare/package.rb`): Assembles the docx ZIP structure using rubyzip. Coordinates XML generation.
- **XML generators** (`lib/ezdoc/xml/`): Generate OOXML-compliant XML: - **XML generators** (`lib/notare/xml/`): Generate OOXML-compliant XML:
- `DocumentXml`: Main content with paragraphs, lists, tables, images - `DocumentXml`: Main content with paragraphs, lists, tables, images
- `StylesXml`: styles.xml with built-in and custom styles - `StylesXml`: styles.xml with built-in and custom styles
- `ContentTypes`: [Content_Types].xml - `ContentTypes`: [Content_Types].xml
- `Relationships`: .rels files - `Relationships`: .rels files
- `Numbering`: numbering.xml for lists - `Numbering`: numbering.xml for lists
- **ImageDimensions** (`lib/ezdoc/image_dimensions.rb`): Uses fastimage gem to read image dimensions for EMU calculations. - **ImageDimensions** (`lib/notare/image_dimensions.rb`): Uses fastimage gem to read image dimensions for EMU calculations.
### Data Flow ### Data Flow
@@ -51,4 +51,4 @@ Ezdoc is a Ruby gem for creating .docx files using a DSL. The gem generates vali
### Testing ### Testing
Tests use Minitest. `EzdocTestHelpers` module provides helpers that create temp documents and extract XML for assertions. Tests use Minitest. `NotareTestHelpers` module provides helpers that create temp documents and extract XML for assertions.

View File

@@ -1,4 +1,4 @@
# Ezdoc # Notare
A Ruby gem for creating docx files with a simple DSL A Ruby gem for creating docx files with a simple DSL
@@ -7,7 +7,7 @@ A Ruby gem for creating docx files with a simple DSL
Add this line to your application's Gemfile: Add this line to your application's Gemfile:
```ruby ```ruby
gem 'ezdoc' gem 'notare'
``` ```
And then execute: And then execute:
@@ -16,16 +16,16 @@ And then execute:
Or install it yourself as: Or install it yourself as:
$ gem install ezdoc $ gem install notare
## Usage ## Usage
### Basic Example ### Basic Example
```ruby ```ruby
require 'ezdoc' require 'notare'
Ezdoc::Document.create("output.docx") do |doc| Notare::Document.create("output.docx") do |doc|
doc.p "Hello World" doc.p "Hello World"
end end
``` ```
@@ -33,7 +33,7 @@ end
### Paragraphs ### Paragraphs
```ruby ```ruby
Ezdoc::Document.create("output.docx") do |doc| Notare::Document.create("output.docx") do |doc|
# Simple paragraph # Simple paragraph
doc.p "This is a paragraph." doc.p "This is a paragraph."
@@ -50,7 +50,7 @@ end
Formatting uses nested blocks. Nesting combines formatting styles. Formatting uses nested blocks. Nesting combines formatting styles.
```ruby ```ruby
Ezdoc::Document.create("output.docx") do |doc| Notare::Document.create("output.docx") do |doc|
doc.p do doc.p do
doc.text "Normal text " doc.text "Normal text "
doc.b { doc.text "bold" } doc.b { doc.text "bold" }
@@ -74,7 +74,7 @@ end
Use `h1` through `h6` for document headings: Use `h1` through `h6` for document headings:
```ruby ```ruby
Ezdoc::Document.create("output.docx") do |doc| Notare::Document.create("output.docx") do |doc|
doc.h1 "Document Title" doc.h1 "Document Title"
doc.h2 "Chapter 1" doc.h2 "Chapter 1"
doc.h3 "Section 1.1" doc.h3 "Section 1.1"
@@ -92,12 +92,12 @@ end
### Styles ### Styles
Ezdoc includes built-in styles and supports custom style definitions. Notare includes built-in styles and supports custom style definitions.
#### Built-in Styles #### Built-in Styles
```ruby ```ruby
Ezdoc::Document.create("output.docx") do |doc| Notare::Document.create("output.docx") do |doc|
doc.p "This is a title", style: :title doc.p "This is a title", style: :title
doc.p "A subtitle", style: :subtitle doc.p "A subtitle", style: :subtitle
doc.p "A quotation", style: :quote doc.p "A quotation", style: :quote
@@ -110,7 +110,7 @@ end
Define your own styles with text and paragraph properties: Define your own styles with text and paragraph properties:
```ruby ```ruby
Ezdoc::Document.create("output.docx") do |doc| Notare::Document.create("output.docx") do |doc|
# Define custom styles # Define custom styles
doc.define_style :warning, doc.define_style :warning,
bold: true, bold: true,
@@ -161,7 +161,7 @@ end
#### Bullet Lists #### Bullet Lists
```ruby ```ruby
Ezdoc::Document.create("output.docx") do |doc| Notare::Document.create("output.docx") do |doc|
doc.ul do doc.ul do
doc.li "First item" doc.li "First item"
doc.li "Second item" doc.li "Second item"
@@ -173,7 +173,7 @@ end
#### Numbered Lists #### Numbered Lists
```ruby ```ruby
Ezdoc::Document.create("output.docx") do |doc| Notare::Document.create("output.docx") do |doc|
doc.ol do doc.ol do
doc.li "First" doc.li "First"
doc.li "Second" doc.li "Second"
@@ -185,7 +185,7 @@ end
### Tables ### Tables
```ruby ```ruby
Ezdoc::Document.create("output.docx") do |doc| Notare::Document.create("output.docx") do |doc|
doc.table do doc.table do
doc.tr do doc.tr do
doc.td "Header 1" doc.td "Header 1"
@@ -204,7 +204,7 @@ end
Images can be added to paragraphs, table cells, and list items. Supports PNG and JPEG formats. Images can be added to paragraphs, table cells, and list items. Supports PNG and JPEG formats.
```ruby ```ruby
Ezdoc::Document.create("output.docx") do |doc| Notare::Document.create("output.docx") do |doc|
# Simple image (uses native dimensions) # Simple image (uses native dimensions)
doc.p do doc.p do
doc.image "photo.png" doc.image "photo.png"
@@ -249,7 +249,7 @@ end
### Complete Example ### Complete Example
```ruby ```ruby
Ezdoc::Document.create("report.docx") do |doc| Notare::Document.create("report.docx") do |doc|
doc.p "Monthly Report" doc.p "Monthly Report"
doc.p do doc.p do

View File

@@ -1,15 +1,15 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true # frozen_string_literal: true
# Full demo of all Ezdoc features # Full demo of all Notare features
# Run with: bundle exec ruby examples/full_demo.rb # Run with: bundle exec ruby examples/full_demo.rb
require_relative "../lib/ezdoc" require_relative "../lib/notare"
OUTPUT_FILE = File.expand_path("../example.docx", __dir__) OUTPUT_FILE = File.expand_path("../example.docx", __dir__)
FIXTURES_DIR = File.expand_path("../test/fixtures", __dir__) FIXTURES_DIR = File.expand_path("../test/fixtures", __dir__)
Ezdoc::Document.create(OUTPUT_FILE) do |doc| Notare::Document.create(OUTPUT_FILE) do |doc|
# ============================================================================ # ============================================================================
# Custom Styles # Custom Styles
# ============================================================================ # ============================================================================
@@ -20,7 +20,7 @@ Ezdoc::Document.create(OUTPUT_FILE) do |doc|
# ============================================================================ # ============================================================================
# Title and Introduction # Title and Introduction
# ============================================================================ # ============================================================================
doc.h1 "Ezdoc Feature Demo" doc.h1 "Notare Feature Demo"
doc.p "A comprehensive example of all supported features", style: :subtitle doc.p "A comprehensive example of all supported features", style: :subtitle
# ============================================================================ # ============================================================================
@@ -173,7 +173,7 @@ Ezdoc::Document.create(OUTPUT_FILE) do |doc|
doc.i { doc.text "formatting" } doc.i { doc.text "formatting" }
doc.text " options with " doc.text " options with "
doc.text "custom styles", style: :highlight doc.text "custom styles", style: :highlight
doc.text " to demonstrate the full power of Ezdoc." doc.text " to demonstrate the full power of Notare."
end end
doc.p "End of demo document.", style: :centered_large doc.p "End of demo document.", style: :centered_large

View File

@@ -1,28 +0,0 @@
# frozen_string_literal: true
require "nokogiri"
require_relative "ezdoc/version"
require_relative "ezdoc/nodes/base"
require_relative "ezdoc/nodes/run"
require_relative "ezdoc/nodes/image"
require_relative "ezdoc/nodes/paragraph"
require_relative "ezdoc/nodes/list"
require_relative "ezdoc/nodes/list_item"
require_relative "ezdoc/nodes/table"
require_relative "ezdoc/nodes/table_row"
require_relative "ezdoc/nodes/table_cell"
require_relative "ezdoc/image_dimensions"
require_relative "ezdoc/style"
require_relative "ezdoc/xml/content_types"
require_relative "ezdoc/xml/relationships"
require_relative "ezdoc/xml/document_xml"
require_relative "ezdoc/xml/numbering"
require_relative "ezdoc/xml/styles_xml"
require_relative "ezdoc/builder"
require_relative "ezdoc/package"
require_relative "ezdoc/document"
module Ezdoc
class Error < StandardError; end
end

28
lib/notare.rb Normal file
View File

@@ -0,0 +1,28 @@
# frozen_string_literal: true
require "nokogiri"
require_relative "notare/version"
require_relative "notare/nodes/base"
require_relative "notare/nodes/run"
require_relative "notare/nodes/image"
require_relative "notare/nodes/paragraph"
require_relative "notare/nodes/list"
require_relative "notare/nodes/list_item"
require_relative "notare/nodes/table"
require_relative "notare/nodes/table_row"
require_relative "notare/nodes/table_cell"
require_relative "notare/image_dimensions"
require_relative "notare/style"
require_relative "notare/xml/content_types"
require_relative "notare/xml/relationships"
require_relative "notare/xml/document_xml"
require_relative "notare/xml/numbering"
require_relative "notare/xml/styles_xml"
require_relative "notare/builder"
require_relative "notare/package"
require_relative "notare/document"
module Notare
class Error < StandardError; end
end

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Builder module Builder
def p(text = nil, style: nil, &block) def p(text = nil, style: nil, &block)
para = Nodes::Paragraph.new(style: resolve_style(style)) para = Nodes::Paragraph.new(style: resolve_style(style))

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
class Document class Document
include Builder include Builder

View File

@@ -2,7 +2,7 @@
require "fastimage" require "fastimage"
module Ezdoc module Notare
class ImageDimensions class ImageDimensions
EMUS_PER_INCH = 914_400 EMUS_PER_INCH = 914_400
DEFAULT_DPI = 96 DEFAULT_DPI = 96

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Nodes module Nodes
class Base class Base
# Base class for all document nodes # Base class for all document nodes

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Nodes module Nodes
class Image < Base class Image < Base
attr_reader :path, :width_emu, :height_emu, :rid, :filename attr_reader :path, :width_emu, :height_emu, :rid, :filename

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Nodes module Nodes
class List < Base class List < Base
attr_reader :items, :type, :num_id attr_reader :items, :type, :num_id

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Nodes module Nodes
class ListItem < Base class ListItem < Base
attr_reader :runs, :list_type, :num_id attr_reader :runs, :list_type, :num_id

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Nodes module Nodes
class Paragraph < Base class Paragraph < Base
attr_reader :runs, :style attr_reader :runs, :style

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Nodes module Nodes
class Run < Base class Run < Base
attr_reader :text, :bold, :italic, :underline, :style attr_reader :text, :bold, :italic, :underline, :style

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Nodes module Nodes
class Table < Base class Table < Base
attr_reader :rows attr_reader :rows

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Nodes module Nodes
class TableCell < Base class TableCell < Base
attr_reader :runs attr_reader :runs

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Nodes module Nodes
class TableRow < Base class TableRow < Base
attr_reader :cells attr_reader :cells

View File

@@ -2,7 +2,7 @@
require "zip" require "zip"
module Ezdoc module Notare
class Package class Package
def initialize(document) def initialize(document)
@document = document @document = document

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
class Style class Style
attr_reader :name, :bold, :italic, :underline, :color, :size, :font, attr_reader :name, :bold, :italic, :underline, :color, :size, :font,
:align, :indent, :spacing_before, :spacing_after :align, :indent, :spacing_before, :spacing_after

View File

@@ -1,5 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
VERSION = "0.0.1" VERSION = "0.0.1"
end end

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Xml module Xml
class ContentTypes class ContentTypes
NAMESPACE = "http://schemas.openxmlformats.org/package/2006/content-types" NAMESPACE = "http://schemas.openxmlformats.org/package/2006/content-types"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Xml module Xml
class DocumentXml class DocumentXml
NAMESPACES = { NAMESPACES = {
@@ -130,27 +130,38 @@ module Ezdoc
end end
def render_table(xml, table) def render_table(xml, table)
column_count = table.rows.first&.cells&.size || 1
col_width = 5000 / column_count
xml["w"].tbl do xml["w"].tbl do
xml["w"].tblPr do xml["w"].tblPr do
xml["w"].tblW("w:w" => "0", "w:type" => "auto") xml["w"].tblW("w:w" => "5000", "w:type" => "pct")
xml["w"].tblBorders do xml["w"].tblBorders do
%w[top left bottom right insideH insideV].each do |border| %w[top left bottom right insideH insideV].each do |border|
xml["w"].send(border, "w:val" => "single", "w:sz" => "4", "w:color" => "000000") xml["w"].send(border, "w:val" => "single", "w:sz" => "4", "w:space" => "0", "w:color" => "000000")
end end
end end
end end
table.rows.each { |row| render_table_row(xml, row) } xml["w"].tblGrid do
column_count.times do
xml["w"].gridCol("w:w" => col_width.to_s)
end
end
table.rows.each { |row| render_table_row(xml, row, col_width) }
end end
end end
def render_table_row(xml, row) def render_table_row(xml, row, col_width)
xml["w"].tr do xml["w"].tr do
row.cells.each { |cell| render_table_cell(xml, cell) } row.cells.each { |cell| render_table_cell(xml, cell, col_width) }
end end
end end
def render_table_cell(xml, cell) def render_table_cell(xml, cell, col_width)
xml["w"].tc do xml["w"].tc do
xml["w"].tcPr do
xml["w"].tcW("w:w" => col_width.to_s, "w:type" => "pct")
end
xml["w"].p do xml["w"].p do
cell.runs.each { |run| render_run(xml, run) } cell.runs.each { |run| render_run(xml, run) }
end end

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Xml module Xml
class Numbering class Numbering
NAMESPACE = "http://schemas.openxmlformats.org/wordprocessingml/2006/main" NAMESPACE = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Xml module Xml
class Relationships class Relationships
NAMESPACE = "http://schemas.openxmlformats.org/package/2006/relationships" NAMESPACE = "http://schemas.openxmlformats.org/package/2006/relationships"

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module Ezdoc module Notare
module Xml module Xml
class StylesXml class StylesXml
NAMESPACE = "http://schemas.openxmlformats.org/wordprocessingml/2006/main" NAMESPACE = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"

View File

@@ -1,14 +1,14 @@
# frozen_string_literal: true # frozen_string_literal: true
require_relative "lib/ezdoc/version" require_relative "lib/notare/version"
Gem::Specification.new do |spec| Gem::Specification.new do |spec|
spec.name = "ezdoc" spec.name = "notare"
spec.version = Ezdoc::VERSION spec.version = Notare::VERSION
spec.authors = ["Mathias"] spec.authors = ["Mathias"]
spec.summary = "A Ruby gem for working with docx files" spec.summary = "A Ruby gem for creating docx files with a simple DSL"
spec.description = "Easy document manipulation for docx files in Ruby" spec.description = "Notare provides a clean DSL for creating Word documents in Ruby"
spec.homepage = "https://github.com/mathias/ezdoc" spec.homepage = "https://github.com/mathias/notare"
spec.license = "MIT" spec.license = "MIT"
spec.required_ruby_version = ">= 3.0.0" spec.required_ruby_version = ">= 3.0.0"

View File

@@ -3,11 +3,11 @@
require "test_helper" require "test_helper"
class DocumentTest < Minitest::Test class DocumentTest < Minitest::Test
include EzdocTestHelpers include NotareTestHelpers
def test_creates_valid_docx_structure def test_creates_valid_docx_structure
Tempfile.create(["test", ".docx"]) do |file| Tempfile.create(["test", ".docx"]) do |file|
Ezdoc::Document.create(file.path) do |doc| Notare::Document.create(file.path) do |doc|
doc.p "Test" doc.p "Test"
end end
@@ -33,7 +33,7 @@ class DocumentTest < Minitest::Test
def test_empty_document def test_empty_document
Tempfile.create(["test", ".docx"]) do |file| Tempfile.create(["test", ".docx"]) do |file|
Ezdoc::Document.create(file.path) { |_doc| } # rubocop:disable Lint/EmptyBlock Notare::Document.create(file.path) { |_doc| } # rubocop:disable Lint/EmptyBlock
assert File.exist?(file.path) assert File.exist?(file.path)
Zip::File.open(file.path) do |zip| Zip::File.open(file.path) do |zip|
@@ -45,30 +45,30 @@ class DocumentTest < Minitest::Test
def test_document_create_returns_document def test_document_create_returns_document
result = nil result = nil
Tempfile.create(["test", ".docx"]) do |file| Tempfile.create(["test", ".docx"]) do |file|
result = Ezdoc::Document.create(file.path) do |doc| result = Notare::Document.create(file.path) do |doc|
doc.p "Test" doc.p "Test"
end end
end end
assert_instance_of Ezdoc::Document, result assert_instance_of Notare::Document, result
end end
def test_document_has_nodes def test_document_has_nodes
doc = Ezdoc::Document.new doc = Notare::Document.new
doc.p "Test" doc.p "Test"
assert_equal 1, doc.nodes.count assert_equal 1, doc.nodes.count
assert_instance_of Ezdoc::Nodes::Paragraph, doc.nodes.first assert_instance_of Notare::Nodes::Paragraph, doc.nodes.first
end end
def test_document_lists_helper def test_document_lists_helper
doc = Ezdoc::Document.new doc = Notare::Document.new
doc.p "Paragraph" doc.p "Paragraph"
doc.ul { doc.li "Bullet" } doc.ul { doc.li "Bullet" }
doc.ol { doc.li "Number" } doc.ol { doc.li "Number" }
doc.table { doc.tr { doc.td "Cell" } } doc.table { doc.tr { doc.td "Cell" } }
assert_equal 2, doc.lists.count assert_equal 2, doc.lists.count
assert(doc.lists.all? { |l| l.is_a?(Ezdoc::Nodes::List) }) assert(doc.lists.all? { |l| l.is_a?(Notare::Nodes::List) })
end end
end end

View File

@@ -3,7 +3,7 @@
require "test_helper" require "test_helper"
class FormattingTest < Minitest::Test class FormattingTest < Minitest::Test
include EzdocTestHelpers include NotareTestHelpers
def test_bold_text def test_bold_text
xml = create_doc_and_read_xml do |doc| xml = create_doc_and_read_xml do |doc|

View File

@@ -3,7 +3,7 @@
require "test_helper" require "test_helper"
class HeadingTest < Minitest::Test class HeadingTest < Minitest::Test
include EzdocTestHelpers include NotareTestHelpers
def test_h1 def test_h1
xml = create_doc_and_read_xml { |doc| doc.h1 "Title" } xml = create_doc_and_read_xml { |doc| doc.h1 "Title" }

View File

@@ -3,7 +3,7 @@
require "test_helper" require "test_helper"
class ImageTest < Minitest::Test class ImageTest < Minitest::Test
include EzdocTestHelpers include NotareTestHelpers
def setup def setup
@png_path = File.expand_path("fixtures/test.png", __dir__) @png_path = File.expand_path("fixtures/test.png", __dir__)
@@ -80,7 +80,7 @@ class ImageTest < Minitest::Test
def test_image_file_embedded_in_docx def test_image_file_embedded_in_docx
files = nil files = nil
Tempfile.create(["test", ".docx"]) do |file| Tempfile.create(["test", ".docx"]) do |file|
Ezdoc::Document.create(file.path) do |doc| Notare::Document.create(file.path) do |doc|
doc.p { doc.image @png_path } doc.p { doc.image @png_path }
end end
Zip::File.open(file.path) do |zip| Zip::File.open(file.path) do |zip|
@@ -124,7 +124,7 @@ class ImageTest < Minitest::Test
def test_invalid_image_path_raises_error def test_invalid_image_path_raises_error
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
Tempfile.create(["test", ".docx"]) do |file| Tempfile.create(["test", ".docx"]) do |file|
Ezdoc::Document.create(file.path) do |doc| Notare::Document.create(file.path) do |doc|
doc.p { doc.image "/nonexistent/image.png" } doc.p { doc.image "/nonexistent/image.png" }
end end
end end
@@ -138,7 +138,7 @@ class ImageTest < Minitest::Test
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
Tempfile.create(["test", ".docx"]) do |docx_file| Tempfile.create(["test", ".docx"]) do |docx_file|
Ezdoc::Document.create(docx_file.path) do |doc| Notare::Document.create(docx_file.path) do |doc|
doc.p { doc.image gif_file.path } doc.p { doc.image gif_file.path }
end end
end end
@@ -149,7 +149,7 @@ class ImageTest < Minitest::Test
def test_same_image_used_multiple_times_deduplication def test_same_image_used_multiple_times_deduplication
files = nil files = nil
Tempfile.create(["test", ".docx"]) do |file| Tempfile.create(["test", ".docx"]) do |file|
Ezdoc::Document.create(file.path) do |doc| Notare::Document.create(file.path) do |doc|
doc.p { doc.image @png_path } doc.p { doc.image @png_path }
doc.p { doc.image @png_path } doc.p { doc.image @png_path }
doc.p { doc.image @png_path } doc.p { doc.image @png_path }
@@ -166,7 +166,7 @@ class ImageTest < Minitest::Test
def test_multiple_different_images def test_multiple_different_images
files = nil files = nil
Tempfile.create(["test", ".docx"]) do |file| Tempfile.create(["test", ".docx"]) do |file|
Ezdoc::Document.create(file.path) do |doc| Notare::Document.create(file.path) do |doc|
doc.p { doc.image @png_path } doc.p { doc.image @png_path }
doc.p { doc.image @jpeg_path } doc.p { doc.image @jpeg_path }
end end

View File

@@ -3,7 +3,7 @@
require "test_helper" require "test_helper"
class IntegrationTest < Minitest::Test class IntegrationTest < Minitest::Test
include EzdocTestHelpers include NotareTestHelpers
def test_complex_document_with_all_features def test_complex_document_with_all_features
xml_files = create_doc_and_read_all_xml do |doc| xml_files = create_doc_and_read_all_xml do |doc|

View File

@@ -3,7 +3,7 @@
require "test_helper" require "test_helper"
class ListTest < Minitest::Test class ListTest < Minitest::Test
include EzdocTestHelpers include NotareTestHelpers
# #
# Bullet List Tests # Bullet List Tests

View File

@@ -3,7 +3,7 @@
require "test_helper" require "test_helper"
class ParagraphTest < Minitest::Test class ParagraphTest < Minitest::Test
include EzdocTestHelpers include NotareTestHelpers
def test_simple_paragraph def test_simple_paragraph
xml = create_doc_and_read_xml { |doc| doc.p "Hello World" } xml = create_doc_and_read_xml { |doc| doc.p "Hello World" }

View File

@@ -3,7 +3,7 @@
require "test_helper" require "test_helper"
class StyleTest < Minitest::Test class StyleTest < Minitest::Test
include EzdocTestHelpers include NotareTestHelpers
def test_define_custom_style def test_define_custom_style
xml_files = create_doc_and_read_all_xml do |doc| xml_files = create_doc_and_read_all_xml do |doc|
@@ -124,7 +124,7 @@ class StyleTest < Minitest::Test
def test_unknown_style_raises_error def test_unknown_style_raises_error
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
Tempfile.create(["test", ".docx"]) do |file| Tempfile.create(["test", ".docx"]) do |file|
Ezdoc::Document.create(file.path) do |doc| Notare::Document.create(file.path) do |doc|
doc.p "Test", style: :nonexistent doc.p "Test", style: :nonexistent
end end
end end
@@ -133,18 +133,18 @@ class StyleTest < Minitest::Test
def test_invalid_color_raises_error def test_invalid_color_raises_error
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
Ezdoc::Style.new(:bad, color: "invalid") Notare::Style.new(:bad, color: "invalid")
end end
end end
def test_invalid_alignment_raises_error def test_invalid_alignment_raises_error
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
Ezdoc::Style.new(:bad, align: :invalid) Notare::Style.new(:bad, align: :invalid)
end end
end end
def test_color_normalizes_hash def test_color_normalizes_hash
style = Ezdoc::Style.new(:test, color: "#ff0000") style = Notare::Style.new(:test, color: "#ff0000")
assert_equal "FF0000", style.color assert_equal "FF0000", style.color
end end

View File

@@ -3,7 +3,7 @@
require "test_helper" require "test_helper"
class TableTest < Minitest::Test class TableTest < Minitest::Test
include EzdocTestHelpers include NotareTestHelpers
def test_simple_table def test_simple_table
xml = create_doc_and_read_xml do |doc| xml = create_doc_and_read_xml do |doc|

View File

@@ -1,17 +1,17 @@
# frozen_string_literal: true # frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path("../lib", __dir__) $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "ezdoc" require "notare"
require "minitest/autorun" require "minitest/autorun"
require "tempfile" require "tempfile"
require "zip" require "zip"
module EzdocTestHelpers module NotareTestHelpers
# Helper to create a document and return the document.xml content # Helper to create a document and return the document.xml content
def create_doc_and_read_xml(&block) def create_doc_and_read_xml(&block)
content = nil content = nil
Tempfile.create(["test", ".docx"]) do |file| Tempfile.create(["test", ".docx"]) do |file|
Ezdoc::Document.create(file.path, &block) Notare::Document.create(file.path, &block)
Zip::File.open(file.path) do |zip| Zip::File.open(file.path) do |zip|
content = zip.read("word/document.xml").force_encoding("UTF-8") content = zip.read("word/document.xml").force_encoding("UTF-8")
end end
@@ -23,7 +23,7 @@ module EzdocTestHelpers
def create_doc_and_read_all_xml(&block) def create_doc_and_read_all_xml(&block)
result = {} result = {}
Tempfile.create(["test", ".docx"]) do |file| Tempfile.create(["test", ".docx"]) do |file|
Ezdoc::Document.create(file.path, &block) Notare::Document.create(file.path, &block)
Zip::File.open(file.path) do |zip| Zip::File.open(file.path) do |zip|
zip.each do |entry| zip.each do |entry|
if entry.name.end_with?(".xml") || entry.name.end_with?(".rels") if entry.name.end_with?(".xml") || entry.name.end_with?(".rels")