class Osheet::WorkbookApi::TemplatedElement
element handling API
Constants
- ELEMENT_CLASS
this class is used to create elements that can be templated. Arguments are handled differently if building an element from a template vs. building from a build block. After the element is built, it is added to the current stack element and either the build or writer is called.
Public Class Methods
new(scope, name, *args, &build)
click to toggle source
# File lib/osheet/workbook_api.rb, line 83 def initialize(scope, name, *args, &build) @scope = scope @workbook = @scope.workbook @name = name @args = args if (@template = @workbook.templates.get(@name, @args.first)) @element = ELEMENT_CLASS[@name].new @build = Proc.new { @scope.instance_exec(*@args[1..-1], &@template) } else @element = ELEMENT_CLASS[@name].new(*@args) @build = build || Proc.new {} end end
Public Instance Methods
add()
click to toggle source
# File lib/osheet/workbook_api.rb, line 97 def add @scope.element_stack.current.send(@name, @element) @scope.element_stack.using(@element) do if @scope.writer @scope.writer.send(@name, @element, &@build) else @build.call end end end