source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/application_component.rb
Ruby
mit
4,370
main
355
class ApplicationComponent < ViewComponent::Base include Turbo::FramesHelper delegate :inline_svg_tag, :inline_svg, to: :helpers class << self attr_reader :class_variants def style(&) @class_variants = ClassVariants.build(&) end end def classes_for(slot) self.class.class_variants.ren...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/announcement_component.rb
Ruby
mit
4,370
main
269
class AnnouncementComponent < ApplicationComponent def initialize(announcement:, closeable: true) @announcement = announcement @closeable = closeable end def render? announcement.present? end private attr_reader :announcement, :closeable end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/lesson_group_component.rb
Ruby
mit
4,370
main
247
class LessonGroupComponent < ApplicationComponent def initialize(title:, lessons:, current_user: nil) @title = title @lessons = lessons @current_user = current_user end private attr_reader :title, :lessons, :current_user end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/sections/lesson_component.rb
Ruby
mit
4,370
main
487
module Sections class LessonComponent < ApplicationComponent def initialize(lesson:, current_user:, classes: '') @lesson = lesson @current_user = current_user @classes = classes end private attr_reader :lesson, :current_user, :classes def icon if lesson.is_project? ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/progress_circle/component.rb
Ruby
mit
4,370
main
966
class ProgressCircle::Component < ApplicationComponent renders_one :icon style do variant type: :default do slot :text, class: 'text-xs sm:text-sm' slot :container_size, class: 'h-24 w-24 sm:h-28 sm:w-28' slot :icon_size, class: 'w-20 h-20 sm:p-2 sm:w-24 sm:h-24' end variant type: :s...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/progress_circle/loading_component.rb
Ruby
mit
4,370
main
387
class ProgressCircle::LoadingComponent < ApplicationComponent style do variant type: :default do slot :container_size, class: 'h-24 w-24 sm:h-28 sm:w-28' end variant type: :small do slot :container_size, class: 'h-24 w-24' end end def initialize(size: :default) @size = size end...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/forms/date_picker_component.rb
Ruby
mit
4,370
main
366
class Forms::DatePickerComponent < ApplicationComponent def initialize(name:, value:, min: nil, max: nil) @name = name @value = value @min = min @max = max end def min_date [min, value].compact.min end def max_date return max if max.present? Time.zone.today.to_s end private...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/Ui/badge_component.rb
Ruby
mit
4,370
main
591
class Ui::BadgeComponent < ApplicationComponent def initialize(color:) @color = color end def color_classes case color when 'yellow' 'bg-yellow-50 text-yellow-700 ring-yellow-600/20 ' \ 'dark:bg-yellow-400/10 dark:text-yellow-500 dark:ring-yellow-400/20' when 'green' 'bg-green-5...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/user/learning_goal_component.rb
Ruby
mit
4,370
main
493
class User::LearningGoalComponent < ApplicationComponent def initialize(current_user:) @current_user = current_user end def learning_goal current_user.learning_goal.presence || settings_link end private attr_reader :current_user def settings_link link_to( "What's your learning goal?"...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/user/profile_dropdown_component.rb
Ruby
mit
4,370
main
247
class User::ProfileDropdownComponent < ApplicationComponent include Turbo::FramesHelper delegate :current_theme, to: :helpers def initialize(current_user:) @current_user = current_user end private attr_reader :current_user end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/user/avatar_component.rb
Ruby
mit
4,370
main
209
class User::AvatarComponent < ApplicationComponent def initialize(current_user:, classes:) @current_user = current_user @classes = classes end private attr_reader :current_user, :classes end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/paths/view_button_component.rb
Ruby
mit
4,370
main
359
module Paths class ViewButtonComponent < ApplicationComponent def initialize(current_user:, path:, classes: '') @current_user = current_user @path = path @classes = classes end def render? current_user.blank? || !current_user.on_path?(path) end private attr_reader :c...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/paths/select_button_component.rb
Ruby
mit
4,370
main
331
module Paths class SelectButtonComponent < ApplicationComponent def initialize(current_user:, path:, classes: '') @current_user = current_user @path = path @classes = classes end def render? current_user.present? end private attr_reader :current_user, :path, :classes...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/charts/line_chart_component.rb
Ruby
mit
4,370
main
785
class Charts::LineChartComponent < ApplicationComponent def initialize(labels:, datasets:, options: {}, display_x_labels: true) @labels = labels @datasets = datasets @options = options @display_x_labels = ActiveModel::Type::Boolean.new.cast(display_x_labels) end def data { labels:, ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/charts/horizontal_bar_chart_component.rb
Ruby
mit
4,370
main
839
class Charts::HorizontalBarChartComponent < ApplicationComponent NORMAL_BAR_THICKNESS = 25 SMALL_DATASET_BAR_THICKNESS = 40 def initialize(labels:, datasets:, options: {}) @labels = labels @datasets = datasets @options = options end def data { labels:, datasets: } end de...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/team/former_member_component.rb
Ruby
mit
4,370
main
272
module Team class FormerMemberComponent < ApplicationComponent FormerTeamMember = Data.define(:name, :image, :url) def initialize(team_member) @team_member = FormerTeamMember.new(**team_member) end private attr_reader :team_member end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/team/member_component.rb
Ruby
mit
4,370
main
725
module Team class MemberComponent < ApplicationComponent Social = Data.define(:name, :url) TeamMember = Data.define(:name, :image, :location, :joined, :socials) do def initialize(**args) socials = args.fetch(:socials, []).map { |social| Social.new(**social) } location = args.fetch(:loca...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/complete/icon_component.rb
Ruby
mit
4,370
main
376
class Complete::IconComponent < ApplicationComponent def initialize(lesson:, current_user:, animate: false) @lesson = lesson @current_user = current_user @animate = animate end def render? current_user.present? end private attr_reader :lesson, :current_user, :animate def animation_clas...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/vertical_navigation/item_component.rb
Ruby
mit
4,370
main
942
class VerticalNavigation::ItemComponent < ApplicationComponent style do variant type: :active do slot :link, class: 'bg-gray-200 text-gray-900 dark:bg-gray-700/50 dark:text-gray-300' slot :icon, class: 'text-gray-500 group-hover:text-gray-700 dark:text-gray-300 dark:group-hover:text-gray-300' end ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/overlays/flash_component.rb
Ruby
mit
4,370
main
1,045
class Overlays::FlashComponent < ApplicationComponent DISALLOWED_TYPES = %i[timedout].freeze style do variant type: :notice do slot :bg, class: 'bg-green-100' slot :icon, class: 'text-green-700' slot :text, class: 'text-green-900' slot :button, class: 'bg-green-100 text-green...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/course/badge_component.rb
Ruby
mit
4,370
main
910
class Course::BadgeComponent < ApplicationComponent delegate :user_signed_in?, to: :helpers style do variant type: :default do slot :default_badge, class: 'w-24 h-24 sm:w-28 sm:h-28' end variant type: :small do slot :default_badge, class: 'w-24 h-24' end end def initialize(course:...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/oauth/connect_button_component.rb
Ruby
mit
4,370
main
344
module Oauth class ConnectButtonComponent < ApplicationComponent with_collection_parameter :provider delegate :omniauth_authorize_path, to: :helpers def initialize(provider:, resource_name:) @provider = provider @resource_name = resource_name end private attr_reader :provider, :...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/markdown/preview_component.rb
Ruby
mit
4,370
main
415
class Markdown::PreviewComponent < ApplicationComponent def initialize(markdown: '') @markdown = markdown end def allowed_tags Rails::HTML5::SafeListSanitizer::DEFAULT_ALLOWED_TAGS + %w[details summary section table thead tbody tr th td] end def allowed_attributes Rails::HTML5::SafeListSanitizer...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/theme/switcher_component.rb
Ruby
mit
4,370
main
1,309
class Theme::SwitcherComponent < ApplicationComponent style do base do slot :link, class: 'text-gray-600 group flex items-center dark:text-gray-300' slot :icon, class: 'h-5 w-5 text-gray-400 group-hover:text-gray-500 dark:text-gray-300 dark:group-hover:text-gray-300' end variant ty...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/project_submissions/item_component.rb
Ruby
mit
4,370
main
336
module ProjectSubmissions class ItemComponent < ApplicationComponent with_collection_parameter :project_submission def initialize(project_submission:) @project_submission = project_submission end def render? project_submission.present? end private attr_reader :project_submi...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/project_submissions/user_solution_component.rb
Ruby
mit
4,370
main
344
module ProjectSubmissions class UserSolutionComponent < ApplicationComponent with_collection_parameter :project_submission def initialize(project_submission:) @project_submission = project_submission end def render? project_submission.present? end private attr_reader :proje...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/project_submissions/like_component.rb
Ruby
mit
4,370
main
643
module ProjectSubmissions class LikeComponent < ApplicationComponent def initialize(project_submission:, current_users_submission: false) @project_submission = project_submission @current_users_submission = current_users_submission end private attr_reader :project_submission, :current_us...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/components/nav/item_component.rb
Ruby
mit
4,370
main
464
class Nav::ItemComponent < ApplicationComponent def initialize(path:, text:, test_id:, icon_path: nil, options: {}) @path = path @text = text @test_id = test_id @icon_path = icon_path @options = options end def active? current_page?(path) end private attr_reader :path, :text, :tes...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/lesson_completion.rb
Ruby
mit
4,370
main
285
class LessonCompletion < ApplicationRecord belongs_to :user belongs_to :lesson belongs_to :course, optional: true belongs_to :path, optional: true validates :user_id, uniqueness: { scope: :lesson_id } scope :completed_on, ->(date) { where(created_at: date.all_day) } end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/announcement.rb
Ruby
mit
4,370
main
1,091
class Announcement < ApplicationRecord include PublicActivity::Common belongs_to :created_by, class_name: 'AdminUser', inverse_of: :announcements validates :message, presence: true validates :message, length: { maximum: 100 } validates :expires_at, presence: true validates :learn_more_url, url: true, allo...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/path.rb
Ruby
mit
4,370
main
810
class Path < ApplicationRecord extend FriendlyId friendly_id :title, use: %i[slugged history finders] has_many :users, dependent: :nullify has_many :courses, -> { order(:position) }, dependent: :destroy, inverse_of: :path has_many :lessons, through: :courses has_many :path_prerequisites, dependent: :destr...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/application_record.rb
Ruby
mit
4,370
main
262
class ApplicationRecord < ActiveRecord::Base self.abstract_class = true def self.ransackable_attributes(_ = nil) authorizable_ransackable_attributes end def self.ransackable_associations(_ = nil) authorizable_ransackable_associations end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/point.rb
Ruby
mit
4,370
main
319
class Point < ApplicationRecord LOWEST_ALLOWED_INCREMENT = 1 MAX_ALLOWED_INCREMENT = 5 validates :discord_id, presence: true, uniqueness: true def increment_points_by(value) return unless value.between?(LOWEST_ALLOWED_INCREMENT, MAX_ALLOWED_INCREMENT) update!(points: self.points += value) end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/user.rb
Ruby
mit
4,370
main
2,548
class User < ApplicationRecord include PgSearch::Model before_create :enroll_in_foundations devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :omniauthable, omniauth_providers: %i[github google] validates :email, uniqueness: true, format...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/flag.rb
Ruby
mit
4,370
main
1,515
class Flag < ApplicationRecord Reason = Data.define(:name, :description, :value) REASONS = [ { name: :broken, description: 'Link does not work', value: 10 }, { name: :insecure, description: 'Link is not secure or safe', value: 20 }, { name: :spam, description: 'Spam or misleading', value: 30 }, { n...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/interview_survey.rb
Ruby
mit
4,370
main
413
class InterviewSurvey < ApplicationRecord belongs_to :user has_many :interview_survey_concepts, dependent: :destroy validates :interview_date, presence: true validate :interview_date_must_be_in_the_past def interview_date_must_be_in_the_past return if interview_date.present? && interview_date <= Time.zo...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/lesson.rb
Ruby
mit
4,370
main
1,261
class Lesson < ApplicationRecord extend FriendlyId friendly_id :slug_candidates, use: %i[slugged history finders] belongs_to :section has_one :course, through: :section has_one :path, through: :course has_one :content, dependent: :destroy has_many :project_submissions, dependent: :destroy has_many :le...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/project_submission.rb
Ruby
mit
4,370
main
1,326
class ProjectSubmission < ApplicationRecord include Discard::Model include Likeable before_update do self.discard_at = nil if repo_url_changed? || live_preview_url_changed? end belongs_to :user belongs_to :lesson has_many :flags, dependent: :destroy validates :repo_url, url: true validates :liv...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/admin_user.rb
Ruby
mit
4,370
main
2,103
class AdminUser < ApplicationRecord include TwoFactorAuthenticatable include PublicActivity::Common include AASM enum :status, %w[pending activated deactivated pending_reactivation].index_by(&:itself) enum :role, %w[moderator maintainer core].index_by(&:itself) devise :two_factor_authenticatable devise ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/course.rb
Ruby
mit
4,370
main
591
class Course < ApplicationRecord extend FriendlyId friendly_id :title, use: %i[scoped slugged history finders], scope: :path belongs_to :path has_many :sections, -> { order(:position) }, dependent: :destroy, inverse_of: :course has_many :lessons, through: :sections validates :position, presence: true ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/like.rb
Ruby
mit
4,370
main
301
class Like < ApplicationRecord belongs_to :user belongs_to :likeable, polymorphic: true, counter_cache: true validates :user_id, uniqueness: { scope: %i[likeable_id likeable_type] } validates :likeable_type, presence: true scope :liked_on, ->(date) { where(created_at: date.all_day) } end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/concerns/two_factor_authenticatable.rb
Ruby
mit
4,370
main
556
module TwoFactorAuthenticatable extend ActiveSupport::Concern def generate_two_factor_secret_if_missing! return if otp_secret.present? update!(otp_secret: self.class.generate_otp_secret) end def two_factor_qr_code_uri otp_provisioning_uri(email, issuer: 'The Odin Project') end def enable_two...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/concerns/likeable.rb
Ruby
mit
4,370
main
456
module Likeable extend ActiveSupport::Concern included do has_many :likes, as: :likeable, dependent: :destroy attribute :liked, :boolean, default: false end def liked_by?(user) likes.exists?(user:) end def like(user) likes.find_or_create_by(user:) liked! end def unlike(user) ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/concerns/materialized_view.rb
Ruby
mit
4,370
main
239
module MaterializedView extend ActiveSupport::Concern class_methods do def refresh Scenic.database.refresh_materialized_view(table_name, concurrently: false, cascade: false) end end def readonly? true end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/omniauth_providers/finder.rb
Ruby
mit
4,370
main
874
module OmniauthProviders class Finder attr_reader :auth private :auth def initialize(auth) @auth = auth end def self.find(auth) new(auth).find end def find return omniauth_provider if omniauth_provider.present? new_user_provider end private def omn...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/omniauth_providers/builder.rb
Ruby
mit
4,370
main
376
module OmniauthProviders class Builder def initialize(auth, user) @auth = auth @user = user end def build UserProvider.create!(provider_attributes) end private attr_reader :auth, :user def provider_attributes { provider: auth.provider, uid: auth....
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/users/theme.rb
Ruby
mit
4,370
main
658
module Users class Theme include Comparable DEFAULT_THEMES = [ %w[light moon], %w[dark sun] ].freeze def self.default_themes DEFAULT_THEMES.map { |name, icon| new(name:, icon:) } end def self.exists?(theme) default_themes.map(&:name).include?(theme) end def ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/reports/path_lesson_completions_day_stat.rb
Ruby
mit
4,370
main
902
class Reports::PathLessonCompletionsDayStat < ApplicationRecord include MaterializedView belongs_to :path belongs_to :course scope :for_date_range, ->(start_date, end_date) { where(date: start_date..end_date) } scope :group_by_lesson, lambda { group(:lesson_title, :lesson_id, :lesson_position, :course_...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/reports/all_lesson_completions_day_stat.rb
Ruby
mit
4,370
main
504
class Reports::AllLessonCompletionsDayStat < ApplicationRecord include MaterializedView scope :for_date_range, ->(start_date, end_date) { where(date: start_date..end_date) } scope :group_by_period, lambda { |period| group("DATE_TRUNC('#{period}', date)") .order(Arel.sql("DATE_TRUNC('#{period}', date) ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/reports/period.rb
Ruby
mit
4,370
main
405
class Reports::Period include Comparable VALID_PERIODS = %w[day month year].freeze attr_reader :name def initialize(name) @name = name end def self.all VALID_PERIODS.map { |period| new(period) } end def self.find(value) all.find { |period| period == new(value) } end def <=>(other) ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/reports/user_sign_ups_day_stat.rb
Ruby
mit
4,370
main
492
class Reports::UserSignUpsDayStat < ApplicationRecord include MaterializedView scope :for_date_range, ->(start_date, end_date) { where(date: start_date..end_date) } scope :group_by_period, lambda { |period| group("DATE_TRUNC('#{period}', date)") .order(Arel.sql("DATE_TRUNC('#{period}', date) ASC")) ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/flags/action_factory.rb
Ruby
mit
4,370
main
413
class Flags::ActionFactory def initialize(action) @action = action.to_sym end def self.for(action) new(action).action end def action { dismiss: Flags::Actions::Dismiss, ban: Flags::Actions::Ban, removed_project_submission: Flags::Actions::RemoveProjectSubmission, notified...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/flags/action.rb
Ruby
mit
4,370
main
297
Flags::Action = Data.define(:value, :name, :description, :past_tense) do include Enumerable def self.all I18n.t('flag_actions').map { |action| new(**action) } end def self.each(&) all.each(&) end def self.for(value) all.find { |action| action.value == value } end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/flags/actions/ban.rb
Ruby
mit
4,370
main
379
class Flags::Actions::Ban < Flags::Actions::Base def perform flag.project_submission_owner.ban! flag.resolve(action_taken: :ban, resolved_by: admin_user) if flag.resolved? Result.new(success: true, message: 'Project submission owner has been banned') else Result.new(success: false, messag...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/flags/actions/dismiss.rb
Ruby
mit
4,370
main
322
class Flags::Actions::Dismiss < Flags::Actions::Base def perform flag.resolve(action_taken: :dismiss, resolved_by: admin_user) if flag.resolved? Result.new(success: true, message: 'Flag dismissed') else Result.new(success: false, message: flag.errors.full_messages.join(', ')) end end en...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/flags/actions/notify_user.rb
Ruby
mit
4,370
main
804
class Flags::Actions::NotifyUser < Flags::Actions::Base def perform # rubocop:disable Metrics/AbcSize ActiveRecord::Base.transaction do flag.project_submission.update!(discard_at: 7.days.from_now) flag.resolve(action_taken: :notified_user, resolved_by: admin_user) end if flag.resolved? ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/flags/actions/remove_project_submission.rb
Ruby
mit
4,370
main
456
class Flags::Actions::RemoveProjectSubmission < Flags::Actions::Base def perform ActiveRecord::Base.transaction do flag.project_submission.discard flag.resolve(action_taken: :removed_project_submission, resolved_by: admin_user) end if flag.resolved? Result.new(success: true, message: '...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/flags/actions/base.rb
Ruby
mit
4,370
main
461
class Flags::Actions::Base def initialize(admin_user:, flag:) @admin_user = admin_user @flag = flag end def self.perform(**) new(**).perform end def perform raise NotImplementedError end private attr_reader :admin_user, :flag class Result attr_reader :message def initiali...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/notifications/flag_notification.rb
Ruby
mit
4,370
main
323
class Notifications::FlagNotification < Noticed::Base deliver_by :database, format: :to_database def to_database { type: self.class.name, params: params[:flag], url: params[:url], message: params[:message], title: params[:title] } end param :flag, :url, :message, :title e...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/github/push_event.rb
Ruby
mit
4,370
main
274
class Github::PushEvent def initialize(payload) @payload = payload end def merged_to_main? payload[:ref] == 'refs/heads/main' end def modified_urls payload[:head_commit][:modified].map { |url| "/#{url}" } end private attr_reader :payload end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/models/github/lesson_content_importer.rb
Ruby
mit
4,370
main
1,293
class Github::LessonContentImporter def initialize(lesson) @lesson = lesson @content = lesson.content || lesson.build_content end def self.for(lesson) new(lesson).import end def self.import_all total = Lesson.count Rails.logger.info 'Importing lesson content...' Lesson.all.each_wit...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/jobs/refresh_materialized_views_job.rb
Ruby
mit
4,370
main
247
class RefreshMaterializedViewsJob < ApplicationJob queue_as :default def perform [ Reports::AllLessonCompletionsDayStat, Reports::PathLessonCompletionsDayStat, Reports::UserSignUpsDayStat ].each(&:refresh) end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/jobs/lessons/update_content_job.rb
Ruby
mit
4,370
main
211
module Lessons class UpdateContentJob < ApplicationJob def perform(github_paths) lessons = Lesson.where(github_path: github_paths) lessons.each(&:import_content_from_github) end end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/views/sitemap/index.xml.builder
Ruby
mit
4,370
main
976
xml.instruct! xml.urlset( 'xmlns'.to_sym => "http://www.sitemaps.org/schemas/sitemap/0.9", 'xmlns:image'.to_sym => "http://www.google.com/schemas/sitemap-image/1.1" ) do # Root xml.url do xml.loc "#{root_url}" xml.changefreq("daily") xml.priority(1.00) end @static_pages.each do |page| xml....
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/builders/tailwind_form_builder.rb
Ruby
mit
4,370
main
4,587
class TailwindFormBuilder < ActionView::Helpers::FormBuilder # rubocop:disable Layout/LineLength TEXT_FIELD_CLASSES = ClassVariants.build( base: 'block w-full border rounded-md py-2 px-3 focus:outline-hidden dark:bg-gray-700/50 dark:border-gray-500 dark:text-gray-300 dark:placeholder-gray-400 dark:focus:ring-2 ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/helpers/button_helper.rb
Ruby
mit
4,370
main
501
module ButtonHelper def sign_up_button link_to 'Sign up', sign_up_path, class: 'button button--primary' end def curriculum_button link_to 'View curriculum', paths_path, class: 'button button--primary text-base' end def contribute_button link_to 'Learn how to contribute', contributing_path, class...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/helpers/application_helper.rb
Ruby
mit
4,370
main
790
module ApplicationHelper require 'kramdown' include Pagy::Frontend def github_link(extension = '') "https://github.com/TheOdinProject/#{extension}" end def title(input = nil) content_for(:title) { "#{input} | The Odin Project" } if input end def sign_up_or_view_curriculum_button if current_...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/helpers/qr_code_helper.rb
Ruby
mit
4,370
main
239
module QrCodeHelper def qr_code_as_svg(uri) RQRCode::QRCode.new(uri).as_svg( offset: 0, color: '000', shape_rendering: 'crispEdges', module_size: 4, standalone: true, viewbox: true ) end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/helpers/announcement_helper.rb
Ruby
mit
4,370
main
256
module AnnouncementHelper def disabled_announcement_ids announcement_cookies.filter_map { |cookie| cookie[1].to_i } end private def announcement_cookies cookies.filter_map { |name, _| name.match(/^announcement_(\d+)/) }.compact end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/helpers/lessons_helper.rb
Ruby
mit
4,370
main
543
module LessonsHelper def github_edit_url(lesson) github_link("curriculum/edit/main#{lesson.github_path}") end def github_commits_url(lesson) github_link("curriculum/commits/main#{lesson.github_path}") end def github_report_url(lesson, template) params = { labels: 'Status: Needs Triage', ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/policies/admin_user_policy.rb
Ruby
mit
4,370
main
456
class AdminUserPolicy def initialize(admin_user) @admin_user = admin_user end def change_role? admin_user.core? end def invite? admin_user.core? || admin_user.maintainer? end def deactivate? admin_user.core? end def reactivate? admin_user.core? || admin_user.maintainer? end ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/policies/submission_like_policy.rb
Ruby
mit
4,370
main
386
class SubmissionLikePolicy def initialize(user) @user = user end def allowed? return true if @user.project_submissions.any? no_recent_accounts_with_same_ip? end private def no_recent_accounts_with_same_ip? User .created_after(1.week.ago) .where(last_sign_in_ip: @user.current_...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/notifications_controller.rb
Ruby
mit
4,370
main
407
class NotificationsController < ApplicationController before_action :authenticate_user! def index @notifications = current_user.notifications end def update notification = current_user.notifications.find(params[:id]) if notification.mark_as_read! redirect_to notification.url else ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/courses_controller.rb
Ruby
mit
4,370
main
496
class CoursesController < ApplicationController before_action :set_cache_control_header_to_no_store def show @path = Path.find(params[:path_id]) @course = @path.courses.friendly.find(params[:id]) @sections = @course.sections.includes(:lessons) mark_completed_lessons end private def mark_co...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/lessons_controller.rb
Ruby
mit
4,370
main
367
class LessonsController < ApplicationController before_action :set_cache_control_header_to_no_store def show @lesson = Lesson.find(params[:id]) if user_signed_in? @project_submission = current_user.project_submissions.find_by(lesson: @lesson) Courses::MarkCompletedLessons.call(user: current_us...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/paths_controller.rb
Ruby
mit
4,370
main
314
class PathsController < ApplicationController def index @foundations = Path.default_path @fullstack_paths = Path.fullstack_paths end def show @path = Path.friendly.find(params[:id]) if @path.courses.size == 1 redirect_to path_course_path(@path, @path.courses.first) end end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/application_controller.rb
Ruby
mit
4,370
main
1,313
class ApplicationController < ActionController::Base include CurrentTheme include Pagy::Backend extend RequiresFeature before_action :configure_permitted_parameters, if: :devise_controller? before_action :set_sentry_user, if: :current_user before_action :store_user_location!, if: :storable_location? res...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/errors_controller.rb
Ruby
mit
4,370
main
303
class ErrorsController < ActionController::Base # rubocop:disable Rails/ApplicationController def not_found render status: :not_found end def unprocessable_entity render status: :unprocessable_content end def internal_server_error render status: :internal_server_error end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/themes_controller.rb
Ruby
mit
4,370
main
579
class ThemesController < ApplicationController before_action :cache_previous_theme def update @new_theme = Users::Theme.for(params[:theme]) respond_to do |format| if @new_theme.present? change_current_theme(params[:theme]) format.turbo_stream else flash.now[:alert] = "...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/sitemap_controller.rb
Ruby
mit
4,370
main
287
class SitemapController < ApplicationController def index @static_pages = static_pages @courses = Course.all respond_to do |format| format.xml end end private def static_pages [root_url, about_url, faq_url, sign_in_url, sign_up_url].freeze end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/static_pages_controller.rb
Ruby
mit
4,370
main
344
class StaticPagesController < ApplicationController def home @landing_page = true @success_stories = SuccessStory.limit(4) @courses = Course.badges end def about; end def faq; end def team; end def terms_of_use; end def privacy_policy; end def success_stories @success_stories = Suc...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/interview_surveys_controller.rb
Ruby
mit
4,370
main
218
class InterviewSurveysController < ApplicationController requires_feature :survey_feature def new; end def create # puts params[:survey] redirect_to dashboard_path, notice: 'Survey Submitted' end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/users_controller.rb
Ruby
mit
4,370
main
248
class UsersController < ApplicationController before_action :authenticate_user! def show @courses = current_user.path.courses @project_submissions = current_user.project_submissions.includes(:lesson).order(created_at: :desc) end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/concerns/current_theme.rb
Ruby
mit
4,370
main
450
module CurrentTheme extend ActiveSupport::Concern included do before_action :set_default helper_method :current_theme end private def set_default return if cookies[:theme].present? cookies.permanent[:theme] = 'light' end def change_current_theme(theme) cookies.permanent[:theme] =...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/concerns/requires_feature.rb
Ruby
mit
4,370
main
249
module RequiresFeature def requires_feature(name, **) before_action( lambda do return if Feature.enabled?(name, current_user) redirect_to dashboard_path, notice: 'Feature not enabled' end, ** ) end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/concerns/two_factor_authentication.rb
Ruby
mit
4,370
main
1,391
module TwoFactorAuthentication extend ActiveSupport::Concern included do before_action :authenticate_with_two_factor, if: :two_factor_enabled?, only: [:create] end private def two_factor_enabled? resource = find_resource resource&.two_factor_enabled? end def authenticate_with_two_factor ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/concerns/sortable.rb
Ruby
mit
4,370
main
263
module Sortable extend ActiveSupport::Concern def sort_column_for(klass) params[:sort].presence_in(klass.sortable_columns) || 'created_at' end def sort_direction(default: 'desc') params[:direction].presence_in(%w[asc desc]) || default end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/lessons/project_submissions_controller.rb
Ruby
mit
4,370
main
2,530
module Lessons class ProjectSubmissionsController < ApplicationController include Sortable before_action :authenticate_user! before_action :set_lesson before_action :can_add_solution def index project_submissions = @lesson .project_submissions .only_public .sort_by_...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/lessons/previews_controller.rb
Ruby
mit
4,370
main
324
module Lessons class PreviewsController < ApplicationController def show @preview = LessonPreview.find_or_initialize_by(id: params[:uuid]) end def create @preview = LessonPreview.new(content: params[:markdown]) respond_to do |format| format.turbo_stream end end end ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/lessons/completions_controller.rb
Ruby
mit
4,370
main
1,398
module Lessons class CompletionsController < ApplicationController before_action :authenticate_user! # rubocop: disable Metrics/MethodLength def create @lesson = Lesson.find(params[:lesson_id]) lesson_completion = current_user.lesson_completions.find_or_create_by!( lesson: @lesson, ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/lessons/previews/share_controller.rb
Ruby
mit
4,370
main
503
module Lessons module Previews class ShareController < ApplicationController def create @preview = LessonPreview.new(content: params[:content]) respond_to do |format| if @preview.save format.turbo_stream else flash.now[:alert] = 'Unable to share p...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/courses/progress_controller.rb
Ruby
mit
4,370
main
752
module Courses class ProgressController < ApplicationController before_action :authenticate_user! before_action :course, only: :show before_action :progress_options, only: :show def show @percentage = @course.progress_for(current_user).percentage end private def course @cour...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/admin/dashboard_controller.rb
Ruby
mit
4,370
main
210
module Admin class DashboardController < Admin::BaseController def show @active_flags_count = Flag.count_for(:active) @active_announcements_count = Announcement.active.count end end end
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/admin/flags_controller.rb
Ruby
mit
4,370
main
641
module Admin class FlagsController < Admin::BaseController def index @pagy, @flags = pagy(Flag.by_status(params.fetch(:status, 'active')).ordered_by_most_recent, items: 20) end def show @flag = Flag.find(params[:id]) end def update @flag = Flag.find(params[:id]) action = ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/admin/team_members_controller.rb
Ruby
mit
4,370
main
835
module Admin class TeamMembersController < Admin::BaseController def index @pending_team_members = AdminUser.awaiting_activation.ordered @active_team_members = AdminUser.activated.ordered @deactivated_team_members = AdminUser.deactivated.ordered end def destroy # rubocop:disable Metrics...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/admin/profile_controller.rb
Ruby
mit
4,370
main
612
module Admin class ProfileController < Admin::BaseController def edit # Use a separate admin user instance to avoid morphing current admin when valildation fails @admin_user = AdminUser.find(current_admin_user.id) end def update @admin_user = AdminUser.find(current_admin_user.id) ...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/admin/sessions_controller.rb
Ruby
mit
4,370
main
497
module Admin class SessionsController < Devise::SessionsController include TwoFactorAuthentication before_action :configure_permitted_parameters, if: :devise_controller? private def after_sign_in_path_for(_resource) admin_dashboard_path end def after_sign_out_path_for(_resource_or_sc...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/admin/passwords_controller.rb
Ruby
mit
4,370
main
369
module Admin class PasswordsController < Devise::PasswordsController def new redirect_to new_admin_user_session_path, alert: 'Please sign in' end def create redirect_to new_admin_user_session_path, alert: 'Please sign in' end private def after_resetting_password_path_for(_resour...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/admin/two_factor_authentication_controller.rb
Ruby
mit
4,370
main
876
module Admin class TwoFactorAuthenticationController < Admin::BaseController skip_before_action :ensure_two_factor_enabled def new if current_admin_user.two_factor_enabled? redirect_to admin_dashboard_path, status: :see_other, alert: 'Two factor authentication is already enabled.' retur...
github
TheOdinProject/theodinproject
https://github.com/TheOdinProject/theodinproject
app/controllers/admin/announcements_controller.rb
Ruby
mit
4,370
main
1,659
module Admin class AnnouncementsController < Admin::BaseController def index @pagy, @announcements = pagy(Announcement .for_status(params.fetch(:status, :active)) .ordered_by_recent, items: 20) end def show @announcement = Announcement.find(params[:id]) end def new ...