Titanium JIRA Archive
Alloy (ALOY)

[ALOY-408] Create special notation for js, constants, etc... in XML attributes of views

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionWon't Fix
Resolution Date2013-01-10T14:43:13.000+0000
Affected Version/sAlloy 0.3.3
Fix Version/sn/a
ComponentsRuntime, XML
Labelsnotable
ReporterTony Lukasavage
AssigneeTony Lukasavage
Created2012-11-30T20:13:35.000+0000
Updated2014-01-28T23:18:04.000+0000

Description

Currently, unless explicitly handled in a parser, all attribute values from XML attributes are treated as strings, as is the standard for XML. It would be nice for developers to have a means of putting numbers, objects, constants, or even JS in those attributes and have them be processed appropriately. To do this, we should introduce a new syntax inside the attribute values that would indicate that a value should be interpreted literally in the generated JS. As much as I'd like to keep it in line with underscore's templating, *<%=%>*, I want to avoid having the additional angle brackets in the XML. I like the idea of using {} to wrap the value, since we are going to use this for model-view binding. We just need a prefix for it to indicate that it is not used for binding, but instead for literal JS. For that reason, I wanted to use *#{}* for the syntax. Initially I thought of using *${}*, but *$* has some meaning as it relates to controllers in Alloy and I didn't want this to be confusing. I think *#{}* is clear and simple, but I am open to alternatives.

examples

<Label text="my string" height="#{Ti.UI.SIZE}"/>
<Button systemButton="#{Ti.UI.iPhone.SystemButton.ADD}"/>
<ButtonBar labels="#{['label1','label2','label3']}"/>
Obviously some of the possible uses wouldn't be considered "best practices", but this functionality would be a great catch all for introducing some dynamism into the XML attribute values while we come up with tighter more concise integrations. Essentially it will prevent developers from saying "I wish I could specify some XXXXXX value in the markup".

Comments

  1. Tony Lukasavage 2013-01-10

    Titanium constants covered by ALOY-284. Will create specific tickets for new syntax is use cases arise for putting more complex notation in markup attributes.

JSON Source