phlex-ruby / phlex

A framework for building object-oriented views in Ruby.
https://beta.phlex.fun
MIT License
1.24k stars 83 forks source link

Allow binding to via the kwarg in tokens #717

Closed bradgessler closed 4 months ago

bradgessler commented 4 months ago

This commit provides a shortcut for binding to a class keyword argument and passing it into tokens, like this:

def view_template
  red(class: "buzz")
end

def red(class:)
  div(class: tokens("fizz", class:))
end

Prior to this commit, I'd have to manually bind to the class keyword argument passed into tokens like this:

def red(class:)
  div(class: tokens("fizz", binding.local_variable_get(:class)))
end
joeldrapper commented 4 months ago

This is an awesome idea. I want to do something with it, but I don’t think tokens is the right place for this as it is currently implemented. Keyword arguments on the tokens method are for conditional tokens, where the key is the condition and the value is the token set.