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
-
#locals ⇒ Set<Symbol>
list of attributes to be used when rendering.
-
#render(renderer:, **args) ⇒ ActionView::OutputBuffer
render template using the given prameters.
-
#template(template) ⇒ Array<Sinclair::MethodDefinition>
Sets template for element type.
-
#template_folder(folder) ⇒ Array<Sinclair::MethodDefinition>
Sets template folder for element type.
-
#with_attribute_locals(*args) ⇒ Array
Adds attribute and locals.
-
#with_locals(*args) ⇒ Set<Symbol>
Add an attribute to locals when rendereing.
Instance Method Details
#locals ⇒ Set<Symbol>
list of attributes to be used when rendering
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
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
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
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
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
56 57 58 |
# File 'lib/magicka/element/class_methods.rb', line 56 def with_locals(*args) locals.merge(args) end |