class View::Helper

Public Class Methods

new(instance, *list) click to toggle source

create helper object that cah be used in template render

# File lib/lux/view/helper.rb, line 8
def initialize instance, *list
  extend ApplicationHelper

  list.flatten.compact.each do |el|
    el = el.to_s.classify+'Helper'
    extend el.constantize
  end

  local_vars = instance.class == Hash ? instance : instance.instance_variables_hash

  # locals overide globals
  for k, v in local_vars
    instance_variable_set("@#{k.to_s.sub('@','')}", v)
  end

  # helper.instance_exec &block if block
end

Public Instance Methods

content(name=nil) { || ... } click to toggle source
  • @foo = content do …

@foo

  • content :foo do …

content :foo

# File lib/lux/view/helper.rb, line 40
def content name=nil
  ivar = '@content_%s' % name

  if block_given?
    yield.tap do |data|
      instance_variable_set(ivar, data) if name
    end
  else
    name ? instance_variable_get(ivar) : nil
  end
no_white_space() { || ... } click to toggle source
# File lib/lux/view/helper.rb, line 32
def no_white_space
  yield.gsub(/>\s+</,'><')
end