Class: MtgCardMaker::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/mtg_card_maker.rb

Overview

Main template class that manages the SVG canvas and layer composition. This class handles creating the SVG canvas, adding layers, and saving the final SVG file. It also manages font embedding and CSS styling.

Examples:

template = MtgCardMaker::Template.new
template.add_layer(MtgCardMaker::BorderLayer.new(dimensions: {...}))
template.add_layer(MtgCardMaker::NameLayer.new(dimensions: {...}, text: "Lightning Bolt"))
template.save("card.svg")

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width: CARD_WIDTH, height: CARD_HEIGHT, embed_font: false) ⇒ Template

Initialize a new template with the given dimensions

Since:

  • 0.1.0



157
158
159
160
161
162
163
# File 'lib/mtg_card_maker.rb', line 157

def initialize(width: CARD_WIDTH, height: CARD_HEIGHT, embed_font: false)
  @width = width
  @height = height
  @svg = Victor::SVG.new width: width, height: height
  embed_font(embed: embed_font)
  define_css_classes
end

Instance Attribute Details

#heightInteger (readonly)

Returns the height of the SVG canvas.

Since:

  • 0.1.0



150
151
152
# File 'lib/mtg_card_maker.rb', line 150

def height
  @height
end

#widthInteger (readonly)

Returns the width of the SVG canvas.

Since:

  • 0.1.0



147
148
149
# File 'lib/mtg_card_maker.rb', line 147

def width
  @width
end

Instance Method Details

#add_layer(layer) ⇒ void

This method returns an undefined value.

Add a layer to the template and render it

Since:

  • 0.1.0



169
170
171
172
# File 'lib/mtg_card_maker.rb', line 169

def add_layer(layer)
  layer.template = self
  layer.render
end

#save(filename) ⇒ void

This method returns an undefined value.

Save the SVG to a file

Since:

  • 0.1.0



178
179
180
# File 'lib/mtg_card_maker.rb', line 178

def save(filename)
  @svg.save(filename)
end

#to_svgString

Get the SVG as a string

Since:

  • 0.1.0



185
186
187
# File 'lib/mtg_card_maker.rb', line 185

def to_svg
  @svg.to_s
end