Class: MtgCardMaker::Template
- Inherits:
-
Object
- Object
- MtgCardMaker::Template
- 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.
Instance Attribute Summary collapse
-
#height ⇒ Integer
readonly
The height of the SVG canvas.
-
#width ⇒ Integer
readonly
The width of the SVG canvas.
Instance Method Summary collapse
-
#add_layer(layer) ⇒ void
Add a layer to the template and render it.
-
#initialize(width: CARD_WIDTH, height: CARD_HEIGHT, embed_font: false) ⇒ Template
constructor
Initialize a new template with the given dimensions.
-
#save(filename) ⇒ void
Save the SVG to a file.
-
#to_svg ⇒ String
Get the SVG as a string.
Constructor Details
#initialize(width: CARD_WIDTH, height: CARD_HEIGHT, embed_font: false) ⇒ Template
Initialize a new template with the given dimensions
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: ) define_css_classes end |
Instance Attribute Details
#height ⇒ Integer (readonly)
Returns the height of the SVG canvas.
150 151 152 |
# File 'lib/mtg_card_maker.rb', line 150 def height @height end |
#width ⇒ Integer (readonly)
Returns the width of the SVG canvas.
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
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
178 179 180 |
# File 'lib/mtg_card_maker.rb', line 178 def save(filename) @svg.save(filename) end |
#to_svg ⇒ String
Get the SVG as a string
185 186 187 |
# File 'lib/mtg_card_maker.rb', line 185 def to_svg @svg.to_s end |