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
0
Popular in Discussions
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
I’m looking for a host for the server part of a small (personal) side project that I’m working on. It’s currently written in Node.js and ...
New
Hello,
I want to share a project I’ve been working on for a while:
https://github.com/almightycouch/gitgud
Background
Some time ago I ...
New
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
Hey guys!
I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
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
Hi everyone, im working on find best language/framework/system for
high concurrency, high performance and stable performance
after wor...
New
Other popular topics
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Hello everyone,
Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Latest Phoenix Threads
Chat & Discussions>Discussions
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









