module WSOC::Helpers::Rendering

Public Instance Methods

json(obj) click to toggle source

Renders a JSON blob and sets the content-type accordingly.

@param [Object] obj

The object to encode.

@return [String]

The JSON encoded object.

@example

json @specs

@since 0.1.0

# File lib/wsoc/helpers/rendering.rb, line 83
def json(obj)
  content_type :json

  obj = obj.to_s unless obj.respond_to?(:to_json)
  return obj.to_json
end
partial(page,options={}) click to toggle source

Renders a partial template.

@param [Symbol] page

The name of the partial template.

@param [Hash] options

Additional options.

@return [String]

The rendered partial.

@example

partial :course_include

@since 0.1.0

# File lib/wsoc/helpers/rendering.rb, line 44
def partial(page,options={})
  erb "_#{page}".to_sym, options.merge(:layout => false)
end
show(page,options={}) click to toggle source

Renders a page.

@param [Symbol] page

Name of the page to render.

@param [Hash] options

Additional options.

@return [String]

The rendered page.

@example

show :course_fail

@since 0.1.0

# File lib/wsoc/helpers/rendering.rb, line 65
def show(page,options={})
  erb(page,options)
end
yaml(obj) click to toggle source

Renders a YAML blob and sets the content-type accordingly.

@param [Object] obj

The object to encode.

@return [String]

The YAML encoded object.

@example

yaml @specs

@since 0.1.0

# File lib/wsoc/helpers/rendering.rb, line 104
def yaml(obj)
  content_type :yaml

  return YAML.dump(obj)
end