class Osheet::Workbook

Public Class Methods

new(writer=nil, data={}, &build) click to toggle source
# File lib/osheet/workbook.rb, line 18
def initialize(writer=nil, data={}, &build)
  # apply :data options to workbook scope
  data ||= {}
  if (data.keys.map(&:to_s) & self.public_methods.map(&:to_s)).size > 0
    raise ArgumentError, "data conflicts with workbook public methods."
  end
  metaclass = class << self; self; end
  data.each {|key, value| metaclass.class_eval { define_method(key){value} }}

  # setup the writer, element stack, and workbook_element
  writer.bind(self) if writer
  @_osheet_writer = writer
  @_osheet_element_stack = Workbook::ElementStack.new
  @_osheet_workbook_element = WorkbookElement.new

  # push the workbook element onto the element stack
  element_stack.push(workbook)

  # run any instance workbook build given
  instance_eval(&build) if build
end

Public Instance Methods

add(partial_name, *args) click to toggle source

add partials to dynamically add markup to your workbook note: you can also define element templates to add element specific markup to your workbook

# File lib/osheet/workbook.rb, line 76
def add(partial_name, *args)
  workbook.partials.get(partial_name).tap do |p|
    instance_exec(*args, &p) if p
  end
end
element_stack() click to toggle source
# File lib/osheet/workbook.rb, line 44
def element_stack
  @_osheet_element_stack
end
inspect(*args)
Alias for: to_str
to_str(*args) click to toggle source

overriding to make less noisy

# File lib/osheet/workbook.rb, line 83
def to_str(*args)
  "#<Osheet::Workbook:#{self.object_id} @title=#{workbook.title.inspect}, " +
  "worksheet_count=#{workbook.worksheets.size.inspect}, " +
  "style_count=#{workbook.styles.size.inspect}>"
end
Also aliased as: inspect
use(mixin) click to toggle source

use a mixin to define its markup handlers (templates, partials, and styles) in your workbook scope all blocks in mixins will be instance eval’d in the workbook scope and should be written as such

# File lib/osheet/workbook.rb, line 57
def use(mixin)
  # templates and partials are just blocks themselves so they just need to
  # be added to the workbook element
  # they will be instance eval'd when they get used
  (mixin.templates || []).each { |mt| template(*mt.args, &mt.build) }
  (mixin.partials  || []).each { |mp| partial(*mp.args, &mp.build)  }

  # styles not only need to be added to the workbook element, but
  # any build passed to the style needs to be instance eval'd
  (mixin.styles || []).each do |ms|
    StyleBuild.new(self, *ms.args, &ms.build).add do |build|
      instance_eval(&build)
    end
  end
end
workbook()
Alias for: workbook_element
workbook_element() click to toggle source
# File lib/osheet/workbook.rb, line 48
def workbook_element
  @_osheet_workbook_element
end
Also aliased as: workbook
writer() click to toggle source
# File lib/osheet/workbook.rb, line 40
def writer
  @_osheet_writer
end