From patchwork Sat Jun 1 18:09:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1, of, 4, V3] hgweb: code selection without line numbers in file code view From: Alexander Plavin X-Patchwork-Id: 1692 Message-Id: <39a32bcfb6581479afb5.1370110191@debian-alexander.dolgopa> To: mercurial-devel@selenic.com Date: Sat, 01 Jun 2013 22:09:51 +0400 # HG changeset patch # User Alexander Plavin # Date 1369988709 -14400 # Fri May 31 12:25:09 2013 +0400 # Node ID 39a32bcfb6581479afb5afc761e8ebcf5f41fbc2 # Parent 1bef6f99a12d9062e737bb623da627719a3987e6 hgweb: code selection without line numbers in file code view File code is presented as HTML ordered list, so that line numbers are not selected with the code itself. Long lines are being wrapped for convenience. diff -r 1bef6f99a12d -r 39a32bcfb658 mercurial/templatefilters.py --- a/mercurial/templatefilters.py Thu May 23 17:53:38 2013 -0500 +++ b/mercurial/templatefilters.py Fri May 31 12:25:09 2013 +0400 @@ -299,6 +299,9 @@ """:shortdate: Date. Returns a date like "2006-09-18".""" return util.shortdate(text) +def spaceifempty(text): + return text or ' ' + def stringescape(text): return text.encode('string_escape') @@ -381,6 +384,7 @@ "short": short, "shortbisect": shortbisect, "shortdate": shortdate, + "spaceifempty": spaceifempty, "stringescape": stringescape, "stringify": stringify, "strip": strip, diff -r 1bef6f99a12d -r 39a32bcfb658 mercurial/templates/paper/filerevision.tmpl --- a/mercurial/templates/paper/filerevision.tmpl Thu May 23 17:53:38 2013 -0500 +++ b/mercurial/templates/paper/filerevision.tmpl Fri May 31 12:25:09 2013 +0400 @@ -67,8 +67,10 @@
-
line source
+
+
    {text%fileline} +
