Module: Serve::ContentHelpers

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

Instance Method Summary collapse

Instance Method Details

#capture(&block) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/serve/view_helpers.rb', line 71

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, capture_erubis



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

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

#content_for(symbol, content = nil, &block) ⇒ Object



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

def content_for(symbol, content = nil, &block)
  content = capture(&block) if block_given?
  set_content_for(symbol, content) if content
  get_content_for(symbol) unless content
end

#content_for?(symbol) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/serve/view_helpers.rb', line 44

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

#get_content_for(symbol = :content) ⇒ Object



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

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



56
57
58
# File 'lib/serve/view_helpers.rb', line 56

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