Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Meta Template Engine
Search
ayato
October 02, 2017
Programming
1.2k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Meta Template Engine
ayato
October 02, 2017
More Decks by ayato
See All by ayato
マイクロサービス内で動くAPIをF#で書いている
ayato0211
1
1.6k
Clojureという言語が私逹にもたらしたもの
ayato0211
6
3.2k
3年間考え続けてきたWebアプリケーションにおけるテストの話
ayato0211
3
310
Re:REPL-Driven Development
ayato0211
3
1.4k
超変換! Hiccup data structure!!
ayato0211
2
680
About Integrant
ayato0211
0
610
Muscle Assert
ayato0211
0
330
Clojureを用いたWebアプリケーション開発
ayato0211
2
3.2k
翻訳にまつわるエトセトラ
ayato0211
6
1.3k
Other Decks in Programming
See All in Programming
Google Apps Script で Ruby を動かす
kawahara
0
150
仕様駆動開発の消費期限
watany
20
8.1k
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
260
AWS DevOps AgentのAzure接続機能を検証して見えた活用法/Use Cases Verified for the AWS DevOps Agent's Azure Connectivity Feature
masakiokuda
1
230
5分で問診!Composer セキュリティ健康診断
codmoninc
0
960
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
560
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
250
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
140
その節約、円になってますか?
isamumumu
1
730
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
220
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
550
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
YesSQL, Process and Tooling at Scale
rocio
174
15k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Typedesign – Prime Four
hannesfritz
42
3.1k
Facilitating Awesome Meetings
lara
57
7.1k
How to train your dragon (web standard)
notwaldorf
97
6.7k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
270
Into the Great Unknown - MozCon
thekraken
41
2.7k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
160
Producing Creativity
orderedlist
PRO
348
40k
Claude Code のすすめ
schroneko
67
230k
Transcript
メタテンプレートエンジンの話 市ヶ谷Geek★Night#14 市ヶ谷java 〜JVM言語の玉手箱〜
メタテンプレートエンジンの話 市ヶ谷Geek★Night#14 市ヶ谷clojure 〜JVM言語の玉手箱〜
あやぴー •ayato-p@github •Cybozu Startups, Inc. •Clojure書いてる •Webアプリ書いてる
TL;DR
というわけで…
Clojureの話をします
事の発端
HTMLフォーム面倒 <div class="form-group"> <label for="input-email">Email Address</label> <input id="input-email" class="form-control" type="email"
name="email" th:classappend= "${errors.containsKey('email')} ? 'is-invalid'" th:value="${values.email}" placeholder="Enter email" /> <div class="invalid-feedback" th:text="${errors.email}"> </div> <small class="form-text text-muted"> We'll never share your email with anyone else. </small> </div>
HTMLフォーム面倒 [:div.form-group [:label {:for "input-email"} "Email address"] [:input#input-email.form-control {:type :email
:name :email :class (when (contains? errors :email) "is-invalid") :value (:email values) :placeholder "Enter email"}] [:div.invalid-feedback (:email errors)] [:small.form-text.text-muted "We'll never share your email with anyone else."]]
面倒なこと •_methodみたいなやつ •formのmethod属性に直接putとかdelete書きたい •__csrf_tokenみたいなやつ •いちいち書くのは面倒 •エラー表示のために書く条件分岐 •前回表示していた値を表示するための式 •たいていの場合name属性に依存している
HTMLフォーム面倒 [:div.form-group [:label {:for "input-email"} "Email address"] [:input#input-email.form-control {:type :email
:name :email :class (when (contains? errors :email) "is-invalid") :value (:email values) :placeholder "Enter email"}] [:div.invalid-feedback (:email errors)] [:small.form-text.text-muted "We'll never share your email with anyone else."]] ここが決まれば…
HTMLフォーム面倒 [:div.form-group [:label {:for "input-email"} "Email address"] [:input#input-email.form-control {:type :email
:name :email :class (when (contains? errors :email) "is-invalid") :value (:email values) :placeholder "Enter email"}] [:div.invalid-feedback (:email errors)] [:small.form-text.text-muted "We'll never share your email with anyone else."]] ここが決まるはず
考えた
テンプレートエンジンが HTMLに変換する前に 求める形に変換できれば いいんじゃない
つまり… メタテンプレートエンジン…
Kuuga https://github.com/ayato-p/kuuga
“こんなやつらのために、 これ以上誰かの涙は⾒たくない! 皆に笑顔でいて欲しいんです! だから⾒ててください!俺の…変⾝!! ”
“HTML Formのために、 これ以上誰かの涙は⾒たくない! Hiccupユーザーに笑顔でいて欲しいんです! だから⾒ててください!俺の…変換!! ”
変換ルール( (defmethod growing/transform-by-tag :input [_ options tag-vector] (let [[tagkw tagopts
contents] (tool/parse-tag-vector tag-vector)] `[~tagkw (update-input-opts ~options ~tagopts) ~@contents]))
変換ルール) (defmethod growing/transform-by-class :form-group [_ options tag-vector] (let [[tagkw tagopts
contents] (tool/parse-tag-vector tag-vector) contents (reduce (fn [contents' tagvec'] (let [[tk to _] (tool/parse-tag-vector tagvec') [_ t] (tool/parse-tag-keyword tk)] (cond-> (conj contents' tagvec') (= t "input") (conj `(invalid-fb ~options ~to))))) [] contents))] `[~tagkw ~tagopts ~@contents]))
そうすると
これを… (ultimate/transform opts [:div.form-group [:label {:for "input-email"} "Email address"] [:input#input-email.form-control
{:type :email :name :email :placeholder "Enter email"}] [:small.form-text.text-muted "We'll never share your email with anyone else."]])
こんな感じで展開できる [:div.form-group [:label {:for "input-email"} "Email address"] [:input#input-email.form-control {:type :email
:name :email :class (when (contains? errors :email) "is-invalid") :value (:email values) :placeholder "Enter email"}] [:div.invalid-feedback (:email errors)] [:small.form-text.text-muted "We'll never share your email with anyone else."]] ※イメージです
[:div.form-group [:label {:for "input-email"} "Email address"] [:input#input-email.form-control {:type :email :name
:email :class (when (contains? errors :email) "is-invalid") :value (:email values) :placeholder "Enter email"}] [:div.invalid-feedback (:email errors)] [:small.form-text.text-muted "We'll never share your email with anyone else."]] ここが消えた! こんな感じで展開できる
まとめ •Kuugaは超便利 •Clojureはいいぞ •9/25(月) Lisp Meetup •10/4(水) 教養としてのClojure
Enjoy Clojure