Build Your Own Web Framework in Elixir by Aditya Iyengar
Author:Aditya Iyengar
Language: eng
Format: epub, pdf
Publisher: Packt Publishing Pvt Ltd
Published: 2023-05-18T00:00:00+00:00
Using EEx Smart Engine
EEx comes with the ability to override the engine that is being used to evaluate a template. The default engine used by EEx is EEx.SmartEngine. This module is built on top of the regular EEx.Engine but provides a way to speed up evaluation of a template by adding a special type of binding, assigns.
Letâs first take a look at an example:
./assigns.eex
<%= @a %> <%= @b %>
Now, letâs use the preceding template file to define a function in a module:
./module_b.ex
defmodule ModuleB do require EEx EEx.function_from_file(:def, :fun_b, "assigns.eex", [:assigns]) end
Updating our template and function to only take :assigns allows us to send different assigns without having to re-compile the template.
Now, letâs test out ModuleB.fun_b/1:
$ iex iex> Code.require_file("module_b.ex") [ {ModuleB, <<70, 79, 82, 49, 0, 0, 7, 68, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0,218, 0, 0, 0, 22, 14, 69, 108, 105, 120, 105, 114, 46, 77, 111, 100, 117, 108, 101, 66, 8, 95, 95, 105, 110, 102, 111, 95, ...>>} ] iex> ModuleB.fun_b(a: "Hello", b: "World") "Hello World
" iex> ModuleB.fun_b(a: "Hola", b: "World") "Hola World
"
This is super helpful to speed up the evaluation of templates while keeping the interface to use the templates simple and consistent. Phoenix uses a similar strategy to evaluate its templates.
Download
Build Your Own Web Framework in Elixir by Aditya Iyengar.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9916)
The Mikado Method by Ola Ellnestam Daniel Brolund(9779)
Dependency Injection in .NET by Mark Seemann(9340)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7780)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Svelte with Test-Driven Development by Daniel Irvine(7171)
Test-Driven Development with PHP 8 by Rainier Sarabia(6898)
Layered Design for Ruby on Rails Applications by Dementyev Vladimir;(6767)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6533)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6416)
Web Development with Django by Ben Shaw Saurabh Badhwar(6232)
React Application Architecture for Production by Alan Alickovic(5956)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5806)
Kotlin in Action by Dmitry Jemerov(5065)
Audition by Ryu Murakami(4583)
Software Architecture for Web Developers by Mihaela Roxana Ghidersa(4456)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4317)
Accelerating Server-Side Development with Fastify by Manuel Spigolon Maksim Sinik & Matteo Collina(4303)
Functional Programming in JavaScript by Mantyla Dan(4038)
