Commit 6475e63ffec37a28533ebb7053e4f6746dc7a5c1

Thomas de Grivel 2022-08-01T17:22:20

add markdown syntax enabled, and fix admin organisation slug_.

diff --git a/README.md b/README.md
index e2276e5..5c930ac 100644
--- a/README.md
+++ b/README.md
@@ -67,18 +67,19 @@ location ~ ^(.*/info/refs|.*/git-upload-pack)$ {
 ## kmxgit 0.4
 
  - Performance improvements :
-   - DONE git bindings
+   - git bindings
+     - free
+     - segfault
    - DONE pygmentize -> prismjs
    - DONE shell commands -> elixir (mkdir mv rm)
    - DONE slugs without joins
    - disk usage
      - DONE disabled port
      - remove
- - Bug: git log only shows first patch
- - Display dotfiles
+ - DONE Display dotfiles
  - Markdown
-   - display "markdown" in edit pages
-   - refactor calls to module
+   - DONE refactor calls to module
+   - DONE display "Markdown syntax enabled" in edit pages
  - Shared deploy SSH keys.
    - For now deploy keys must be unique (cannot be shared between repos).
  - Releases
diff --git a/lib/kmxgit_web.ex b/lib/kmxgit_web.ex
index 5045be6..c9fca60 100644
--- a/lib/kmxgit_web.ex
+++ b/lib/kmxgit_web.ex
@@ -56,6 +56,7 @@ defmodule KmxgitWeb do
       unquote(view_helpers())
 
       alias Kmxgit.UserManager.User
+      alias KmxgitWeb.LayoutView
 
       def disk_usage(size) do
         units = {:kb, :mb, :gb, :tb}
diff --git a/lib/kmxgit_web/controllers/repository_controller.ex b/lib/kmxgit_web/controllers/repository_controller.ex
index 236969b..c0323f9 100644
--- a/lib/kmxgit_web/controllers/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/repository_controller.ex
@@ -287,7 +287,7 @@ defmodule KmxgitWeb.RepositoryController do
           #content_html = Pygmentize.html(content, filename)
           line_numbers = line_numbers(content)
           markdown_html = if ext && String.match?(ext, ~r/md/i) do
-            Earmark.as_html!(content)
+            Markdown.to_html!(content)
           end
           lang = lang(ext, filename)
           #IO.inspect(path: path, name: name, type: type)
@@ -306,7 +306,7 @@ defmodule KmxgitWeb.RepositoryController do
     readme = Enum.map(files, fn f ->
       if String.match?(f.name, ~r/^readme\.md$/i) do
         {:ok, content} = Git.content(Repository.full_slug(repo), f.sha1)
-        %{html: Earmark.as_html!(content),
+        %{html: Markdown.to_html!(content),
           name: f.name,
           txt: content}
       else
diff --git a/lib/kmxgit_web/templates/admin/organisation/form.html.heex b/lib/kmxgit_web/templates/admin/organisation/form.html.heex
index f67a37b..a4d15b7 100644
--- a/lib/kmxgit_web/templates/admin/organisation/form.html.heex
+++ b/lib/kmxgit_web/templates/admin/organisation/form.html.heex
@@ -1,12 +1,10 @@
 <%= form_for @changeset, @action, fn f -> %>
 
-  <%= inputs_for f, :slug, fn ff -> %>
-    <div class="mb-3">
-      <%= label ff, :slug, class: "form-label" %>
-      <%= text_input ff, :slug, class: "form-control" %>
-      <%= error_tag ff, :slug %>
-    </div>
-  <% end %>
+  <div class="mb-3">
+    <%= label f, :slug_, class: "form-label" %>
+    <%= text_input f, :slug_, class: "form-control" %>
+    <%= error_tag f, :slug_ %>
+  </div>
 
   <div class="mb-3">
     <%= label f, :name, class: "form-label" %>
@@ -17,6 +15,7 @@
   <div class="mb-3">
     <%= label f, :description, class: "form-label" %>
     <%= textarea f, :description, class: "form-control" %>
+    <%= render LayoutView, "markdown_enabled.html" %>
     <%= error_tag f, :description %>
   </div>
 
diff --git a/lib/kmxgit_web/templates/admin/organisation/show.html.heex b/lib/kmxgit_web/templates/admin/organisation/show.html.heex
index f2cb2a7..f99b43d 100644
--- a/lib/kmxgit_web/templates/admin/organisation/show.html.heex
+++ b/lib/kmxgit_web/templates/admin/organisation/show.html.heex
@@ -18,7 +18,7 @@
       <th><%= gettext "Description" %></th>
       <td>
         <%= if @org.description do %>
-          <%= raw Earmark.as_html!(@org.description) %>
+          <%= raw Markdown.to_html!(@org.description) %>
         <% end %>
       </td>
     </tr>
diff --git a/lib/kmxgit_web/templates/admin/repository/form.html.heex b/lib/kmxgit_web/templates/admin/repository/form.html.heex
index 71f5573..ceb8ae7 100644
--- a/lib/kmxgit_web/templates/admin/repository/form.html.heex
+++ b/lib/kmxgit_web/templates/admin/repository/form.html.heex
@@ -20,6 +20,7 @@
   <div class="mb-3">
     <%= label f, :description, class: "form-label" %>
     <%= textarea f, :description, class: "form-control" %>
+    <%= render LayoutView, "markdown_enabled.html" %>
     <%= error_tag f, :description %>
   </div>
 
diff --git a/lib/kmxgit_web/templates/admin/repository/show.html.heex b/lib/kmxgit_web/templates/admin/repository/show.html.heex
index b64214a..e152469 100644
--- a/lib/kmxgit_web/templates/admin/repository/show.html.heex
+++ b/lib/kmxgit_web/templates/admin/repository/show.html.heex
@@ -47,7 +47,7 @@
       <th><%= gettext "Description" %></th>
       <td>
         <%= if @repo.description do %>
-          <%= raw Earmark.as_html!(@repo.description) %>
+          <%= raw Markdown.to_html!(@repo.description) %>
         <% end %>
       </td>
     </tr>
diff --git a/lib/kmxgit_web/templates/admin/user/new.html.heex b/lib/kmxgit_web/templates/admin/user/new.html.heex
index 8d67860..65e59de 100644
--- a/lib/kmxgit_web/templates/admin/user/new.html.heex
+++ b/lib/kmxgit_web/templates/admin/user/new.html.heex
@@ -31,6 +31,7 @@
     <div class="mb-3">
       <%= label f, :description, class: "form-label" %>
       <%= textarea f, :description, class: "form-control" %>
+      <%= render LayoutView, "markdown_enabled.html" %>
       <%= error_tag f, :description %>
     </div>
 
diff --git a/lib/kmxgit_web/templates/layout/markdown_enabled.html.heex b/lib/kmxgit_web/templates/layout/markdown_enabled.html.heex
new file mode 100644
index 0000000..bd12b00
--- /dev/null
+++ b/lib/kmxgit_web/templates/layout/markdown_enabled.html.heex
@@ -0,0 +1 @@
+<small id="descriptionHelp" class="form-text text-muted"><%= link "Markdown syntax", to: "https://daringfireball.net/projects/markdown/syntax" %> enabled.</small>
diff --git a/lib/kmxgit_web/templates/organisation/form.html.heex b/lib/kmxgit_web/templates/organisation/form.html.heex
index 95b5cde..ed778ff 100644
--- a/lib/kmxgit_web/templates/organisation/form.html.heex
+++ b/lib/kmxgit_web/templates/organisation/form.html.heex
@@ -15,6 +15,7 @@
   <div class="mb-3">
     <%= label f, :description, class: "form-label" %>
     <%= textarea f, :description, class: "form-control" %>
+    <%= render LayoutView, "markdown_enabled.html" %>
     <%= error_tag f, :description %>
   </div>
 
diff --git a/lib/kmxgit_web/templates/repository/form.html.heex b/lib/kmxgit_web/templates/repository/form.html.heex
index 08c3228..ccb2526 100644
--- a/lib/kmxgit_web/templates/repository/form.html.heex
+++ b/lib/kmxgit_web/templates/repository/form.html.heex
@@ -20,6 +20,7 @@
   <div class="mb-3">
     <%= label f, :description, class: "form-label" %>
     <%= textarea f, :description, class: "form-control" %>
+    <%= render LayoutView, "markdown_enabled.html" %>
     <%= error_tag f, :description %>
   </div>
 
diff --git a/lib/kmxgit_web/templates/repository/show_properties.html.heex b/lib/kmxgit_web/templates/repository/show_properties.html.heex
index e0fd1e8..e455cf9 100644
--- a/lib/kmxgit_web/templates/repository/show_properties.html.heex
+++ b/lib/kmxgit_web/templates/repository/show_properties.html.heex
@@ -24,7 +24,7 @@
     <th><%= gettext "Description" %></th>
     <td>
       <%= if @repo.description do %>
-        <%= raw Earmark.as_html!(@repo.description) %>
+        <%= raw Markdown.to_html!(@repo.description) %>
       <% end %>
     </td>
   </tr>
diff --git a/lib/kmxgit_web/templates/user/edit.html.heex b/lib/kmxgit_web/templates/user/edit.html.heex
index 68c7705..28e4472 100644
--- a/lib/kmxgit_web/templates/user/edit.html.heex
+++ b/lib/kmxgit_web/templates/user/edit.html.heex
@@ -24,6 +24,7 @@
     <div class="mb-3">
       <%= label f, :description, class: "form-label" %>
       <%= textarea f, :description, class: "form-control" %>
+      <%= render LayoutView, "markdown_enabled.html" %>
       <%= error_tag f, :description %>
     </div>