Class: Amy
Overview
Amy’s role in life is to map and build html pages
Defined Under Namespace
Classes: PageBuilder
Instance Method Summary
collapse
Methods inherited from Jeremy
#list_of_web_files, #webfile
Constructor Details
#initialize(working_directory) ⇒ Amy
Returns a new instance of Amy.
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/staticweb.rb', line 183
def initialize(working_directory)
if !File.exists?(working_directory) then raise MissingWorkingDirectory, "Folder containing required files doesn't seem to exist"
else @working_directory = working_directory end
@jeremy = Jeremy.new(@working_directory)
@isaac = Isaac.new(@working_directory)
@montgomery = Montgomery.new(@working_directory)
@jenny = Jenny.new(@working_directory)
@egbert = Egbert.new(@working_directory)
@samantha = Samantha.new(@working_directory)
end
|
Instance Method Details
#apply_config_to_template ⇒ Object
299
300
301
302
303
304
305
306
307
308
309
|
# File 'lib/staticweb.rb', line 299
def apply_config_to_template
list = []
apply_keywords_to_template.each_with_index do |template,i|
txt = template.html.clone
find_config_files_that_match_mapping[i].each do |config|
txt.gsub!(/\[#{config.config_setting_name}\]/, config.config_setting_value)
end
list << PageBuilder.new(template.file_name, template.file_path, txt)
end
return list
end
|
#apply_dynamic_to_template ⇒ Object
313
314
315
316
317
318
319
320
321
322
323
324
|
# File 'lib/staticweb.rb', line 313
def apply_dynamic_to_template
list = []
apply_config_to_template.each_with_index do |template,i|
txt = template.html.clone
@jenny.dynamicfile.each do |dynamic|
require dynamic.file_path
txt.gsub!(/\[#{dynamic.keyword_name}\]/, eval(dynamic.method_name))
end
list << PageBuilder.new(template.file_name, template.file_path, txt)
end
return list
end
|
#apply_keywords_to_template ⇒ Object
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
# File 'lib/staticweb.rb', line 282
def apply_keywords_to_template
make_keyword_file_if_web_exists_but_keyword_doesnt
list = []
find_template_files_that_match_mapping.each_with_index do |template,i|
txt = template.file_content.to_s.clone
find_keyword_files_that_match_mapping[i].each do |keyword|
txt.gsub!(/\[#{keyword.keyword_name}\]/, keyword.keyword_file_content.to_s)
end
list << PageBuilder.new(find_web_files_that_match_mapping[i].file_name, find_web_files_that_match_mapping[i].file_path, txt)
end
return list
end
|
#build_html ⇒ Object
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
# File 'lib/staticweb.rb', line 326
def build_html
if File.exists?("output") then @target_dir = "output"
else Dir.mkdir("output") ; @target_dir = "output" end
Dir.entries(@working_directory).each{|file| if file.match(".css") then
FileUtils.cp_r(@working_directory + "/" + file, @target_dir) end}
apply_dynamic_to_template.each_with_index do |file,i|
f = File.open(@target_dir + "/" + file.file_name.split(".")[0].to_s + ".html", "w")
f.puts file.html
f.close
end
end
|
#find_config_files_that_match_mapping ⇒ Object
203
204
205
206
207
208
209
210
211
|
# File 'lib/staticweb.rb', line 203
def find_config_files_that_match_mapping
list = []
@samantha.mappingfile.each do |mapping|
sub_list = []
@isaac.configfile.each{|config| if mapping.mapping_config == config.file_name then sub_list << config end}
list << sub_list
end
return list
end
|
#find_keyword_files_that_match_mapping ⇒ Object
257
258
259
260
261
262
263
264
265
|
# File 'lib/staticweb.rb', line 257
def find_keyword_files_that_match_mapping
list = []
@samantha.mappingfile.each do |mapping|
sub_list = []
@egbert.keywordfile.each{|keyword| if mapping.mapping_keyword == keyword.file_name then sub_list << keyword end}
list << sub_list
end
return list
end
|
#find_template_files_that_match_mapping ⇒ Object
213
214
215
216
217
218
219
220
221
|
# File 'lib/staticweb.rb', line 213
def find_template_files_that_match_mapping
list = []
@samantha.mappingfile.each do |mapping|
@montgomery.templatefile.each{|template| if mapping.mapping_template == template.file_name then list << template end}
end
return list
end
|
#find_web_files_that_match_mapping ⇒ Object
195
196
197
198
199
200
201
|
# File 'lib/staticweb.rb', line 195
def find_web_files_that_match_mapping
list = []
@samantha.mappingfile.each do |mapping|
@jeremy.webfile.each{|web| if web.file_name == mapping.mapping_web then list << web end}
end
return list
end
|
#make_keyword_file_if_web_exists_but_keyword_doesnt ⇒ Object
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
# File 'lib/staticweb.rb', line 223
def make_keyword_file_if_web_exists_but_keyword_doesnt
web_array = []
keyword_array = []
@jeremy.webfile.each{|web| web_array << web.file_name }
@egbert.keywordfile.each{|keyword| keyword_array << keyword.file_name}
keyword_array.uniq!
test_array = []
web_array.each{|web| test_array << web.split(".")[0].to_s + ".keyword"}
missing_keywords = test_array - keyword_array
unless missing_keywords.empty?
missing_keywords.each{|missing_keyword|
if !missing_keyword.empty?
puts "missing: #{missing_keyword}"
puts "Auto-creating #{missing_keyword}"
web_word = missing_keyword.to_s.split(".")[0].to_s + ".web"
data = <<-EOF
CONTENT:#{web_word}
EOF
f = File.open("src/#{missing_keyword}","w")
f.puts data
f.close
project_file = @samantha.mappingfile[0].file_name.to_s
puts "Adding entry to #{project_file}"
f = File.open("src/#{project_file}", "a")
f.puts "#{web_word}\t\tindex.template\t\tindex.config\t\t#{missing_keyword}"
f.close
end
}
end
end
|