Ask Your Question
0

Sage cell server - do I really need so many makeSagecell invocations?

asked 2012-06-27 09:09:41 -0500

kcrisman gravatar image

If I'm writing a web page with (say) 15 different Sage cells embedded in it, do I really need 15 explicit invocations of

sagecell.makeSagecell({inputLocation:  '#sagecell-plotP',
                       template:       sagecell.templates.restricted});

with a slightly different name each time, or is there a way to just use the same formatting etc. for a bunch of them and just have a class for the div instead of an id? This could be a very HTML/CSS-ignorant question...

My guess is "sadly, no" because the cell server needs to know what div to put the results in, but one can always hope.

edit retag flag offensive close merge delete

4 answers

Sort by ยป oldest newest most voted
1

answered 2012-08-25 09:30:28 -0500

As of commit 8f99d8, you can use any JQuery selector, including ones that select multiple elements, as an inputLocation. You can create a Sage cell in multiple locations using something like:

sagecell.makeSagecell({inputLocation:  '.sagecell-plot',
                       template:       sagecell.templates.restricted});

where sagecell-plot is the name of the class of which each of the inputLocations is a member.

edit flag offensive delete link more

Comments

That sounds cool! How would the HTML look for that guy in the actual cell location? (I haven't done these kind of things for a long time, and I know little about JQuery.)

kcrisman gravatar imagekcrisman ( 2012-08-27 03:46:03 -0500 )edit
1

Something like

<script type="application/sage">plot(x^2)</script>

Jason Grout gravatar imageJason Grout ( 2012-08-27 12:24:58 -0500 )edit

Thanks again for implementing this, Ira! Sorry I've been so busy I couldn't commit it until the other day. (I needed it for my class :).

Jason Grout gravatar imageJason Grout ( 2012-08-27 12:26:03 -0500 )edit

Awesome!

kcrisman gravatar imagekcrisman ( 2012-08-28 03:25:45 -0500 )edit
1

answered 2012-06-28 11:38:32 -0500

Alex Kramer gravatar image

updated 2012-06-28 11:38:48 -0500

Here's a quick example of some HTML+javascript that automatically makes all elements with a given class into sagecells: http://sage.math.washington.edu/home/alexkramer/sagecell_test.html (view source to see the JS) ... However, it looks like right now there's some sort of CSS bug that's preventing a lot of debugging-type printing from being dynamically hidden. But it at least shows that what you want is certainly possible to do.

edit flag offensive delete link more

Comments

Wow, cool. Luckily, I asked whether *I* could do this, which still seems implausible, not knowing much js, so I won't have to accept this answer either :)

kcrisman gravatar imagekcrisman ( 2012-06-28 16:44:04 -0500 )edit
1

answered 2012-06-27 15:46:00 -0500

Jason Grout gravatar image

The way it's written right now, you do need specific locations for each one, so yes, you do need 15 invocations. That said, you could make some sort of jquery something that, when a div gets a certain class, will automatically make it a sagecell. Sorry; that's a little vague.

edit flag offensive delete link more

Comments

Upvoted. But you are correct that this is vague. Give me the code (and exactly where to put it) and you'll not only get a check mark, but a nice article with your name on it besides!

kcrisman gravatar imagekcrisman ( 2012-06-27 15:48:48 -0500 )edit
0

answered 2012-06-28 13:49:07 -0500

benjaminfjones gravatar image

A non-sage solution to your problem would be to use a static site generator / HTML templates. I've used jinja2 before, it's pretty easy to use and powerful (and built using Python).

You can use jinja to do things like this (stolen from their webpage)

{% extends "layout.html" %}
{% block body %}
  <ul>
  {% for user in users %}
    <li><a href="{{ user.url }}">{{ user.username }}</a></li>
  {% endfor %}
  </ul>
{% endblock %}
edit flag offensive delete link more

Comments

Sadly, beyond my meager web skills :( I'll probably code it all in by hand anyway, doing 15 on five or six pages is way better than doing 100 on 20 pages :)

kcrisman gravatar imagekcrisman ( 2012-06-28 16:45:30 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-06-27 09:09:41 -0500

Seen: 776 times

Last updated: Aug 25 '12