Update ruler extension

This commit is contained in:
Juergen Hasch
2015-09-05 15:20:31 +02:00
parent b0381b89ed
commit d4eec510b2
3 changed files with 50 additions and 13 deletions
+32 -12
View File
@@ -7,38 +7,58 @@ define([
'require',
'base/js/events',
'services/config',
'base/js/utils',
'base/js/utils',
'codemirror/lib/codemirror',
'codemirror/addon/display/rulers'
], function(IPython, $, require, events, configmod, utils, codemirror) {
"use strict";
var RULERCOLUMN = 78;
var base_url = utils.get_body_data("baseUrl")
var ruler_column = 78;
var ruler_color = "#ff0000";
var ruler_linestyle = "dashed";
var base_url = utils.get_body_data("baseUrl");
var config = new configmod.ConfigSection('notebook', {base_url: base_url});
var rulers = [];
function isNumber(n) {
var isNumber = function(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
};
config.loaded.then(function() {
if (config.data.hasOwnProperty('ruler_column') ){
if (isNumber(config.data.ruler_column)) RULERCOLUMN = config.data.ruler_column;
if (config.data.hasOwnProperty('ruler_color')) {
ruler_color = config.data.ruler_color;
}
console.log("RULER:", RULERCOLUMN)
rulers.push({color: "#f00", column: RULERCOLUMN, lineStyle: "dashed"});
console.log("ruler_color:", ruler_color);
if (config.data.hasOwnProperty('ruler_column')) {
if (isNumber(config.data.ruler_column)) {
ruler_column = config.data.ruler_column;
}
}
console.log("ruler_column:", ruler_column);
if (config.data.hasOwnProperty('ruler_linestyle')) {
ruler_linestyle = config.data.ruler_linestyle;
}
console.log("ruler_linestyle:", ruler_linestyle);
rulers.push({
color: ruler_color,
column: ruler_column,
lineStyle: ruler_linestyle
});
var cells = IPython.notebook.get_cells();
for(var i in cells){
for(var i in cells) {
var cell = cells[i];
if ((cell instanceof IPython.CodeCell)) {
cell.code_mirror.setOption('rulers', rulers);
}
}
events.on('create.Cell',createCell);
events.on('create.Cell', createCell);
});
var createCell = function (event,nbcell) {
var createCell = function (event, nbcell) {
var cell = nbcell.cell;
if ((cell instanceof IPython.CodeCell)) {
cell.code_mirror.setOption('rulers', rulers);
+11 -1
View File
@@ -1 +1,11 @@
Display a rulter
This extension enables the Ruler CodeMirror feature
## Configuration
You can set the number of characters in the notebook extensions configration page or use the ConfigManager:
```Python
from IPython.html.services.config import ConfigManager
ip = get_ipython()
cm = ConfigManager(parent=ip)
cm.update('notebook', {"ruler_column": 80})
```
+7
View File
@@ -10,3 +10,10 @@ Parameters:
input_type: number
description: Column where ruler is displayed
default: 78
ruler_color:
input_type: color
description: Color of the ruler
default: "#ff0000"
ruler_linestyle:
description: 'Ruler style, e.g. solid, dashed'
default: dashed