Skip to content

Instantly share code, notes, and snippets.

@coreyhaines
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreyhaines/7e24bf612f59d2dfbbb1 to your computer and use it in GitHub Desktop.
Save coreyhaines/7e24bf612f59d2dfbbb1 to your computer and use it in GitHub Desktop.
Basic templating - better way?
def render_template template, question:
template % {
:"question.text" => CGI::escapeHTML(question.display_text.to_s),
:"question.name" => CGI::escapeHTML(question.name.to_s),
:"question.email" => CGI::escapeHTML(question.email.to_s)
}
end
@coreyhaines
Copy link
Author

I don't need it super dynamic right now, just replace these three things.

@coreyhaines
Copy link
Author

Eventually could manage doing more of a detection of what is desired and use #send to get the value from question, but this is the basic that I need right now.

@coreyhaines
Copy link
Author

Thanks to Avdi for reminding me about String#%
https://twitter.com/avdi/status/622516300183683073

template % {
  :"question.text" =>  CGI::escapeHTML(question.display_text.to_s),
  :"question.name" =>  CGI::escapeHTML(question.name.to_s),
  :"question.email" => CGI::escapeHTML(question.email.to_s)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment