Sha256: e951b5232fa16fa254153b34e167036f6916b6b1a48f80126733d6166a6b7970

Contents?: true

Size: 908 Bytes

Versions: 40

Compression:

Stored size: 908 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: 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

40 entries across 40 versions & 2 rubygems

Version Path
mumuki-domain-7.4.1 app/models/concerns/with_editor.rb
mumuki-domain-7.4.0 app/models/concerns/with_editor.rb
mumuki-domain-7.3.2 app/models/concerns/with_editor.rb
mumuki-domain-7.3.1 app/models/concerns/with_editor.rb
mumuki-domain-7.2.3 app/models/concerns/with_editor.rb
mumuki-domain-7.3.0 app/models/concerns/with_editor.rb
mumuki-domain-7.2.2 app/models/concerns/with_editor.rb
mumuki-domain-7.2.1 app/models/concerns/with_editor.rb
mumuki-domain-7.2.0 app/models/concerns/with_editor.rb
mumuki-laboratory-7.1.0 vendor/bundle/ruby/2.3.0/bundler/gems/mumuki-domain-925adf85cca8/app/models/concerns/with_editor.rb
mumuki-domain-7.1.0 app/models/concerns/with_editor.rb
mumuki-laboratory-7.0.12 vendor/bundle/ruby/2.3.0/bundler/gems/mumuki-domain-74da3d4af98c/app/models/concerns/with_editor.rb
mumuki-domain-7.0.6 app/models/concerns/with_editor.rb
mumuki-domain-7.0.5 app/models/concerns/with_editor.rb
mumuki-domain-7.0.4 app/models/concerns/with_editor.rb
mumuki-domain-7.0.3 app/models/concerns/with_editor.rb
mumuki-laboratory-7.0.11 vendor/bundle/ruby/2.3.0/bundler/gems/mumuki-domain-f892f79c60f0/app/models/concerns/with_editor.rb
mumuki-domain-7.0.2 app/models/concerns/with_editor.rb
mumuki-domain-7.0.1 app/models/concerns/with_editor.rb
mumuki-domain-7.0.0 app/models/concerns/with_editor.rb