I''m adding a support for a variation of the :global_directive? mechanism that we currently use for unconditionally installing the GlobalInlineErb directive. Purpose is to allow a directive to conditionally install itself on an element even if not explictly specified in the markup. Details below. Let me know what you think. ~ Deb -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Use case: I have a custom directive in my app that I want applied to all <img> elements and I don''t want to have to manually annotate each document. My template docs use local refs to some images for design-time viewing that need to be mapped to the rails asset dirs in the running site. I don''t care about the rails image helper because my template already says what it needs to, so mv:image_tag isn''t relevant. The explicit directive markup I''d have to use would be: <img class="docIcon" src="../ximages/mydocimage.gif" mvx:image_attrs="" /> but I really want to simply write what I would have in my normal html markup: <img class="docIcon" src="../ximages/mydocimage.gif" /> Experimenting a bit with the protocol and metadata decl notation. Basic idea is that the metadata value specifies ''true'' for unconditional use (GlobalInlineErb), or a callback which takes args tag_name and element_attrs and returns the attr_value for instantiating the directive if it wants to be activated or nil/false if not applicable. E.g., my global img element directive specifies its activation condition as: metadata :priority => :default, :global_directive? => Proc.new { | tag_name, element_attrs | # activate on all <img> attributes w/out explicit directive markup ( tag_name == ''img'' && ! element_attrs.has_key?( attribute_qname ) ) ? '''' : false } A more general variation of this might also check for mv:image_tag, although in my case I don''t bother because I don''t use that. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
On 10/8/06, Deb Lewis <djlewis at acm.org> wrote:> I''m adding a support for a variation of the :global_directive? mechanism > that we currently use for unconditionally installing the GlobalInlineErb > directive. Purpose is to allow a directive to conditionally install itself > on an element even if not explictly specified in the markup. > > Details below. Let me know what you think. > > ~ Deb > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > > Use case: I have a custom directive in my app that I want applied to all > <img> elements and I don''t want to have to manually annotate each document. > My template docs use local refs to some images for design-time viewing that > need to be mapped to the rails asset dirs in the running site. I don''t care > about the rails image helper because my template already says what it needs > to, so mv:image_tag isn''t relevant. > > The explicit directive markup I''d have to use would be: > > <img class="docIcon" src="../ximages/mydocimage.gif" mvx:image_attrs="" > /> > > but I really want to simply write what I would have in my normal html > markup: > > <img class="docIcon" src="../ximages/mydocimage.gif" /> > > Experimenting a bit with the protocol and metadata decl notation. Basic > idea is that the metadata value specifies ''true'' for unconditional use > (GlobalInlineErb), or a callback which takes args tag_name and element_attrs > and returns the attr_value for instantiating the directive if it wants to be > activated or nil/false if not applicable. > > E.g., my global img element directive specifies its activation condition as: > > metadata :priority => :default, > :global_directive? => Proc.new { | tag_name, element_attrs | > # activate on all <img> attributes w/out explicit directive markup > ( tag_name == ''img'' && ! element_attrs.has_key?( attribute_qname ) > ) ? '''' : false > } > > A more general variation of this might also check for mv:image_tag, although > in my case I don''t bother because I don''t use that. > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > >That sounds pretty good!! I will look closer at it. Does this or should this be related in anyway to the ability to customize default options for directives? Kind of seems like one could specify something like this at the app or page level similar to what we were thinking about for default settings. Something like this might allow one to use standard directives in a similar fashion. For instance the app or page level setting might provide a block that gets executed determining whether it is a global_directive and it might allow the massaging of attributes (and the directive''s attribute) as well setting some default behavior. Just wondering what you thought.
...>> ... related in anyway to the ability to customize default options >> for directives? ... specify something like this at the app or page level >> similar to what we were thinking about for default settings.Yeah, might be interesting, would like to think about this whole area a bit more before we decide what/how to tackle. I kind of tabled the per-directive config setting until everything else got settled, too many things broken and in flux to cope with new ideas. But I think this notion will be useful. Per-page mv config might be done with a directive that we introduce for that purpose - maybe an element containing the code to evaluate so that notationally it follows the same pattern as in the mv config settings .rb files. BTW note that the config settings we introduced recently to allow customization of the relative paths for assets (images, stylesheets) are really a case of per-directive customization - we just didn''t recognize that at the tme! ~ Deb
On 10/9/06, Deb Lewis <djlewis at acm.org> wrote:> ... > >> ... related in anyway to the ability to customize default options > >> for directives? ... specify something like this at the app or page level > >> similar to what we were thinking about for default settings. > > Yeah, might be interesting, would like to think about this whole area a bit > more before we decide what/how to tackle. I kind of tabled the > per-directive config setting until everything else got settled, too many > things broken and in flux to cope with new ideas. But I think this notion > will be useful.Yes, I agree.> > Per-page mv config might be done with a directive that we introduce for that > purpose - maybe an element containing the code to evaluate so that > notationally it follows the same pattern as in the mv config settings .rb > files.That sounds like a nice approach.> > BTW note that the config settings we introduced recently to allow > customization of the relative paths for assets (images, stylesheets) are > really a case of per-directive customization - we just didn''t recognize that > at the tme! >Sooner or later things evolve into what they need to be :-)
On 10/8/06, Deb Lewis <djlewis at acm.org> wrote:> I''m adding a support for a variation of the :global_directive? mechanism > that we currently use for unconditionally installing the GlobalInlineErb > directive. Purpose is to allow a directive to conditionally install itself > on an element even if not explictly specified in the markup. > > Details below. Let me know what you think. > > ~ Deb > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > > Use case: I have a custom directive in my app that I want applied to all > <img> elements and I don''t want to have to manually annotate each document. > My template docs use local refs to some images for design-time viewing that > need to be mapped to the rails asset dirs in the running site. I don''t care > about the rails image helper because my template already says what it needs > to, so mv:image_tag isn''t relevant. > > The explicit directive markup I''d have to use would be: > > <img class="docIcon" src="../ximages/mydocimage.gif" mvx:image_attrs="" > /> > > but I really want to simply write what I would have in my normal html > markup: > > <img class="docIcon" src="../ximages/mydocimage.gif" /> > > Experimenting a bit with the protocol and metadata decl notation. Basic > idea is that the metadata value specifies ''true'' for unconditional use > (GlobalInlineErb), or a callback which takes args tag_name and element_attrs > and returns the attr_value for instantiating the directive if it wants to be > activated or nil/false if not applicable. > > E.g., my global img element directive specifies its activation condition as: > > metadata :priority => :default, > :global_directive? => Proc.new { | tag_name, element_attrs | > # activate on all <img> attributes w/out explicit directive markup > ( tag_name == ''img'' && ! element_attrs.has_key?( attribute_qname ) > ) ? '''' : false > } > > A more general variation of this might also check for mv:image_tag, although > in my case I don''t bother because I don''t use that. >Looks like a nice addition.