Comments (10)
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.
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.
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.
Ah, disregard my last comment, I haven't seen ticket #16 when I replied.
from slim.
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.
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.
This is what you'd want:
class="#{ ( params[:active] ? "active" : "inactive" ) }"
I added the spaces for clarity
from slim.
Just a quick note: I'm working on this ticket.
from slim.
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.
Allows pure ruby attribute values. Closed by a0ed999
The code is a bit cryptic for now, will refactor soon.
from slim.
Related Issues (20)
- [master] Using a ruby attribute breaks html tag, its attributes and content concatenation HOT 10
- feature request: slimrb to work on directory recursively. HOT 2
- Support of Tailwind Arbitrary Classes HOT 14
- CodeClimate maintinability badge is not working
- Slim 5 no longer working with Middleman: "NameError: uninitialized constant #<Class:0x0000000106bf2320>::ActionView" HOT 20
- Is it possible to release a JavaScript version HOT 1
- uninitialized constant Slim::RailsTemplate (NameError) HOT 5
- How can I set <script> attribute? HOT 6
- Heads up: Tilt lazy loading of slim is being deprecated HOT 5
- Test Rails 7 in CI
- nested output rendering HOT 6
- Setup Rubocop in CI
- Better way to handle boolean attributes? HOT 1
- Rails 7.1 breaks slim partial block rendering when the partial is empty HOT 3
- Weird behavior in rails 7.1 HOT 1
- Undefined method `+' for ActionView::OutputBuffer when using the splat operator HOT 1
- Using uppercase tags for components HOT 1
- tree-sitter support
- Cannot call method defined in ruby: HOT 2
- Conversion back to ERB results in oddities
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slim.