diff -r 1bef6f99a12d -r 39a32bcfb658 mercurial/templates/paper/footer.tmpl --- a/mercurial/templates/paper/footer.tmpl Thu May 23 17:53:38 2013 -0500 +++ b/mercurial/templates/paper/footer.tmpl Fri May 31 12:25:09 2013 +0400 @@ -1,4 +1,7 @@ - + {motd} diff -r 1bef6f99a12d -r 39a32bcfb658 mercurial/templates/paper/map --- a/mercurial/templates/paper/map Thu May 23 17:53:38 2013 -0500 +++ b/mercurial/templates/paper/map Fri May 31 12:25:09 2013 +0400 @@ -72,7 +72,7 @@ filecomparison = filecomparison.tmpl filelog = filelog.tmpl fileline = ' -
{linenumber} {line|escape}
' +
  • {line|escape|spaceifempty}
  • ' filelogentry = filelogentry.tmpl annotateline = ' diff -r 1bef6f99a12d -r 39a32bcfb658 mercurial/templates/static/mercurial.js --- a/mercurial/templates/static/mercurial.js Thu May 23 17:53:38 2013 -0500 +++ b/mercurial/templates/static/mercurial.js Fri May 31 12:25:09 2013 +0400 @@ -3,6 +3,7 @@ // Rendering of branch DAGs on the client side // Display of elapsed time // Show or hide diffstat +// Link to a line when clicking on it // // Copyright 2008 Dirkjan Ochtman // Copyright 2006 Alexander Schremmer @@ -274,3 +275,21 @@ document.getElementById('diffstatdetails').style.display = 'none'; document.getElementById('diffstatexpand').style.display = 'inline'; } + + +function addOnclickSource() { + var nodes = document.querySelectorAll('ol.sourcelines'); + + clickHandler = function (event) { + if (event.offsetX < 0 || event.target.tagName == 'LI') { + var id = event.target.id || event.target.parentNode.id; + if (id) { + window.location.hash = '#' + id; + } + } + }; + + for (i = 0; i < nodes.length; i++) { + nodes[i].onclick = clickHandler; + } +} diff -r 1bef6f99a12d -r 39a32bcfb658 mercurial/templates/static/style-paper.css --- a/mercurial/templates/static/style-paper.css Thu May 23 17:53:38 2013 -0500 +++ b/mercurial/templates/static/style-paper.css Fri May 31 12:25:09 2013 +0400 @@ -198,10 +198,9 @@ .bigtable td.annotate { font-size: smaller; } .bigtable td.source { font-size: inherit; } -.source, .sourcefirst, .sourcelast { +.source { font-family: monospace; - white-space: pre; - padding: 1px 4px; + white-space: pre-wrap; font-size: 90%; } .sourcefirst { border-bottom: 1px solid #999; font-weight: bold; } @@ -209,6 +208,39 @@ .source a { color: #999; font-size: smaller; font-family: monospace;} .bottomline { border-bottom: 1px solid #999; } +div.source, td.source { padding: 1px 4px; } + +ol { + background-color: #eee; + font-size: 90%; + margin: 0; + padding-left: 50px; +} + +li.source { + -moz-user-select: -moz-none; + -khtml-user-select: none; + -webkit-user-select: none; + -ms-user-select: none; + user-select: none; + color: #999; + padding: 0 5px; +} + +li.source div { + -moz-user-select: text; + -khtml-user-select: text; + -webkit-user-select: text; + -ms-user-select: text; + user-select: text; + padding: 1px 5px; + border-left: 1px solid #ccc; + margin: 0 0 0 -7px; + position: relative; + color: #000; + font-size: 111%; +} + .fileline { font-family: monospace; } .fileline img { border: 0; } diff -r 1bef6f99a12d -r 39a32bcfb658 tests/test-help.t --- a/tests/test-help.t Thu May 23 17:53:38 2013 -0500 +++ b/tests/test-help.t Fri May 31 12:25:09 2013 +0400 @@ -1456,7 +1456,10 @@ - + @@ -1622,7 +1625,10 @@ - + @@ -1818,7 +1824,10 @@ - + @@ -1913,7 +1922,10 @@ - + diff -r 1bef6f99a12d -r 39a32bcfb658 tests/test-hgweb-commands.t --- a/tests/test-hgweb-commands.t Thu May 23 17:53:38 2013 -0500 +++ b/tests/test-hgweb-commands.t Fri May 31 12:25:09 2013 +0400 @@ -338,7 +338,10 @@ - + @@ -465,7 +468,10 @@ - + @@ -557,7 +563,10 @@ - + @@ -667,16 +676,21 @@
    -
    line source
    +
    +
      -
      1 foo -
      +
    1. foo +
    2. +
    - + diff -r 1bef6f99a12d -r 39a32bcfb658 tests/test-hgweb-descend-empties.t --- a/tests/test-hgweb-descend-empties.t Thu May 23 17:53:38 2013 -0500 +++ b/tests/test-hgweb-descend-empties.t Fri May 31 12:25:09 2013 +0400 @@ -132,7 +132,10 @@ - + diff -r 1bef6f99a12d -r 39a32bcfb658 tests/test-hgweb-diffs.t --- a/tests/test-hgweb-diffs.t Thu May 23 17:53:38 2013 -0500 +++ b/tests/test-hgweb-diffs.t Fri May 31 12:25:09 2013 +0400 @@ -157,7 +157,10 @@ - + @@ -282,7 +285,10 @@ - + @@ -420,7 +426,10 @@ - + @@ -545,7 +554,10 @@ - + @@ -663,7 +675,10 @@ - + @@ -789,7 +804,10 @@ - + @@ -913,7 +931,10 @@ - + diff -r 1bef6f99a12d -r 39a32bcfb658 tests/test-hgweb-empty.t --- a/tests/test-hgweb-empty.t Thu May 23 17:53:38 2013 -0500 +++ b/tests/test-hgweb-empty.t Fri May 31 12:25:09 2013 +0400 @@ -91,7 +91,10 @@ - + @@ -184,7 +187,10 @@ - + @@ -328,7 +334,10 @@ - + @@ -401,7 +410,10 @@ - + diff -r 1bef6f99a12d -r 39a32bcfb658 tests/test-hgweb-filelog.t --- a/tests/test-hgweb-filelog.t Thu May 23 17:53:38 2013 -0500 +++ b/tests/test-hgweb-filelog.t Fri May 31 12:25:09 2013 +0400 @@ -207,7 +207,10 @@ - + @@ -314,7 +317,10 @@ - + @@ -416,7 +422,10 @@ - + @@ -518,7 +527,10 @@ - + @@ -583,7 +595,10 @@ - + diff -r 1bef6f99a12d -r 39a32bcfb658 tests/test-hgweb-removed.t --- a/tests/test-hgweb-removed.t Thu May 23 17:53:38 2013 -0500 +++ b/tests/test-hgweb-removed.t Fri May 31 12:25:09 2013 +0400 @@ -126,7 +126,10 @@ - + @@ -226,7 +229,10 @@ - + diff -r 1bef6f99a12d -r 39a32bcfb658 tests/test-hgweb.t --- a/tests/test-hgweb.t Thu May 23 17:53:38 2013 -0500 +++ b/tests/test-hgweb.t Fri May 31 12:25:09 2013 +0400 @@ -96,7 +96,10 @@ - + @@ -186,7 +189,10 @@ - + @@ -290,7 +296,10 @@ - + diff -r 1bef6f99a12d -r 39a32bcfb658 tests/test-hgwebdir.t --- a/tests/test-hgwebdir.t Thu May 23 17:53:38 2013 -0500 +++ b/tests/test-hgwebdir.t Fri May 31 12:25:09 2013 +0400 @@ -655,7 +655,10 @@ - + @@ -722,7 +725,10 @@ - + @@ -1082,7 +1088,10 @@ - + diff -r 1bef6f99a12d -r 39a32bcfb658 tests/test-highlight.t --- a/tests/test-highlight.t Thu May 23 17:53:38 2013 -0500 +++ b/tests/test-highlight.t Fri May 31 12:25:09 2013 +0400 @@ -136,46 +136,51 @@
    -
    line source
    +
    +
      -
      1 #!/usr/bin/env python
      - -
      3 """Fun with generators. Corresponding Haskell implementation:
      - -
      5 primes = 2 : sieve [3, 5..]
      -
      6 where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]
      -
      7 """
      - -
      9 from itertools import dropwhile, ifilter, islice, count, chain
      - -
      11 def primes():
      -
      12 """Generate all primes."""
      -
      13 def sieve(ns):
      -
      14 p = ns.next()
      -
      15 # It is important to yield *here* in order to stop the
      -
      16 # infinite recursion.
      -
      17 yield p
      -
      18 ns = ifilter(lambda n: n % p != 0, ns)
      -
      19 for n in sieve(ns):
      -
      20 yield n
      - -
      22 odds = ifilter(lambda i: i % 2 == 1, count())
      -
      23 return chain([2], sieve(dropwhile(lambda n: n < 3, odds)))
      - -
      25 if __name__ == "__main__":
      -
      26 import sys
      -
      27 try:
      -
      28 n = int(sys.argv[1])
      -
      29 except (ValueError, IndexError):
      -
      30 n = 10
      -
      31 p = primes()
      -
      32 print "The first %d primes: %s" % (n, list(islice(p, n)))
      +
    1. #!/usr/bin/env python
    2. +
    3. +
    4. """Fun with generators. Corresponding Haskell implementation:
    5. +
    6. +
    7. primes = 2 : sieve [3, 5..]
    8. +
    9. where sieve (p:ns) = p : sieve [n | n <- ns, mod n p /= 0]
    10. +
    11. """
    12. +
    13. +
    14. from itertools import dropwhile, ifilter, islice, count, chain
    15. +
    16. +
    17. def primes():
    18. +
    19. """Generate all primes."""
    20. +
    21. def sieve(ns):
    22. +
    23. p = ns.next()
    24. +
    25. # It is important to yield *here* in order to stop the
    26. +
    27. # infinite recursion.
    28. +
    29. yield p
    30. +
    31. ns = ifilter(lambda n: n % p != 0, ns)
    32. +
    33. for n in sieve(ns):
    34. +
    35. yield n
    36. +
    37. +
    38. odds = ifilter(lambda i: i % 2 == 1, count())
    39. +
    40. return chain([2], sieve(dropwhile(lambda n: n < 3, odds)))
    41. +
    42. +
    43. if __name__ == "__main__":
    44. +
    45. import sys
    46. +
    47. try:
    48. +
    49. n = int(sys.argv[1])
    50. +
    51. except (ValueError, IndexError):
    52. +
    53. n = 10
    54. +
    55. p = primes()
    56. +
    57. print "The first %d primes: %s" % (n, list(islice(p, n)))
    58. +
    - + @@ -502,7 +507,10 @@ - + @@ -586,24 +594,24 @@ > > echo % hgweb filerevision, html > "$TESTDIR/get-with-headers.py" localhost:$HGPORT "file/tip/$2" \ - > | grep '
    ' + > | grep '
  • ' > echo % errors encountered > cat errors.log > } $ hgserveget euc-jp eucjp.txt % HGENCODING=euc-jp hg serve % hgweb filerevision, html -
    1 \xb5\xfe
    (esc) +
  • \xb5\xfe
  • (esc) % errors encountered $ hgserveget utf-8 eucjp.txt % HGENCODING=utf-8 hg serve % hgweb filerevision, html -
    1 \xef\xbf\xbd\xef\xbf\xbd
    (esc) +
  • \xef\xbf\xbd\xef\xbf\xbd
  • (esc) % errors encountered $ hgserveget us-ascii eucjp.txt % HGENCODING=us-ascii hg serve % hgweb filerevision, html -
    1 ??
    +
  • ??
  • % errors encountered $ cd ..