3 ms·
I learnt about this a while back when sinatra was released, you could have your html template in the same file. great idea for a micro framework.
by lukeholder 14y ago
I learnt about this a while back when sinatra was released, you could have your html template in the same file. great idea for a micro framework.
- caiusdurling 14y agoI'd forgotten sinatra let you do this, I remember it being really nice for a small simple app with a couple of templates.
- bemurphy 14y agoMinor correction (mostly because, I think the code is kinda interesting), Sinatra does something close to this. It actually uses the __END__ tag for its inline templates, but then internally it splits the file itself in two and then parses the latter portion: https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L1139 https://github.com/sinatra/sinatra/blob/master/lib/sinatra/b... I suspect the reason it does so is for the point the author of the article makes briefly: "And it only exists for the first ruby file to be invoked by the interpreter."