I've just got started with Play2 and I'm struggling with scala.
In a view I've got this simple form helper to create a news item.
@textarea(
newsItemForm("content"),
'_label -> "Content",
'rows -> 3,
'cols -> 50,
)
Now I'd like to add a data-wysiwyg
to the attributes, but since it contains a - scala complains about - not being a member of Symbol.
since '
is just a nice way of writing Symbol("data-wysiwyg") I can get it working, but then my views will look ugly with some attributes beeing specified with Symbol
and others with '
My question is: is there a way to use the scala '
notation for html5 data-
attributes?
You can also use the apply method of the Symbol
companion object. I think this is more readable, as it makes it very obvious that you're creating a symbol:
scala> Symbol("data-wysiwyg");
res0: Symbol = 'data-wysiwyg
I don't think it's possible because the dash will be interpreted as a minus sign. If the matter is to shorten the declaration, why not add a method s
to strings to produce the corresponding symbol (akin to the r
method for producing regexp) ?
class SymbolString( str: String ) {
def s = Symbol(str)
}
implicit def str2symstr( str: String ) = new SymbolString(str)
scala> "hello".s
res20: Symbol = 'hello
scala> "data-wysiwyg".s
res21: Symbol = 'data-wysiwyg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With