Module: WSOC::Helpers::Rendering

Included in:
WSOC::Helpers
Defined in:
lib/wsoc/helpers/rendering.rb

Instance Method Summary collapse

Instance Method Details

#json(obj) ⇒ String

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

Examples:

json @specs

Parameters:

  • obj (Object)

    The object to encode.

Returns:

  • (String)

    The JSON encoded object.

Since:

  • 0.1.0



83
84
85
86
87
88
# 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 = {}) ⇒ String

Renders a partial template.

Examples:

partial :course_include

Parameters:

  • page (Symbol)

    The name of the partial template.

  • options (Hash) (defaults to: {})

    Additional options.

Returns:

  • (String)

    The rendered partial.

Since:

  • 0.1.0



44
45
46
# File 'lib/wsoc/helpers/rendering.rb', line 44

def partial(page,options={})
  erb "_#{page}".to_sym, options.merge(:layout => false)
end

#show(page, options = {}) ⇒ String

Renders a page.

Examples:

show :course_fail

Parameters:

  • page (Symbol)

    Name of the page to render.

  • options (Hash) (defaults to: {})

    Additional options.

Returns:

  • (String)

    The rendered page.

Since:

  • 0.1.0



65
66
67
# File 'lib/wsoc/helpers/rendering.rb', line 65

def show(page,options={})
  erb(page,options)
end

#yaml(obj) ⇒ String

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

Examples:

yaml @specs

Parameters:

  • obj (Object)

    The object to encode.

Returns:

  • (String)

    The YAML encoded object.

Since:

  • 0.1.0



104
105
106
107
108
# File 'lib/wsoc/helpers/rendering.rb', line 104

def yaml(obj)
  content_type :yaml

  return YAML.dump(obj)
end