Skip to content

Commit 650597c

Browse files
committed
Resolved several issues relating to the object model for METAL templates:
--- * Resolved #514 - providing ZPT documents with a mechanism to specify a class that they should inherit from * * Created a new class: ZptMetadata * * * This describes the optional attributes that relate to a ZPT template document * * Wrote unit tests for all of this * * Improved an existing unit test to provider faster rendering of the test document * * Created a method by which 'foreign' types (types from other assemblies) may be registered as ZPT template document types * * Created a simple class to provide a heirarchical structure (like folders) for use with a TalesContext: TalesStructureProvider * * * This is also tested --- * Resolved #512 - creating an object model for METAL documents to refer to each other and their macros * * Created new child class of TalesStructureProvider: ZptDocumentCollection which includes a method to read a collection of ZPT documents from the filesystem. * * Created unit tests for this functionality * Created and tested implementation for loading other macros from a METAL document * The GetUseMacro() method of a MetalElement is working and tested
1 parent f8f0359 commit 650597c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3565
-371
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
bin/
2+
obj/
23
*.pidb
34
*.desktop
45
*.userprefs
56
TestResult.xml
67
.directory
8+
ZopePageTemplates.VisualState.xml

Parser/ITemplateDocument.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//
2+
// ITemplateDocument.cs
3+
//
4+
// Author:
5+
// Craig Fowler <[email protected]>
6+
//
7+
// Copyright (c) 2010 Craig Fowler
8+
//
9+
// This program is free software: you can redistribute it and/or modify
10+
// it under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 3 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// This program is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
using System;
22+
using CraigFowler.Web.ZPT.Tales;
23+
using CraigFowler.Web.ZPT.Tal;
24+
using System.Xml;
25+
namespace CraigFowler.Web.ZPT
26+
{
27+
/// <summary>
28+
/// <para>Interface describes a document template which may expose the TAL and/or METAL functionality.</para>
29+
/// </summary>
30+
public interface ITemplateDocument
31+
{
32+
/// <summary>
33+
/// <para>
34+
/// Gets and sets whether or not this document should force the reindentation and reformatting of the document on
35+
/// rendering. This property is only applicable if <see cref="XmlDocument.PreserveWhitespace"/> is false.
36+
/// </para>
37+
/// </summary>
38+
bool ReformatDocument { get; set; }
39+
40+
/// <summary>
41+
/// <para>Gets and sets the <see cref="TalesContext"/> for this document.</para>
42+
/// </summary>
43+
TalesContext TalesContext { get; set; }
44+
45+
/// <summary>
46+
/// <para>Overloaded. Renders this node and its children using the given <see cref="TalOutput"/> instance.</para>
47+
/// </summary>
48+
/// <param name="output">
49+
/// A <see cref="TalOutput"/>
50+
/// </param>
51+
void Render(TalOutput output);
52+
53+
/// <summary>
54+
/// <para>Overloaded. Renders the output of this document to the given <see cref="XmlWriter"/>.</para>
55+
/// </summary>
56+
/// <param name="writer">
57+
/// An <see cref="XmlWriter"/> to write the rendere output of this document to.
58+
/// </param>
59+
void Render(XmlWriter writer);
60+
61+
/// <summary>
62+
/// <para>Overloaded. Convenience method that renders the output of this document to a string.</para>
63+
/// </summary>
64+
/// <returns>
65+
/// A <see cref="System.String"/>, the rendered output document.
66+
/// </returns>
67+
string Render();
68+
69+
/// <summary>
70+
/// <para>Overloaded. Reads XML from a file at <paramref name="path"/> into this instance.</para>
71+
/// </summary>
72+
/// <param name="path">
73+
/// A <see cref="System.String"/>
74+
/// </param>
75+
void Load(string path);
76+
}
77+
}
78+

