First time here? Check out the FAQ!

Ask Your Question
0

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

asked 12 years ago

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.

Preview: (hide)

4 Answers

Sort by » oldest newest most voted
1

answered 12 years ago

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.

Preview: (hide)
link

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 ( 12 years ago )
1

Something like

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

Jason Grout gravatar imageJason Grout ( 12 years ago )

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 ( 12 years ago )

Awesome!

kcrisman gravatar imagekcrisman ( 12 years ago )
1

answered 12 years ago

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.

Preview: (hide)
link

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 ( 12 years ago )
1

answered 12 years ago

Alex Kramer gravatar image

updated 12 years ago

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.

Preview: (hide)
link

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 ( 12 years ago )
0

answered 12 years ago

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 %}
Preview: (hide)
link

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 ( 12 years ago )

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: 12 years ago

Seen: 1,372 times

Last updated: Aug 25 '12