Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 10 additions & 0 deletions report/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(defproject report "0.1.0-SNAPSHOT"
:description "Give a report of the yas snippets"
:dependencies [[org.clojure/clojure "1.10.0"]
[hiccup "1.0.5"]]

:uberjar-name "report.jar"
:min-lein-version "2.8.1"
:source-paths ["src"]
:test-paths ["test"]
:resource-paths ["resources"])
88 changes: 88 additions & 0 deletions report/src/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
(ns core
"Parse files and generate some html reports"
(:require [clojure.string :as str]
[hiccup.core :as hiccup]
[clojure.java.io :as io]))

;; TODO: do something whenever the mode has just `.yas-parents` and nothing else?
(def bulma-url "https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.css")

(defn kw-pattern
[kw]
(re-pattern (format "# %s: (.*)" kw)))

(defn extract-keyword
[filename keyword]
(let [lines (-> filename
slurp
str/split-lines)]
(first
(remove nil?
(map #(last (re-find (kw-pattern keyword) %)) lines)))))

(defn mode-files
[mode-dir]
(filter #(.isFile %)
(file-seq (io/file mode-dir))))

(defn parse-mode
[mode-dir]
(for [f (mode-files mode-dir)]
{:filename (.getName (io/file mode-dir f))
:name (extract-keyword f "name")
:key (or (extract-keyword f "key")
(extract-keyword f "name"))
:group (extract-keyword f "group")
:desc (extract-keyword f "desc")}))

(defn parse-everything
[snippets-dir]
(into {}
(remove nil?)
(for [d (file-seq (io/file snippets-dir))]
(when (.isDirectory d)
{(.getName d) (parse-mode d)}))))

(defn store-to-edn
[snippets-dir output-file]
(spit output-file (parse-everything snippets-dir)))

(def header [:name :key :filename :group :desc])

(defn table
"Generate a table"
[header rows]
[:table.table.is-striped
[:thead (into [:tr.tr]
(for [h header]
[:td.td (name h)]))]

(into [:tbody.tbody]
(for [r rows]
(into [:tr.tr]
(for [h header]
[:td.td (r h)]))))])

(defn structure
[body]
[:html
[:head
[:link {:rel "stylesheet"
:href bulma-url
:crossorigin "anonymous"}]]
(into [:body] body)])

(defn gen-html
[snips-dir]
(let [all-modes (parse-everything snips-dir)
tables (for [[m snips] (sort all-modes)]
[:div.section
[:h2.subtitle m]
(table header snips)])]
(spit
"hello.html"
(hiccup/html
(structure tables)))))

(comment
(gen-html "../snippets"))
2 changes: 1 addition & 1 deletion snippets/c++-mode/beginend
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- mode: snippet -*-
# name : v.begin(), v.end()
# name: v.begin(), v.end()
# key: beginend
# --
${1:v}.begin(), $1.end
2 changes: 1 addition & 1 deletion snippets/c++-mode/ns
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#name : namespace ...
# name: namespace ...
# key: ns
# --
namespace
2 changes: 1 addition & 1 deletion snippets/c++-mode/using
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#name : using namespace ...
# name: using namespace ...
# key: using
# --
using namespace ${std};
Expand Down
2 changes: 1 addition & 1 deletion snippets/c-lang-common/inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- mode: snippet -*-
# name : #include <...>
# name: #include <...>
# key : incs
# --
#include <$1>
2 changes: 1 addition & 1 deletion snippets/c-lang-common/inc.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- mode: snippet -*-
# name : #include "..."
# name: #include "..."
# key : incl
# --
#include "$1"
2 changes: 1 addition & 1 deletion snippets/c-lang-common/once
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#name : #ifndef XXX; #define XXX; #endif
# name: #ifndef XXX; #define XXX; #endif
# key: once
# --
#ifndef ${1:`(upcase (file-name-nondirectory (file-name-sans-extension (or (buffer-file-name) ""))))`_H}
Expand Down
2 changes: 1 addition & 1 deletion snippets/cc-mode/case
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- mode: snippet -*-
# name : case : {...}
# name: case : {...}
# key: case
# expand-env: ((yas-also-auto-indent-first-line t))
# --
Expand Down
2 changes: 1 addition & 1 deletion snippets/cc-mode/do
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#name : do { ... } while (...)
# name: do { ... } while (...)
# key: do
# --
do
Expand Down
2 changes: 1 addition & 1 deletion snippets/cc-mode/else
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- mode: snippet -*-
# name : else { ... }
# name: else { ... }
# key: else
# --
else${1: {
Expand Down
6 changes: 3 additions & 3 deletions snippets/cc-mode/file_description
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- mode: snippet -*-
#cotributor: Henrique Jung <henriquenj@gmail.com>
#name: File description
#key: \file
#group: doxygen
# name: File description
# key: \file
# group: doxygen
# --
/**
* \file ${1:`(file-name-nondirectory(buffer-file-name))`}
Expand Down
6 changes: 3 additions & 3 deletions snippets/cc-mode/function_description
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- mode: snippet -*-
#cotributor: Henrique Jung <henriquenj@gmail.com>
#name: Function description
#key: \brief
#group: doxygen
# name: Function description
# key: \brief
# group: doxygen
# --
/**
* \brief ${1:function description}
Expand Down
2 changes: 1 addition & 1 deletion snippets/cc-mode/if
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- mode: snippet -*-
# name : if (...) { ... }
# name: if (...) { ... }
# key: if
# --
if (${1:condition}) ${2:{
Expand Down
6 changes: 3 additions & 3 deletions snippets/cc-mode/member_description
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- mode: snippet -*-
#cotributor: Henrique Jung <henriquenj@gmail.com>
#name: Member description
#key: !<
#group: doxygen
# name: Member description
# key: !<
# group: doxygen
# --
/*!< ${1:Detailed description after the member} */
2 changes: 1 addition & 1 deletion snippets/cc-mode/struct
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#name : struct ... { ... }
# name: struct ... { ... }
# key: struct
# --
struct ${1:name}
Expand Down
2 changes: 1 addition & 1 deletion snippets/cc-mode/switch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- mode: snippet -*-
# name : switch (...) { case : ... default: ...}
# name: switch (...) { case : ... default: ...}
# key: switch
# --
switch (${1:expr}) {
Expand Down
4 changes: 2 additions & 2 deletions snippets/csharp-mode/attrib
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : private attribute ....;
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: private attribute ....;
# key: attrib
# --
/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions snippets/csharp-mode/attrib.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : private attribute ....; public property ... ... { ... }
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: private attribute ....; public property ... ... { ... }
# key: attrib
# --
/// <summary>
Expand All @@ -19,4 +19,4 @@ public $1 $2
set {
this.$2 = value;
}
}
}
6 changes: 3 additions & 3 deletions snippets/csharp-mode/attrib.2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : private _attribute ....; public Property ... ... { ... }
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: private _attribute ....; public Property ... ... { ... }
# key: attrib
# --
/// <summary>
Expand All @@ -19,4 +19,4 @@ public ${1:Type} ${2:Name}
set {
this.${2:$(if (> (length yas-text) 0) (format "_%s%s" (downcase (substring yas-text 0 1)) (substring yas-text 1 (length yas-text))) "")} = value;
}
}
}
4 changes: 2 additions & 2 deletions snippets/csharp-mode/class
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : class ... { ... }
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: class ... { ... }
# key: class
# --
${5:public} class ${1:Name}
Expand Down
4 changes: 2 additions & 2 deletions snippets/csharp-mode/comment
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : /// <summary> ... </summary>
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: /// <summary> ... </summary>
# key: comment
# --
/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions snippets/csharp-mode/comment.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : /// <param name="..."> ... </param>
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: /// <param name="..."> ... </param>
# key: comment
# --
/// <param name="$1">$2</param>
/// <param name="$1">$2</param>
6 changes: 3 additions & 3 deletions snippets/csharp-mode/comment.2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : /// <param name="..."> ... </param>
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: /// <param name="..."> ... </param>
# key: comment
# --
/// <returns>$1</returns>
/// <returns>$1</returns>
6 changes: 3 additions & 3 deletions snippets/csharp-mode/comment.3
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : /// <exception cref="..."> ... </exception>
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: /// <exception cref="..."> ... </exception>
# key: comment
# --
/// <exception cref="$1">$2</exception>
/// <exception cref="$1">$2</exception>
4 changes: 2 additions & 2 deletions snippets/csharp-mode/fore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Jostein Kjønigsen <jostein@kjonigsen.net>
#name : foreach { ... }
# contributor : Jostein Kjønigsen <jostein@kjonigsen.net>
# name: foreach { ... }
# key: fore
# --
foreach (${1:var} ${2:item} in ${3:list})
Expand Down
4 changes: 2 additions & 2 deletions snippets/csharp-mode/method
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : public void Method { ... }
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: public void Method { ... }
# key: method
# --
/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions snippets/csharp-mode/namespace
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : namespace .. { ... }
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: namespace .. { ... }
# key: namespace
# --
namespace $1
{
$0
}
}
4 changes: 2 additions & 2 deletions snippets/csharp-mode/prop
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : property ... ... { ... }
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: property ... ... { ... }
# key: prop
# --
/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions snippets/csharp-mode/region
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : #region ... #endregion
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: #region ... #endregion
# key: region
# --
#region $1
Expand Down
4 changes: 2 additions & 2 deletions snippets/csharp-mode/using
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : using ...;
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: using ...;
# key: using
# --
using $1;
6 changes: 3 additions & 3 deletions snippets/csharp-mode/using.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : using System;
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: using System;
# key: using
# --
using System;
using System;
6 changes: 3 additions & 3 deletions snippets/csharp-mode/using.2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
#name : using System....;
# contributor : Alejandro Espinoza Esparza <aespinoza@structum.com.mx>
# name: using System....;
# key: using
# --
using System.$1;
using System.$1;
2 changes: 1 addition & 1 deletion snippets/css-mode/bg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#name : background-color: ...
# name: background-color: ...
# --
background-color: #${1:DDD};
4 changes: 2 additions & 2 deletions snippets/css-mode/bg.1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#name : background-image: ...
# name: background-image: ...
# --
background-image: url($1);
background-image: url($1);
2 changes: 1 addition & 1 deletion snippets/css-mode/bor
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#name : border size style color
# name: border size style color
# --
border: ${1:1px} ${2:solid} #${3:999};
Loading