Parser/IZptDocument.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// IZptDocument.cs
3+
//
4+
// Author:
5+
// Craig Fowler <[email protected]>
6+
//
7+
// Copyright (c) 2010 Craig Fowler
8+
//
9+
// This program is free software: you can redistribute it and/or modify
10+
// it under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 3 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// This program is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
using System;
22+
using CraigFowler.Web.ZPT.Tal;
23+
using CraigFowler.Web.ZPT.Metal;
24+
using CraigFowler.Web.ZPT.Tales;
25+
using System.Collections.Generic;
26+
27+
namespace CraigFowler.Web.ZPT
28+
{
29+
/// <summary>
30+
/// <para>Interface describes a Zope Page Templates document.</para>
31+
/// <seealso cref="ZptMetadata.DocumentClass"/>
32+
/// </summary>
33+
public interface IZptDocument
34+
{
35+
/// <summary>
36+
/// <para>Gets and sets the document metadata for this ZPT document.</para>
37+
/// </summary>
38+
ZptMetadata Metadata { get; set; }
39+
40+
/// <summary>
41+
/// <para>
42+
/// Read-only. Gets whether this ZPT document has macro-expansions (METAL) enabled or not. If this property is
43+
/// false then the underlying document will be a <see cref="TalDocument"/> instead of a
44+
/// <see cref="MetalDocument"/>.
45+
/// </para>
46+
/// </summary>
47+
bool MetalEnabled { get; }
48+
49+
/// <summary>
50+
/// <para>Gets the XML template document that is associated with this instance.</para>
51+
/// </summary>
52+
/// <returns>
53+
/// An object instance that implements <see cref="ITemplateDocument"/>.
54+
/// </returns>
55+
ITemplateDocument GetTemplateDocument();
56+
57+
/// <summary>
58+
/// <para>Gets a collection of the <see cref="MetalMacro"/> instances that this instance contains.</para>
59+
/// </summary>
60+
/// <returns>
61+
/// A dictionary of <see cref="MetalMacro"/>, indexed by <see cref="System.String"/>
62+
/// </returns>
63+
[TalesAlias("macros")]
64+
MetalMacroCollection GetMacros();
65+
}
66+
}
67+
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//
2+
// MetalException.cs
3+
//
4+
// Author:
5+
// Craig Fowler <[email protected]>
6+
//
7+
// Copyright (c) 2011 Craig Fowler
8+
//
9+
// This program is free software: you can redistribute it and/or modify
10+
// it under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 3 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// This program is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
using System;
22+
namespace CraigFowler.Web.ZPT.Metal.Exceptions
23+
{
24+
/// <summary>
25+
/// <para>
26+
/// Represents an <see cref="Exception"/> that is raised in relation to handling of METAL macros.
27+
/// </para>
28+
/// </summary>
29+
public class MetalException : Exception
30+
{
31+
#region constants
32+
33+
private const string DEFAULT_MESSAGE = "There was an error relating to a METAL document or element";
34+
35+
#endregion
36+
37+
#region properties
38+
39+
/// <summary>
40+
/// <para>
41+
/// Gets and sets a value that indicates whether this exception indicates a permanent error in parsing the
42+
/// expression.
43+
/// </para>
44+
/// <para>
45+
/// In a permanent error, changing the values within the domain model will not help resolving the error.
46+
/// </para>
47+
/// </summary>
48+
public bool PermanentError
49+
{
50+
get;
51+
protected set;
52+
}
53+
54+
#endregion
55+
56+
#region constructors
57+
58+
/// <summary>
59+
/// <para>Initialises this instance with default values.</para>
60+
/// </summary>
61+
public MetalException() : this(DEFAULT_MESSAGE, null) {}
62+
63+
/// <summary>
64+
/// <para>Initialises this instance with an exception message.</para>
65+
/// </summary>
66+
/// <param name="message">
67+
/// A <see cref="System.String"/>
68+
/// </param>
69+
public MetalException(string message) : this(message, null) {}
70+
71+
/// <summary>
72+
/// <para>Initialises this instance with an inner exception.</para>
73+
/// </summary>
74+
/// <param name="inner">
75+
/// A <see cref="Exception"/>
76+
/// </param>
77+
public MetalException(Exception inner) : this(DEFAULT_MESSAGE, inner) {}
78+
79+
/// <summary>
80+
/// <para>Initialises this instance with an exception message and an inner exception.</para>
81+
/// </summary>
82+
/// <param name="message">
83+
/// A <see cref="System.String"/>
84+
/// </param>
85+
/// <param name="inner">
86+
/// A <see cref="Exception"/>
87+
/// </param>
88+
public MetalException(string message, Exception inner) : base(message, inner)
89+
{
90+
this.PermanentError = true;
91+
}
92+
93+
#endregion
94+
}
95+
}
96+

Parser/Metal/IMetalDocument.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// IMetalDocument.cs
3+
//
4+
// Author:
5+
// Craig Fowler <[email protected]>
6+
//
7+
// Copyright (c) 2011 Craig Fowler
8+
//
9+
// This program is free software: you can redistribute it and/or modify
10+
// it under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 3 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// This program is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
using System;
22+
using System.Collections.Generic;
23+
24+
namespace CraigFowler.Web.ZPT.Metal
25+
{
26+
/// <summary>
27+
/// <para>Marker interface for a <see cref="ITemplateDocument"/> that is METAL-capable.</para>
28+
/// </summary>
29+
public interface IMetalDocument : ITemplateDocument
30+
{
31+
/// <summary>
32+
/// <para>
33+
/// Read-only. Gets a collection of the <see cref="MetalMacro"/>s that are defined within this document.
34+
/// </para>
35+
/// </summary>
36+
MetalMacroCollection Macros { get; }
37+
}
38+
}
39+

0 commit comments

Comments
 (0)