Module: Serve::ContentHelpers

Included in:
ViewHelpers
Defined in:
lib/serve/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#capture(&block) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/serve/view_helpers.rb', line 68

def capture(&block)
  capture_method = "capture_#{script_extension}"
  if respond_to? capture_method
    send capture_method, &block
  else
    raise "Capture not supported for `#{script_extension}' template (#{engine_name})"
  end
end

#capture_erb(&block) ⇒ Object Also known as: capture_rhtml



58
59
60
61
62
63
64
65
# File 'lib/serve/view_helpers.rb', line 58

def capture_erb(&block)
  buffer = ""
  old_buffer, @out_var = @_out_var, buffer
  yield
  buffer
ensure
  @out_var = old_buffer
end

#content_for(symbol, &block) ⇒ Object



38
39
40
# File 'lib/serve/view_helpers.rb', line 38

def content_for(symbol, &block)
  set_content_for(symbol, capture(&block))
end

#content_for?(symbol) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/serve/view_helpers.rb', line 42

def content_for?(symbol)
  !(get_content_for(symbol)).nil?
end

#get_content_for(symbol = :content) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/serve/view_helpers.rb', line 46

def get_content_for(symbol = :content)
  if symbol.to_s.intern == :content
    @content
  else
    instance_variable_get("@content_for_#{symbol}")
  end
end

#set_content_for(symbol, value) ⇒ Object



54
55
56
# File 'lib/serve/view_helpers.rb', line 54

def set_content_for(symbol, value)
  instance_variable_set("@content_for_#{symbol}", value)
end