Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75352 - in branches/quickbook-dev/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2011-11-06 17:20:16


Author: danieljames
Date: 2011-11-06 17:20:14 EST (Sun, 06 Nov 2011)
New Revision: 75352
URL: http://svn.boost.org/trac/boost/changeset/75352

Log:
Quickbook: `xmlbase` docinfo attributes.

Useful for escaped `xi:include`.

(does this break horribly if it's given an absolute path?).
Added:
   branches/quickbook-dev/tools/quickbook/test/xmlbase-1_6.gold (contents, props changed)
   branches/quickbook-dev/tools/quickbook/test/xmlbase-1_6.quickbook (contents, props changed)
Text files modified:
   branches/quickbook-dev/tools/quickbook/src/actions.cpp | 39 ++++++++++++++++++---------------------
   branches/quickbook-dev/tools/quickbook/src/actions.hpp | 10 ++++++++++
   branches/quickbook-dev/tools/quickbook/src/actions_class.cpp | 2 ++
   branches/quickbook-dev/tools/quickbook/src/actions_state.hpp | 1 +
   branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp | 25 +++++++++++++++++++++++--
   branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp | 1 +
   branches/quickbook-dev/tools/quickbook/src/doc_info_tags.hpp | 1 +
   branches/quickbook-dev/tools/quickbook/test/Jamfile.v2 | 1 +
   8 files changed, 57 insertions(+), 23 deletions(-)

Modified: branches/quickbook-dev/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.cpp 2011-11-06 17:20:14 EST (Sun, 06 Nov 2011)
@@ -1711,9 +1711,10 @@
         return result;
     }
 
- std::string check_path(value const& path, quickbook::actions& actions)
+ fs::path check_path(value const& path, quickbook::actions& actions)
     {
- std::string path_text = path.get_quickbook();
+ std::string path_text = path.is_encoded() ? path.get_boostbook() :
+ path.get_quickbook();
 
         if(path_text.find('\\') != std::string::npos)
         {
@@ -1729,26 +1730,24 @@
         
         boost::replace(path_text, '\\', '/');
         
- return path_text;
+ return detail::generic_to_path(path_text);
     }
 
- fs::path calculate_relative_path(std::string const& name, quickbook::actions& actions)
+ xinclude_path calculate_xinclude_path(value const& p, quickbook::actions& actions)
     {
- // Given a source file and the current filename, calculate the
- // path to the source file relative to the output directory.
+ fs::path path = check_path(p, actions);
 
- fs::path path = detail::generic_to_path(name);
- if (path.has_root_directory())
+ // If the path is relative
+ if (!path.has_root_directory())
         {
- return path;
- }
- else
- {
- return path_difference(
- actions.xinclude_base,
- actions.current_file->path.parent_path() / path);
-
+ // Resolve the path from the current file
+ path = actions.current_file->path.parent_path() / path;
+
+ // Then calculate relative to the current xinclude_base.
+ path = path_difference(actions.xinclude_base, path);
         }
+
+ return xinclude_path(path, detail::escape_uri(detail::path_to_generic(path)));
     }
 
     void xinclude_action(quickbook::actions& actions, value xinclude)
@@ -1756,12 +1755,11 @@
         write_anchors(actions, actions.out);
 
         value_consumer values = xinclude;
- fs::path path = calculate_relative_path(
- check_path(values.consume(), actions), actions);
+ xinclude_path x = calculate_xinclude_path(values.consume(), actions);
         values.finish();
 
         actions.out << "\n<xi:include href=\"";
- detail::print_string(detail::escape_uri(path.generic_string()), actions.out.get());
+ detail::print_string(x.uri, actions.out.get());
         actions.out << "\" />\n";
     }
 
@@ -1776,11 +1774,10 @@
             fs::path filename_relative;
         };
 
