Class: Docforge::Renderers::Docx

Inherits:
Object
  • Object
show all
Defined in:
lib/docforge/renderers/docx.rb

Overview

Renders a Brief to a styled .docx using caracal.

Visual language: “modern tech” — sans-serif throughout, one blue accent, table-heavy, generous whitespace, callout boxes for the pull quote and sharable footer.

Constant Summary collapse

ACCENT =

blue

"2563eb"
NEUTRAL_700 =
"374151"
NEUTRAL_500 =
"6b7280"
NEUTRAL_200 =
"e5e7eb"
CALLOUT_BG =
"f8fafc"

Instance Method Summary collapse

Constructor Details

#initialize(brief:, config:, slug:) ⇒ Docx

Returns a new instance of Docx.



20
21
22
23
24
# File 'lib/docforge/renderers/docx.rb', line 20

def initialize(brief:, config:, slug:)
  @brief  = brief
  @config = config
  @slug   = slug
end

Instance Method Details

#renderObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/docforge/renderers/docx.rb', line 26

def render
  FileUtils.mkdir_p(@config.output_dir)
  path = File.join(@config.output_dir, "#{@slug}.docx")
  b = @brief
  renderer = self
  Caracal::Document.save(path) do |doc|
    doc.font name: "Calibri"
    doc.page_margins do
      top    1080  # 0.75"
      bottom 1080
      left   1080
      right  1080
    end

    renderer.send(:render_cover, doc, b)
    doc.page

    renderer.send(:render_problem, doc, b)
    renderer.send(:render_capabilities, doc, b)
    renderer.send(:render_worked_example, doc, b)
    renderer.send(:render_how_it_works, doc, b)
    renderer.send(:render_capabilities_table, doc, b)
    renderer.send(:render_numbers, doc, b)
    renderer.send(:render_future, doc, b)
    renderer.send(:render_stack, doc, b)

    doc.page
    renderer.send(:render_sharable, doc, b)
  end
  path
end