This commit is contained in:
95
README.md
95
README.md
@@ -69,6 +69,93 @@ Ezdoc::Document.create("output.docx") do |doc|
|
||||
end
|
||||
```
|
||||
|
||||
### Headings
|
||||
|
||||
Use `h1` through `h6` for document headings:
|
||||
|
||||
```ruby
|
||||
Ezdoc::Document.create("output.docx") do |doc|
|
||||
doc.h1 "Document Title"
|
||||
doc.h2 "Chapter 1"
|
||||
doc.h3 "Section 1.1"
|
||||
doc.h4 "Subsection"
|
||||
doc.h5 "Minor heading"
|
||||
doc.h6 "Smallest heading"
|
||||
|
||||
# Headings with formatted content
|
||||
doc.h2 do
|
||||
doc.text "Chapter with "
|
||||
doc.i { doc.text "emphasis" }
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
### Styles
|
||||
|
||||
Ezdoc includes built-in styles and supports custom style definitions.
|
||||
|
||||
#### Built-in Styles
|
||||
|
||||
```ruby
|
||||
Ezdoc::Document.create("output.docx") do |doc|
|
||||
doc.p "This is a title", style: :title
|
||||
doc.p "A subtitle", style: :subtitle
|
||||
doc.p "A quotation", style: :quote
|
||||
doc.p "puts 'code'", style: :code
|
||||
end
|
||||
```
|
||||
|
||||
#### Custom Styles
|
||||
|
||||
Define your own styles with text and paragraph properties:
|
||||
|
||||
```ruby
|
||||
Ezdoc::Document.create("output.docx") do |doc|
|
||||
# Define custom styles
|
||||
doc.define_style :warning,
|
||||
bold: true,
|
||||
color: "FF0000",
|
||||
size: 14
|
||||
|
||||
doc.define_style :note,
|
||||
italic: true,
|
||||
color: "0066CC",
|
||||
font: "Georgia"
|
||||
|
||||
doc.define_style :centered,
|
||||
align: :center,
|
||||
size: 12
|
||||
|
||||
# Apply to paragraphs
|
||||
doc.p "Warning message!", style: :warning
|
||||
doc.p "Centered text", style: :centered
|
||||
|
||||
# Apply to text runs
|
||||
doc.p do
|
||||
doc.text "Normal text, "
|
||||
doc.text "important!", style: :warning
|
||||
doc.text ", and "
|
||||
doc.text "a note", style: :note
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
#### Style Properties
|
||||
|
||||
**Text properties:**
|
||||
- `bold: true/false`
|
||||
- `italic: true/false`
|
||||
- `underline: true/false`
|
||||
- `color: "FF0000"` (hex RGB)
|
||||
- `size: 14` (points)
|
||||
- `font: "Arial"` (font family)
|
||||
|
||||
**Paragraph properties:**
|
||||
- `align: :left / :center / :right / :justify`
|
||||
- `indent: 720` (twips, 1 inch = 1440 twips)
|
||||
- `spacing_before: 240` (twips)
|
||||
- `spacing_after: 240` (twips)
|
||||
|
||||
### Lists
|
||||
|
||||
#### Bullet Lists
|
||||
@@ -202,12 +289,14 @@ end
|
||||
|
||||
| Method | Description |
|
||||
|--------|-------------|
|
||||
| `p(text)` | Create a paragraph with text |
|
||||
| `p { }` | Create a paragraph with block content |
|
||||
| `text(value)` | Add text to the current context |
|
||||
| `p(text, style:)` | Create a paragraph with text and optional style |
|
||||
| `p(style:) { }` | Create a paragraph with block content and optional style |
|
||||
| `text(value, style:)` | Add text with optional style to the current context |
|
||||
| `h1(text)` - `h6(text)` | Create headings (level 1-6) |
|
||||
| `b { }` | Bold formatting |
|
||||
| `i { }` | Italic formatting |
|
||||
| `u { }` | Underline formatting |
|
||||
| `define_style(name, **props)` | Define a custom style |
|
||||
| `ul { }` | Bullet list |
|
||||
| `ol { }` | Numbered list |
|
||||
| `li(text)` | List item with text |
|
||||
|
||||
Reference in New Issue
Block a user