[英]Hyperstack add dynamic class to manual class names
I need to add a dynamic class to some regular classes while updating syntax for Hyperstack: 我需要在更新Hyperstack的语法时为一些常规类添加动态类:
div.upload_header.text_left(class: ('uploaded' if
FileUploads.complete?)) do
Should become something like this: 应该成为这样的事情:
DIV(class: 'upload-header text-left (dynamic 'uploaded' should go
here)') do
I just can't seem to figure out how/if regular and dynamic classes can be declared together. 我似乎无法弄清楚如何将常规和动态类一起声明。
String interpolation can be done conditionally: 字符串插值可以有条件地完成:
DIV(class: "upload-header text-left #{'uploaded' if FileUploads.complete?}")
The class parameter can also accept an array: class参数也可以接受一个数组:
def upload_header_classes
['upload-header', 'text-left'].tap do |classes|
classes << 'uploaded' if FileUploads.complete?
end
end
DIV(class: upload_header_classes)
I'm sure there are plenty of other ways to do it too, this is ruby! 我确信还有很多其他方法可以做到这一点,这就是红宝石!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.