Prelude to Fusebox

38
Prelude to Fusebox The Basics: <cfinclude> <cfmodule> <cfswitch> - <cfcase> <cfapplication> Variable scopes: session/client/application/request/attributes/c aller Custom Tags URLToken

description

Prelude to Fusebox. The Basics: - Variable scopes: session/client/application/request/attributes/caller Custom Tags URLToken. Fusebox Changes The World!. How lazy coders make big bucks Compiled by the Fusebox Community - PowerPoint PPT Presentation

Transcript of Prelude to Fusebox

Page 1: Prelude to Fusebox

Prelude to Fusebox

The Basics:<cfinclude><cfmodule><cfswitch> - <cfcase><cfapplication>Variable scopes: session/client/application/request/attributes/callerCustom TagsURLToken

Page 2: Prelude to Fusebox

Fusebox Changes The World!

How lazy coders make big bucks

Compiled by the Fusebox Communitywith the help of Hal Helms and Steve Nelson

Page 3: Prelude to Fusebox

The situation with web application development these days...

Skilled craftspeople are needed to create the product.Each product is a unique work of its creator.There is a shortage of skilled workers.There is a wide variation in the quality of finished goods.Maintenance of our products require the user to go back to the creator or to employ the skills of a highly-paid master craftsperson.There is no ability to interchange parts from one product to another.There is very limited division of labor.There is no efficiency of scale: it takes 10 times as long to produce 10 products.

Page 4: Prelude to Fusebox

A CF Programmer’s Dream World...Imagine if….

You could work in a team of developers and have all the code look like it was written by single person.You could understand the structure of your co-workers code in 5 minutes, without asking questions.You could concentrate on solving the problem instead of thinking about how to write the application.

Nice, huh?

Page 5: Prelude to Fusebox

Why use a Structured Architecture?File based applications get messy. A structured architecture helps to clean this up.Multiple person development is more easily facilitated – without stepping on toes.If your structure is clearly defined, your application documents itself.You only focus on the client’s problem instead of the application’s architecture.

Page 6: Prelude to Fusebox

What is Fusebox?Fusebox is:

A structured application architecture for building web applications, primarily using ColdFusion.

A methodology of coding so you can use others’ labors without feeling guilty - as if you ever did.An open-source project, created by the ColdFusion community for the ColdFusion community.Quick to learn. Adopt as much or as little as you want.Flexible and extensible. There is no Fusebox Gestapo to make sure you followed all the rules.Free.

Page 7: Prelude to Fusebox

Before You Write Any CodeTalk to the client about general ideas, business requirements and specifications.With the client on-hand, write down these ideas into a loose specification. Better yet, have him/her do it.Create a tight specification from the loose specification. Figure out all the sections of the application and all the actions required to do everything the client wants the application to do.Repeat this process until every action in the application is understood by everyone involved.Write a Fusedoc for the application from these use-case scenarios.

Page 8: Prelude to Fusebox

Create the Directory StructuresUse the tight specification to figure out all the sections of the application.Each section is given its own directory; these sections are known as “Circuit Applications”.A circuit application is a section of the overall home application.Examples:

www.ebags.com/search www.autobytel.com/customerlogin www.ecommerce.com/cart

Page 9: Prelude to Fusebox

Create the Index.cfm FilesEvery directory (circuit application) has one index.cfm file.Index.cfm controls all the Fuseactions of that circuit application.It is the Fusebox.All links and form submissions go to the index.cfm.It is a single <CFSWITCH> statement with multiple <CFCASE> statements.Each <CFCASE> is a different Fuseaction.

Page 10: Prelude to Fusebox

Fusebox Anatomy: the Fusebox (index.cfm)

Fusebox

<!--index.cfm-->

<cf_formURL2attributes>

<cfinclude template=“app_globals.cfm”>

<cfparam name=“fuseaction”Default=“login”>

<cfswitch expression=“#attributes.fuseaction#”> <cfcase value=“login”> <cf_do_logic> <cfinclude template=“dsp_UserLogin.cfm”> </cfcase> ....</cfswitch>

Page 11: Prelude to Fusebox

The Fusebox Architecture

This isMeant toBe Just textThat isn’tClear. I hopeIt works theWay I wantIt to.

dsp_UserLogin.cfm

http://index.cfm?http://index.cfm?fuseaction=loginfuseaction=login

Fusebox

Page 12: Prelude to Fusebox

The Fusebox Architecture

http://index.cfm?http://index.cfm?fuseaction=loginfuseaction=login

Fusebox

http://index.cfm?http://index.cfm?fuseaction=validateUserfuseaction=validateUser

This isMeant toBe Just textThat isn’tClear. I hopeIt works theWay I wantIt to.

Page 13: Prelude to Fusebox

Create the FuseactionsA Fuseaction is made up of one or more .cfm files.Determine what types of files (display/action/query) are needed to create each Fuseaction.Create a CFCASE statement for each Fuseaction and CFINCLUDE each necessary file.

Page 14: Prelude to Fusebox

Conventions, Extensions, and RulesFile Naming ConventionsFusedocs<cf_formurl2attributes>

Page 15: Prelude to Fusebox

