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
テンプレートの静的解析とリファクタリング
Search
aereal
October 17, 2014
Programming
2
5.6k
テンプレートの静的解析とリファクタリング
Talk at テンプレートエンジン Night
aereal
October 17, 2014
Tweet
Share
More Decks by aereal
See All by aereal
How to send distibuted traces to Datadog using build own OpenTelemetry-Lambda distribution
aereal
3
210
好きな技術《コト》で、 生きていく技術 / life with what you like
aereal
5
2.4k
qron: Cloud Native Cron Alternativeの今
aereal
2
2.1k
自動作曲入門 / introduction to programatic music composition
aereal
1
530k
はてなブログ タグとCDK / The epic of AWS CDK and Hatena Blog Tag
aereal
3
200k
はてなブログ タグの技術選択 / The technical details of Hatena Blog Tag
aereal
3
200k
ブログサービスのHTTPS化を支えたAWSで作るピタゴラスイッチ / The construction of large scale TLS certificates management system with AWS
aereal
3
400k
AWSではてなブログの常時HTTPS配信をバーンとやる話 / The Epic of migration from HTTP to HTTPS on Hatena Blog with AWS
aereal
14
17k
ScalaとPerlでMicroservices in production / Building microservices with Perl and Scala in production
aereal
0
5.4k
Other Decks in Programming
See All in Programming
たのしいparse.y
ydah
3
120
Haze - Real time background blurring
chrisbanes
1
500
Criando Commits Incríveis no Git
marcelgsantos
2
170
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
130
Symfony Mapper Component
soyuka
2
730
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
170
CSC509 Lecture 14
javiergs
PRO
0
130
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
130
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
94
Statistics for Hackers
jakevdp
796
220k
Side Projects
sachag
452
42k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
510
Automating Front-end Workflow
addyosmani
1366
200k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Designing Experiences People Love
moore
138
23k
Site-Speed That Sticks
csswizardry
2
190
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Transcript
ςϯϓϨʔτͷ! ੩తղੳͱ! ϦϑΝΫλϦϯά! ! id:aereal
ࣗݾհ • id:aereal • aereal.org • Hatena • Web
ΞδΣϯμ •Web ΞϓϦέʔγϣϯͱςϯϓϨʔτ Τϯδϯ •Text::Xslate ͱ੩తղੳ •՝ͱల
ςϯϓϨʔτΤϯδϯ •Template::Toolkit •Text::MicroMason •HTML::Template • Text::Xslate
Web ΞϓϦέʔγϣϯ ͱςϯϓϨʔτΤϯδϯ
ߘΛදࣔ͢Δ! ૉͳςϯϓϨʔτ
post.tt <h1>[% post.title %]</h1> <div class="body">[% post.body %]</div>
ίϯτϩʔϥ $c->render('post.tt', { post => $post });
ʮߘΛҰཡදࣔ͠Α͏ʯ
•ςϯϓϨʔτΛϞδϡʔϧԽ •post.tt → _post.tt •posts/index.tt → _post.tt •posts/show.tt → _post.tt
ʮҰཡͰຊจΛ! লུ͍ͨ͠ʯ
_post.tt [%- SET formatted = with_ellipsis ? (post.body | truncate)
: post.body %] <h1>[% post.title %]</h1> <div class="body">[% formatted %]</div>
िؒޙ……
index.tt [% INCLUDE "_post.tt" WITH with_ellipsis = 1, show_social_buttons =
1, ... ... show_category = 1, %]
INCLUDE ͢Δͱ͖ʹ! ԿΛͤΑ͍ͷ͔! Θ͔Βͳ͍
ʮίϝϯτʹॻ͜͏ʯ
_post.tt [%# post, show_social_buttons, show_category, ... %] ...
ॿ͔ͬͨ
࣌ྲྀΕͨɺ͋Δ
ίϝϯτ่յ •_post.tt Ͱ blog ͕ඞཁʹͳͬͨ •index.tt Ͱ blog ͕ఆٛࡁΈͩͬͨ •_post.tt
ʹίϝϯτ͕ه͞Εͳ͔ͬͨ
_post.tt <div class="post" data-blog-id="[% blog.id %]"> ... </div>
index.tt [%# blog %] ... [% FOR post IN posts
%] [% INCLUDE "_post.tt" WITH blog = blog, ... %] [% END %]
͏μϝͩ
ͦΕ੩తղੳͰ
ͳͥ੩తղੳ •نଇ͕͋ΔͷͰϓϩάϥϜͷಘҙ •Text::Xslate ʹϦονͳ API ͕͋Δ
ొਓ •Text::Xslate::Parser •(Text::Xslate::Syntax::*) •Text::Xslate::Symbol •Text::Xslate::AST::Walker ˑ
Text::Xslate::Parser •࣮ࡍʹ͏ͷαϒΫϥε •e.g. Text::Xslate::Syntax::TTerse •Text::Xslate::Parser#parse •AST ͕ಘΒΕΔ •AST = [
Text::Xslate::Symbol ]
T::X::Parser my $template = "my name is [% name %]";
my $parser = Text::Xslate::Syntax::TTerse->new; my $ast = $parser->parse($template);
Text::Xslate::Symbol •#arity •ࣜͷछྨ(?) •e.g. print, literal
Text::Xslate::Symbol •#id •ࣝผࢠ •e.g. name
Text::Xslate::Symbol •#first #second •Φϖϥϯυ͕ฦΔ •#is_value ͳͲ
มͰ͋ΔτʔΫϯ grep { $_->arity eq 'variable' } @$ast
͏ͪΐͬͱஸೡʹ •ߏͳͷͰ࠶ؼతʹ୳͞ͳ͍ͱ͍͚ͳ ͍ •#first #second
Text::Xslate::AST::Walker https://github.com/aereal/Text-Xslate-AST-Walker
ະఆٛͷม͕ͳ͍ ͜ͱΛظ͢ΔσϞ
՝ •INCLUDE ͢Δ࣌ʹ͢ύϥϝʔλͷ໊લະ ఆٛʹݟ͑ͯ͠·͏ •અ͕ೖ (assign) ͩͬͨΒεΩοϓ͢ΕΑ ͦ͞͏ •#traverse Έ͍ͨͳϝιουΛ࣮͍ͯ͠·
͢ •(inspired by Path::Class::Dir#traverse)
ύϥϝʔλͷ໊લ [% INCLUDE "..." WITH post = post %] ~~~~
՝ •ϦϑΝΫλϦϯάࣗಈԽ͍ͨ͠ •→ நతͰͳ͍ߏจ͕ཉ͍͠