Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Add Inheritance for Problems/Questions #2

Closed
jeresig opened this issue May 16, 2011 · 2 comments
Closed

Add Inheritance for Problems/Questions #2

jeresig opened this issue May 16, 2011 · 2 comments
Assignees

Comments

@jeresig
Copy link
Member

jeresig commented May 16, 2011

Right now you can only bulk overwrite an entire problem description or question, it would be nice if it was possible to just override individual elements. Perhaps a class to mark those elements as being able to be substituted? Maybe something like class="sub".

jeresig added a commit that referenced this issue May 16, 2011
… overwrite the existing problem, question, or solution - no way to currently pick-and-choose which items you wish to substitute. I've filed a bug under issue #2.
@ghost ghost assigned jeresig May 18, 2011
@jochu
Copy link
Contributor

jochu commented May 30, 2011

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

jochu pushed a commit to jochu/khan-exercises that referenced this issue Jun 1, 2011
jeresig added a commit that referenced this issue Jun 1, 2011
More sophisticated template inheritance, fixes issue #2.
@jeresig
Copy link
Member Author

jeresig commented Jun 2, 2011

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

@jeresig jeresig closed this as completed Jun 2, 2011
sundars pushed a commit to sundars/khan-exercises that referenced this issue Feb 9, 2012
sophiebits pushed a commit to sophiebits/khan-exercises that referenced this issue Mar 31, 2012
beneater pushed a commit that referenced this issue Jun 29, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants