Giter VIP home page Giter VIP logo

Comments (5)

titanous avatar titanous commented on August 20, 2024

This behaviour is intended (see fce8bcb). I've removed the example from the wiki.

from liquid.

To1ne avatar To1ne commented on August 20, 2024

I don't really get why that change was made?
String multiplication is valid in Ruby: http://www.ruby-doc.org/core/classes/String.html#M001126
And I don't see why casting to a number will help you out?

from liquid.

jamesmacaulay avatar jamesmacaulay commented on August 20, 2024

The arithmetic filters were always intended primarily for numbers. I originally implemented them to accomodate strings as well, because I figured "what the heck, ruby provides it for free." The problem is that there's no other way of casting strings to numbers in liquid, and it meant that when you're using e.g. the value of an input field or the result of a {%capture%} tag as the filter argument, there was no way to do actual arithmetic with it.

from liquid.

To1ne avatar To1ne commented on August 20, 2024

Ok, understood.

But can I make an suggestion?
{{ 'foo111' | times:4 }} #=> 'foo111foo111foo111foo111'
{{ 'foo111' | to_number | times:4 }} #=> '444'

It's no real problem to me (and I'm no contributor to liquid), but I was just wondering...

from liquid.

jamesmacaulay avatar jamesmacaulay commented on August 20, 2024

Yeah, that was the other alternative that we considered, but ultimately we decided it was more important to make the common case easy than to accomodate the edge case with the same interface. (And as you say, the edge case is still possible with a loop).

One of the nice things about liquid is how extensible it is, so if you want to make your own filters for string manipulation to use in your project, it's easy to do that.

from liquid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.