We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Template Engines in Ruby

00:00

Formal Metadata

Title
Template Engines in Ruby
Title of Series
Number of Parts
65
Author
License
CC Attribution - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Identifiers
Publisher
Release Date
Language
Producer

Content Metadata

Subject Area
Genre
Abstract
HTML template engine is one of the most important library to build a web application. But who actually knows how it works? Who can explain how the engine parses the given template and finally composes the HTML body? In this session, I will dig into implementation details of several Ruby libraries such as ERB, Haml, Slim, Tilt, Temple, etc. and give you a quick tour into the world of template engines!
39
Template (C++)Key (cryptography)InternetworkingTwitterTemplate (C++)WhiteboardSelf-organizationEvent horizonLink (knot theory)VideoconferencingRevision controlScheduling (computing)Theory
VideoconferencingSlide ruleLink (knot theory)Scheduling (computing)Group actionLocal ringMultiplication signComputer animation
Template (C++)Computer fileImplementationCompilerParameter (computer programming)String (computer science)ExpressionLatent heatEinbettung <Mathematik>Poisson-KlammerArmMereologyComputer programmingQuicksortFreezingArithmetic meanDirectory serviceInstance (computer science)Port scannerBuffer solutionFormal languageResultantSign (mathematics)Process (computing)Line (geometry)System callLibrary (computing)CodeBoss CorporationStandard deviationLecture/Conference
Data bufferCodeString (computer science)CompilerContent (media)Default (computer science)Core dumpParameter (computer programming)MereologyCore dumpComa BerenicesString (computer science)CodeComputer animationLecture/Conference
Codierung <Programmierung>Content (media)Equivalence relationScripting languageCompilerComputer fileCartesian coordinate systemInstance (computer science)CodeCASE <Informatik>ResultantDirectory serviceTemplate (C++)String (computer science)Right angleBuffer solutionComputer animationLecture/Conference
CompilerTemplate (C++)View (database)Group actionEuclidean vectorVolumenvisualisierungComputer virusBlock (periodic table)CompilerSource codeCodeModulo (jargon)SicCASE <Informatik>Computer fileCompilation albumView (database)Template (C++)VolumenvisualisierungSystem callObject (grammar)Directory serviceRuby on RailsCartesian coordinate systemGroup actionFlagDependent and independent variablesString (computer science)CodeConnectivity (graph theory)Arithmetic meanSurjective functionInstance (computer science)Beat (acoustics)Similarity (geometry)Source codeRight angleImplementationRing (mathematics)1 (number)ArmComputer animation
Group actionView (database)VolumenvisualisierungCodeString (computer science)String (computer science)View (database)ResultantSource codeCodeCASE <Informatik>Overhead (computing)Compilation albumComputer animation
Overhead (computing)CodeTemplate (C++)CodeSystem callCompilation albumCartesian coordinate systemProduct (business)Overhead (computing)Computer animation
Modulo (jargon)System callSicTemplate (C++)Group actionView (database)ImplementationCellular automatonImplementationSocial classComputer animation
ImplementationSource codeMultiplication signReading (process)ImplementationEscape characterString (computer science)Template (C++)Computer animation
ImplementationView (database)Group actionDefault (computer science)Latent heatGroup actionView (database)Configuration spaceComputer animation
Computer configurationGroup actionView (database)Template (C++)Fiber bundleError messageSoftware testingWaveSoftware repositoryTexture mappingString (computer science)Inheritance (object-oriented programming)Cellular automatonSource codeMathematicsError messageLink (knot theory)Template (C++)Equaliser (mathematics)Patch (Unix)Repository (publishing)Multiplication signForm (programming)Block (periodic table)Software testingRegular graphNumberMassCausalityArmConnectivity (graph theory)Equals signInformation securityWeightView (database)Sign (mathematics)FehlererkennungRight angleGroup actionReal numberMeasurementComputer animationLecture/Conference
Default (computer science)Data bufferInformation securityString (computer science)Texture mappingSystem callSource codeAttribute grammarChi-squared distributionEscape characterTemplate (C++)String (computer science)Spring (hydrology)Object (grammar)Commitment schemeDefault (computer science)Group actionView (database)Line (geometry)Reading (process)Right angleInformation securityCartesian coordinate systemChainTemplate (C++)Escape characterOrder (biology)Computer animationLecture/Conference
String (computer science)Inheritance (object-oriented programming)System callSource codeMenu (computing)Template (C++)Default (computer science)Modulo (jargon)View (database)Group actionSoftware frameworkImplementationDefault (computer science)Social classTemplate (C++)Variable (mathematics)Lecture/ConferenceComputer animation
Extension (kinesiology)AdditionTemplate (C++)Default (computer science)Template (C++)ImplementationExtension (kinesiology)AdditionPoint (geometry)Software maintenanceComputer animationLecture/Conference
Extension (kinesiology)Point (geometry)MathematicsTemplate (C++)CodeBlock (periodic table)View (database)Group actionDifferent (Kate Ryan album)Group actionMereologyView (database)CodeExpressionBlock (periodic table)Template (C++)Computer animation
CodeTemplate (C++)Block (periodic table)Group actionView (database)Exponential functionExpressionBit rateRegulärer Ausdruck <Textverarbeitung>Matching (graph theory)Open setBlock (periodic table)Computer animation
Block (periodic table)String (computer science)Token ringExponential functionOpen setRegulärer Ausdruck <Textverarbeitung>Block (periodic table)Right angleMatching (graph theory)Validity (statistics)Computer animationLecture/Conference
Block (periodic table)CodeError messageView (database)Group actionExponential functionError messageBlock (periodic table)SpacetimeCode2 (number)Open setView (database)Group actionSineProcess (computing)Template (C++)Line (geometry)CausalityString (computer science)ExpressionCASE <Informatik>Patch (Unix)Matching (graph theory)Greatest elementComputer animationLecture/Conference
CodeBlock (periodic table)Library (computing)ExpressionCodeParsingParsingBitSoftware bugRepository (publishing)Computer animation
ParsingParsingTraffic reportingSubject indexingStandard deviationDifferent (Kate Ryan album)Axiom of choiceTemplate (C++)Right angleComputer animationLecture/Conference
ExpressionPRINCE2Arithmetic meanComputer virusTemplate (C++)Computer animationLecture/Conference
Computer virusVolumenvisualisierungCodeCompilerFunction (mathematics)Template (C++)CodeHamiltonian (quantum mechanics)Computer animationLecture/Conference
Computer animation
InformationDuality (mathematics)Hash functionPlanningProduct (business)Slide ruleVideo game consoleGodStreamlines, streaklines, and pathlinesComputer animation
Duality (mathematics)Arithmetic meanDemo (music)Computer animation
CodeCompilerLink (knot theory)Price indexMenu (computing)outputMeta elementComputer fontTrailFile formatData bufferSource codeComputer virusFunction (mathematics)Computer clusterWordDemo (music)Letterpress printingComputer virusComputer animationLecture/Conference
CompilerComputer fontMeta elementPrice indexLink (knot theory)Menu (computing)outputTrailSource codeFile formatCodeAreaData bufferCompilation albumBenchmarkObject (grammar)ExplosionCodeLibrary (computing)Overhead (computing)Compilation albumRight angleBenchmarkMultiplication signCASE <Informatik>MathematicsRow (database)ResultantObject (grammar)Computer animationLecture/Conference
BenchmarkCalculationObject (grammar)CompilerExplosionGroup actionView (database)Image resolutionTemplate (C++)VolumenvisualisierungComputer fileComa BerenicesGroup actionReal numberCASE <Informatik>VolumenvisualisierungBenchmarkBitRight angleRevision controlTemplate (C++)Image resolutionMultiplication signCodeResultantView (database)Computer animationLecture/Conference
Group actionView (database)Image resolutionBenchmarkTemplate (C++)Artistic renderingProduct (business)CalculationUniform resource locatorReal numberVolumenvisualisierungGroup actionInstance (computer science)Expected valueSlide ruleBenchmarkSinc functionResultantComputer animationLecture/Conference
Computer virusData bufferCodeAreaoutputLink (knot theory)Source codeMenu (computing)Meta elementTrailFile formatPointer (computer programming)Object (grammar)Traffic reportingNumberCodeMassMereologyBuffer solutionComputer configurationSet (mathematics)Point (geometry)Computer animation
Data bufferWechselseitige InformationComputer configurationFunction (mathematics)Run time (program lifecycle phase)Default (computer science)Computer configurationMultiplication signCartesian coordinate systemFigurate numberObject (grammar)Run time (program lifecycle phase)Buffer solutionSet (mathematics)Computer animationLecture/Conference
Data bufferRun time (program lifecycle phase)Default (computer science)Computer configurationComputer virusCodierung <Programmierung>Phase transitionPrice indexoutputMeta elementMenu (computing)Source codeLink (knot theory)TrailCodeAreaConvex hullFatou-MengeExecution unitComputer-integrated manufacturingMIDIRight angleComputer configurationDefault (computer science)CodeModule (mathematics)Source codeOnline helpLatent heatBuffer solutionComputer animationLecture/Conference
Data bufferInstance (computer science)Module (mathematics)Execution unitInclusion mapoutputCodeComputer virusBuffer solutionVariable (mathematics)File formatPoint (geometry)Variable (mathematics)Cycle (graph theory)Computer virusBuffer solutionCodeFunction (mathematics)Escape characterComputer animationLecture/Conference
Data bufferFile formatBuffer solutionComputer virusLibrary (computing)View (database)Group actionCodeComputer animationLecture/Conference
CodeComputer virusFunction (mathematics)Data bufferRevision controlString (computer science)Buffer solutionFunction (mathematics)MathematicsComputer animationLecture/Conference
Revision controlMathematicsPlanningMultiplication signComputer animationLecture/Conference
Electric currentCalculationBranch (computer science)Mereology2 (number)Point (geometry)Computer animationLecture/Conference
Default (computer science)Computer configurationEscape characterSoftware frameworkLibrary (computing)Ocean currentTemplate (C++)CodeCompilation albumExpert systemComputer configurationComputer animation
Core dumpAbstractionSoftware frameworkTemplate (C++)Compilation albumGeneric programmingInterface (computing)Template (C++)CodeExpressionLibrary (computing)Interface (computing)MultiplicationRevision controlWeb 2.0Bridging (networking)Server (computing)TunisSoftware developerSoftware frameworkWordComputer animation
SoftwareEvent horizonVideoconferencing
Transcript: English(auto-generated)
So, hello everybody.
I'm Akira from Japan. This is me on internet. I'm a M-A-T-S-D on GitHub and a on the board M-A-T-S-D on Twitter. This is me on GitHub.
As you see, I'm on Rails team and I'm a Ruby committer. Also, I'm a Hamel committer and that is why I'm talking about template engines and I've created a Ruby gem called Kaminari. Also, I'm a organizer of Ruby Kaigi.
Ruby Kaigi, this is Ruby Kaigi. This year, we did a international Ruby conference in Japan called Ruby Kaigi like two months ago, I guess. So if you missed the event,
there's a, there are tons of slides and videos online, so please check them out. You can get them via that schedule link. All right, and what's next?
Ah, asakusa.rb. So this is a local user group based in Tokyo. We have a weekly meetup on every Ruby Tuesday. So this time, I came to San Diego for you.
So it's your turn next. Please visit us in Tokyo and come to our meetup. We'll welcome your visit. All right, so this starts from ERB.
Firstly, I want you to know that there's a template engine specification in Ruby, which is called ERuby. Have you heard about ERuby? Do you know what it is?
ERuby stands for embedded Ruby. I'm not talking about MRuby thing, but this is yet another embedded Ruby. And this embedded Ruby does, I'm sorry, this embedded Ruby is a spec for embedding Ruby code into a text file,
like HTML files. This MRuby, I'm sorry, embedded Ruby was created by Matt and Shugo Maeda, who's known as Matt's boss. I actually asked Shugo-san, and he said
that the concept is based on ERuby, I mean, E-Pearl. So the ERuby spec was mainly stolen from Pearl. And there's yet another ERuby. This ERuby has small R, right?
So this ERuby is the referential implementation of ERuby written in C language. This ERuby was created by Shugo-san, but unfortunately this ERuby is no more maintained.
And, but instead we have ERB, which you know very well. ERB is a pure Ruby implementation of ERuby, I mean, ERuby. And this is included in Ruby package as a standard library.
ERB was created by Masatoshi Seki, who's a legendary Ruby programmer, who also created things like, you know, Linza, Rinza, and DRB, lot of these awesome libraries.
So, I was talking about ERB. I see so many mistakes on books, even on, I think, pickaxe, like misspelling on ERB. ERB, don't spell ERB like E-R small b.
It used to be called ER small b, but it was renamed to full capital E-R-B when becoming a Ruby standard library. So, as I said, ERB is implemented purely in Ruby,
which is actually only one file in the lib directory, and which has approximately 1,000 lines of Ruby code. It looks like a huge library, but actually half of them are documents.
So, it's actually less than 500 lines. Quite small, you can read it. So, let me show you how to use ERB.
This is the basic usage of ERB. ERB.new, give a template string into ERB.new, and call .result method on the instance. This will return the,
not that, Ruby embedded string, like this. Pretty easy, right? So, this is how we can embed Ruby code into the template. Of course you know. And this is how you can embed Ruby expressions,
as you know. So, how does this work? Let's see the implementation. Firstly, I called ERB.new. This is what's gonna happen when calling ERB.new.
It creates something called compiler, and then the compiler compiles the given template into at sign SRC, right?
So, compiler.compile does this. It creates a buffer thing, and then scans through the given template and splits the template into some tokens,
starting from this bracket percent sign, and then executes some kind of command for each of those token. And then, so I'm gonna pick up one command called add port CMD here.
The implementation looks like this. It pushes into the buffer some string. It pushes a Ruby code string into the buffer.
And the former part, port CMD, is a method and the latter part is a parameter. Then the port CMD is actually defined like this.
It's a string on the bar ERB of .concat. This becomes a Ruby command. And the content dump, the parameter, it just dumps the string. So, the whole hello code generates this Ruby code.
It prepares the buffer and pushes this ERB of .concat hello dot dump. Then, it valves the string.
It valves this string as a Ruby code. So, in total, ERB dot new dot result executes something like this. Creates a ERB out instance
and puts some code into that and then evolves the buffer. So, this is the basic usage of ERB. And how do we actually use ERB on our applications? I guess this is the major use case.
We use template file, put template file on the application directory and to generate HTML response body text. And I'm sure, mainly on Ruby on Rails.
So, in Ruby on Rails, what renders templates is, rendering template is done in this component named action view. So, how does action view renders? This is the simplest code that can kick action view
to render the template. You can just create the instance of action view base and call the render method. Render method is implemented like this. Again, it compiles the given template
and sends something into some kind of object called view. Sends some kind of method name. It's a ton of magic, but this is what's happening.
So, let's look into the compile definition. This is how action view compiles the template. It compiles only once. I mean, if the compilation is done,
it sets the flag to true so that it never runs again. And actual compile is like this. I'm not gonna explain in detail, but it creates some Ruby method,
the whole Ruby def expression, and executes it right afterwards. So, to compile template means to define a method
which is generated from the template. Onto something called mod. And then, what's happening next is handler called self. This is handler.call.
Call calls erbimplementation.new.source. This is, of course, as you see, erb.new.source, which returns the generated Ruby string.
And then, it puts the generated string into this method body, right? So, in summary, what action view render does is it defines a Ruby method on the view object,
and the method body is generated by erb.new.source. Erb source returns the Ruby code string to be valed. This is how, this was how erb result vales the string.
But, so, yeah, erb source looks like this. But in Rails case, we don't eval but define a method. But it works the same, basically. So, the short summary is, again, the template compiles into a Ruby method.
And it compiles only once. So, compilation overhead is not at all a big deal. I mean, it happens only once on the production application. So, what really matters is
not the compilation speed, but the code execution speed. The execution speed performance of the generated Ruby code. So, reprise. Again, this is the definition of erb handler call.
So, it's not directly calling erb.new, but something called class.erbimplementation.new. What is erb implementation?
It's actually set to something else called erubies, not erb. It's defaulted to erubies. So, what is this erubies thing? Erubies is yet another pure Ruby implementation of erubie.
It's not in the standard library, but it's a gem, which is called by a Japanese guy named Makoto Kuata. You can find the source code of this gem here. And according to its readme, it's very fast,
almost three times faster than erb. Awesome. And this has some unique features, like it auto escapes the, I mean, it can auto escape the template strings, and it supports Ruby on Rails, et cetera, et cetera.
So, I said erubies is a implementation of erubie, but actually, it's not purely erubie compatible. It's erb compatible, but it has something else
plus erubie, the general erubie specification, right? Like auto escaping or Ruby on Rails support, such things.
So, why does ActionView use erubies by default? Why not erb? I want to use something standard, right? So, I want to use erb. It should be quite easy, because it's configurable, okay? Let's try. It's easy with this patch.
So, actually, I tried this, and run the rake test for the ActionView component, and yes, it fails. Yes.
I saw a massive number of this kind of syntax errors. So, I looked at the error code, and actually, this simple Ruby template
causes syntax error on erb. It works on erubies, but doesn't work on erb. Why doesn't it? Because this is not allowed in erubie spec.
This is not the regular erubie template. Instead, it should be written like this. Do you remember this? Before Rails 3, we had to,
we could not add an equal time in front of form four, or link two with block, or what else, these kind of things, these kind of method that takes a block, right? So, this is the right way to call
a method with block in erubie spec. But Rails somehow allows this to magic. So, let's dig into the magic. How did things change in Rails 2 style
and Rails 3 style? Let's take a look at the Rails repository this time. So, this was what happened at the very first commit. It's a huge commit that improves the Rails security.
Sorry. This introduced something called safe buffer, and after this commit, we could create
safe string and unsafe string, and the string objects are regarded unsafe by default since this commit. Then, in action view, this commit adds these lines,
like it requires erubies, and uses erubies instead of erb, erubies.new, right? So, why erubies? Because, as you've seen on the readme,
erubies had auto-escaping support. Rails needed this in order to implement the Rails 3 auto-escaping thing.
I guess some of you might remember this HTML escape in templates. You had to put H onto each of the possibly unsafe strings, or else your application might be unsecure.
Rails 1 and 2 used to be like this, so you could easily create unsafe applications. So, the Rails team changed the default strings
to be default treated unsafe, and automatically called this H method inside the framework. And then, Coze changed the hard-coded erubies name,
class name, into a variable, so that you can configure. And then, someone else called Jose
changed its name from erubies implementation to erb implementation, despite this doesn't actually support erb. So, Rails default template handle is erubies, not erb,
because erubies has some original extensions in addition to erubies spec, and the Rails team liked it. And thus, now we cannot switch erb implementation back to erb.
I actually noticed this problem like two years ago. Before releasing Ruby 2.0, and I actually asked the maintainer of erb
that isn't it possible to support Rails extension? Like, erb to be Rails compatible in Ruby 2.0? He said, yes, I'll try. And he actually tried. He tried to add some extension points to erb,
and he investigated into the difference between erb and erubies, but he gave up. Because he didn't really like this part in action view.
Block expression. So, this code scans the template with this expression and does something. And this was not acceptable for Seksum.
So, what is this expression? And why is this problematic? Let's carefully take a look at this regular expression. This is how it's used.
And the expression matches, if the given token matches this expression, it does something. And it does not match, it does something else, okay?
So, the token can be something like this. This regular expression is for detecting if the token includes a block, opening block or not. So, this becomes true if the token
contains something like this, for and for do. So, let's try. Let's try matching some Ruby blocks. These are all valid Ruby block syntax, right?
I tried this and I found, actually, some of these doesn't match. It's buggy. Apparently, this regular expression is buggy.
So, for and for, foo, without putting a space in front of the opening brace. It works. If you're familiar with Ruby golf, I'm sure you always write blocks like this,
but ActionView doesn't accept this code. ActionView does not regard this as a block and causes a syntax error. But it's easy to fix, I think. S plus requires one or more spaces,
but in this case, we want to match these blocks. Bottom two lines. So, it can be like this. It's easy. Just one byte patch.
Seems good. Now, this expression becomes to match something else, like any string that ends with do matches this expression. So, now, this expression regards a template like this
as a block and causes another syntax error, which is weird. So, in summary, I guess I would fix this particular case, like I wrote another expression.
It can be detected, like a little bit longer expression, but, I mean, basically trying to parse Ruby in your Ruby library is a wrong approach.
Having such Ruby parsing code other than Ruby parser would cause such weird bug. This is, I guess, again, wrong approach, as this guy said.
The Ruby parser is a nightmare. So, don't deal with Ruby parser unless you're a noble. So, that is why this syntax is not acceptable on the standard ERB, right?
Anyway, now you see how ERB works and the difference between ERB and ERB, I mean, ERubist. But, anyway, difference between ERB and ERubist
is not a big deal because we don't use neither of them, anyway, and our choice is, of course, Haml. So, chapter two. What is Haml? Haml is a templating haiku, according to its readme.
I don't know what exactly means templating haiku exactly means. I suppose it means just a short expression means
does a lot of work, means a lot. I think it's what the haiku means. So, usage of Haml. This is how to output hello in Haml.
Haml has a random method. It's kind of similar to ERB's result method. This prints hello and Haml engine new actually parses the Haml template into a Ruby code.
If you would like to see the Ruby code instead of executing it, it has something like this. It's equivalent to ERB source. I'm gonna show you how it works.
So let's start with IRB require Haml.
Whoops, I'm sorry, I made a typo.
Did you mean Haml? Oh my god, what's this? Did you mean Haml? Oh my god, my console is so clever, so smart. I don't know what's happening here. What's this? Can anyone please explain what's happening on my console?
Can anyone please? Anyone knows what is this? Raise your hand, stand up, come up to the stage. Come on.
Majide. Well, all right, one minute. I'll give you one minute to introduce your product. I know he prepared his slide
for the lightning talk yesterday, but unfortunately, he signed up late, so he couldn't get the chance. I tried to give him a chance, but all right.
The gem is called did you mean? So please gem install this one, which should work this way. It's pretty useful. Thank you.
How can I switch back?
Can I have the windows? Ah, and I forgot to do the demo.
Anyway, I'll skip the demo. This would output something like this.
Just for printing out hello. Hello. This is how ERB outputs hello. And again, this is how Haml outputs hello.
All right, okay. Nice haiku. So, seriously. I think we don't usually have to care what's happening inside the library, but isn't this too much? It apparently looks slow, slow Ruby code.
So I said compilation overhead doesn't matter, but the generated Ruby code, if the generated Ruby code looks like this, this does matter, right? Let's prove if it's fast or slow.
So, the benchmark. Let's start with the simplest benchmark. It can be like this. You can put the,
I mean, you can define the Ruby method onto any object. In this case, just object new, and define the generated Ruby code as a method, and call it. Put, and the result, I get this result.
The Haml code runs 26 times slower than ERB1 in this microbenchmark. But, I think this is not the real use case, because ActionView does something more complex, indeed.
So, let's see the actual rendering speed using ActionView, right? This benchmark might be something more, a little bit more realistic. It uses ActionView template for executing the Ruby methods,
and I get this result. It's still, Haml is still two times slower than ERB in this benchmark version two. But, actually I skipped the template resolution code,
because it's actually slow in Rails. So, what really happens when you, in your Rails application, is actually this.
As I showed you in my previous slide, ActionView base instance, call the render method for the ActionView instance. And, in this benchmark, I got this result.
On the real Hello application, and ERB template renders like 20% faster than Haml. I guess this is like a real benchmark result. So, why is Haml slow?
I have six more minutes, okay. Why is Haml slow? So, let's read the haiku. The haiku consists of three parts, go-shi-go,
and this is the three parts. It prepares massive number of objects, and generates Hello code, and returns the buffer. And, you see, apparently, the setup part does something wrong.
So, in this part, we have many, many options that is given to Haml buffer new. Yes, Haml has many options, like this. And, Haml configures this option in run time
for each Haml buffer object. I don't know why, but it does so. But, who actually configures Haml in your application?
Have you ever configured, have you ever used, or changed these settings? I guess nobody. We don't need such a feature. Everyone uses default value, right? So, let's just remove them.
Removing the option, the code looks like this. Much better, right? The next one is Haml helpers, which is, you see, at the very top, it extends Haml helpers.
What is Haml helpers? So, there's a module in the Haml source code, and, yeah, it defines tons of helpers, lovely helpers, like, it's actually Haml specific helper methods,
and which is put into each Haml buffers. But, again, anyone have used it?
I guess nobody, again. So, let's remove them. And, the next point is buffers. You see many, many buffer, buffer, buffer, buffer. Actually, this high code includes six buffers,
six buffer variables, just to print out hello. Why don't we just remove some of these, and make the code look like this? It should be possible. And, HTML safe.
As we're already using ActionView output buffer, why you have to escape in the Ruby side? The library does it. So, we can,
Haml should be totally, completely depend on action view, I mean, active support and action view, and in that way, the code could be much simpler. Who uses Haml off Rails?
I'm sorry. But, the Haml on Rails can be like this, much simpler. The buffer has concat method, which takes, if the given string is unsafe,
then it escapes inside the concat method. So, I think this is the goal. I want to make Haml as fast as possible, and to change the final output to be like this.
But, these changes would bring some incompatibilities. So, I'm not gonna push these changes into the Haml master, but instead, I'm trying to create my own Haml fork,
which is called Haml X. Unfortunately, Haml X is not finished yet. I hoped, I planned to finish implementing this
until this talk, and I planned to do the demonstration, but it's not finished yet. It's not online yet. I'm still working on it, and hopefully, I'm gonna ship it soon. But, this is the current status.
It's still pretty much slower than ERB. Actually, 16% slower than ERB, but my branch is already 50% faster than the original Haml. I think this is not bad.
And, I think I only have 30 seconds left. So, part three, slim. I've got 30 seconds for slim.
Slim is, looks like Haml. It does automatic HTML escaping. In my opinion, slim is actually slimmer than the current Haml master. Woo, okay.
Actually, the slim code is slim because it's built on some libraries like Temple and Tilt, and it has less options. It has no lovely helpers. Temple is a template compilation framework. It compiles the template into its expression first,
and then compiles it into Ruby code. It's a very clever library. Tilt, Tilt is a generic interface to multiple Ruby template engines, which bridges over template engines and like web servers and framework and such things.
So, slim is awesome. Thank you, slim, for being a good competitor for a Haml developer. So, this is the end of my talk, conclusion. Now that I think you understand
how ERB and Arubis and Haml works, and yes, Haml is slow, and I'm going to improve Haml. The, my, my version of Haml called Haml X is hopefully coming soon.
So, please stay tuned. Thank you very much.