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.4k
Other Decks in Programming
See All in Programming
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
130
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
620
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
イベント駆動で成長して委員会
happymana
1
320
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
役立つログに取り組もう
irof
28
9.6k
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Become a Pro
speakerdeck
PRO
25
5k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
RailsConf 2023
tenderlove
29
900
Optimizing for Happiness
mojombo
376
70k
Adopting Sorbet at Scale
ufuk
73
9.1k
A Modern Web Designer's Workflow
chriscoyier
693
190k
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 %] ~~~~
՝ •ϦϑΝΫλϦϯάࣗಈԽ͍ͨ͠ •→ நతͰͳ͍ߏจ͕ཉ͍͠