- include_search_return include_search(std::string const & name,
+ include_search_return include_search(fs::path const& path,
                 quickbook::actions const& actions)
         {
             fs::path current = actions.current_file->path.parent_path();
- fs::path path = detail::generic_to_path(name);
 
             // If the path is relative, try and resolve it.
             if (!path.has_root_directory() && !path.has_root_name())

Modified: branches/quickbook-dev/tools/quickbook/src/actions.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.hpp 2011-11-06 17:20:14 EST (Sun, 06 Nov 2011)
@@ -61,6 +61,16 @@
         actions& escape_actions,
         std::string const& source_mode);
 
+ struct xinclude_path {
+ xinclude_path(fs::path& path, std::string const& uri) :
+ path(path), uri(uri) {}
+
+ fs::path path;
+ std::string uri;
+ };
+
+ xinclude_path calculate_xinclude_path(value const&, quickbook::actions&);
+
     struct error_message_action
     {
         // Prints an error message to std::cerr

Modified: branches/quickbook-dev/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_class.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_class.cpp 2011-11-06 17:20:14 EST (Sun, 06 Nov 2011)
@@ -97,6 +97,7 @@
         , doc_type(a.doc_type)
         , current_file(a.current_file)
         , filename_relative(a.filename_relative)
+ , xinclude_base(a.xinclude_base)
         , source_mode(a.source_mode)
         , macro()
     {
@@ -117,6 +118,7 @@
         boost::swap(a.doc_type, doc_type);
         boost::swap(a.current_file, current_file);
         boost::swap(a.filename_relative, filename_relative);
+ boost::swap(a.xinclude_base, xinclude_base);
         boost::swap(a.source_mode, source_mode);
         if (scope & scope_output) {
             a.out.pop();

Modified: branches/quickbook-dev/tools/quickbook/src/actions_state.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions_state.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions_state.hpp 2011-11-06 17:20:14 EST (Sun, 06 Nov 2011)
@@ -39,6 +39,7 @@
         std::string doc_type;
         file const* current_file;
         fs::path filename_relative;
+ fs::path xinclude_base;
         std::string source_mode;
         string_symbols macro;
     private:

Modified: branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/doc_info_actions.cpp 2011-11-06 17:20:14 EST (Sun, 06 Nov 2011)
@@ -113,6 +113,7 @@
         value license = consume_last_single(values, doc_info_attributes::license, &duplicates);
         std::vector<value> biblioids = consume_multiple(values, doc_info_attributes::biblioid);
         value compatibility_mode = consume_last(values, doc_info_attributes::compatibility_mode, &duplicates);
+ value xmlbase = consume_last_single(values, doc_info_attributes::xmlbase, &duplicates);
         
         // Skip over source-mode tags (already dealt with)
 
@@ -241,6 +242,18 @@
         assert(doc_title.check() && !actions.doc_type.empty() &&
             !start_file_info.doc_id.empty());
 
+ // Set xmlbase
+
+ std::string xmlbase_value;
+
+ if (!xmlbase.empty())
+ {
+ xinclude_path x = calculate_xinclude_path(xmlbase, actions);
+
+ xmlbase_value = x.uri;
+ actions.xinclude_base = x.path;
+ }
+
         // Warn about invalid fields
 
         if (actions.doc_type != "library")
@@ -330,8 +343,16 @@
             out << strdate;
         }
 
- out << "\" \n"
- << " xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n";
+ out << "\" \n";
+
+ if (!xmlbase.empty())
+ {
+ out << " xml:base=\""
+ << xmlbase_value
+ << "\"\n";
+ }
+
+ out << " xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n";
 
         std::ostringstream tmp;
 

Modified: branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/doc_info_grammar.cpp 2011-11-06 17:20:14 EST (Sun, 06 Nov 2011)
@@ -164,6 +164,7 @@
         local.attribute_rules[doc_info_attributes::category] = &local.doc_simple;
         local.attribute_rules[doc_info_attributes::last_revision] = &local.doc_simple;
         local.attribute_rules[doc_info_attributes::lang] = &local.doc_simple;
+ local.attribute_rules[doc_info_attributes::xmlbase] = &local.doc_simple;
 
         local.doc_copyright_holder
             = *( ~cl::eps_p

Modified: branches/quickbook-dev/tools/quickbook/src/doc_info_tags.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/doc_info_tags.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/doc_info_tags.hpp 2011-11-06 17:20:14 EST (Sun, 06 Nov 2011)
@@ -37,6 +37,7 @@
         ((biblioid)("biblioid"))
         ((source_mode)("source-mode"))
         ((compatibility_mode)("compatibility-mode"))
+ ((xmlbase)("xmlbase"))
     )
 }
 

Modified: branches/quickbook-dev/tools/quickbook/test/Jamfile.v2
==============================================================================
--- branches/quickbook-dev/tools/quickbook/test/Jamfile.v2 (original)
+++ branches/quickbook-dev/tools/quickbook/test/Jamfile.v2 2011-11-06 17:20:14 EST (Sun, 06 Nov 2011)
@@ -95,6 +95,7 @@
     [ quickbook-error-test version-1_7-fail ]
     [ quickbook-error-test version-2_0-fail ]
     [ quickbook-test xinclude-1_1 : : : <quickbook-xinclude-base>../src ]
+ [ quickbook-test xmlbase-1_6 : : : <quickbook-xinclude-base>../src ]
     [ quickbook-test xml_escape-1_2 ]
     [ quickbook-test xml_escape-1_5 ]
 

Added: branches/quickbook-dev/tools/quickbook/test/xmlbase-1_6.gold
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/xmlbase-1_6.gold 2011-11-06 17:20:14 EST (Sun, 06 Nov 2011)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE article PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
+<article id="xinclude_with_xmlbase" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+ xml:base="../test" xmlns:xi="http://www.w3.org/2001/XInclude">
+ <title>XInclude with xmlbase</title>
+ <xi:include href="stub.xml" />
+</article>

Added: branches/quickbook-dev/tools/quickbook/test/xmlbase-1_6.quickbook
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/xmlbase-1_6.quickbook 2011-11-06 17:20:14 EST (Sun, 06 Nov 2011)
@@ -0,0 +1,6 @@
+[article XInclude with xmlbase
+[quickbook 1.6]
+[xmlbase .]
+]
+
+[xinclude stub.xml]


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