Download presentation
Presentation is loading. Please wait.
Published byAshlynn Williamson Modified over 9 years ago
1
Practical Code Generation with CF Template Peter Bell SystemsForge Peter Bell SystemsForge CF United 2008
2
Overview Why Generate? Types of Generation How to Generate Benefits of CF Template Working with Metadata
3
Who Am I? Programmer - 50-80 projects/yr. Entrepreneur - Profitable/practical Writer - CFDJ, Fusion Authority Quarterly, Flex Authority Presenter - CF United 2007/8, SoTR 2007/8, cf.objective() 2006/8, Frameworks, Webmaniacs, Code Generation 2007/8, ooPSLA, Domain Specific Modeling Forum, CFCamps...
4
Why Generate? Duplicated code: within applications between applications
5
We Already Generate GENERATING HTML: FirstName: #FirstName# LastName: #LastName# GENERATING SCRIPTS: > > %ThisField%: %#ThisField#% > >
6
Three Stages of Code 1. Duplicated select FirstName,LastName from tbl_User where Email = select Title,Price from tbl_Product where ProductID =
7
Three Stages of Code 2. Dynamic select #FieldNameList# from #TableName# where #FilterFieldName# = '#form.FieldValue#' where #FilterFieldName# = #form.FieldValue#
8
Three Stages of Code 3. Generated select %FieldNameList% from %TableName% where %FilterFieldName% = <cfqueryparam cfsqltype= "%FilterFieldType%" value="#form.%FilterFieldName%#"> GENERATES: select FirstName,LastName from tbl_User where Email =
9
Reasons to Generate Prototype with Dynamic Code Generate for: Performance Language Limitations Simplicity IP
10
Types of Generation Passive vs. Active Passive (wizard) Passive (automated) Active (round trip)
11
Active Code Generation Separate files: Inheritance Mixins AOP CF Includes Protected blocks
12
Approaches To Generation Approaches to Generation Concatenation Template Transformation
13
Concatenation "> ">
14
Generation: XML http://www.w3.org/1999/XSL/Transform <cfquery name="Get by " datasource="Scratch"> select from where ##FilterFieldName## = <cfqueryparam cfsqltype=" " value="form. "> </cfquery> Sample XML modified from Illudium Generator by Brian Rinaldi
15
Generation: CF Template select %FieldNameList% from %TableName% where %FilterFieldName% = GENERATES: select FirstName,LastName from tbl_User where Email =
16
CF Template Syntax Generation Time Tags: > vs. Generation Time Variables % vs. # That is IT! ALL ColdFusion features available Including cfscript ( >)
17
Benefits of CF Template More Readable no </> Less “Junk” http://www.w3.org/1999/XSL/Transform Shorter Variables %TableName% vs. Full Power of ColdFusion DateFormat(), cfif, cfloop, cfoutput, UDFs, etc. Nothing New to Learn!
18
Sources of Metadata Database metadata Explicit Metadata Static code analysis Runtime reflection
19
Metadata Options Comma delimited "test.csv", ",", "FirstName,LastName,Email", "tbl_User", "update" XML Databased “Little Language” Import test.csv using commas update tbl_User with FirstName,LastName,Email Visual
20
Example Metadata Product extends: BaseObject tableName: tbl_Product Identity: ProductID Properties: Title title required Price money optional default:0 Description WYSIWYG optional ClassMethods: AdminList: Title,Price OrderBy Title DefaultAdd: Title,Price,Description QuickAdd: Title,Price multiple:5 DefaultEdit: ID, Title,Price,Description Relationship has-many Category associated optional
21
Samples/Questions Find out more at http://cftemplate.riaforge.comhttp://cftemplate.riaforge.com Presentation will be posted tomorrow Check out http://www.pbell.comhttp://www.pbell.com
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.