File Naming Convention (Fuses)app_globals.cfm - Global variables, one per Home applicationapp_locals.cfm - Local variables, one per Circuit application dsp_filename.cfm - Display files act_filename.cfm - Action filesqry_filename.cfm - Query files

Page 16: Prelude to Fusebox

Fusedoc: A Documentation StandardA Fusedoc outlines responsibilities, customizations, and expectations.A Fusedoc is a collection of Fusecards which are granular to the actions and steps of the application.A Fusecard contains the following elements:

Fusename Responsibilities (hopefully non-technical, in plain English) Author / Coder Variables list (incoming, outgoing, and persistent)

Page 17: Prelude to Fusebox

Fusedoc Legend

--> explicitly passed incoming parameter<-- explicitly passed outgoing parameter<-> pass-thru parameter (unchanged)++> existing persistent parameter (session, client, etc.)<++ created persistent parameter+++ included file

[parameter] indicates optional

Examples:--> CurrentUser: a WDDX STRUCTURE<-- [badLogin]: a STRING<++ Session.ColorChoice: a STRING (Red|Blue)<-> UserID: an INTEGER+++ myGlobals.cfm

Page 18: Prelude to Fusebox

Sample Fusecard / Fusestub<!-- dsp_UserLogin.cfm

Author: [email protected] -->

<!---FUSEDOC|| Responsibilities: I make sure that the UserName and Password match what’s in the TableName table. If so, I let the person pass with a parameter ofUserAuth set to “yes”. If not, I send the user back to the Fusebox withBadLogin set to “yes”.|| FuseStub: [email protected]: [email protected]: ||<-- [BadLogin]: variable sent if user tried to login unsuccessfully<-- [UserAuth]: on success, a STRING value set to “yes”--> UserName: a STRING indicating the user’s name--> Password: a STRING indicating the user’s password--> DSN: a STRING of the ODBC datasource name to use to verify--> TableName: a STRING of the table name to use to verify

END FUSEDOC--->

Page 19: Prelude to Fusebox

What’s in a Fuse?1. Fusedoc2. [HTML]3. Code

• The perfect fuse is small and has a verynarrow focus.

Page 20: Prelude to Fusebox

Create the Necessary Files (Fuses)All links and forms in the display files should point to one of the index.cfm files in the application, never to the specific dsp or act files.

All links and forms must specify which Fuseaction they point to.

A hint now, for advanced Fusebox techniques:

Use the “attributes” scope instead of form/url scope. This allows you to call the index.cfm file as a custom tag.

Page 21: Prelude to Fusebox

Fusebox Anatomy: a fuse

A Fuse

<!-- dsp_UserLogin.cfmAuthor: [email protected] -->

<!---FUSEDOC – blah blah blah (Hal likes his Fusedocs)END FUSEDOC--->

<form action=“index.cfm” method=“post”> <input type=“hidden” name=“fuseaction” value=“FormAction1”> Name: <input type=“text” name=“userName”><br> Password:<input type=“password” name=“password”><br> <input type = “submit” value=“OK”></form>

I am a fuse…

Page 22: Prelude to Fusebox

Putting it all TogetherOne home application is made up of many smaller circuit applications.One circuit application is made up of a directory of files.Each circuit must contain an app_locals.cfm and index.cfm file plus other display/action/query files as Fuses.One index.cfm file is made up of one or more Fuseactions.One Fuseaction includes one or more display/action/query files plus any necessary CFML logic.

Page 23: Prelude to Fusebox

Extending Fusebox

?

Fusebox

Circuits

?

?

?

UserManager

ShoppingCart

CompanyInfo

This isMeant toBe Just textThat isn’tClear. I hopeIt works theWay I wantIt to.

This isMeant toBe Just textThat isn’tClear. I hopeIt works theWay I wantIt to.

This isMeant toBe Just textThat isn’tClear. I hopeIt works theWay I wantIt to.

This isMeant toBe Just textThat isn’tClear. I hopeIt works theWay I wantIt to.

This isMeant toBe Just textThat isn’tClear. I hopeIt works theWay I wantIt to.

This isMeant toBe Just textThat isn’tClear. I hopeIt works theWay I wantIt to.

Page 24: Prelude to Fusebox

Building A Fusebox Shopping Cart

Display Fuses showCartSummary showCatalog showItem

We’ll look at: only Fusedocs for individual Fuses. code for app_locals, app_globals, index.cfm.

Action Fuses addItemToCart removeItemFromCart clearCart

Page 25: Prelude to Fusebox

The Shopping Cart Array

Implement shopping cart as 2d array

itemID quantity description price

2105 2 ColdFusion To Go

49.99

3995 1 Fusebox Essentials

99.99

Page 26: Prelude to Fusebox

The Cart Summary page<!-- dsp_CartSummary.cfm

Author: [email protected] -->

<!---FUSEDOC|| Responsibilities: I show the contents of the user’s shopping Cart.|| Edits: ||++> session.shoppingCart: a 2D ARRAY with columnsof itemID, quantity, description, price<-- [itemID]: a PK from Items tableEND FUSEDOC--->

Page 27: Prelude to Fusebox

