|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65360 - in trunk/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2010-09-08 20:11:36
Author: danieljames
Date: 2010-09-08 20:11:35 EDT (Wed, 08 Sep 2010)
New Revision: 65360
URL: http://svn.boost.org/trac/boost/changeset/65360
Log:
Fix a bug in nested template support.
Text files modified:
trunk/tools/quickbook/src/actions.cpp | 48 ++++++++++++++++++++-------------------
trunk/tools/quickbook/src/actions.hpp | 3 +
trunk/tools/quickbook/test/templates.gold | 43 +++++++++++++++++++++++++++++++++++
trunk/tools/quickbook/test/templates.quickbook | 22 ++++++++++++++++++
4 files changed, 92 insertions(+), 24 deletions(-)
Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp (original)
+++ trunk/tools/quickbook/src/actions.cpp 2010-09-08 20:11:35 EDT (Wed, 08 Sep 2010)
@@ -740,7 +740,6 @@
bool parse_template(
template_body const& body
, bool escape
- , std::string& result
, quickbook::actions& actions
)
{
@@ -755,7 +754,7 @@
{
// escape the body of the template
// we just copy out the literal body
- result = body.content;
+ (body.is_block ? actions.out : actions.phrase) << body.content;
return true;
}
else if (!body.is_block)
@@ -766,9 +765,7 @@
iterator first(body.content.begin(), body.content.end(),
position(body.position.file.c_str(), body.position.line, body.position.column));
iterator last(body.content.end(), body.content.end());
- bool r = call_parse(first, last, phrase_p).full;
- actions.phrase.swap(result);
- return r;
+ return call_parse(first, last, phrase_p).full;
}
else
{
@@ -782,10 +779,7 @@
iterator first(content.begin(), content.end(),
position(body.position.file.c_str(), body.position.line, body.position.column));
iterator last(content.end(), content.end());
- bool r = call_parse(first, last, block_p).full;
- actions.inside_paragraph();
- actions.out.swap(result);
- return r;
+ return call_parse(first, last, block_p).full;
}
}
}
@@ -833,8 +827,10 @@
template_symbol const* symbol = actions.templates.find(identifier);
BOOST_ASSERT(symbol);
-
- std::string result;
+
+ std::string block;
+ std::string phrase;
+
actions.push(); // scope the actions' states
{
// Store the current section level so that we can ensure that
@@ -910,7 +906,7 @@
///////////////////////////////////
// parse the template body:
- if (!parse_template(symbol->body, actions.template_escape, result, actions))
+ if (!parse_template(symbol->body, actions.template_escape, actions))
{
position const pos = first.get_position();
detail::outerr(pos.file,pos.line)
@@ -940,11 +936,15 @@
}
}
+ actions.write_paragraphs(); // Deal with any content in 'temp_para'
+ actions.out.swap(block);
+ actions.phrase.swap(phrase);
actions.pop(); // restore the actions' states
if(symbol->callout && symbol->callouts.size() > 0)
{
- result += "<calloutlist>";
+ BOOST_ASSERT(phrase.empty());
+ block += "<calloutlist>";
BOOST_FOREACH(template_body const& c, symbol->callouts)
{
std::string callout_id = actions.doc_id +
@@ -952,7 +952,8 @@
std::string callout_value;
actions.push();
- bool r = parse_template(c, false, callout_value, actions);
+ bool r = parse_template(c, false, actions);
+ actions.out.swap(callout_value);
actions.pop();
if(!r)
@@ -968,20 +969,21 @@
return;
}
- result += "<callout arearefs=\"" + callout_id + "co\" ";
- result += "id=\"" + callout_id + "\">";
- result += callout_value;
- result += "</callout>";
+ block += "<callout arearefs=\"" + callout_id + "co\" ";
+ block += "id=\"" + callout_id + "\">";
+ block += callout_value;
+ block += "</callout>";
}
- result += "</calloutlist>";
+ block += "</calloutlist>";
}
- if(symbol->body.is_block) {
+ if(symbol->body.is_block || !block.empty()) {
actions.inside_paragraph();
- actions.temp_para << result; // print it!!!
+ actions.temp_para << block;
+ actions.phrase << phrase;
}
else {
- actions.phrase << result; // print it!!!
+ actions.phrase << phrase;
}
--actions.template_depth;
}
@@ -1395,7 +1397,7 @@
out.raw = std::string(first, last);
}
- void copy_stream_action::operator()(iterator first, iterator last) const
+ void copy_stream_action::operator()() const
{
std::string str;
phrase.swap(str);
Modified: trunk/tools/quickbook/src/actions.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions.hpp (original)
+++ trunk/tools/quickbook/src/actions.hpp 2010-09-08 20:11:35 EDT (Wed, 08 Sep 2010)
@@ -858,7 +858,8 @@
copy_stream_action(collector& out, collector& phrase)
: out(out) , phrase(phrase) {}
- void operator()(iterator first, iterator last) const;
+ void operator()(iterator, iterator) const { (*this)(); }
+ void operator()() const;
collector& out;
collector& phrase;
Modified: trunk/tools/quickbook/test/templates.gold
==============================================================================
--- trunk/tools/quickbook/test/templates.gold (original)
+++ trunk/tools/quickbook/test/templates.gold 2010-09-08 20:11:35 EDT (Wed, 08 Sep 2010)
@@ -64,4 +64,47 @@
<section id="templates.empty_templates">
<title><link linkend="templates.empty_templates">Empty Templates</link></title>
</section>
+ <section id="templates.nested_templates">
+ <title><link linkend="templates.nested_templates">Nested Templates</link></title>
+ <para>
+ Start block template.
+ </para>
+ <para>
+ Start block template.
+ </para>
+ <para>
+ Hello!
+ </para>
+ <para>
+ End block template.
+ </para>
+ <para>
+ End block template.
+ </para>
+ <para>
+ Start block template.
+ </para>
+ <para>
+ Start phrase template. Hello! End phrase template.
+ </para>
+ <para>
+ End block template.
+ </para>
+ <para>
+ Start phrase template.
+ </para>
+ <para>
+ Start block template.
+ </para>
+ <para>
+ Hello!
+ </para>
+ <para>
+ End block template.
+ </para>
+ <para>
+ End phrase template. Start phrase template. Start phrase template. Hello! End
+ phrase template. End phrase template.
+ </para>
+ </section>
</article>
Modified: trunk/tools/quickbook/test/templates.quickbook
==============================================================================
--- trunk/tools/quickbook/test/templates.quickbook (original)
+++ trunk/tools/quickbook/test/templates.quickbook 2010-09-08 20:11:35 EDT (Wed, 08 Sep 2010)
@@ -143,4 +143,26 @@
[empty_arg1 1]
[empty_arg2 1 2]
+[endsect]
+
+[/----------------------------------- Nested templates ]
+
+[section Nested Templates]
+
+[template block[content]
+
+Start block template.
+
+[content]
+
+End block template.
+]
+
+[template phrase[content] Start phrase template. [content] End phrase template.]
+
+[block [block Hello!]]
+[block [phrase Hello!]]
+[phrase [block Hello!]]
+[phrase [phrase Hello!]]
+
[endsect]
\ No newline at end of file
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk