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

Don't remove false values #34

Closed
yoursdearboy opened this issue Nov 9, 2016 · 2 comments
Closed

Don't remove false values #34

yoursdearboy opened this issue Nov 9, 2016 · 2 comments
Labels

Comments

@yoursdearboy
Copy link

It is impossible to use false values in documents because Sablon::Statement::Insertion removes them. Does it intended or maybe content should be checked there using #nil? method.

@senny
Copy link
Owner

senny commented Nov 28, 2016

I'm not sure I understand your use case. dou want to insert false into the template? In that case I suggest to use boolean.to_s instead of the true/false values.

@yoursdearboy
Copy link
Author

yoursdearboy commented Dec 5, 2016

If I can use true, then why not false?

Anyway, I have custom rails-specific wrapper for Sablon::Content that replaces true/false with localized strings (actually I've just patched Sablon::Content::String). But mentioned code just skips false values.

Here's the wrapper.

class Sablon::Content::String
  def initialize(value)
    if value.is_a?(Date)
      super I18n.l(value)
    elsif value.is_a?(TrueClass) || value.is_a?(FalseClass)
      super I18n.t(value.to_s)
    else
      super value.to_s
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants