1# doctoc.tcl --
2#
3#	Exporting indices into other formats.
4#
5# Copyright (c) 2009 Andreas Kupries <andreas_kupries@sourceforge.net>
6#
7# See the file "license.terms" for information on usage and redistribution
8# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9#
10# RCS: @(#) $Id: export.tcl,v 1.2 2009/11/15 05:50:03 andreas_kupries Exp $
11
12# Each object manages a set of plugins for the conversion of keyword
13# indices into some textual representation. I.e. this object manages
14# the conversion to specialized serializations of keyword indices.
15
16# ### ### ### ######### ######### #########
17## Requisites
18
19package require Tcl 8.4
20package require doctools::config
21package require doctools::toc::structure
22package require pluginmgr
23package require snit
24
25# ### ### ### ######### ######### #########
26## API
27
28snit::type ::doctools::toc::export {
29
30    # ### ### ### ######### ######### #########
31    ## Options :: None
32
33    # ### ### ### ######### ######### #########
34    ## Creation, destruction.
35
36    constructor {} {
37	install myconfig using ::doctools::config ${selfns}::config
38	return
39    }
40
41    destructor {
42	$myconfig destroy
43	# Clear the cache of loaded export plugins.
44	foreach k [array names myplugin] {
45	    $myplugin($k) destroy
46	}
47	return
48    }
49
50    # ### ### ### ######### ######### #########
51    ## Convert from the Tcl toc serialization to other formats.
52
53    method {export object} {obj {format {}}} {
54	return [$self export serial [$obj serialize] $format]
55    }
56
57    method {export serial} {serial {format {}}} {
58	doctools::toc::structure verify $serial iscanonical
59
60	set plugin [$self GetPlugin $format]
61
62	# We have a plugin, now feed it.
63
64	if {!$iscanonical} {
65	    set serial [doctools::toc::structure canonicalize $serial]
66	}
67
68	set     configuration [$myconfig get]
69	lappend configuration user   $::tcl_platform(user)
70	lappend configuraton  format [$plugin plugin]
71
72	return [$plugin do export $serial $configuration]
73    }
74
75    # ### ### ### ######### ######### #########
76    ## Internal methods
77
78    method GetPlugin {format} {
79	if {$format eq {}} { set format doctoc }
80
81	if {![info exists myplugin($format)]} {
82	    set plugin [pluginmgr ${selfns}::fmt-$format \
83			       -pattern doctools::toc::export::* \
84			       -api { export } \
85			       -setup [mymethod PluginSetup]]
86	    ::pluginmgr::paths $plugin doctools::toc::export
87	    $plugin load $format
88	    set myplugin($format) $plugin
89	} else {
90	    set plugin $myplugin($format)
91	}
92
93	return $plugin
94    }
95
96    method PluginSetup {mgr ip} {
97	# Inject a pseudo package into the plugin interpreter the
98	# formatters can use to check that they were loaded into a
99	# proper environment.
100	$ip eval {package provide doctools::toc::export::plugin 1}
101	return
102    }
103
104    # ### ### ### ######### ######### #########
105    ## State
106
107    # Array serving as a cache for the various plugin managers holding
108    # a specific export plugin.
109
110    variable myplugin -array {}
111
112    # A component managing the configuration given to the export
113    # plugins when they are invoked.
114
115    component myconfig -public config
116
117    ##
118    # ### ### ### ######### ######### #########
119}
120
121# ### ### ### ######### ######### #########
122## Ready
123
124package provide doctools::toc::export 0.1
125return
126