Browse Source

Fix issue #1

tags/v1.2.0
Simon Vieille 2 years ago
parent
commit
96f199adaa

+ 3
- 2
bower.json View File

@@ -11,11 +11,12 @@
11 11
     "GIT"
12 12
   ],
13 13
   "license": "LGPL",
14
-  "homepage": "https://gitlab.deblan.org/deblan/gist.deblan.org",
14
+  "homepage": "https://gitnet.fr/deblan/gist",
15 15
   "dependencies": {
16 16
     "bootstrap": "3.3.4",
17 17
     "flag-icon-css": "0.7.1",
18 18
     "SyntaxHighlighter": "3.0.83",
19
-    "iframe-resizer": "2.8.6"
19
+    "iframe-resizer": "2.8.6",
20
+    "jsdiff": "~2.2.2"
20 21
   }
21 22
 }

+ 1
- 1
src/Gist/Model/Gist.php View File

@@ -39,7 +39,7 @@ class Gist extends BaseGist
39 39
     {
40 40
         $data = array(
41 41
             'javascript' => 'js',
42
-            'yaml'=> 'yml',
42
+            'yaml' => 'yml',
43 43
             'perl' => 'pl',
44 44
             'python' => 'py',
45 45
             'bash' => 'sh',

+ 30
- 0
src/Gist/Resources/views/View/cipherJs.html.twig View File

@@ -0,0 +1,30 @@
1
+<script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/XRegExp.js"></script> <!-- XRegExp is bundled with the final shCore.js during build -->
2
+<script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/shCore.js"></script>
3
+<script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/shAutoloader.js"></script>
4
+<script type="text/javascript">
5
+    SyntaxHighlighter.autoloader(
6
+        ['applescript',                    '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushAppleScript.js' ],
7
+        ['actionscript3', 'as3',           '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushAS3.js' ],
8
+        ['bash', 'shell',                  '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushBash.js' ],
9
+        ['coldfusion', 'cf',               '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushColdFusion.js' ],
10
+        ['cpp', 'c',                       '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCpp.js' ],
11
+        ['c#', 'c-sharp', 'csharp',        '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCSharp.js' ],
12
+        ['css',                            '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCss.js' ],
13
+        ['delphi', 'pascal',               '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushDelphi.js' ],
14
+        ['diff', 'patch', 'pas',           '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushDiff.js' ],
15
+        ['erl', 'erlang',                  '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushErlang.js' ],
16
+        ['groovy',                         '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushGroovy.js' ],
17
+        ['java',                           '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJava.js' ],
18
+        ['jfx', 'javafx',                  '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJavaFX.js' ],
19
+        ['js', 'jscript', 'javascript',    '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJScript.js' ],
20
+        ['perl', 'pl',                     '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPerl.js' ],
21
+        ['php',                            '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPhp.js' ],
22
+        ['text', 'plain',                  '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPlain.js' ],
23
+        ['py', 'python',                   '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPython.js' ],
24
+        ['ruby', 'rails', 'ror', 'rb',     '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushRuby.js' ],
25
+        ['scala',                          '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushScala.js' ],
26
+        ['sql',                            '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushSql.js' ],
27
+        ['vb', 'vbnet',                    '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushVb.js' ],
28
+        ['xml', 'xhtml', 'xslt', 'html',   '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushXml.js' ]
29
+    );
30
+</script>

+ 60
- 2
src/Gist/Resources/views/View/revisions.html.twig View File

@@ -52,9 +52,10 @@
52 52
                                     </p>
53 53
                                     <div>
54 54
                                         {% if not loop.first %}
55
-
56 55
                                             <div class="diff" id="diff-{{ loop.index }}">
57
-                                                {{ commit.diff|raw }}
56
+                                                {% if not gist.cipher %}
57
+                                                    {{ commit.diff|raw }}
58
+                                                {% endif %}
58 59
                                             </div>
59 60
                                         {% endif %}
60 61
                                     </div>
@@ -74,4 +75,61 @@
74 75
 
75 76
 {% block js %}
76 77
     {{ parent() }}
78
+
79
+    {% if gist.cipher %}
80
+        {{ include('View/cipherJs.html.twig') }}
81
+
82
+        <script src="{{ web_path }}components/jsdiff/diff.min.js"></script>
83
+
84
+        <script>
85
+            var key = getKey();
86
+
87
+            var decrypt = function(content) {
88
+                var decrypted = CryptoJS.AES.decrypt(content, key, {
89
+                    format: JsonFormatter
90
+                });
91
+
92
+                return decrypted.toString(CryptoJS.enc.Utf8);
93
+            }
94
+
95
+            var commits = [];
96
+
97
+            {% for commit in history %}
98
+                try {
99
+                    var content = decrypt('{{ commit.content|raw }}');
100
+                    commits[{{ loop.index - 1 }}] = content;
101
+                } catch(e) {
102
+                }
103
+            {% endfor %}
104
+
105
+            for (var u = commits.length - 1; u > 0; u--) {
106
+                if (commits.hasOwnProperty(u) && commits.hasOwnProperty(u - 1)) {
107
+                    var previous = commits[u - 1];
108
+                    var current = commits[u];
109
+                    var diff = JsDiff.diffLines(previous, current);
110
+                    var diffContent = [];
111
+
112
+                    for (var v = 0, c = diff.length; v < c; v++) {
113
+                        var value = diff[v].value;
114
+                        var sign = diff[v].added ? '+' : '-';
115
+                        var lines = value.split("\n");
116
+
117
+                        for (var i = 0, l = lines.length; i < l; i++) {
118
+                            diffContent.push(sign + lines[i]);
119
+                        }
120
+                    }
121
+
122
+                    diffContent = diffContent.join("\n");
123
+                    
124
+                    var $pre = $('<pre>')
125
+                        .attr('class', 'brush: diff; syntaxhighlighter')
126
+                        .html(diffContent);
127
+                                    
128
+                    $('#diff-' + (u + 1).toString()).append($pre);
129
+                }
130
+            }
131
+
132
+            SyntaxHighlighter.all();
133
+        </script>
134
+    {% endif %}
77 135
 {% endblock %}

+ 1
- 30
src/Gist/Resources/views/View/view.html.twig View File

@@ -84,35 +84,6 @@
84 84
     {{ parent() }}
85 85
     
86 86
     {% if gist.cipher %}
87
-        <script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/XRegExp.js"></script> <!-- XRegExp is bundled with the final shCore.js during build -->
88
-        <script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/shCore.js"></script>
89
-        <script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/shAutoloader.js"></script>
90
-        <script type="text/javascript">
91
-            SyntaxHighlighter.autoloader(
92
-                ['applescript',                    '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushAppleScript.js' ],
93
-                ['actionscript3', 'as3',           '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushAS3.js' ],
94
-                ['bash', 'shell',                  '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushBash.js' ],
95
-                ['coldfusion', 'cf',               '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushColdFusion.js' ],
96
-                ['cpp', 'c',                       '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCpp.js' ],
97
-                ['c#', 'c-sharp', 'csharp',        '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCSharp.js' ],
98
-                ['css',                            '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCss.js' ],
99
-                ['delphi', 'pascal',               '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushDelphi.js' ],
100
-                ['diff', 'patch', 'pas',           '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushDiff.js' ],
101
-                ['erl', 'erlang',                  '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushErlang.js' ],
102
-                ['groovy',                         '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushGroovy.js' ],
103
-                ['java',                           '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJava.js' ],
104
-                ['jfx', 'javafx',                  '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJavaFX.js' ],
105
-                ['js', 'jscript', 'javascript',    '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJScript.js' ],
106
-                ['perl', 'pl',                     '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPerl.js' ],
107
-                ['php',                            '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPhp.js' ],
108
-                ['text', 'plain',                  '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPlain.js' ],
109
-                ['py', 'python',                   '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPython.js' ],
110
-                ['ruby', 'rails', 'ror', 'rb',     '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushRuby.js' ],
111
-                ['scala',                          '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushScala.js' ],
112
-                ['sql',                            '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushSql.js' ],
113
-                ['vb', 'vbnet',                    '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushVb.js' ],
114
-                ['xml', 'xhtml', 'xslt', 'html',   '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushXml.js' ]
115
-            );
116
-        </script>
87
+        {{ include('View/cipherJs.html.twig') }}
117 88
     {% endif %}
118 89
 {% endblock %}

+ 4
- 0
src/Gist/Service/Gist.php View File

@@ -65,6 +65,10 @@ class Gist
65 65
                 'diff' => $this->highlight('diff', $diff),
66 66
             );
67 67
 
68
+            if ($gist->isCipher()) {
69
+                $data['content'] = $this->getContent($gist, $commit);
70
+            }
71
+
68 72
             $history[] = $data;
69 73
         }
