mumuki / mumuki-laboratory

:microscope: Where students practice and receive automated and human feedback
http://mumuki.io
GNU Affero General Public License v3.0
203 stars 26 forks source link

Exercise markdown language #756

Closed Charlyzzz closed 7 years ago

Charlyzzz commented 7 years ago

Wollok and Gobstones exercises are being tagged with Javascript and Puppet, hence there would not be any visual change in rouge.

flbulgarelli commented 7 years ago

Add the following script to the migrations directory of a bibliotheca:

def do_migrate!
  Bibliotheca::Collection::Guides.migrate_exercises! do |exercise, guide|
    puts "migrating #{guide.name}/#{exercise.name}..."

    next if !exercise.description.include?('```') || !exercise.corollary&.include?('```')

    case exercise.effective_language_name(guide)
      when 'gobstones' then
        exercise.description = exercise.description.gsub('```puppet', '```gobstones')
        exercise.corollary = exercise.corollary&.gsub('```puppet', '```gobstones')
        print_change exercise
      when 'wollok' then
        exercise.description = exercise.description.gsub('```javascript', '```wollok')
        exercise.corollary = exercise.corollary&.gsub('```javascript', '```wollok')
        print_change exercise
      when 'qsim' then
        exercise.description = exercise.description.gsub(/```\n(.*?)```/m) { "```qsim\n#{$1}```" }
        exercise.corollary = exercise.corollary&.gsub(/```\n(.*?)```/m) { "```qsim\n#{$1}```" }
        print_change exercise
      else
        ;
    end
  end
end

def print_change(exercise)
  puts "Updating #{exercise.name}\n\n#{exercise.description}\n\n#{exercise.description}"
end

And then run

bundle exec rake db:migrate[exercise_markdown_language]

That will do the trick.