tio407
API client design: generating template code for client
Hello I am forking a project’s recaptcha code. But want to make this a little bit more readable for my local project. Here is the code. It returns a string with reCAPTCHA code, which means that the consumer will have to convert the string to HTML code using Phoenix.HTML.Raw/1, is there another way to do this? A better way perhaps, without the use of raw?
defmodule Recaptcha.Template do
require Elixir.EEx
alias Recaptcha.Config
EEx.function_from_file(:defp, :render_template, "lib/template.html.eex", [
:assigns
])
def display(options \\ []) do
public_key =
options[:public_key] || Config.get_env(:recaptcha, :public_key)
callback =
if options[:size] == "invisible" && is_nil(options[:callback]) do
"recaptchaCallback"
else
options[:callback]
end
onload =
if options[:onload] do
"onload=#{options[:onload]}&"
else
""
end
options_dict = Keyword.put(options, :onload, onload)
render_template(%{
public_key: public_key,
callback: callback,
options: options_dict
})
end
end
The template.html.eex that it references is just standard html code with variables interpolated.
Thank you for your help.
First Post!
gregvaughn
You could wrap your recaptcha in a struct and have it implement Phoenix.HTML.Safe protocol
Popular in Discussions
I would like to better understand what the advantages/disadvantages of umbrella applications are compared to structuring your app as as s...
New
So useless benchmarks aside, Its possible to write a webserver that can serve 300k requests per second (perhaps more with optimizations)....
New
Background
This question comes mainly from my ignorance. Today is Black Friday, one of my favorite days of the year to buy books. One boo...
New
Just saw that dhh announced https://hotwire.dev/
Is it just me or is this essentially live view? :smiley:
Although I like the “iFrame-e...
New
Hi there Elixir friends :vulcan_salute:
In a recent task I was on, I needed to check in two dates which of them is the maximum and which...
New
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
New
This is a post to discuss the new Phoenix LiveView functionality.
From Chris’s talk, it appears that they generate all HTML on the serve...
New
Hey everyone, this has been on my mind for some time and I’d love your input on it!
TLDR: I feel like maps are superioer for storing and...
New
Hi all
How can I compare haskell with elixir, included tools, webservices, ect.
Thanks
New
Phoenix Live View is now publicly available on GitHub.
Here’s Chris McCord’s tweet announcing making it public.
New
Other popular topics
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Hello guys,
I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition)
It’s been a while since we first asked this, I...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New








