Public Member Functions | Private Attributes | List of all members
TemplateNodeCreate Class Reference

Class representing an 'create' tag in a template. More...

Inheritance diagram for TemplateNodeCreate:
TemplateNodeCreator< TemplateNodeCreate > TemplateNode

Public Member Functions

 TemplateNodeCreate (TemplateParser *parser, TemplateNode *parent, int line, const QCString &data)
 
 ~TemplateNodeCreate ()
 
void render (FTextStream &, TemplateContext *c)
 
- Public Member Functions inherited from TemplateNodeCreator< TemplateNodeCreate >
 TemplateNodeCreator (TemplateParser *parser, TemplateNode *parent, int line)
 
TemplateImplgetTemplate ()
 
- Public Member Functions inherited from TemplateNode
 TemplateNode (TemplateNode *parent)
 
virtual ~TemplateNode ()
 
TemplateNodeparent ()
 

Private Attributes

ExprAstm_templateExpr
 
ExprAstm_fileExpr
 

Additional Inherited Members

- Static Public Member Functions inherited from TemplateNodeCreator< TemplateNodeCreate >
static TemplateNodecreateInstance (TemplateParser *parser, TemplateNode *parent, int line, const QCString &data)
 
- Protected Member Functions inherited from TemplateNodeCreator< TemplateNodeCreate >
void mkpath (TemplateContextImpl *ci, const QCString &fileName)
 
- Protected Attributes inherited from TemplateNodeCreator< TemplateNodeCreate >
QCString m_templateName
 
int m_line
 

Detailed Description

Class representing an 'create' tag in a template.

Definition at line 3478 of file template.cpp.

Constructor & Destructor Documentation

TemplateNodeCreate::TemplateNodeCreate ( TemplateParser parser,
TemplateNode parent,
int  line,
const QCString data 
)
inline

Definition at line 3481 of file template.cpp.

3483  {
3484  TRACE(("TemplateNodeCreate(%s)\n",data.data()));
3485  ExpressionParser ep(parser,line);
3486  if (data.isEmpty())
3487  {
3488  parser->warn(m_templateName,line,"create tag is missing arguments");
3489  }
3490  int i = data.find(" from ");
3491  if (i==-1)
3492  {
3493  if (data.right(3)==" from")
3494  {
3495  parser->warn(m_templateName,line,"create is missing template name after 'from' keyword");
3496  }
3497  else if (data=="from")
3498  {
3499  parser->warn(m_templateName,line,"create needs a file name and a template name");
3500  }
3501  else
3502  {
3503  parser->warn(m_templateName,line,"create is missing 'from' keyword");
3504  }
3505  }
3506  else
3507  {
3508  ExpressionParser ep(parser,line);
3509  m_fileExpr = ep.parse(data.left(i).stripWhiteSpace());
3510  m_templateExpr = ep.parse(data.mid(i+6).stripWhiteSpace());
3511  }
3512  }
ExprAst * m_templateExpr
Definition: template.cpp:3587
QCString stripWhiteSpace() const
Definition: qcstring.cpp:295
bool isEmpty() const
Definition: qcstring.h:189
QCString left(uint len) const
Definition: qcstring.cpp:213
int find(char c, int index=0, bool cs=TRUE) const
Definition: qcstring.cpp:41
TemplateNode * parent()
Definition: template.cpp:1647
QCString right(uint len) const
Definition: qcstring.cpp:231
const char * data() const
Definition: qcstring.h:207
QCString mid(uint index, uint len=0xffffffff) const
Definition: qcstring.cpp:246
void line(double t, double *p, double &x, double &y, double &z)
Recursive decent parser for Django style template expressions.
Definition: template.cpp:1680
#define TRACE(x)
Definition: template.cpp:43
ExprAst * m_fileExpr
Definition: template.cpp:3588
TemplateNodeCreate::~TemplateNodeCreate ( )
inline

Definition at line 3513 of file template.cpp.

3514  {
3515  delete m_templateExpr;
3516  delete m_fileExpr;
3517  }
ExprAst * m_templateExpr
Definition: template.cpp:3587
ExprAst * m_fileExpr
Definition: template.cpp:3588

Member Function Documentation

void TemplateNodeCreate::render ( FTextStream ,
TemplateContext c 
)
inlinevirtual

Implements TemplateNode.

Definition at line 3518 of file template.cpp.

