Mar 14, 2011

Tag replace - Actions in ColdFusion Builder

Tag search is that one powerful feature in ColdFusion Builder 2.0 which allows you to search for tags that match some criteria. Also, there are various actions that the user can perform once the tag is found. Actions such as
  •  'Replacing the tag block' with some text,
  •  'Removing the Tag block', 
  •  'Setting an attribute', 
  •  'Removing an attribute',
  •  'Adding text before the tag block' and
  •  'Adding text after the tag block'. 
In this post I'll explain how these actions can help you increase your productivity in your day to day application development.

Action - Setting an attribute

Consider a use-case where you would like your ColdFusion application to be available to other web clients such as a HTML client or a FLEX client. In these cases you will have to update the cffunction's access attribute to remote. Updating each and every function definition can be a time consuming task. With the action Set attribute one can specify the attribute that you would like to update with the given value:


As we can see in the above screenshot, a condition 'cffunction tag with attribute access is Any value' is specified (i.e. the tag search engine would search for cffunction tags whose access attribute will be any value). The action selected is Set attribute with attribute access selected with its value set to remote. On clicking 'Replace All', all cffunction tags in the CFC will now have the access attribute set to remote. How easy was that? Gone are the days when you had to go through the entire file and update the tag attributes where ever required.

If you specify an attribute which doesn't exist, then the attribute would be added to the tag definition. Action Set Attribute is used for both adding and updating the tag definitions.

Action - Remove attribute

Action Remove attribute is used to remove an attribute from the tag. So if you would like to remove an attribute, say output attribute of cffunction tag, then select Remove attribute as the action and specify the attribute that you would like to remove:


Actions - Adding text before and after the tag block

While editing a CFC containing various cffunction tags, there are times when you would like to add a generic comment before the function definition, stating its description. Also you would want to add a comment stating the end of the function tag block at the end of the cffunction tag. With the new Tag search, you can specify the tag as cffunction and then add a condition (if required) and click 'Add'. Now in the Action list, select Add before Tag and specify the text that you would like to add. In this case, it would be a comment as shown in the picture below:


Click on Replace All and you will see that the comment is added before the tag block.

Similarly, in case of Adding text after the tag block, select Add after tag and specify the text that you want to add after the function definition:


Again, click 'Replace All' to add the comment at the end of every function definition.

Actions - Replace tag block and Remove tag block


Other actions provided include Replacing a tag block and Removing a tag block. As the name suggests, on selecting the action Replace tag block, the tag block is replaced with the text that the user has provided:


Similarly if you would like to remove the tag block, then select the action Remove tag block:


All the actions mentioned above can be performed in all the scopes. Please refer to my previous post where in I have describe various scopes available for both text and tag search. 

2 comments:

  1. That is a pretty cool feature! I need to get my hands on that beta. I really want to start playing with the plugins again.

    ReplyDelete
  2. Hey Sagar,

    Would you consider becoming a DZone.com MVB?

    www.dzone.com/aboutmvb

    You can reach our curator through that link.

    Best,
    Mitch

    ReplyDelete