Class: ContentModules::LessonModule
- Inherits:
-
BitCore::ContentModule
- Object
- BitCore::ContentModule
- ContentModules::LessonModule
- Defined in:
- app/models/content_modules/lesson_module.rb
Overview
Container for didactic content.
Class Method Summary collapse
Instance Method Summary collapse
- #build_slide(attrs = {}) ⇒ Object
- #destroy_slide(slide) ⇒ Object
- #lesson_provider ⇒ Object
- #plain_title ⇒ Object
- #pretty_title ⇒ Object
- #slides ⇒ Object
- #sort(slide_ids) ⇒ Object
Class Method Details
.sort(arm_id, lesson_ids) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/content_modules/lesson_module.rb', line 6 def self.sort(arm_id, lesson_ids) start_position = Arm.find(arm_id) .bit_core_tools.find_by_type("Tools::Learn") .content_modules .where(type: [nil, "BitCore::ContentModule"]) .order(position: :asc).maximum(:position) start_position ||= 1 start_position += 1 transaction do connection.execute "SET CONSTRAINTS " \ "bit_core_content_module_position DEFERRED" lesson_ids.each_with_index do |id, idx| find(id).update_attribute(:position, idx + start_position) end end end |
Instance Method Details
#build_slide(attrs = {}) ⇒ Object
51 52 53 54 55 |
# File 'app/models/content_modules/lesson_module.rb', line 51 def (attrs = {}) .build(attrs.merge(position: .count + 1)) end |
#destroy_slide(slide) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/models/content_modules/lesson_module.rb', line 57 def () position = .position .transaction do if .destroy! .where("position >= ?", position).each_with_index do |s, i| s.update_column(:position, position + i) end end end true rescue false end |
#lesson_provider ⇒ Object
41 42 43 44 45 |
# File 'app/models/content_modules/lesson_module.rb', line 41 def lesson_provider @lesson_provider ||= (content_providers.first || add_content_provider("BitCore::ContentProviders::SlideshowProvider") ) end |
#plain_title ⇒ Object
35 36 37 38 39 |
# File 'app/models/content_modules/lesson_module.rb', line 35 def plain_title return "" if title.nil? title.gsub(/\*\*/, "") end |
#pretty_title ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/content_modules/lesson_module.rb', line 24 def pretty_title return "" if title.nil? Redcarpet::Markdown.new( Redcarpet::Render::HTML.new( filter_html: true, safe_links_only: true ) ).render(title).html_safe end |
#slides ⇒ Object
47 48 49 |
# File 'app/models/content_modules/lesson_module.rb', line 47 def lesson_provider.try(:source_content).try(:slides) || [] end |
#sort(slide_ids) ⇒ Object
74 75 76 77 78 |
# File 'app/models/content_modules/lesson_module.rb', line 74 def sort() lesson_provider.source_content.sort() end |