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
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
370
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
240
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
580
How I Won Prize Money at a Hackathon Using Codex and Symphony Alpha
yasei_no_otoko
0
120
Loosening the Reins: Go Generics Get More Flexible
kuro_kurorrr
0
290
My Marp Sample
sinoue0108
0
110
MySQLとPostgreSQLって何が違うの?
akagami
0
130
AWS Transform Customによる Spring Boot 2.xから4.xへのVerUp
satoshi256kbyte
2
100
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
220
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
250
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
280
AIに既存システムを理解させる技術 ~レガシーを見捨てないハーネスエンジニアリング入門~
ochtum
0
140
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Building Adaptive Systems
keathley
44
3.2k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
280
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
RailsConf 2023
tenderlove
30
1.5k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
660
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
420
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