3519  {
3520  TemplateContextImpl* ci = dynamic_cast<TemplateContextImpl*>(c);
3521  if (ci==0) return; // should not happen
3523  if (m_templateExpr && m_fileExpr)
3524  {
3525  QCString templateFile = m_templateExpr->resolve(c).toString();
3527  if (templateFile.isEmpty())
3528  {
3529  ci->warn(m_templateName,m_line,"empty template name parameter for create command\n");
3530  }
3531  else if (outputFile.isEmpty())
3532  {
3533  ci->warn(m_templateName,m_line,"empty file name parameter for create command\n");
3534  }
3535  else
3536  {
3537  TemplateImpl *t = getTemplate();
3538  if (t)
3539  {
3540  QCString extension=outputFile;
3541  int i=extension.findRev('.');
3542  if (i!=-1)
3543  {
3544  extension=extension.right(extension.length()-i-1);
3545  }
3546  t->engine()->setOutputExtension(extension);
3547  Template *ct = t->engine()->loadByName(templateFile,m_line);
3548  TemplateImpl *createTemplate = ct ? dynamic_cast<TemplateImpl*>(ct) : 0;
3549  if (createTemplate)
3550  {
3551  mkpath(ci,outputFile);
3552  if (!ci->outputDirectory().isEmpty())
3553  {
3554  outputFile.prepend(ci->outputDirectory()+"/");
3555  }
3556  //printf("NoteCreate(%s)\n",outputFile.data());
3557  QFile f(outputFile);
3558  if (f.open(IO_WriteOnly))
3559  {
3560  TemplateEscapeIntf *escIntf = ci->escapeIntf();
3561  ci->selectEscapeIntf(extension);
3562  FTextStream ts(&f);
3563  QGString out;
3564  FTextStream os(&out);
3565  createTemplate->render(os,c);
3567  ts << out;
3568  t->engine()->unload(t);
3569  ci->setActiveEscapeIntf(escIntf);
3570  }
3571  else
3572  {
3573  ci->warn(m_templateName,m_line,"failed to open output file '%s' for create command",outputFile.data());
3574  }
3575  }
3576  else
3577  {
3578  ci->warn(m_templateName,m_line,"failed to load template '%s' for include",templateFile.data());
3579  }
3580  t->engine()->setOutputExtension("");
3581  }
3582  }
3583  }
3584  }
ExprAst * m_templateExpr
Definition: template.cpp:3587
QCString outputDirectory() const
Definition: template.cpp:544
Abstract interface for a template.
Definition: template.h:542
bool isEmpty() const
Definition: qcstring.h:189
Internal class representing the implementation of a template.
Definition: template.cpp:2262
Internal class representing the implementation of a template context.
Definition: template.cpp:511
uint length() const
Definition: qcstring.h:195
#define IO_WriteOnly
Definition: qiodevice.h:62
Simplified and optimized version of QTextStream.
Definition: ftextstream.h:11
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition: qcstring.cpp:95
void render(FTextStream &ts, TemplateContext *c)
Definition: template.cpp:4809
void setOutputExtension(const char *extension)
Definition: template.cpp:4996
void setActiveEscapeIntf(TemplateEscapeIntf *intf)
Definition: template.cpp:534
TemplateEscapeIntf * escapeIntf() const
Definition: template.cpp:545
QCString toString() const
Definition: template.h:232
virtual TemplateVariant resolve(TemplateContext *)
Definition: template.cpp:1368
QCString right(uint len) const
Definition: qcstring.cpp:231
void unload(Template *t)
Definition: template.cpp:4976
QCString & prepend(const char *s)
Definition: qcstring.cpp:387
Interface used to escape characters in a string.
Definition: template.h:457
const char * data() const
Definition: qcstring.h:207
TemplateEngine * engine() const
Definition: template.cpp:2270
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
Template * loadByName(const QCString &fileName, int fromLine)
Definition: template.cpp:4971
static void stripLeadingWhiteSpace(QGString &s)
Definition: template.cpp:3459
void mkpath(TemplateContextImpl *ci, const QCString &fileName)
Definition: template.cpp:2684
void warn(const char *fileName, int line, const char *fmt,...) const
Definition: template.cpp:2431
void setLocation(const QCString &templateName, int line)
Definition: template.cpp:540
void selectEscapeIntf(const QCString &ext)
Definition: template.cpp:530
ExprAst * m_fileExpr
Definition: template.cpp:3588

Member Data Documentation

ExprAst* TemplateNodeCreate::m_fileExpr
private

Definition at line 3588 of file template.cpp.

ExprAst* TemplateNodeCreate::m_templateExpr
private

Definition at line 3587 of file template.cpp.


The documentation for this class was generated from the following file: