module Thinreports::Generator::PDF::DrawTemplateItems

Public Instance Methods

draw_template_items(items) click to toggle source

@param [Array<Hash>] items

# File lib/thinreports/generator/pdf/document/draw_template_items.rb, line 8
def draw_template_items(items)
  items.each do |item_attributes|
    next unless drawable?(item_attributes)

    case item_attributes['type']
    when 'text' then draw_text(item_attributes)
    when 'image' then draw_image(item_attributes)
    when 'rect' then draw_rect(item_attributes)
    when 'ellipse' then draw_ellipse(item_attributes)
    when 'line' then draw_line(item_attributes)
    end
  end
end

Private Instance Methods

draw_ellipse(item_attributes) click to toggle source

@see draw_rect

# File lib/thinreports/generator/pdf/document/draw_template_items.rb, line 35
def draw_ellipse(item_attributes)
  x, y, rx, ry = item_attributes.values_at('cx', 'cy', 'rx', 'ry')
  ellipse(x, y, rx, ry, build_graphic_attributes(item_attributes['style']))
end
draw_image(item_attributes) click to toggle source

@see draw_rect

# File lib/thinreports/generator/pdf/document/draw_template_items.rb, line 56
def draw_image(item_attributes)
  x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
  image_data = item_attributes['data']

  base64image(image_data['base64'], x, y, w, h)
end
draw_line(item_attributes) click to toggle source

@see draw_rect

# File lib/thinreports/generator/pdf/document/draw_template_items.rb, line 41
def draw_line(item_attributes)
  x1, y1, x2, y2 = item_attributes.values_at('x1', 'y1', 'x2', 'y2')
  line(x1, y1, x2, y2, build_graphic_attributes(item_attributes['style']))
end
draw_rect(item_attributes) click to toggle source

@param [Hash] item_attributes

# File lib/thinreports/generator/pdf/document/draw_template_items.rb, line 25
def draw_rect(item_attributes)
  x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
  graphic_attributes = build_graphic_attributes(item_attributes['style']) do |attrs|
    attrs[:radius] = item_attributes['border-radius']
  end

  rect(x, y, w, h, graphic_attributes)
end
draw_text(item_attributes) click to toggle source

@see draw_rect

# File lib/thinreports/generator/pdf/document/draw_template_items.rb, line 47
def draw_text(item_attributes)
  x, y, w, h = item_attributes.values_at('x', 'y', 'width', 'height')
  text(
    item_attributes['texts'].join("\n"), x, y, w, h,
    build_text_attributes(item_attributes['style'])
  )
end
drawable?(item_attributes) click to toggle source
# File lib/thinreports/generator/pdf/document/draw_template_items.rb, line 63
def drawable?(item_attributes)
  item_attributes['id'].empty? && item_attributes['display']
end