Ask Your Question
0

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

asked 2012-06-27 16:09:41 +0100

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 16:30:28 +0100

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 10:46:03 +0100 )edit
1

Something like

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

Jason Grout gravatar imageJason Grout ( 2012-08-27 19:24:58 +0100 )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 19:26:03 +0100 )edit

Awesome!

kcrisman gravatar imagekcrisman ( 2012-08-28 10:25:45 +0100 )edit
1

answered 2012-06-27 22:46:00 +0100

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 22:48:48 +0100 )edit
1

answered 2012-06-28 18:38:32 +0100

Alex Kramer gravatar image

updated 2012-06-28 18:38:48 +0100

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 23:44:04 +0100 )edit
0

answered 2012-06-28 20:49:07 +0100

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 23:45:30 +0100 )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 16:09:41 +0100

Seen: 1,341 times

Last updated: Aug 25 '12