• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


Commit MetaInfo

修訂f49a7af095a5ef5355b0bccd5329b11f0a667fd9 (tree)
時間2012-05-04 19:17:37
作者bolkimen <bolkimen@yaho...>
Commiterbolkimen

Log Message

ticket:47 add tests and change code

Change Summary

差異

--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -542,7 +542,7 @@ def paging_sanitizer(limit, page, total_count, zero_based_pages=True):
542542 page = min(max(int(page), (0 if zero_based_pages else 1)), max_page)
543543 return limit, page
544544
545-def render_any_markup(name, text):
545+def render_any_markup(name, text, code_mode=False):
546546 """
547547 renders any markup format using the pypeline
548548 Returns jinja-safe text
@@ -551,6 +551,15 @@ def render_any_markup(name, text):
551551 text = '<p><em>Empty File</em></p>'
552552 else:
553553 text = pylons.g.pypeline_markup.render(name, text)
554- if not pylons.g.pypeline_markup.can_render(name):
555- text = '<pre>%s</pre>' % text
554+ if not pylons.g.pypeline_markup.can_render(name) or True:
555+ if code_mode:
556+ markup_text = '<div class="codehilite"><pre>'
557+ line_num = 1
558+ for line in text.splitlines():
559+ markup_text = markup_text + '<div id="l%s" class="code_block"><span class="lineno">%s</span> %s</div>' % (line_num, line_num, line)
560+ line_num += 1
561+ markup_text = markup_text + '</pre></div>'
562+ text = markup_text
563+ else:
564+ text = '<pre>%s</pre>' % text
556565 return Markup(text)
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -407,7 +407,6 @@ class LineAnchorCodeHtmlFormatter(HtmlFormatter):
407407 num = self.linenostart
408408 yield 0, ('<pre' + (style and ' style="%s"' % style) + '>')
409409 for tup in inner:
410- yield (tup[0], '<a class="linelink" href="#codeline_%s">'\
411- '<div id="codeline_%s" class="code_block">%s</div></a>' % (num, num, tup[1]))
410+ yield (tup[0], '<div id="l%s" class="code_block">%s</div>' % (num, tup[1]))
412411 num += 1
413412 yield 0, '</pre>'
--- a/Allura/allura/public/nf/css/forge/hilite.css
+++ b/Allura/allura/public/nf/css/forge/hilite.css
@@ -64,7 +64,6 @@
6464
6565 .codehilite pre { margin:0; }
6666 .codehilite div { margin:0; padding: 0; }
67-.codehilite a.linelink { text-decoration: none; }
68-.codehilite a.linelink .code_block { width:100%; }
69-.codehilite a.linelink .code_block:hover { background-color: #ffff99; }
67+.codehilite .code_block { width:100%; }
68+.codehilite .code_block:hover { background-color: #ffff99; }
7069 .codehilite .lineno { background-color: #ebebeb; display:inline-block; padding:0 .5em; border-width: 0 1px 0 0; border-style: solid; border-color: #ddd; }
--- a/Allura/allura/templates/repo/file.html
+++ b/Allura/allura/templates/repo/file.html
@@ -22,17 +22,18 @@
2222 {{ super() }}
2323 <script type="text/javascript">(function() {
2424 var hash = window.location.hash.substring(1);
25- if (hash != '' && hash.substring(0, 9) == 'codeline_') {
25+ if (hash != '' && hash.substring(0, 1) == 'l' && !isNaN(hash.substring(1))) {
2626 $('#' + hash).css('background-color', '#ffff99');
2727 }
2828
2929 $('.code_block').each(function(index, element) {
3030 $(element).bind('click', function() {
3131 var hash = window.location.hash.substring(1);
32- if (hash != '' && hash.substring(0, 9) == 'codeline_') {
32+ if (hash != '' && hash.substring(0, 1) == 'l' && !isNaN(hash.substring(1))) {
3333 $('#' + hash).css('background-color', 'transparent');
3434 }
3535 $(element).css('background-color', '#ffff99');
36+ window.location.href = '#' + $(element).attr('id');
3637 });
3738 });
3839 }());
@@ -68,7 +69,7 @@
6869 <div class="clip grid-19">
6970 <h3><span class="ico-l"><b data-icon="{{g.icons['table'].char}}" class="ico {{g.icons['table'].css}}"></b> {{h.really_unicode(blob.name)}}</span></h3>
7071 {% if blob.has_pypeline_view %}
71- {{h.render_any_markup(blob.name, blob.text)}}
72+ {{h.render_any_markup(blob.name, blob.text, True)}}
7273 {% else %}
7374 {{g.highlight(blob.text, filename=blob.name)}}
7475 {% endif %}
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -5,6 +5,10 @@ import unittest
55 import pylons
66 from webob import Request
77
8+from pygments import highlight
9+from pygments.lexers import PythonLexer, get_lexer_for_filename
10+from pygments.formatters import HtmlFormatter
11+
812 from ming.orm import state
913 from alluratest.controller import setup_unit_test
1014
@@ -115,3 +119,16 @@ class TestCaseInsensitiveDict(unittest.TestCase):
115119 assert d == dict(foo=1, bar=2)
116120 assert d != dict(Foo=1, bar=2)
117121 assert d == utils.CaseInsensitiveDict(Foo=1, bar=2)
122+
123+class TestLineAnchorCodeHtmlFormatter(unittest.TestCase):
124+ def test_render(self):
125+ code = '#!/usr/bin/env python\n'\
126+ 'print "Hello, world!"'
127+
128+ formatter = utils.LineAnchorCodeHtmlFormatter(cssclass='codehilite',
129+ linenos='inline')
130+ lexer = get_lexer_for_filename("some.py", encoding='chardet')
131+ hl_code = highlight(code, lexer, formatter)
132+ assert '<div class="codehilite">' in hl_code
133+ assert '<div id="l1" class="code_block">' in hl_code
134+ assert '<span class="lineno">1</span>' in hl_code
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -149,6 +149,8 @@ class TestRootController(TestController):
149149 assert 'README' in resp.html.find('h2',{'class':'dark title'}).contents[2]
150150 content = str(resp.html.find('div',{'class':'clip grid-19'}))
151151 assert 'This is readme' in content, content
152+ assert '<div id="l1" class="code_block">' in resp
153+ assert 'var hash = window.location.hash.substring(1);' in resp
152154
153155 def test_invalid_file(self):
154156 ci = self._get_ci()
--- a/ForgeHg/forgehg/tests/functional/test_controllers.py
+++ b/ForgeHg/forgehg/tests/functional/test_controllers.py
@@ -126,6 +126,8 @@ class TestRootController(TestController):
126126 assert 'README' in resp.html.find('h2',{'class':'dark title'}).contents[2]
127127 content = str(resp.html.find('div',{'class':'clip grid-19'}))
128128 assert 'This is readme' in content, content
129+ assert '<div id="l1" class="code_block">' in resp
130+ assert 'var hash = window.location.hash.substring(1);' in resp
129131
130132 def test_invalid_file(self):
131133 ci = self._get_ci()
--- a/ForgeSVN/forgesvn/tests/functional/test_controllers.py
+++ b/ForgeSVN/forgesvn/tests/functional/test_controllers.py
@@ -76,6 +76,8 @@ class TestRootController(TestController):
7676 assert 'README' in resp.html.find('h2',{'class':'dark title'}).contents[2]
7777 content = str(resp.html.find('div',{'class':'clip grid-19'}))
7878 assert 'This is readme' in content, content
79+ assert '<div id="l1" class="code_block">' in resp
80+ assert 'var hash = window.location.hash.substring(1);' in resp
7981
8082 def test_invalid_file(self):
8183 resp = self.app.get('/src/1/tree/READMEz', status=404)