class Victor::Component

Public Instance Methods

append(component) click to toggle source

Appending/Embedding - DSL for the ‘#body` implementation

# File lib/victor/component.rb, line 35
def append(component)
  svg_instance.append component.svg
  merged_css.merge! component.merged_css
end
body() click to toggle source

Subclasses MUST implement this

# File lib/victor/component.rb, line 14
def body
  raise(NotImplementedError, "#{self.class.name} must implement `body'")
end
height() click to toggle source

Subclasses MUST override these methods, OR assign instance vars

# File lib/victor/component.rb, line 19
def height
  @height || raise(NotImplementedError,
    "#{self.class.name} must implement `height' or `@height'")
end
marshaling(= %i[width height x y svg merged_css]) click to toggle source

Marshaling data

# File lib/victor/component.rb, line 11
  def marshaling = %i[width height x y svg merged_css]

  # Subclasses MUST implement this
  def body
    raise(NotImplementedError, "#{self.class.name} must implement `body'")
  end

  # Subclasses MUST override these methods, OR assign instance vars
  def height
    @height || raise(NotImplementedError,
      "#{self.class.name} must implement `height' or `@height'")
  end

  def width
    @width || raise(NotImplementedError,
      "#{self.class.name} must implement `width' or `@width'")
  end

  # Subclasses MAY override these methods, OR assign instance vars
  def style = @style ||= {}
  def x = @x ||= 0
  def y = @y ||= 0

  # Appending/Embedding - DSL for the `#body` implementation
  def append(component)
    svg_instance.append component.svg
    merged_css.merge! component.merged_css
  end
  alias embed append

  # SVG / CSS
  def svg
    @svg ||= begin
      body
      svg_instance.css = merged_css
      svg_instance
    end
  end

protected

  # Start with an ordinary SVG instance
  def svg_instance = @svg_instance ||= SVG.new(viewBox: "#{x} #{y} #{width} #{height}")

  # Internal DSL to enable `add.anything` in the `#body` implementation
  alias add svg_instance

  # Start with a copy of our own style
  def merged_css = @merged_css ||= 
merged_css(= @merged_css ||= style.dup) click to toggle source

Start with a copy of our own style

# File lib/victor/component.rb, line 59
  def merged_css = @merged_css ||= style.dup
end
style(= @style ||= {}) click to toggle source

Subclasses MAY override these methods, OR assign instance vars

# File lib/victor/component.rb, line 30
  def style = @style ||= {}
  def x = @x ||= 0
  def y = @y ||= 0

  # Appending/Embedding - DSL for the `#body` implementation
  def append(component)
    svg_instance.append component.svg
    merged_css.merge! component.merged_css
  end
  alias embed append

  # SVG / CSS
  def svg
    @svg ||= begin
      body
      svg_instance.css = merged_css
      svg_instance
    end
  end

protected

  # Start with an ordinary SVG instance
  def svg_instance = @svg_instance ||= SVG.new(viewBox: "#{x} #{y} #{width} #{height}")

  # Internal DSL to enable `add.anything` in the `#body` implementation
  alias add svg_instance

  # Start with a copy of our own style
  def merged_css = @merged_css ||= style.
svg() click to toggle source

SVG / CSS

# File lib/victor/component.rb, line 42
def svg
  @svg ||= begin
    body
    svg_instance.css = merged_css
    svg_instance
  end
end
svg_instance(= @svg_instance ||= SVG.new(viewBox: " click to toggle source

Start with an ordinary SVG instance

# File lib/victor/component.rb, line 53
    def svg_instance = @svg_instance ||= SVG.new(viewBox: "#{x} #{y} #{width} #{height}")

    # Internal DSL to enable `add.anything` in the `#body` implementation
    alias add svg_instance

    # Start with a copy of our own style
    def merged_css = @merged_css ||= style.dup
  end
end
width() click to toggle source
# File lib/victor/component.rb, line 24
def width
  @width || raise(NotImplementedError,
    "#{self.class.name} must implement `width' or `@width'")
end
x(= @x ||= 0) click to toggle source
# File lib/victor/component.rb, line 31
  def x = @x ||= 0
  def y = @y ||= 0

  # Appending/Embedding - DSL for the `#body` implementation
  def append(component)
    svg_instance.append component.svg
    merged_css.merge! component.merged_css
  end
  alias embed append

  # SVG / CSS
  def svg
    @svg ||= begin
      body
      svg_instance.css = merged_css
      svg_instance
    end
  end

protected

  # Start with an ordinary SVG instance
  def svg_instance = @svg_instance ||= SVG.new(viewBox: "#{x} #{y} #{width} #{height}")

  # Internal DSL to enable `add.anything` in the `#body` implementation
  alias add svg_instance

  # Start with a copy of our own style
  def merged_css = @merged_css ||= style.dup
y(= @y ||= 0) click to toggle source
# File lib/victor/component.rb, line 32
  def y = @y ||= 0

  # Appending/Embedding - DSL for the `#body` implementation
  def append(component)
    svg_instance.append component.svg
    merged_css.merge! component.merged_css
  end
  alias embed append

  # SVG / CSS
  def svg
    @svg ||= begin
      body
      svg_instance.css = merged_css
      svg_instance
    end
  end

protected

  # Start with an ordinary SVG instance
  def svg_instance = @svg_instance ||= SVG.new(viewBox: "#{x} #{y} #{width} #{height}")

  # Internal DSL to enable `add.anything` in the `#body` implementation
  alias add svg_instance

  # Start with a copy of our own style
  def merged_css = @merged_css ||= style.dup
end