My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 3618 of file template.cpp.

Constructor & Destructor Documentation

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

Definition at line 3621 of file template.cpp.

References m_fileExpr, m_templateExpr, TemplateNodeCreator< TemplateNodeCreate >::m_templateName, ExpressionParser::parse(), TRACE, and TemplateParser::warn().

{
TRACE(("TemplateNodeCreate(%s)\n",data.data()));
ExpressionParser ep(parser,line);
if (data.isEmpty())
{
parser->warn(m_templateName,line,"create tag is missing arguments");
}
int i = data.find(" from ");
if (i==-1)
{
if (data.right(3)==" from")
{
parser->warn(m_templateName,line,"create is missing template name after 'from' keyword");
}
else if (data=="from")
{
parser->warn(m_templateName,line,"create needs a file name and a template name");
}
else
{
parser->warn(m_templateName,line,"create is missing 'from' keyword");
}
}
else
{
ExpressionParser ep(parser,line);
m_fileExpr = ep.parse(data.left(i).stripWhiteSpace());
m_templateExpr = ep.parse(data.mid(i+6).stripWhiteSpace());
}
}
TemplateNodeCreate::~TemplateNodeCreate ( )
inline

Definition at line 3653 of file template.cpp.

References m_fileExpr, and m_templateExpr.

{
delete m_fileExpr;
}

Member Function Documentation

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

Implements TemplateNode.

Definition at line 3658 of file template.cpp.

References TemplateImpl::engine(), TemplateContextImpl::escapeIntf(), TemplateNodeCreator< TemplateNodeCreate >::getTemplate(), TemplateEngine::loadByName(), m_fileExpr, TemplateNodeCreator< TemplateNodeCreate >::m_line, m_templateExpr, TemplateNodeCreator< TemplateNodeCreate >::m_templateName, TemplateNodeCreator< TemplateNodeCreate >::mkpath(), TemplateContextImpl::outputDirectory(), TemplateImpl::render(), ExprAst::resolve(), TemplateContextImpl::selectEscapeIntf(), TemplateContextImpl::setActiveEscapeIntf(), TemplateContextImpl::setLocation(), TemplateEngine::setOutputExtension(), stripLeadingWhiteSpace(), TemplateVariant::toString(), TemplateEngine::unload(), and TemplateContextImpl::warn().

{
TemplateContextImpl* ci = dynamic_cast<TemplateContextImpl*>(c);
if (ci==0) return; // should not happen
{
QCString templateFile = m_templateExpr->resolve(c).toString();
QCString outputFile = m_fileExpr->resolve(c).toString();
if (templateFile.isEmpty())
{
ci->warn(m_templateName,m_line,"empty template name parameter for create command\n");
}
else if (outputFile.isEmpty())
{
ci->warn(m_templateName,m_line,"empty file name parameter for create command\n");
}
else
{
if (t)
{
QCString extension=outputFile;
int i=extension.findRev('.');
if (i!=-1)
{
extension=extension.right(extension.length()-i-1);
}
t->engine()->setOutputExtension(extension);
Template *ct = t->engine()->loadByName(templateFile,m_line);
TemplateImpl *createTemplate = ct ? dynamic_cast<TemplateImpl*>(ct) : 0;
if (createTemplate)
{
mkpath(ci,outputFile);
if (!ci->outputDirectory().isEmpty())
{
outputFile.prepend(ci->outputDirectory()+"/");
}
//printf("NoteCreate(%s)\n",outputFile.data());
QFile f(outputFile);
if (f.open(IO_WriteOnly))
{
TemplateEscapeIntf *escIntf = ci->escapeIntf();
ci->selectEscapeIntf(extension);
FTextStream ts(&f);
QGString out;
FTextStream os(&out);
createTemplate->render(os,c);
ts << out;
t->engine()->unload(t);
ci->setActiveEscapeIntf(escIntf);
}
else
{
ci->warn(m_templateName,m_line,"failed to open output file '%s' for create command",outputFile.data());
}
}
else
{
ci->warn(m_templateName,m_line,"failed to load template '%s' for include",templateFile.data());
}
}
}
}
}

Member Data Documentation

ExprAst* TemplateNodeCreate::m_fileExpr
private

Definition at line 3728 of file template.cpp.

Referenced by render(), TemplateNodeCreate(), and ~TemplateNodeCreate().

ExprAst* TemplateNodeCreate::m_templateExpr
private

Definition at line 3727 of file template.cpp.

Referenced by render(), TemplateNodeCreate(), and ~TemplateNodeCreate().


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