d: composite documents (.ssm), extract insert files list
[software/sisu] / lib / sisu / develop / utils_composite.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** system environment, debug related
8
9 ** Author: Ralph Amissah
10 <ralph@amissah.com>
11 <ralph.amissah@gmail.com>
12
13 ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
14 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
15 All Rights Reserved.
16
17 ** License: GPL 3 or later:
18
19 SiSU, a framework for document structuring, publishing and search
20
21 Copyright (C) Ralph Amissah
22
23 This program is free software: you can redistribute it and/or modify it
24 under the terms of the GNU General Public License as published by the Free
25 Software Foundation, either version 3 of the License, or (at your option)
26 any later version.
27
28 This program is distributed in the hope that it will be useful, but WITHOUT
29 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
31 more details.
32
33 You should have received a copy of the GNU General Public License along with
34 this program. If not, see <http://www.gnu.org/licenses/>.
35
36 If you have Internet connection, the latest version of the GPL should be
37 available at these locations:
38 <http://www.fsf.org/licensing/licenses/gpl.html>
39 <http://www.gnu.org/licenses/gpl.html>
40
41 <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
42
43 ** SiSU uses:
44 * Standard SiSU markup syntax,
45 * Standard SiSU meta-markup syntax, and the
46 * Standard SiSU object citation numbering and system
47
48 ** Hompages:
49 <http://www.jus.uio.no/sisu>
50 <http://www.sisudoc.org>
51
52 ** Git
53 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
54 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/develop/utils_composite.rb;hb=HEAD>
55
56 =end
57 module SiSU_Composite_Doc_Utils
58 def inserts_array(loadfilename)
59 IO.readlines(loadfilename,'')
60 end
61 def insert_filename?(para)
62 if para =~ /^<<\s+((?:https?|file):\/\/\S+?\.ss[it])$/ # and NetTest
63 url($1.strip)
64 elsif para =~/^<<\s*(\S+?\.ss[it])$/
65 $1.strip
66 end
67 end
68 def extract_filenames(loadfilename,file_names_arr)
69 file_names_arr << loadfilename
70 ssi_files=[]
71 if loadfilename =~/\S+?\.ss[im]$/
72 inserts_array(loadfilename).each do |para|
73 filen=insert_filename?(para)
74 file_names_arr << filen
75 if filen =~/\S+?\.ssi$/
76 ssi_files << filen
77 end
78 end
79 end
80 ssi_files.each do |fn|
81 extract_filenames(fn,file_names_arr)
82 end
83 file_names_arr.flatten.compact.uniq.sort
84 end
85 def composite_and_imported_filenames_array(loadfilename)
86 file_names_arr=[]
87 begin
88 if FileTest.file?(loadfilename)
89 if loadfilename =~/\S+?\.ss[itm]$/
90 if (@opt.act[:verbose][:set]==:on \
91 || @opt.act[:verbose_plus][:set]==:on \
92 || @opt.act[:maintenance][:set]==:on)
93 SiSU_Screen::Ansi.new(
94 @opt.act[:color_state][:set],
95 'loading:',
96 loadfilename,
97 ).txt_grey
98 end
99 file_names_arr=extract_filenames(loadfilename,file_names_arr)
100 end
101 end
102 if (@opt.act[:verbose_plus][:set]==:on \
103 || @opt.act[:maintenance][:set]==:on)
104 p file_names_arr ;p file_names_arr.length
105 end
106 file_names_arr
107 rescue
108 SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
109 __LINE__.to_s + ':' + __FILE__
110 end
111 ensure
112 end
113 end
114 end
115 __END__