Sha256: 9fe1966bd93449e4572a257a78bc39f146282685e9c156dd02c6ab63137affaf

Contents?: true

Size: 890 Bytes

Versions: 35

Compression:

Stored size: 890 Bytes

Contents

module WithEditor
  extend ActiveSupport::Concern

  included do
    enum editor: [:code, :upload, :text, :single_choice, :multiple_choice, :hidden, :multiple_files, :custom]
    validate :ensure_has_choices, if: :choice?
  end

  def choice?
    [:single_choice, :multiple_choice].include? editor.to_sym
  end

  def editor_with_defaults?
    code?
  end

  def pretty_choices
    choices.each_with_index.map do |choice, index|
      struct id: "content_choice_#{index}",
             index: index,
             value: choice,
             text: Mumukit::ContentType::Markdown.to_html(choice_text(choice))
    end
  end

  private

  def choice_text(choice)
    if language.name != 'text'
      Mumukit::ContentType::Markdown.inline_code choice
    else
      choice
    end
  end

  def ensure_has_choices
    errors.add(:base, :choice_problem_has_no_choices) if choices.blank?
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
mumuki-laboratory-5.10.4 app/models/concerns/with_editor.rb
mumuki-laboratory-5.10.3 app/models/concerns/with_editor.rb
mumuki-laboratory-5.10.2 app/models/concerns/with_editor.rb
mumuki-laboratory-5.10.1 app/models/concerns/with_editor.rb
mumuki-laboratory-5.10.0 app/models/concerns/with_editor.rb
mumuki-laboratory-5.9.1 app/models/concerns/with_editor.rb
mumuki-laboratory-5.9.0 app/models/concerns/with_editor.rb
mumuki-laboratory-5.8.3 app/models/concerns/with_editor.rb
mumuki-laboratory-5.8.1 app/models/concerns/with_editor.rb
mumuki-laboratory-5.8.0 app/models/concerns/with_editor.rb
mumuki-laboratory-5.7.0 app/models/concerns/with_editor.rb
mumuki-laboratory-5.6.3 app/models/concerns/with_editor.rb
mumuki-laboratory-5.6.2 app/models/concerns/with_editor.rb
mumuki-laboratory-5.6.1 app/models/concerns/with_editor.rb
mumuki-laboratory-5.6.0 app/models/concerns/with_editor.rb
mumuki-laboratory-5.5.0 app/models/concerns/with_editor.rb
mumuki-laboratory-5.4.0 app/models/concerns/with_editor.rb
mumuki-laboratory-5.3.0 app/models/concerns/with_editor.rb
mumuki-laboratory-5.2.1 app/models/concerns/with_editor.rb
mumuki-laboratory-5.2.0 app/models/concerns/with_editor.rb