From ee8ec78da76e3773246b4e144b637ef1f3420e80 Mon Sep 17 00:00:00 2001 From: Daniel Kimsey Date: Wed, 7 Nov 2012 17:17:49 -0500 Subject: [PATCH] Add --user-icons option: none, gravatar, and identicon. --- bin/gollum | 4 + gollum.gemspec | 5 + lib/gollum.rb | 1 + .../frontend/public/gollum/images/man_24.png | Bin 0 -> 376 bytes .../public/gollum/javascript/gollum.js | 17 +++ .../gollum/javascript/identicon_canvas.js | 111 ++++++++++++++++++ .../frontend/templates/history.mustache | 6 +- .../history_authors/gravatar.mustache | 5 + .../history_authors/identicon.mustache | 5 + .../templates/history_authors/none.mustache | 3 + lib/gollum/frontend/templates/layout.mustache | 3 + lib/gollum/frontend/views/history.rb | 25 +++- lib/gollum/frontend/views/page.rb | 4 + lib/gollum/wiki.rb | 6 + licenses/licenses.txt | 20 ++++ 15 files changed, 209 insertions(+), 6 deletions(-) create mode 100644 lib/gollum/frontend/public/gollum/images/man_24.png create mode 100644 lib/gollum/frontend/public/gollum/javascript/identicon_canvas.js create mode 100644 lib/gollum/frontend/templates/history_authors/gravatar.mustache create mode 100644 lib/gollum/frontend/templates/history_authors/identicon.mustache create mode 100644 lib/gollum/frontend/templates/history_authors/none.mustache diff --git a/bin/gollum b/bin/gollum index b35f37d8..23ee3c48 100755 --- a/bin/gollum +++ b/bin/gollum @@ -73,6 +73,10 @@ opts = OptionParser.new do |opts| wiki_options[:mathjax] = true end + opts.on("--user-icons [SOURCE]", "Set the history user icons. Valid values: gravatar, identicon, none. Default: none.") do + wiki_options[:user_icons] = source + end + opts.on("--show-all", "Shows all files in file view. By default only valid pages are shown.") do wiki_options[:show_all] = true end diff --git a/gollum.gemspec b/gollum.gemspec index 3f3973df..8afc9204 100644 --- a/gollum.gemspec +++ b/gollum.gemspec @@ -69,6 +69,7 @@ Gem::Specification.new do |s| lib/gollum/frontend/public/gollum/css/gollum.css lib/gollum/frontend/public/gollum/css/ie7.css lib/gollum/frontend/public/gollum/css/template.css + lib/gollum/frontend/public/gollum/images/man_24.png lib/gollum/frontend/public/gollum/images/dirty-shade.png lib/gollum/frontend/public/gollum/images/fileview/document.png lib/gollum/frontend/public/gollum/images/fileview/folder-horizontal.png @@ -91,6 +92,7 @@ Gem::Specification.new do |s| lib/gollum/frontend/public/gollum/javascript/gollum.dialog.js lib/gollum/frontend/public/gollum/javascript/gollum.js lib/gollum/frontend/public/gollum/javascript/gollum.placeholder.js + lib/gollum/frontend/public/gollum/javascript/identicon_canvas.js lib/gollum/frontend/public/gollum/javascript/jquery-1.7.2.min.js lib/gollum/frontend/public/gollum/javascript/jquery.color.js lib/gollum/frontend/public/gollum/javascript/mousetrap.min.js @@ -443,6 +445,9 @@ Gem::Specification.new do |s| lib/gollum/frontend/templates/pages.mustache lib/gollum/frontend/templates/search.mustache lib/gollum/frontend/templates/searchbar.mustache + lib/gollum/frontend/templates/history_authors/gravatar.mustache + lib/gollum/frontend/templates/history_authors/identicon.mustache + lib/gollum/frontend/templates/history_authors/none.mustache lib/gollum/frontend/uri_encode_component.rb lib/gollum/frontend/views/compare.rb lib/gollum/frontend/views/create.rb diff --git a/lib/gollum.rb b/lib/gollum.rb index 2d0da59a..be2b3612 100644 --- a/lib/gollum.rb +++ b/lib/gollum.rb @@ -1,6 +1,7 @@ # ~*~ encoding: utf-8 ~*~ # stdlib require 'digest/md5' +require 'digest/sha1' require 'ostruct' # external diff --git a/lib/gollum/frontend/public/gollum/images/man_24.png b/lib/gollum/frontend/public/gollum/images/man_24.png new file mode 100644 index 0000000000000000000000000000000000000000..0734f1f59b4eb6fa438051cc255aae2b3b5b5875 GIT binary patch literal 376 zcmV-;0f+vHP)K<)w6h9Y6<^;KeyGW(6XI`OHSE;-HE5POaJ+dxUM#nMxYcG2NJRk)PB++C?6E-r5PLjGefD$(pD zch_+bHo%McBJd}&1fuc|LLbB+sOy@ea75NeMRDzXh`*|#D=f(@DDezxI!H_L6kq^$ Wfk-dsKpUC>0000').get(0); + render_identicon(canvas, code, 16); + img_bin = canvas.toDataURL("image/png"); + lookup[code] = img_bin; + } + $item.attr('src', img_bin); + }); + } }); diff --git a/lib/gollum/frontend/public/gollum/javascript/identicon_canvas.js b/lib/gollum/frontend/public/gollum/javascript/identicon_canvas.js new file mode 100644 index 00000000..a533d8ef --- /dev/null +++ b/lib/gollum/frontend/public/gollum/javascript/identicon_canvas.js @@ -0,0 +1,111 @@ +/* +Client-side Canvas tag based Identicon rendering code + +@author Don Park +@version 0.2 +@date January 21th, 2007 +*/ + +var patch0 = new Array( 0, 4, 24, 20 ); +var patch1 = new Array( 0, 4, 20 ); +var patch2 = new Array( 2, 24, 20 ); +var patch3 = new Array( 0, 2, 20, 22 ); +var patch4 = new Array( 2, 14, 22, 10 ); +var patch5 = new Array( 0, 14, 24, 22 ); +var patch6 = new Array( 2, 24, 22, 13, 11, 22, 20 ); +var patch7 = new Array( 0, 14, 22 ); +var patch8 = new Array( 6, 8, 18, 16 ); +var patch9 = new Array( 4, 20, 10, 12, 2 ); +var patch10 = new Array( 0, 2, 12, 10 ); +var patch11 = new Array( 10, 14, 22 ); +var patch12 = new Array( 20, 12, 24 ); +var patch13 = new Array( 10, 2, 12 ); +var patch14 = new Array( 0, 2, 10 ); +var patchTypes = new Array( patch0, patch1, patch2, patch3, patch4, + patch5, patch6, patch7, patch8, patch9, patch10, patch11, + patch12, patch13, patch14, patch0 ); +var centerPatchTypes = new Array(0, 4, 8, 15); + +function render_identicon_patch(ctx, x, y, size, patch, turn, invert, foreColor, backColor) { + patch %= patchTypes.length; + turn %= 4; + if (patch == 15) + invert = !invert; + + var vertices = patchTypes[patch]; + var offset = size / 2; + var scale = size / 4; + + ctx.save(); + + // paint background + ctx.fillStyle = invert ? foreColor : backColor; + ctx.fillRect(x, y, size, size); + + // build patch path + ctx.translate(x + offset, y + offset); + ctx.rotate(turn * Math.PI / 2); + ctx.beginPath(); + ctx.moveTo((vertices[0] % 5 * scale - offset), (Math.floor(vertices[0] / 5) * scale - offset)); + for (var i = 1; i < vertices.length; i++) + ctx.lineTo((vertices[i] % 5 * scale - offset), (Math.floor(vertices[i] / 5) * scale - offset)); + ctx.closePath(); + + // offset and rotate coordinate space by patch position (x, y) and + // 'turn' before rendering patch shape + + // render rotated patch using fore color (back color if inverted) + ctx.fillStyle = invert ? backColor : foreColor; + ctx.fill(); + + // restore rotation + ctx.restore(); +} + +function render_identicon(node, code, size) { + if (!node || !code || !size) return; + + var patchSize = size / 3; + var middleType = centerPatchTypes[code & 3]; + var middleInvert = ((code >> 2) & 1) != 0; + var cornerType = (code >> 3) & 15; + var cornerInvert = ((code >> 7) & 1) != 0; + var cornerTurn = (code >> 8) & 3; + var sideType = (code >> 10) & 15; + var sideInvert = ((code >> 14) & 1) != 0; + var sideTurn = (code >> 15) & 3; + var blue = (code >> 16) & 31; + var green = (code >> 21) & 31; + var red = (code >> 27) & 31; + var foreColor = "rgb(" + (red << 3) + "," + (green << 3) + "," + (blue << 3) + ")"; + var backColor = "rgb(255,255,255)"; + + var ctx = node.getContext("2d"); + + // middle patch + render_identicon_patch(ctx, patchSize, patchSize, patchSize, middleType, 0, middleInvert, foreColor, backColor); + // side patchs, starting from top and moving clock-wise + render_identicon_patch(ctx, patchSize, 0, patchSize, sideType, sideTurn++, sideInvert, foreColor, backColor); + render_identicon_patch(ctx, patchSize * 2, patchSize, patchSize, sideType, sideTurn++, sideInvert, foreColor, backColor); + render_identicon_patch(ctx, patchSize, patchSize * 2, patchSize, sideType, sideTurn++, sideInvert, foreColor, backColor); + render_identicon_patch(ctx, 0, patchSize, patchSize, sideType, sideTurn++, sideInvert, foreColor, backColor); + // corner patchs, starting from top left and moving clock-wise + render_identicon_patch(ctx, 0, 0, patchSize, cornerType, cornerTurn++, cornerInvert, foreColor, backColor); + render_identicon_patch(ctx, patchSize * 2, 0, patchSize, cornerType, cornerTurn++, cornerInvert, foreColor, backColor); + render_identicon_patch(ctx, patchSize * 2, patchSize * 2, patchSize, cornerType, cornerTurn++, cornerInvert, foreColor, backColor); + render_identicon_patch(ctx, 0, patchSize * 2, patchSize, cornerType, cornerTurn++, cornerInvert, foreColor, backColor); +} + +function render_identicon_canvases(prefix) { + var canvases = document.getElementsByTagName("canvas"); + var n = canvases.length; + for (var i = 0; i < n; i++) { + var node = canvases[i]; + if (node.title && node.title.indexOf(prefix) == 0) { + if (node.style.display == 'none') node.style.display = "inline"; + var code = node.title.substring(prefix.length) * 1; + var size = node.width; + render_identicon(node, code, size); + } + } +} diff --git a/lib/gollum/frontend/templates/history.mustache b/lib/gollum/frontend/templates/history.mustache index 5ef9a6b5..15502d29 100644 --- a/lib/gollum/frontend/templates/history.mustache +++ b/lib/gollum/frontend/templates/history.mustache @@ -30,11 +30,7 @@ - - avatar: {{author}} - {{author}} - + {{>author_template}} {{date}}:  diff --git a/lib/gollum/frontend/templates/history_authors/gravatar.mustache b/lib/gollum/frontend/templates/history_authors/gravatar.mustache new file mode 100644 index 00000000..96f72066 --- /dev/null +++ b/lib/gollum/frontend/templates/history_authors/gravatar.mustache @@ -0,0 +1,5 @@ + +avatar: {{author}} + {{author}} + diff --git a/lib/gollum/frontend/templates/history_authors/identicon.mustache b/lib/gollum/frontend/templates/history_authors/identicon.mustache new file mode 100644 index 00000000..65cb17ea --- /dev/null +++ b/lib/gollum/frontend/templates/history_authors/identicon.mustache @@ -0,0 +1,5 @@ + + avatar: {{author}} + {{author}} + diff --git a/lib/gollum/frontend/templates/history_authors/none.mustache b/lib/gollum/frontend/templates/history_authors/none.mustache new file mode 100644 index 00000000..4539dabd --- /dev/null +++ b/lib/gollum/frontend/templates/history_authors/none.mustache @@ -0,0 +1,3 @@ + + {{author}} + diff --git a/lib/gollum/frontend/templates/layout.mustache b/lib/gollum/frontend/templates/layout.mustache index f632475d..95d97c1d 100644 --- a/lib/gollum/frontend/templates/layout.mustache +++ b/lib/gollum/frontend/templates/layout.mustache @@ -19,6 +19,9 @@ + {{#use_identicon}} + + {{/use_identicon}} {{#mathjax}}