[PATCH 6 of 7 v3] diff: refactor code-block of the 2 templates into 1

Jan Heylen heyleke at gmail.com
Sat Jan 2 12:15:06 UTC 2016


# HG changeset patch
# User Jan Heylen <heyleke at gmail.com>
# Date 1451732018 -3600
#      Sat Jan 02 11:53:38 2016 +0100
# Node ID c81bb24c4c768b470202e2960368983b2970e8ba
# Parent  36c5b558da1f46926effdc6c8d97b62879a55dd1
diff: refactor code-block of the 2 templates into 1

diff -r 36c5b558da1f -r c81bb24c4c76 kallithea/templates/changeset/diff_block.html
--- a/kallithea/templates/changeset/diff_block.html	Sat Jan 02 10:58:06 2016 +0100
+++ b/kallithea/templates/changeset/diff_block.html	Sat Jan 02 11:53:38 2016 +0100
@@ -3,6 +3,29 @@
 ## <%namespace name="diff_block" file="/changeset/diff_block.html"/>
 ## ${diff_block.diff_block(change)}
 ##
+
+<%def name="code_body(diff,path,fid,change,reponame1,reponame2,rev1,rev2)">
+<div class="code-body full_f_path" data-f_path="${h.safe_unicode(path)}">
+    ${diff|n}
+    %if path.rsplit('.')[-1] in ['png', 'gif', 'jpg', 'bmp']:
+    <div class="btn btn-image-diff-show">Show images</div>
+    %if change == 'M':
+    <div id="${h.FID(fid,path)}_image-diff" class="btn btn-image-diff-swap" style="display:none">Press to swap images</div>
+    %endif
+    <div style="font-size: 0">
+        %if change in 'DM':
+        <img id="${h.FID(fid,path)}_image-diff-img-a" class="img-diff img-diff-swapable" style="display:none"
+            realsrc="${h.url('files_raw_home',repo_name=reponame1,revision=rev1,f_path=path)}" />
+        %endif
+        %if change in 'AM':
+        <img id="${h.FID(fid,path)}_image-diff-img-b" class="img-diff img-diff-swapable" style="display:none"
+            realsrc="${h.url('files_raw_home',repo_name=reponame2,revision=rev2,f_path=path)}" />
+        %endif
+    </div>
+    %endif
+</div>
+</%def>
+
 <%def name="diff_block(change)">
 <div class="diff-collapse">
     <span target="${'diff-container-%s' % (id(change))}" class="diff-collapse-button">↑ ${_('Collapse Diff')} ↑</span>
@@ -41,25 +64,7 @@
                 </span>
             </div>
         </div>
-        <div class="code-body full_f_path" data-f_path="${h.safe_unicode(path)}">
-            ${diff|n}
-            %if path.rsplit('.')[-1] in ['png', 'gif', 'jpg', 'bmp']:
-              <div class="btn btn-image-diff-show">Show images</div>
-              %if change =='M':
-                <div id="${FID}_image-diff" class="btn btn-image-diff-swap" style="display:none">Press to swap images</div>
-              %endif
-              <div style="font-size: 0">
-                %if change in 'DM':
-                  <img id="${FID}_image-diff-img-a" class="img-diff img-diff-swapable" style="display:none"
-                      realsrc="${h.url('files_raw_home',repo_name=c.repo_name,revision=cs1,f_path=path)}" />
-                %endif
-                %if change in 'AM':
-                  <img id="${FID}_image-diff-img-b" class="img-diff img-diff-swapable" style="display:none"
-                      realsrc="${h.url('files_raw_home',repo_name=c.repo_name,revision=cs2,f_path=path)}" />
-                %endif
-              </div>
-            %endif
-        </div>
+        <% code_body(diff,path,FID,change,c.repo_name,c.repo_name,cs1,cs2) %>
     </div>
 %endfor
 </div>
@@ -120,25 +125,7 @@
               </div>
           </div>
       </div>
-        <div class="code-body full_f_path" data-f_path="${h.safe_unicode(filenode_path)}">
-            ${diff|n}
-            %if filenode_path.rsplit('.')[-1] in ['png', 'gif', 'jpg', 'bmp']:
-              <div class="btn btn-image-diff-show">Show images</div>
-              %if op == 'M':
-                <div id="${h.FID('',filenode_path)}_image-diff" class="btn btn-image-diff-swap" style="display:none">Press to swap images</div>
-              %endif
-              <div style="font-size: 0">
-                %if op in 'DM':
-                  <img id="${h.FID('',filenode_path)}_image-diff-img-a" class="img-diff img-diff-swapable" style="display:none"
-                      realsrc="${h.url('files_raw_home',repo_name=c.a_repo.repo_name,revision=c.a_rev,f_path=filenode_path) if op in 'DM' else ''}" />
-                %endif
-                %if op in 'AM':
-                  <img id="${h.FID('',filenode_path)}_image-diff-img-b" class="img-diff img-diff-swapable" style="display:none"
-                      realsrc="${h.url('files_raw_home',repo_name=c.cs_repo.repo_name,revision=c.cs_rev,f_path=filenode_path) if op in 'AM' else ''}" />
-                %endif
-              </div>
-            %endif
-        </div>
+      <% code_body(diff,filenode_path,'',op,c.a_repo.repo_name,c.cs_repo.repo_name,c.a_rev,c.cs_rev) %>
     </div>
   %endfor
 %endfor


More information about the kallithea-general mailing list