- Timestamp:
- 15-01-2008 23:52:28 (12 months ago)
- Author:
- s0undt3ch
- Message:
-
Implemented rudimentary unidiff between pastes, and allow users to download pastes(No download for diffs yet, should we enabled that?).
- Location:
- trunk/pastie
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r111
|
r113
|
|
| 26 | 26 | map.connect('tagcloud', '/tags', controller='pastetags', action='index') |
| 27 | 27 | map.connect('paste', '/:id', controller="pasties", action='show') |
| 28 | | map.connect('pastetree', '', controller='pasties', action='tree') |
| | 28 | map.connect('pastetree', '/tree/:id', controller='pasties', action='tree') |
| | 29 | map.connect('rawpaste', '/download/:id', controller='pasties', action='download') |
| | 30 | map.connect('diffpaste', '/diff/:id/:parent', controller='pasties', action='diff') |
| | 31 | map.connect('replypaste', '/reply/:id', controller='pasties', action='new') |
| 29 | 32 | |
| 30 | 33 | |
-
|
r112
|
r113
|
|
| 89 | 89 | c.id = int(id) |
| 90 | 90 | return render('paste.tree') |
| | 91 | |
| | 92 | def download(self, id): |
| | 93 | if not id: |
| | 94 | redirect_to('list') |
| | 95 | paste = Session.query(Paste).get(int(id)) |
| | 96 | if not paste: |
| | 97 | abort(404) |
| | 98 | |
| | 99 | mimetype = h.get_lexer_by_name(paste.language or 'text').mimetypes[0] |
| | 100 | response.content_type__set(mimetype) |
| | 101 | response.charset__set('utf-8') |
| | 102 | response.write(paste.code) |
| | 103 | return |
| | 104 | |
| | 105 | def diff(self, id, parent): |
| | 106 | c.langdict = langdict |
| | 107 | c.paste = Session.query(Paste).get(int(id)) |
| | 108 | c.parent = Session.query(Paste).get(int(parent)) |
| | 109 | # c.diff = c.paste.compare_to(c.other) |
| | 110 | # c.diff.language = 'diff' |
| | 111 | return render('paste.diff') |
-
|
r35
|
r113
|
|
| 6 | 6 | import StringIO |
| 7 | 7 | |
| 8 | | __all__ = ['code_highlight', 'get_lexers'] |
| | 8 | __all__ = ['code_highlight', 'get_lexers', 'get_lexer_by_name'] |
| 9 | 9 | |
| 10 | 10 | langdict = {} |
| … |
… |
|
| 96 | 96 | lineanchorlinks=True, linenospecial=10) |
| 97 | 97 | |
| 98 | | def code_highlight(code, truncate_lines=None): |
| | 98 | def code_highlight(code, truncate_lines=None, diff_to=None): |
| 99 | 99 | source = code.code |
| | 100 | if diff_to: |
| | 101 | source = code.compare_to(diff_to) |
| | 102 | print source |
| 100 | 103 | if truncate_lines: |
| 101 | 104 | split_source = source.split('\n') |
| … |
… |
|
| 104 | 107 | source.append('...') |
| 105 | 108 | source = ''.join(source) |
| | 109 | |
| 106 | 110 | lexer = get_lexer_by_name(code.language or 'text', stripall=True) |
| | 111 | if diff_to: |
| | 112 | lexex = get_lexer_by_name('diff') |
| 107 | 113 | return XML(highlight(source, lexer, formatter).decode('utf-8')) |
| 108 | 114 | |
-
|
r29
|
r113
|
|
| 2 | 2 | from datetime import datetime |
| 3 | 3 | import math |
| | 4 | import difflib |
| 4 | 5 | |
| 5 | 6 | from sqlalchemy import desc, Column, ForeignKey, func, select, Table, types |
| … |
… |
|
| 84 | 85 | paste_id = paste.parent_id |
| 85 | 86 | |
| | 87 | def compare_to(self, other, context_lines=4): |
| | 88 | if not isinstance(other, Paste): |
| | 89 | other = Session.query(Paste).get(int(other)) |
| | 90 | udiff = u'\n'.join(difflib.unified_diff( |
| | 91 | self.code.splitlines(), |
| | 92 | other.code.splitlines(), |
| | 93 | fromfile='Paste #%d' % self.id, |
| | 94 | tofile='Paste #%d' % other.id, |
| | 95 | lineterm='', |
| | 96 | n=context_lines) |
| | 97 | ) |
| | 98 | return udiff |
| | 99 | |
| 86 | 100 | mapper(Paste, paste_table, |
| 87 | 101 | properties=dict( |
-
|
r49
|
r113
|
|
| 173 | 173 | float: right; |
| 174 | 174 | background: url(../img/cell_bg.png) no-repeat left bottom; |
| 175 | | font-weight: bold; |
| | 175 | /*font-weight: bold;*/ |
| 176 | 176 | font-size: 0.6em; |
| 177 | 177 | } |
-
|
r111
|
r113
|
|
| 29 | 29 | <div id="paste"> |
| 30 | 30 | <div id="paste_menu"><ul> |
| | 31 | <li> |
| | 32 | <a href="${h.url_for('replypaste', id=c.paste.id)}">Reply To Paste</a> |
| | 33 | </li> |
| | 34 | <li> |
| | 35 | <a href="${h.url_for('rawpaste', id=c.paste.id)}">Download Paste</a> |
| | 36 | </li> |
| | 37 | <li py:if="c.paste.parent_id"> |
| | 38 | <a href="${h.url_for('diffpaste', parent=c.paste.parent.id, id=c.paste.id)}" |
| | 39 | title="Diferences between current and parent paste">Diff With Parent</a> |
| | 40 | </li> |
| 31 | 41 | <li py:if="c.paste.children or c.paste.parent_id"> |
| 32 | 42 | <a href="${h.url_for('pastetree', id=c.paste.id)}">Show Tree</a> |
| 33 | | </li> |
| 34 | | <li> |
| 35 | | <a href="${h.url_for('newpaste', id=c.paste.id)}">Reply To Paste</a> |
| 36 | 43 | </li> |
| 37 | 44 | <li style="display:none;"><a class="toggle_linenumbers" |
Download in other formats:
|
|