forked from mtex-toolbox/makeDoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocFile.m
103 lines (84 loc) · 2.67 KB
/
DocFile.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
function file = DocFile(files,varargin)
% constructor
%
% Syntax
% files = DocFile(path) - recusively adds all files in sub--dirs
% files = DocFile({fname,fname,...}) - adds a given cell--array of full--fill names
% files = DocFile('function') - add a single function which is on search path
%
% See also
% getFiles
%
% Example
% doc = DocFile(fullfile(docHelpPath,'help','docGuide'))
%
if nargin < 1
error('I need at least one file or path!')
end
if ~iscell(files) && isfolder(files)
files = getFiles(files,'*.m',true);
end
file = struct(...
'sourceFile',reshape(files,1,[]),...
'sourceInfo',struct(...
'docName','',...
'isFunction',false,...
'Syntax','',...
'name','',...
'ext','',...
'path',''),...
'targetTemporary','');
%
% outputDir = fullfile(cd,'help','html');
% evalCode = false;
% for k=1:2:numel(varargin)
% switch lower(varargin{k})
% case 'outputdir'
% outputDir = varargin{k+1};
% case 'evalcode'
% evalCode = varargin{k+2};
% otherwise
% error(['unkown option: ' varargin{k}]);
% end
% end
% outputDir = get_option(varargin,'outputDir',fullfile(mtex_path,'help','html'));
for k=1:numel(file)
currentFile = file(k);
sourceInfo = currentFile.sourceInfo;
% if ~isempty(dir(currentFile.sourceFile))
[sourceInfo.path,sourceInfo.name,sourceInfo.ext] = fileparts(currentFile.sourceFile);
if isempty(sourceInfo.path)
currentFile.sourceFile = which(currentFile.sourceFile);
[sourceInfo.path,sourceInfo.name,sourceInfo.ext] = fileparts(currentFile.sourceFile);
end
switch sourceInfo.ext
case '.m'
[currentFile, sourceInfo] = setupmfileInfo(currentFile,sourceInfo);
otherwise
% target = fullfile(outputDir,sourceInfo.name);
currentFile.targetTemporary = [sourceInfo.name,sourceInfo.ext];
end
currentFile.sourceInfo = sourceInfo;
% currentFile.outputDir = outputDir;
file(k) = currentFile;
% end
end
file = class(file,'DocFile');
function [currentFile, sourceInfo] = setupmfileInfo(currentFile, sourceInfo)
pos = strfind(sourceInfo.path,'@');
if ~isempty(pos)
sourceInfo.docName = [sourceInfo.path(pos+1:end) '.' sourceInfo.name];
else
sourceInfo.docName = sourceInfo.name;
end
%
% target = fullfile(outputDir,sourceInfo.docName);
currentFile.targetTemporary = ['script_' regexprep(sourceInfo.docName,'\.','__'),sourceInfo.ext];
% currentFile.targetFile = [target,'.html'];
%
% % eval or not?
% [sourceInfo.isFunction,sourceInfo.Syntax] = isFunction(currentFile.sourceFile);
% if sourceInfo.isFunction
% currentFile.targetTemporary(end+1:end+3) = 'ref';
% end
%