Skip to content

Instantly share code, notes, and snippets.

@camertron
Last active December 22, 2015 00:58
Show Gist options
  • Select an option

  • Save camertron/6392632 to your computer and use it in GitHub Desktop.

Select an option

Save camertron/6392632 to your computer and use it in GitHub Desktop.
Dashboard tiles
class DashboardTile
PARAMS = [
:image, :name, :description, :count,
:count_suffix, :status, :url, :url_class
]
PARAMS.each do |param|
define_method(param) { raise NotImplementedError }
define_method(:"#{param}=") { raise NotImplementedError }
end
def initialize(options = {})
PARAMS.each do |param|
public_send(:"#{param}=", options[param])
end
end
end
class LessonTile
def self.build(user)
completed_count = Lesson.completed_by(user).count
total_count = Lesson.for(user.default_locale).count
DashboardTile.new({
image: 'learn/lessons.png',
name: 'Lessons',
description: 'Learn how to use the Twitter Translation Center '\
'and create better translations.',
count: "#{completed_count}/#{total_count}",
count_suffix: 'COMPLETE',
status: completed_count == 0 ? 'Get Started' : 'Continue',
url: lessons_path,
url_class: completed_count >= total_count ? 'disabled' : '',
})
end
end
class FeedbackTile
def self.build(user)
feedback_count = TranslationFeedback.incomplete_for(user).count
DashboardTile.new({
image: 'learn/feedback.png',
name: 'Feedback',
description: 'Which translation do you think is approved for the given phrase?',
count: feedback_count.to_s,
count_suffix: 'AVAILABLE',
status: 'Get Started',
url: translation_feedbacks_path,
url_class: feedback_count == 0 ? 'disabled' : '',
})
end
end
@jakl

jakl commented Aug 30, 2013

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment