GithubHelp home page GithubHelp logo

Comments (2)

jochu avatar jochu commented on August 12, 2024

While looking at some exercises, I started fiddling with an idea for inheritance via templating and hacked together a quick proof of concept. It's two new attributes (whose names I'm not completely sold on): data-apply and data-replace.

data-apply is a simple content splicing mechanism. So say you had:

<div id="generic-question" class="question">
  <p>For the following equation:</p>
  <p class="content">x + 1 = 2</p>
  <p>Please solve for x</p>
</div>

And you wanted to pull it into another problem. You would then go:

<div class="question">
  <div data-apply="generic-question">
    <p>x + 2 = 3</p>
  </div>
</div>

This would yield:

<div class="question">
  <p>For the following equation:</p>
  <p>x + 2 = 3<p>
  <p>Please solve for x</p>
</div>

The content element is optional. If not provided, it will just append to the end. It would be nice to be able to name/bind several different elements, but I didn't want to spend too much time on just a proof of concept.

data-replace is like the reverse of data-apply. Instead of pulling content, it replaces existing elements. So say you had in the exercise definition:

<div class="vars">
  <var id="X">3</var>
  <var id="Y">X + 3</var>
</div>

And within a particular problem, you wanted to define a different X but didn't want to redefine Y. You could instead go:

<div class="vars">
  <var data-replace="X">5</var>
</div>

Now, for the vars example to work - I had to modify the sequence of events a bit. Instead of:

  1. Generate VARS for exercises
  2. Pick a problem
  3. Generate VARS for problem

I had it

  1. Pick a problem
  2. Move or prepend exercise .vars into problem .vars
  3. Execute data-replace logic
  4. Generate VARS for problem

The kind of hacky proof of concept is available at my splices branch with the absolute value equations exercise using data-replace.

Please let me know what you think

from khan-exercises.

jeresig avatar jeresig commented on August 12, 2024

Looks like this has been landed and it's working well!

from khan-exercises.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.