class View::Cell

Public Class Methods

base_folder() click to toggle source

CityCell.folder -> “./app/cells/city”

# File lib/lux/view/cell.rb, line 20
def base_folder
  name = instance_methods(false).first || dir('Can not find method')
  file = instance_method(name).source_location
  File.dirname file.first
end
get(name, parent, vars={}) click to toggle source
# File lib/lux/view/cell.rb, line 26
def get name, parent, vars={}
  w = ('%sCell' % name.to_s.classify).constantize
  w = w.new parent, vars
  w
end
new(parent, vars={}) click to toggle source
# File lib/lux/view/cell.rb, line 39
def initialize parent, vars={}
  @_parent = parent

  Object.class_callback :before, self

  vars.each { |k,v| instance_variable_set "@#{k}", v}

  # add runtime file reference
  if m = self.class.instance_methods(false).first
    src = method(m).source_location[0].split(':').first
    src = src.sub(Lux.root.to_s+'/', '')
    Lux.log " #{src}" unless Lux.current.files_in_use.include?(src)
    Lux.current.files_in_use src
  end
end

Public Instance Methods

cell(name=nil) click to toggle source
# File lib/lux/view/cell.rb, line 95
def cell name=nil
  return parent.cell unless name

  w = ('%sCell' % name.to_s.classify).constantize
  w = w.new @_parent
  w
end
once(id=nil) { || ... } click to toggle source

execute block only once per page

# File lib/lux/view/cell.rb, line 90
def once id=nil
  id ||= self.class
  Lux.current.once('cell-once-%s' % id) { yield }
end
parent(&block) click to toggle source
# File lib/lux/view/cell.rb, line 55
def parent &block
  if block_given?
    @_parent.instance_exec &block
  else
    @_parent
  end
end
tag(name=nil, opts={}) { |opts| ... } click to toggle source

tag :div, { 'class'=>'iform' } do

# File lib/lux/view/cell.rb, line 82
def tag name=nil, opts={}, data=nil
  return HtmlTagBuilder unless name

  data = yield(opts) if block_given?
  HtmlTagBuilder.tag name, opts, data
end
template(name=:cellm, &block) click to toggle source

if block is passed, template render will be passed as an argument

# File lib/lux/view/cell.rb, line 64
def template name=:cellm, &block
  tpl = 'cell-tpl-%s-%s' % [self.class, name]

  tpl = Lux.ram_cache(tpl) do
    file = '%s/%s.haml' % [self.class.base_folder, name]
    file = file.sub(Lux.root.to_s+'/', '')

    Lux.log ' ' + file unless Lux.current.files_in_use(file)

    Tilt[:haml].new { File.read(file) }
  end

  data = tpl.render(self)
  data = block.call(data) if block
  data
end