Sha256: a6f1308bdaafea8f739abd47a3f48c91c7b388d0ef85c2d7ff9b75ff35ca4a85

Contents?: true

Size: 882 Bytes

Versions: 77

Compression:

Stored size: 882 Bytes

Contents

module WithEditor
  extend ActiveSupport::Concern

  included do
    enum editor: [:code, :upload, :text, :single_choice, :multiple_choice, :hidden, :multiple_files, :custom, :free_form]
    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
    choice_values.each_with_index.map do |choice, index|
      struct id: "content_choice_#{index}",
             index: index,
             value: choice,
             text: choice_text(choice).markdownified
    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

77 entries across 77 versions & 2 rubygems

Version Path
mumuki-domain-9.23.0 app/models/concerns/with_editor.rb
mumuki-domain-9.22.1 app/models/concerns/with_editor.rb
mumuki-domain-9.22.0 app/models/concerns/with_editor.rb
mumuki-domain-9.21.0 app/models/concerns/with_editor.rb
mumuki-domain-9.20.0 app/models/concerns/with_editor.rb
mumuki-domain-9.19.0 app/models/concerns/with_editor.rb
mumuki-domain-9.18.0 app/models/concerns/with_editor.rb
mumuki-domain-9.17.0 app/models/concerns/with_editor.rb
mumuki-domain-9.16.0 app/models/concerns/with_editor.rb
mumuki-domain-9.15.0 app/models/concerns/with_editor.rb
mumuki-domain-9.14.1 app/models/concerns/with_editor.rb
mumuki-domain-9.14.0 app/models/concerns/with_editor.rb
mumuki-domain-9.13.1 app/models/concerns/with_editor.rb
mumuki-domain-9.13.0 app/models/concerns/with_editor.rb
mumuki-domain-9.12.0 app/models/concerns/with_editor.rb
mumuki-domain-9.11.0 app/models/concerns/with_editor.rb
mumuki-domain-9.10.0 app/models/concerns/with_editor.rb
mumuki-domain-9.9.0 app/models/concerns/with_editor.rb
mumuki-domain-9.8.1 app/models/concerns/with_editor.rb
mumuki-domain-9.8.0 app/models/concerns/with_editor.rb