Class: ChartBibz::ViewComponents::CanvasViewComponent

Inherits:
ApplicationViewComponent show all
Defined in:
lib/chart_bibz/view_components/canvas_view_component.rb

Overview

Generate the canvas view through the render method

Constant Summary collapse

WIDTH =

Constants

400
HEIGHT =

Default width for the html canvas

400

Instance Attribute Summary

Attributes inherited from ApplicationViewComponent

#output_buffer

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ void

Only html_options can be passed

Examples:

ChartBibz::ViewComponents::CanvasViewComponent.new(class: 'test')

Parameters:

  • args (Hash) (defaults to: {})

    The html options



21
22
23
# File 'lib/chart_bibz/view_components/canvas_view_component.rb', line 21

def initialize(args = {})
  @args = args
end

Instance Method Details

#idString

Get the id

Examples:

ChartBibz::ViewComponents::CanvasViewComponent.new(class: 'test').id

Returns:

  • (String)

    The canvas html id



46
47
48
# File 'lib/chart_bibz/view_components/canvas_view_component.rb', line 46

def id
  html_options[:id]
end

#renderString

Generate the html canvas

Examples:

ChartBibz::ViewComponents::CanvasViewComponent.new(class:
'test').render

Returns:

  • (String)

    The html canvas



34
35
36
# File 'lib/chart_bibz/view_components/canvas_view_component.rb', line 34

def render
  tag.canvas(**html_options)
end