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
200
好きな技術《コト》で、 生きていく技術 / life with what you like
aereal
5
2.3k
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.3k
Other Decks in Programming
See All in Programming
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
最新TCAキャッチアップ
0si43
0
140
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
Macとオーディオ再生 2024/11/02
yusukeito
0
370
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
660
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Code Reviewing Like a Champion
maltzj
520
39k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Practical Orchestrator
shlominoach
186
10k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Speed Design
sergeychernyshev
24
610
A Modern Web Designer's Workflow
chriscoyier
693
190k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
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 %] ~~~~
՝ •ϦϑΝΫλϦϯάࣗಈԽ͍ͨ͠ •→ நతͰͳ͍ߏจ͕ཉ͍͠