70 74
 

+ 17
- 3
web/app/js/app.js View File

@@ -66,14 +66,28 @@ var editorEvents = function() {
66 66
         $(this).trigger('change');
67 67
     });
68 68
 
69
+    var key = getKey();
70
+
71
+    if (key) {
72
+        $('.show-diff').each(function() {
73
+            var href = $(this).attr('href');
74
+            href = href.replace('#', '#key=' + key + '&');
75
+
76
+            $(this).attr('href', href);
77
+        });
78
+    }
79
+
69 80
     $('.show-diff').click(function() {
70 81
         $($(this).data('target')).toggle();
71 82
     });
72 83
 
73
-    if ((document.location.href).indexOf('#diff-') !== -1) {
84
+    var diffLinkTest1 = (document.location.href).indexOf('#diff-') !== -1;
85
+    var diffLinkTest2 = (document.location.href).indexOf('&diff-') !== -1;
86
+
87
+    if (diffLinkTest1 || diffLinkTest2) {
74 88
         var anchor = '#' + (document.location.href).toString().split('#')[1];
89
+
75 90
         $('.show-diff[href="' + anchor + '"]').click();
76
-        document.location.href = anchor;
77 91
     }
78 92
 }
79 93
 
@@ -119,7 +133,7 @@ var getKey = function() {
119 133
     var parts = url.split('#key=');
120 134
 
121 135
     if (parts.length === 2) {
122
-        return parts[1];
136
+        return parts[1].split('&')[0];
123 137
     }
124 138
 
125 139
     return null;

Loading…
Cancel
Save