Class: SiSU_Assemble::Composite
Instance Method Summary
collapse
#composite_and_imported_filenames_array, #extract_filenames, #insert_filename?, #inserts_array
Constructor Details
#initialize(opt) ⇒ Composite
Returns a new instance of Composite.
91
92
93
94
|
# File 'lib/sisu/ao_composite.rb', line 91
def initialize(opt)
@opt=opt
@env=SiSU_Env::InfoEnv.new
end
|
Instance Method Details
#download_images(download_from, images_array) ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/sisu/ao_composite.rb', line 184
def download_images(download_from,images_array)
path="#{@env.processing_path.processing}/external_document/image"
FileUtils::mkdir_p(path) unless FileTest.directory?(path)
images_array.each do |i|
image="#{path}/#{i}"
unless FileTest.exists?(image)
imagefile=File.new(image,'w+')
open("#{download_from}/#{i}") do |g|
imagefile << g.read
end
imagefile.close
end
end
end
|
#insert?(para) ⇒ Boolean
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/sisu/ao_composite.rb', line 118
def insert?(para)
if para =~ /^<<\s+((?:https?|file):\/\/\S+?\.ss[it])$/ url($1.strip)
elsif para =~/^<<\s+(\S+?\.ss[it])$/
loadfilename=$1.strip
insert_array=loadfile(loadfilename)
file=insertion(loadfilename,insert_array)
file[:prepared]
else para
end
end
|
#insertion(fni, insert_array) ⇒ Object
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'lib/sisu/ao_composite.rb', line 198
def insertion(fni,insert_array)
file={ prepared: [], images: [] }
rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/
file[:prepared] << "\n% |#{fni}|@|^|>>ok\n\n"
@code_flag=false
insert_array.each do |i|
@code_flag=if i =~/^code\{/ then true
elsif i =~/^\}code/ then false
else @code_flag
end
if not @code_flag \
and i !~/^%+\s/
i=i.
gsub(/^([123]|:?[ABCD])~\? /,
'% [conditional heading:] \1~ ') if i =~/^@\S+?:/
i=i.gsub(/\n/m,"\n% ").
gsub(/\n%\s+$/m,'').
gsub(/^@\S+?:/m,"\n% [imported header:] ") end
end
file[:prepared] << i
if i !~/^%+\s/ \
and i =~rgx_image
file[:images] << i.scan(rgx_image).uniq
end
end
file[:prepared] << "\n% end import" << "\n\n"
if file[:images].length > 0
file[:images]=file[:images].flatten.uniq
file[:images].delete_if {|x| x =~/https?:\/\// }
end
file
end
|
#loadfile(loadfilename) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/sisu/ao_composite.rb', line 129
def loadfile(loadfilename)
begin
if FileTest.file?(loadfilename)
insert_array=IO.readlines(loadfilename,'')
if loadfilename =~/\S+?\.ss[itm]$/
if (@opt.act[:verbose][:set]==:on \
|| @opt.act[:verbose_plus][:set]==:on \
|| @opt.act[:maintenance][:set]==:on)
SiSU_Screen::Ansi.new(
@opt.act[:color_state][:set],
'loading:',
loadfilename,
).txt_grey
end
tuned_file=if loadfilename =~/\S+?\.ss[im]$/
insert_array.each.map do |para|
insert?(para)
end
elsif loadfilename =~/\S+?\.sst$/
insert_array.each.map do |para|
para
end
end.flatten.compact
end
end
rescue
SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
__LINE__.to_s + ':' + __FILE__
end
ensure
end
end
|
#read ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/sisu/ao_composite.rb', line 95
def read
begin
pwd=Dir.pwd
Dir.chdir(@opt.f_pth[:pth])
if @opt.fno =~/\S+?\.ssm$/
SiSU_Screen::Ansi.new(
@opt.act[:color_state][:set],
'Composite Document',
"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}",
).grey_title_hi unless @opt.act[:quiet][:set]==:on
composite_and_imported_filenames_array(@opt.fno) assembled=loadfile(@opt.fno)
write(assembled)
end
Dir.chdir(pwd)
rescue
SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).
location do
__LINE__.to_s + ':' + __FILE__
end
ensure
end
end
|
#url(loadfilename) ⇒ Object
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/sisu/ao_composite.rb', line 161
def url(loadfilename)
if loadfilename =~ /((?:https?|file):\/\/\S+?\.ss[it])$/ loadfilename=$1
begin
require 'uri'
require 'open-uri'
require 'pp'
rescue LoadError
SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
error('uri, open-uri or pp NOT FOUND (LoadError)')
end
insert=open(loadfilename)
insert_array=insert.dup
insert.close
file=insertion(loadfilename,insert_array)
file[:prepared]
end
end
|
#write(assembled) ⇒ Object
179
180
181
182
183
|
# File 'lib/sisu/ao_composite.rb', line 179
def write(assembled)
assembled_file=File.new("#{@env.processing_path.composite_file}/#{@opt.fnb}.ssm.sst",'w+')
assembled.each {|a| assembled_file << a }
assembled_file.close
end
|