|
| 1 | +# Copyright (C) 2011 Bradley N. Miller |
| 2 | +# |
| 3 | +# This program is free software: you can redistribute it and/or modify |
| 4 | +# it under the terms of the GNU General Public License as published by |
| 5 | +# the Free Software Foundation, either version 3 of the License, or |
| 6 | +# (at your option) any later version. |
| 7 | +# |
| 8 | +# This program is distributed in the hope that it will be useful, |
| 9 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +# GNU General Public License for more details. |
| 12 | +# |
| 13 | +# You should have received a copy of the GNU General Public License |
| 14 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | +# |
| 16 | +__author__ = 'bmiller' |
| 17 | + |
| 18 | +from docutils import nodes |
| 19 | +from docutils.parsers.rst import directives |
| 20 | +from docutils.parsers.rst import Directive |
| 21 | +import json |
| 22 | +import random |
| 23 | + |
| 24 | +# setup is called in activecode.py |
| 25 | + |
| 26 | + |
| 27 | +def textfield_role(name, rawtext, text, lineno, inliner, options={}, content=[]): |
| 28 | + ''' |
| 29 | + Usage: |
| 30 | + In your document you can write :textfield:`myid:myvalue:width` |
| 31 | + This will translate to: |
| 32 | + <input type='text' id='myid' class="form-control input-small" style="display:inline; width:width;" value='myvalue'></input> |
| 33 | +
|
| 34 | + where width can be specified in pixels or percentage of page width (standard CSS syntax). |
| 35 | + Width can also be specified using relative sizes: |
| 36 | + mini, small, medium, large, xlarge, and xxlarge |
| 37 | + ''' |
| 38 | + iid, value, width = text.split(':') |
| 39 | + |
| 40 | + if 'mini' in width: |
| 41 | + width = '60px' |
| 42 | + elif 'small' in width: |
| 43 | + width = '90px' |
| 44 | + elif 'medium' in width: |
| 45 | + width = '150px' |
| 46 | + elif 'large' in width: |
| 47 | + width = '210px' |
| 48 | + elif 'xlarge' in width: |
| 49 | + width = '270px' |
| 50 | + elif 'xxlarge' in width: |
| 51 | + width = '530px' |
| 52 | + |
| 53 | + res = '''<input type='text' id='%s' class="form-control" style="display:inline; width: %s;" value="%s"></input>''' % (iid,width,value) |
| 54 | + |
| 55 | + return [nodes.raw('',res, format='html')],[] |
0 commit comments