Coder Social home page Coder Social logo

Allow pure Ruby attribute values about slim HOT 10 CLOSED

judofyr avatar judofyr commented on June 15, 2024
Allow pure Ruby attribute values

from slim.

Comments (10)

stonean avatar stonean commented on June 15, 2024

So, to summarize, an attribute without quotes means the attribute's value is set by a method call. I like it, less typing!

from slim.

judofyr avatar judofyr commented on June 15, 2024

Or a local variable. Or foo[:hello] etc. You can think about it as the Hash syntax:

name="hello" # => { :name => "hello" } 
name=hello   # => { :name => hello }

from slim.

fredwu avatar fredwu commented on June 15, 2024

There is a slight catch - We already allow custom delimiters on attributes. For example:

meta(name="#{something}" value="#{anotherthing}")

Having another set of delimiters, while not conflicting with the attributes delimiter, might cause confusion to the end users.

meta(name=(1 + 1) value=(another("evaluated", :ruby => "method")))

Although, one might argue that it's to the end users to determine the best use for delimiters. :)

Just a thought.

from slim.

fredwu avatar fredwu commented on June 15, 2024

Ah, disregard my last comment, I haven't seen ticket #16 when I replied.

from slim.

stonean avatar stonean commented on June 15, 2024

Here's what I think should be allowed for attributes:

/ standard
meta name="keywords" value="slim, template"  

/ interpolation, standard Ruby stuff inside
meta name="keywords" value="#{page_keywords}"

/ no quotes = method call
meta name="keywords" value=page_keywords

/ no_quotes = method call with params
/ we won't evaluate these, so valid Ruby code is required
/ just as if it were being called in a String
meta name="keywords" value=page_keywords(params[:action])

I don't think we should allow for the use case:
meta name=(1 + 1)

The delimiters issue ( #16 ), should only apply to enclosing the attributes of a tag. I like the quote/no quote cleanliness for the attributes. So options should be:

meta name="keywords" value=page_keywords
meta(name="keywords" value=page_keywords)
meta[name="keywords" value=page_keywords]
meta{name="keywords" value=page_keywords}

Let's face it, attributes are typically quoted, so interpolation should be the common option. I think it will be more of a pain to have the method calls return quoted strings than to just use interpolation.

from slim.

activestylus avatar activestylus commented on June 15, 2024

While we are on this subject, I'm wondering how this haml example would translate to Slim:

div{:class => params[:active] ? "active" : "inactive"}

I've tried plain string interpolation:

div(class="#{params[:active] ? "active" : "inactive"}")

syntax error, unexpected $undefined, expecting '}'
...menu(class="#{params[:active]">? "active" : "inactive"}")<...

I know, I know, logic almost always belongs in a helper, but these one-line conditionals are a life saver sometimes.

from slim.

stonean avatar stonean commented on June 15, 2024

This is what you'd want:

class="#{ ( params[:active] ? "active" : "inactive" ) }" 

I added the spaces for clarity

from slim.

fredwu avatar fredwu commented on June 15, 2024

Just a quick note: I'm working on this ticket.

from slim.

activestylus avatar activestylus commented on June 15, 2024

Thanks stonean, that did it - I assume that eventually we will just do this, seeing as interpolation is overkill here?

class=( params[:active] ? "active" : "inactive" )

from slim.

fredwu avatar fredwu commented on June 15, 2024

Allows pure ruby attribute values. Closed by a0ed999

The code is a bit cryptic for now, will refactor soon.

from slim.

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.