Commit a0fc7909e341a92dd85cacba10618a2825eab7a8

Thomas de Grivel 2022-05-26T18:47:37

use prismjs for diffs

diff --git a/lib/kmxgit/git.ex b/lib/kmxgit/git.ex
index 69241ba..ba77dce 100644
--- a/lib/kmxgit/git.ex
+++ b/lib/kmxgit/git.ex
@@ -69,11 +69,11 @@ defmodule Kmxgit.Git do
   def log(repo, tree \\ "HEAD", path \\ "") do
     tree = tree || "HEAD"
     dir = git_dir(repo)
+    # [%{author: author, author_email: email, hash: hash, date: date, message: msg}]
     log_nif(dir, tree, path)
-    # %{author: author, author_email: email, hash: hash, date: date, message: msg}
   end
 
-  def log_nif(repo, tree, path) do
+  def log_nif(_repo, _tree, _path) do
     exit(:nif_not_loaded)
   end
 end
diff --git a/lib/kmxgit_web/controllers/repository_controller.ex b/lib/kmxgit_web/controllers/repository_controller.ex
index 33f8e58..51ccaac 100644
--- a/lib/kmxgit_web/controllers/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/repository_controller.ex
@@ -401,13 +401,13 @@ defmodule KmxgitWeb.RepositoryController do
              {:ok, diff} -> diff
              _ -> nil
            end
-    diff_html = diff && Pygmentize.html(diff, "diff.patch")
+    #diff_html = diff && Pygmentize.html(diff, "diff.patch")
     diff_line_numbers = diff && line_numbers(diff)
     conn
     |> assign(:commit, git.log1)
     |> assign_current_organisation(org)
     |> assign(:current_repository, repo)
-    |> assign(:diff_html, diff_html)
+    |> assign(:diff, diff)
     |> assign(:diff_line_numbers, diff_line_numbers)
     |> assign(:path, path)
     |> assign(:repo, repo)
@@ -416,14 +416,14 @@ defmodule KmxgitWeb.RepositoryController do
   defp show_op(conn, :diff, %{from: from, org: org, path: path, repo: repo, to: to}) do
     case GitManager.diff(Repository.full_slug(repo), from, to) do
       {:ok, diff} ->
-        diff_html = Pygmentize.html(diff, "diff.patch")
+        #diff_html = Pygmentize.html(diff, "diff.patch")
         diff_line_numbers = line_numbers(diff)
         #IO.inspect(from: from, to: to, diff: diff, html: diff_html, line_numbers: diff_line_numbers)
         conn
         |> assign_current_organisation(org)
         |> assign(:current_repository, repo)
+        |> assign(:diff, diff)
         |> assign(:diff_from, from)
-        |> assign(:diff_html, diff_html)
         |> assign(:diff_line_numbers, diff_line_numbers)
         |> assign(:diff_to, to)
         |> assign(:path, path)
diff --git a/lib/kmxgit_web/templates/repository/commit.html.heex b/lib/kmxgit_web/templates/repository/commit.html.heex
index 4beb3e7..0b97275 100644
--- a/lib/kmxgit_web/templates/repository/commit.html.heex
+++ b/lib/kmxgit_web/templates/repository/commit.html.heex
@@ -23,13 +23,13 @@
         </p>
         <div class="clear"></div>
       </div>
-      <%= if @diff_html do %>
+      <%= if @diff do %>
         <div class="content_text">
           <div class="line_numbers">
             <pre><%= for ln <- @diff_line_numbers do %><%= link ln, id: ln, to: "##{ln}" %>
             <% end %></pre>
           </div>
-          <%= raw @diff_html %>
+          <pre><code class="language-diff"><%= @diff %></code></pre>
         </div>
         <hr/>
       <% end %>
diff --git a/lib/kmxgit_web/templates/repository/diff.html.heex b/lib/kmxgit_web/templates/repository/diff.html.heex
index d8a43cc..875b17d 100644
--- a/lib/kmxgit_web/templates/repository/diff.html.heex
+++ b/lib/kmxgit_web/templates/repository/diff.html.heex
@@ -19,7 +19,7 @@
           <pre><%= for ln <- @diff_line_numbers do %><%= link ln, id: ln, to: "##{ln}" %>
           <% end %></pre>
         </div>
-        <%= raw @diff_html %>
+        <pre><code class="language-diff"><%= @diff %></code></pre>
       </div>
     </div>
   </div>