Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liquid templates vs Formatter pattern #25

Open
ronaldtse opened this issue May 4, 2022 · 0 comments
Open

Liquid templates vs Formatter pattern #25

ronaldtse opened this issue May 4, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@ronaldtse
Copy link

ronaldtse commented May 4, 2022

In some situations it may be wise to use a Formatter pattern instead of a liquid template.

i.e.

class MyFormatter
  def author(surnames:, givennames:)
    "#{surnames.join(', ')}, #{givennames.map(&:first).join('. ')}."
  end

  def order
    [:author, :title]
  end
end

relaton_object = Relaton.find("xxx")
Relaton::Render.new(relaton_object, MyFormatter.new).to_s
=> "Bean, M. A. __Some Title.__"
@ronaldtse ronaldtse added the enhancement New feature or request label May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant