Ticket #7249: trac_7249_switch_notebook_to_jinja2.patch

File trac_7249_switch_notebook_to_jinja2.patch, 10.0 KB (added by ddrake, 10 years ago)

apply to sagenb repo

  • sagenb/data/templates/notebook/head.tmpl

    # HG changeset patch
    # User Dan Drake <drake@kaist.edu>
    # Date 1255998429 -32400
    # Node ID 05504b86bc50dc4e6d6780f8eeadfb213ed3cc73
    # Parent  0eef97b1aaf7c9381f2642d82feacf33b3f6227a
    [mq]: trac_7249_switch_notebook_to_jinja2
    
    diff --git a/sagenb/data/templates/notebook/head.tmpl b/sagenb/data/templates/notebook/head.tmpl
    a b  
    1717    {% endif %}
    1818{% endmacro %}
    1919
    20 {% macro common_css %}
     20{% macro common_css() %}
    2121<link rel=stylesheet href="/css/main.css" type="text/css" />
    2222{% endmacro %}
    2323
     
    2525<!-- Load the Sage javascript library. -->
    2626<script type="text/javascript" src="/javascript/jquery/jquery.js"></script>
    2727<script type="text/javascript" src="/javascript/main.js"></script>
    28  
     28
    2929{% if JSMATH %}
    3030    <!-- Turn off font warning. -->
    3131    <style>
     
    5252    <script type="text/javascript" src="/javascript/jsmath/jsMath.js"></script>
    5353    <script type="text/javascript">
    5454        /* The extensions here do the following:
    55             - verb implements the \verb command: 
     55            - verb implements the \verb command:
    5656              see http://www.math.union.edu/~dpvc/jsMath/authors/verb.html
    5757            - moreArrows implements \xrightarrow, among other things:
    5858              see http://www.math.union.edu/~dpvc/jsMath/authors//moreArrows.html
     
    7878<script type="text/javascript" src="/javascript/jquery/plugins/dimensions/jquery.dimensions.min.js"></script>
    7979<script type="text/javascript" src="/javascript/jquery/plugins/jquery.event.extendedclick.js"></script>
    8080
    81 <link rel="stylesheet" href="/javascript/jquery/plugins/farbtastic/farbtastic.css" type="text/css" /> 
     81<link rel="stylesheet" href="/javascript/jquery/plugins/farbtastic/farbtastic.css" type="text/css" />
    8282<link rel="stylesheet" href="/javascript/jqueryui/themes/flora/flora.all.css" />
    8383
    8484<!-- TODO: get the lazy loading plugin -->
     
    108108    <script type="text/javascript" src="/javascript/tiny_mce/tiny_mce.js"></script>
    109109    <script src="/javascript/jquery/plugins/jquery.jeditable.mini.js" type="text/javascript" charset="utf-8"></script>
    110110    <script type="text/javascript">
    111    
     111
    112112    function toggleEditor(id) {
    113113            if (!tinyMCE.get(id))
    114114                    tinyMCE.execCommand('mceAddControl', false, id);
    115115            else
    116116                    tinyMCE.execCommand('mceRemoveControl', false, id);
    117117    }
    118    
     118
    119119    $.fn.tinymce = function(options){
    120120       return this.each(function(){
    121121          tinyMCE.execCommand("mceAddControl", true, this.id);
     
    146146              if(key_enter_shift(key_event(e))) {
    147147                $(ed.formElement).submit();
    148148              }
    149           })} 
     149          })}
    150150       });
    151151    };
    152    
     152
    153153    initMCE();
    154    
    155    
     154
     155
    156156    $.editable.addInputType('mce', {
    157157       element : function(settings, original) {
    158158          var textarea = $('<textarea id="'+$(original).attr("id")+'_mce"/>');
  • sagenb/data/templates/notebook/index.html

    diff --git a/sagenb/data/templates/notebook/index.html b/sagenb/data/templates/notebook/index.html
    a b  
    2020{% if not backwards %}
    2121    {% set backwards = false %}
    2222{% endif %}
    23    
    24 {% include "notebook/head.tmpl" %}
     23
     24{% from "notebook/head.tmpl" import common_title, common_css, common_javascript %}
    2525
    2626{% block title %}
    2727{{ common_title(worksheet_filename, worksheet) }}
    2828{% endblock %}
    29    
     29
    3030{% block css %}main{% endblock %}
    3131
    3232{% block javascript %}
  • sagenb/data/templates/notebook/top_bar_and_worksheet.html

    diff --git a/sagenb/data/templates/notebook/top_bar_and_worksheet.html b/sagenb/data/templates/notebook/top_bar_and_worksheet.html
    a b  
    66- worksheet_html - a string containing the html for a worksheet
    77- show_debug - a boolean stating whether to show debug information
    88  #}
    9 {% include "notebook/user_controls.tmpl" %}
    10 {% include "notebook/worksheet_topbar.tmpl" %}
     9{% from "notebook/user_controls.tmpl" import user_controls %}
     10{% from "notebook/worksheet_topbar.tmpl" import worksheet_topbar %}
    1111{% set entries = [("$('#topbar').toggle()", 'Toggle', 'Toggle the top bar'),
    1212                       ('/', 'Home', 'Back to your personal worksheet list'),
    1313                       ('/pub', 'Published', 'Browse the published worksheets'),
    1414                       ('history_window()', 'Log', 'View a log of recent computations'),
    15                        ('/settings', 'Settings', 'Account Settings'), 
     15                       ('/settings', 'Settings', 'Account Settings'),
    1616                       ('bugreport()', 'Report a Problem', 'Report a problem or submit a bug to improve Sage'),
    1717                       ('help()', 'Help', 'Documentation'),
    1818                       ('/logout', 'Sign out', 'Log out of the Sage notebook')] %}
  • sagenb/data/templates/notebook/worksheet_page_template.html

    diff --git a/sagenb/data/templates/notebook/worksheet_page_template.html b/sagenb/data/templates/notebook/worksheet_page_template.html
    a b  
    2020{% if not backwards %}
    2121    {% set backwards = false %}
    2222{% endif %}
    23    
    24 {% include "notebook/head.tmpl" %}
    25 {% include "notebook/worksheet_top.tmpl" %}
    26 {% include "notebook/worksheet_topbar.tmpl" %}
     23
     24{% from "notebook/head.tmpl" import common_title, common_css,
     25common_javascript %}
     26{% from "notebook/worksheet_top.tmpl" import worksheet_top %}
     27{% from "notebook/worksheet_topbar.tmpl" import worksheet_topbar %}
    2728
    2829{% block title %}
    2930{{ common_title(worksheet_filename, worksheet) }}
    3031{% endblock %}
    31    
     32
    3233{% block css %}main{% endblock %}
    3334
    3435{% block javascript %}
     
    4344<span class="sharebar">{{ title }}</span>
    4445<br /><br /><br />
    4546{% block body_addition %}{% endblock %}
    46 {% endblock %}
    47  No newline at end of file
     47{% endblock %}
  • sagenb/data/templates/notebook/worksheet_top.tmpl

    diff --git a/sagenb/data/templates/notebook/worksheet_top.tmpl b/sagenb/data/templates/notebook/worksheet_top.tmpl
    a b  
    44#}
    55
    66{% macro worksheet_top(username) %}
    7 {% include "notebook/user_controls.tmpl" %}
    8 {% include "notebook/worksheet_topbar.tmpl" %}
     7{% from "notebook/user_controls.tmpl" import user_controls %}
     8{% from "notebook/worksheet_topbar.tmpl" import worksheet_topbar %}
    99{% set entries = [("$('#topbar').toggle()", 'Toggle', 'Toggle the top bar'),
    1010                       ('/', 'Home', 'Back to your personal worksheet list'),
    1111                       ('/pub', 'Published', 'Browse the published worksheets'),
    1212                       ('history_window()', 'Log', 'View a log of recent computations'),
    13                        ('/settings', 'Settings', 'Account Settings'), 
     13                       ('/settings', 'Settings', 'Account Settings'),
    1414                       ('bugreport()', 'Report a Problem', 'Report a problem or submit a bug to improve Sage'),
    1515                       ('help()', 'Help', 'Documentation'),
    1616                       ('/logout', 'Sign out', 'Log out of the Sage notebook')] %}
  • sagenb/data/templates/worksheet/share_publish_buttons.html

    diff --git a/sagenb/data/templates/worksheet/share_publish_buttons.html b/sagenb/data/templates/worksheet/share_publish_buttons.html
    a b  
    99{% macro cls(x) %}
    1010{{ "control-select" if x == select else "control" }}
    1111{% endmacro %}
    12 {% macro backwards_text %}
     12{% macro backwards_text() %}
    1313{{ "../" if backwards else "" }}
    1414{% endmacro %}
    1515<a title="Print this worksheet" class="usercontrol" onClick="print_worksheet()"><img border=0 src="/images/icon_print.gif" alt="Print">Print</a>
    16 <a class="{{ cls('use') }}" title="Interactively use this worksheet" onClick="edit_worksheet();">Worksheet</a>       
     16<a class="{{ cls('use') }}" title="Interactively use this worksheet" onClick="edit_worksheet();">Worksheet</a>
    1717<a class="{{ cls('edit') }}" title="Edit text version of this worksheet" href="{{ backwards_text() }}edit">Edit</a>
    1818<a class="{{ cls('text') }}" title="View plain text version of this worksheet" href="{{ backwards_text() }}text">Text</a>
    1919<a class="{{ cls('undo') }}" title="View changes to this worksheet over time" href="{{ backwards_text() }}revisions">Undo</a>
  • sagenb/notebook/template.py

    diff --git a/sagenb/notebook/template.py b/sagenb/notebook/template.py
    a b  
    1515#                  http://www.gnu.org/licenses/
    1616#############################################################################
    1717
    18 import jinja
     18import jinja2
    1919import sys
    2020
    2121from sagenb.misc.misc import SAGE_VERSION, DATA
    2222
    2323
    2424TEMPLATE_PATH = DATA + '/templates/'
    25 env = jinja.Environment(loader=jinja.FileSystemLoader(TEMPLATE_PATH))
     25env = jinja2.Environment(loader=jinja2.FileSystemLoader(TEMPLATE_PATH))
    2626
    2727def contained_in(container):
    2828    """
     
    4747    def wrapped(env, context, value):
    4848        return value in container
    4949    return wrapped
    50    
     50
    5151env.tests['contained_in'] = contained_in
    5252
    5353#A dictionary containing the default context
    5454#The values in this dictionary will be updated
    55 #by the 
     55#by the
    5656default_context = {'sitename': 'Sage Notebook',
    5757                   'sage_version': SAGE_VERSION}
    5858
    59 def template(filename, **user_context): 
     59def template(filename, **user_context):
    6060    """
    6161    Returns HTML, CSS, etc., for a template file rendered in the given
    6262    context.
     
    7070      the file's template variables
    7171
    7272    OUTPUT:
    73      
     73
    7474    - a string - the rendered HTML, CSS, etc.
    7575
    7676    EXAMPLES::
     
    8989    """
    9090    try:
    9191        tmpl = env.get_template(filename)
    92     except jinja.exceptions.TemplateNotFound:
     92    except jinja2.exceptions.TemplateNotFound:
    9393        return "Notebook Bug -- missing template %s"%filename
    9494    context = dict(default_context)
    9595    context.update(user_context)
    96     r = tmpl.render(**context) 
     96    r = tmpl.render(**context)
    9797    return r.encode('utf-8')