The Catalog page<!-- dsp_Catalog.cfm

Author: [email protected] -->

<!---FUSEDOC|| Responsibilities: I show the contents of the Items tableto the customer, letting them examine an item or buy it.|| Edits: ||--> request.DSN: a valid ODBC DATASOURCE<-- [itemID]: a PK from Items table <-- quantity: an INTEGER END FUSEDOC--->

Page 28: Prelude to Fusebox

The Item page<!-- dsp_Item.cfm

Author: [email protected] -->

<!---FUSEDOC|| Responsibilities: I show the details of a particular item to the customer hoping they’ll buy it.|| Edits: ||

--> request.DSN: a valid ODBC DATASOURCE--> itemID: a valid PK from Items table<-- [itemID]: a PK from Items table<-- [quantity]: an INTEGEREND FUSEDOC--->

Page 29: Prelude to Fusebox

Adding an item to the cart<!-- act_addItem.cfm

Author: [email protected] -->

<!---FUSEDOC|| Responsibilities: I add an item to the cart. If Ialready have one of these items in my cart, I’ll justincrement the value.|| Edits: ||--> itemID: a valid PK from Items table--> quantity: an INTEGER--> request.dsn: a valid ODBC DATASOURCE++> session.shoppingCart: a 2D ARRAY with columnsof itemID, quantity, description, priceEND FUSEDOC--->

Page 30: Prelude to Fusebox

Removing an item from cart<!-- act_removeItem.cfm

Author: [email protected] -->

<!---FUSEDOC|| Responsibilities: I remove an item from the cart. If I have more than one of these items in my cart, I will justdecrement the value.|| Edits: ||--> itemID: a valid PK from Items table++> session.shoppingCart: a 2D ARRAY with columnsof itemID, quantity, description, priceEND FUSEDOC--->

Page 31: Prelude to Fusebox

Clearing the cart<!-- act_clearCart.cfm

Author: [email protected] -->

<!---FUSEDOC|| Responsibilities: I remove all items from the cart|| Edits: ||++> session.shoppingCart: a 2D ARRAY with columnsof itemID, quantity, description, priceEND FUSEDOC--->

Page 32: Prelude to Fusebox

The Fusebox – index.cfm<!--index.cfm-->

<cfinclude template=“app_locals.cfm”>

<cfswitch expression=“#attributes.fuseaction#”>

<cfcase value=“main”> <cfinclude template=“qry_GetShoppingCart.cfm”> <cfset UserShoppingCart=session.UserShoppingCart> <cflocation url=“index.cfm?fuseaction=Catalog”> </cfcase>

<cfcase value=“addItem”> <cfinclude template=“act_AddItem.cfm”> <cflocation url=“index.cfm?fuseaction=cartSummary”> </cfcase>

<cfcase value=“ClearCart”> <cfinclude template=“act_ClearCart.cfm”> <cflocation=“index.cfm?fuseaction=Catalogue”> </cfcase>

</cfswitch>

Page 33: Prelude to Fusebox

App_Locals.cfm<!—app_locals.cfm-->

<cfinclude template=“../app_globals.cfm”>

<cfparam name=“attributes.fuseaction” default=“main”>

<cfif not IsDefined(“application.statelist”)> <cfset application.statelist=“AK,AL,AR,(etc,etc)”></cfif>

<cfparam name=“session.UserAuth” default=“no”>

<cfif not session.UserAuth> <cflocation url=“../index.cfm?fuseaction=login”></cfif>

Page 34: Prelude to Fusebox

App_Globals.cfm<!—app_globals.cfm-->

<cf_formurl2attribues>

<cfparam name=“attributes.fuseaction” default=“main”>

<cfapplication Name=“NatsFuseboxApp" SessionManagement="Yes">

Page 35: Prelude to Fusebox

Congratulations!

That’s all there is to Fusebox.Not too scary, eh?

Page 36: Prelude to Fusebox

Current Enhancements to Vanilla Fusebox

<cf_bodycontent>Application.cfm<cfif ListLast(GetTemplatePath(),'\') is not “index.cfm”>

<cflocation url="/index.cfm?fuseaction=logoff2"></cfif>

Return fuseactionsExploded Benchmarking for 4.01HKEY_LOCAL_MACHINE\SOFTWARE\Allaire\ColdFusion\CurrentVersion\Debug String Value: WriteExplodedBenchmarkingInfo=1

Page 37: Prelude to Fusebox

Conclusion: Why use FuseboxFusebox is (most likely) very similar to how you may already build an application, thus it will be easy to learn.It is a well thought out process, and will continue to be improved by the CF community.It’ll save you time, which will save you money.Cut-n-paste your way into completed applications. (No, really. I’m serious!)Most importantly it will prevent hair loss.

Page 38: Prelude to Fusebox

Fusebox Resourceshttp://www.fusebox.org

Old white paper, etc.http://www.houseoffusion.com

Fusebox mailing listhttp://www.teamAllaire.com/hal/

Fusebox primershttp://home.san.rr.com/natp/fuseboxnframes.zip

Source code for using Fusebox and frames happilyhttp://www.fuseml.org

Incorporating UML and Fusebox.