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
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
130
Zoneless Testing
rainerhahnekamp
0
120
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
380
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
良いユニットテストを書こう
mototakatsu
7
2.2k
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
330
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
220
103 Early Hints
sugi_0000
1
230
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
快速入門可觀測性
blueswen
0
350
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Designing Experiences People Love
moore
138
23k
Done Done
chrislema
181
16k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
Building Your Own Lightsaber
phodgson
103
6.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Unsuck your backbone
ammeep
669
57k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Faster Mobile Websites
deanohume
305
30k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Thoughts on Productivity
jonyablonski
67
4.4k
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 %] ~~~~
՝ •ϦϑΝΫλϦϯάࣗಈԽ͍ͨ͠ •→ நతͰͳ͍ߏจ͕ཉ͍͠