Module: Magicka::Element::ClassMethods

Included in:
Magicka::Element
Defined in:
lib/magicka/element/class_methods.rb

Overview

Class methods used for metaprograming of elements

Instance Method Summary collapse

Instance Method Details

#localsSet<Symbol>

list of attributes to be used when rendering

Returns:

  • (Set<Symbol>)


23
24
25
# File 'lib/magicka/element/class_methods.rb', line 23

def locals
  @locals ||= superclass.try(:locals)&.dup || Set.new([])
end

#render(renderer:, **args) ⇒ ActionView::OutputBuffer

render template using the given prameters

Parameters:

  • renderer (Object)

    object responsible for rendering the HTML

  • args (Hash)

    Extra options

Returns:

  • (ActionView::OutputBuffer)


16
17
18
# File 'lib/magicka/element/class_methods.rb', line 16

def render(renderer:, **args)
  new(renderer: renderer, **args).render
end

#template(template) ⇒ Array<Sinclair::MethodDefinition>

Sets template for element type

Returns:

  • (Array<Sinclair::MethodDefinition>)


30
31
32
33
34
# File 'lib/magicka/element/class_methods.rb', line 30

def template(template)
  MethodBuilder
    .new(self)
    .add_template(template)
end

#template_folder(folder) ⇒ Array<Sinclair::MethodDefinition>

Sets template folder for element type

Returns:

  • (Array<Sinclair::MethodDefinition>)


39
40
41
42
43
# File 'lib/magicka/element/class_methods.rb', line 39

def template_folder(folder)
  MethodBuilder
    .new(self)
    .add_template_folder(folder)
end

#with_attribute_locals(*args) ⇒ Array

Adds attribute and locals

Returns:

  • (Array)


66
67
68
69
# File 'lib/magicka/element/class_methods.rb', line 66

def with_attribute_locals(*args)
  with_locals(*args)
  with_attributes(*args)
end

#with_locals(*args) ⇒ Set<Symbol>

Add an attribute to locals when rendereing

the attribute will be a call to the a method with same name

Returns:

  • (Set<Symbol>)


56
57
58
# File 'lib/magicka/element/class_methods.rb', line 56

def with_locals(*args)
  locals.merge(args)
end