Module: Course::ControllerHelper

Includes:
LeaderboardsHelper, LessonPlan::TodosHelper
Defined in:
app/helpers/course/controller_helper.rb

Instance Method Summary collapse

Methods included from LeaderboardsHelper

#display_user_count, #leaderboard_position

Methods included from Achievement::AchievementsHelper

#achievement_badge_path, #display_achievement_badge

Methods included from LessonPlan::TodosHelper

#todo_status_class

Instance Method Details

#display_course_logo(course) ⇒ String

Helper method to display the course logo. If logo is present, returns the medium version of the logo (see ImageUploader for more versions). Otherwise, returns the default course logo.

Returns:

  • (String)

    HTML string to render the course logo


81
82
83
84
85
# File 'app/helpers/course/controller_helper.rb', line 81

def (course)
  (:span, class: ['image']) do
    image_tag(course..medium.url || 'course_default_logo.svg')
  end
end

#display_course_user(user) ⇒ String

Formats the given +CourseUser+ as a user-visible string.

Parameters:

Returns:

  • (String)

    The user-visible string to represent the User, suitable for rendering as output.


11
12
13
# File 'app/helpers/course/controller_helper.rb', line 11

def display_course_user(user)
  user.name
end

#display_course_user_badge(course_user) ⇒ String

Display the course_user_badge given the course_user

Parameters:

  • course_user (CourseUser)

    The CourseUser for which the badge is to be displayed

Returns:

  • (String)

    HTML string to render the course_user_badge


71
72
73
74
# File 'app/helpers/course/controller_helper.rb', line 71

def display_course_user_badge(course_user)
  render partial: 'layouts/course_user_badge',
         locals: { course_user: course_user }
end

#display_user(user) ⇒ String

Formats the given +User+ as a user-visible string. If the current user is a course_user in the course, the course_user.name would be used instead.

Parameters:

Returns:

  • (String)

    The user-visible string to represent the User, suitable for rendering as output.


21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/course/controller_helper.rb', line 21

def display_user(user)
  return nil unless user
  return display_course_user(user) if user.is_a?(CourseUser)

  course_user = user.course_users.find_by(course: controller.current_course)
  if course_user
    display_course_user(course_user)
  else
    super(user)
  end
end

Links to the given +CourseUser+.

Parameters:

  • user (CourseUser)

    The User to display.

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

    The options to pass to +link_to+

Yields:

  • The user will be yielded to the provided block, and the block can override the display of the User.

Yield Parameters:

  • user (User)

    The user to display.

Returns:

  • (String)

    The user-visible string, including embedded HTML which will display the string within a link to bring to the User page.


42
43
44
45
46
# File 'app/helpers/course/controller_helper.rb', line 42

def link_to_course_user(user, options = {})
  link_text = capture { block_given? ? yield(user) : display_course_user(user) }
  link_path = course_user_path(user.course, user)
  link_to(link_text, link_path, options)
end

Links to the given User or CourseUser. If a User is given, the CourseUser under current_course of the given user will be displayed.

Parameters:

  • user (CourseUser|User)

    The CourseUser/User to display.

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

    The options to pass to +link_to+

  • block (Proc)

    The block to use for displaying the user.

Returns:

  • (String)

    The user-visible string, including embedded HTML which will display the string within a link to bring to the User page.


56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/course/controller_helper.rb', line 56

def link_to_user(user, options = {}, &block)
  return link_to_course_user(user, options, &block) if user.is_a?(CourseUser)

  course_user = user.course_users.find_by(course: controller.current_course)
  if course_user
    link_to_course_user(course_user, options, &block)
  else
    super(user, options, &block)
  end
end