[Dredging up an old conversation, because it is relevant to another problem
we have.]

Henry and I were talking this morning about our heuristic that tries to
pluck HTML content out of a <text> element (actually, out of any element
that has an attribute named 'text' whose type is also 'text' [can you say
kludge?]).  Henry is trying to tear out a lot of stale text metric code that
was really only for swf5, and stumbled across this.

Our proposal is that we deprecate mixing HTML markup with LZX markup.  We
will keep the existing heuristic, but we will issue a deprecation warning
when we detect any LZX markup in a text-like tag.  The way to silence the
warning is to define a class, put the methods on the class, and then use the
class tag instead to enclose your HTML.

This is not the ideal solution, because it prevents people from writing
"one-off" instances with HTML content.  So we have a longer-term proposal
which would bring this feature back in a more disciplined way.  We will add
a new "when" processor, called `source`, which allows you to capture a value
from an xpath expression on your source.  This means that the <text> tag can
be defined as follows:

<class name="text">
  <attribute name="text" type="text" value="$source{../text()}" />
</class<

I.e., the value of the `text` attribute of the <text> tag is taken from the
content of the attribute's parent node -- the text tag.

If you need to create a one-off <text> instance with an additional method,
the way you do that is to redefine how the content is picked up, e.g.:

<text>
  <handler name="onfoo" ... />
  <attribute name="text" value="$source{text()}">
    The <b>HTML</b> content of the <i>text</i> node
    is the body of the attribute tag.
  </attribute>
</text>

It seems the same solution would work for <dataset>.  This would also allow
us to get rid of the magical processing of attributes named text with type
text and just have a standard way for attributes to take their initial value
from source content.

Comments?

On Wed, Jun 1, 2005 at 5:01 PM, Oliver Steele <[email protected]>wrote:

> [Added laszlo-dev.]
>
> On May 29, 2005, at 10:37 AM, P T Withington wrote:
>
> On 29 May 2005, at 10:01, Oliver Steele wrote:
>
> On May 24, 2005, at 8:01 PM, P T Withington wrote:
>
> Er, I can see why you can't subclass a dataset instance, because you can't
> distinguish the content from members, but why can't you create a subclass of
> dataset?  Is this because dataset is really a special form?  [I'm really
> asking Oliver this.]
>
>
> Right.  Technically, it's because
>   <class name="myclass" extends="tag">stuff</class>
>   <myclass/>
> is defined to be equivalent to:
>   <tag>stuff</tag>
>
> But we could say this isn't true for extends="dataset", and then you could
> add methods to a subclass.
>
>
> Oh right.  Adam's nifty thing where you can start with an instance and
> switch to a class when you need it.
>
>
> Also here: <http://osteele.com/archives/2004/03/classes-and-prototypes>.
> And it made into into the dguide too, I think.
>
> Text works because it ignores anything that isn't a declared as an HTML
> element in the schema.  (Well, that's the spec.  The implementation is
> WETter than that.  Now ask me what WET means :-)
>
> We have a similar problem with text, right?  Except text happens to work
> because we can distinguish between plain text (which is treated as content)
> and tags (which are treated as extensions).  That won't work if the
> content of the text is html will it?  Or are we being even trickier and
> knowing that only certain tags are extensions?
>
> Could we do something like this?
>
>
> <dataset ...>
>   <?lzx
>     <attribute ... />
>     <method ...>
>       ...
>     </method>
>   ?>
>   <xml>
>     <content>
>       <goes here>
>     </content>
>   </xml>
> </dataset>
>
> Or instead of <?lzx ... ?> use <![CDATA[ ... ]]>?
>
>
> I don't like these, since neither one gives <dataset> an <attribute>
> element in the source, causing problems for editors and another path in the
> compiler.
>
> Some other ideas:
>
> *Namespaces*
>   <dataset name="ds" xmlns:data="local:data">
>     <attribute name="a" value="1"/>  <!-- This adds an attribute to the
> dataset -->
>     <data:attribute name="a" value="1"/> <!-- This is the xml content of
> the dataset -->
>   </dataset>
>
> I admit I can't quite get this to work, but in case anyone else can kick
> life into it...
>
> *<Model> element*
> Require a <model> element for inline data, so anything that *isn't* inside
> the <model> element is property of the instance (or class):
>
>   <dataset name="ds">
>     <attribute name="a" value="1"/>  <!-- This adds an attribute to the
> dataset -->
>     <model>
>       <attribute name="a" value="1"/> <!-- This is the xml content of the
> dataset -->
>     </model>
>   </dataset>
>
> This is a breaking change, so it would need to be phased in.  It also has
> the disadvantage that not every XML fragment represents an MVC model.  This
> is already a source of confusion for server-side developers.
>
> *Subclassing*
> Fix subclassing dataset, and specify that the class definition can't have
> inline data.  (This is the original proposal at the top of this message.)
>
>   <dataset name="ds">
>     <attribute name="a" value="1"/> <!-- This is the xml content of the
> dataset -->
>   </dataset>
>
>   <class name="mydataset" extends="dataset">
>     <attribute name="a" value="1"/>  <!-- This adds an attribute to the
> dataset -->
>   </dataset>
>   <mydataset name="ds">
>     <attribute name="a" value="1"/> <!-- This is the xml content of the
> dataset -->
>   </dataset>
>
> This breaks the instance substitution principle: it's not the same as
> subclassing works for other base classes, so it requires special knowledge
> on the part of developers and refactoring tools.
>
> *Partial classes*
> I'm going to propose (Real Soon Now) that we add *partial classes* (aka *open
> classes*), in order to make it possible to reskin components with the
> maintenance overhead of copying files, and without the runtime overhead of
> subclassing.  This could also be used to add methods to datasets, if the
> rule were that inline data is only allowed in the main class declaration
> (probably a good rule for independent reasons).
>
>   <dataset name="ds">
>     <attribute name="a" value="1"/> <!-- This is the xml content of the
> dataset -->
>   </dataset>
>
>   <extend name="ds">
>     <attribute name="a" value="1"/>  <!-- This adds an attribute to the
> dataset -->
>   </extend>
>
> (The syntax for partial classes is yet to be decided; this is a stub so you
> can see how it would interact with this particular problem.)
>
> _______________________________________________
> Laszlo-dev mailing list
> [email protected]
> http://www.openlaszlo.org/mailman/listinfo/laszlo-dev
>
>

Reply via email to