Question

I am using sage cell to convert html to math stuff

Template.home.rendered = function(){
  \\ apply sagecell and mathjax
}

However, the content that are rendered comes from mongo, so it's sometimes loaded after sage cell is applied to it. I can do something like this

Template.home.rendered = function(){
  Deps.autorun(function(){
    if (Content.findOne({_id: ...})){
      \\ apply sagecell and mathjax
    }
  });
}

It's better but still doesn't work all the time. Is there other things I can use to detect the content is completely rendered?

Was it helpful?

Solution 2

The script

<script type='text/javascript' src="http://sagecell.sagemath.org/static/embedded_sagecell.js"></script>

that is supposed to be in the head needs to be removed and instead be loaded after the content is completely loaded like so:

Template.content.rendered = function(){
  // sage
  Deps.autorun(function(){
    if (Session.get('contentChanged')){
      // loading this script causes mathjax to run
      $.getScript("http://sagecell.sagemath.org/static/embedded_sagecell.js", function(d, textStatus){
        if (textStatus=='success'){
          // this converts <div class='compute'> to a sage cell
          sagecell.makeSagecell({
            inputLocation: 'div.compute',
            evalButtonText: 'Evaluate',
            hide: ['editorToggle']
          });
        }
      })
    }
  })

and if I go from 1 content template to another content template, it seems that nothing is rerendered and so the mathjax was not applied. The only fix I can think is to force a page reload:

Template.content.events({
'click a': function(evt){
  evt.preventDefault();
  location.href = evt.currentTarget.href;
}
})

which makes the site much slower, unfortunately.

OTHER TIPS

Edited with new response:

<template name='pendingAnswer'>
    The answer to your question, coming back whenever, is:
    {{>answer}}
</template>

<template name='answer'>
    {{fromSage}}
</template>     

Template.answer.helpers({ 
    fromSage: function () {  
        Session.get('fromSage');
    }
});

Invoked whenever - from a button, from navigating to the page, on blur...        
function GetAnswerFromSage(data) {
        callHTTP(website,data, callbackFromSage)
}        

function callbackFromSage(err, data) {
        if (err) then log(err);
        Session.set('fromSage', data);
        }

Earlier: try transform upon retrieval of mongo: From Meteor Doc

// An Animal class that takes a document in its constructor
Animal = function (doc) {
  _.extend(this, doc);
};
_.extend(Animal.prototype, {
  makeNoise: function () {
    console.log(this.sound);
  }
});

// Define a Collection that uses Animal as its document
Animals = new Meteor.Collection("Animals", {
  transform: function (doc) { return new Animal(doc); }
});

// Create an Animal and call its makeNoise method
Animals.insert({name: "raptor", sound: "roar"});
Animals.findOne({name: "raptor"}).makeNoise(); // prints "roar"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top