source: branches/testa/ex.rb @ 83

Last change on this file since 83 was 28, checked in by anonymous, 6 years ago

replace new value with index.html

File size: 921 bytes
Line 
1require 'erb'
2require 'fileutils'
3#options = {:noop => true }
4#options = {}
5options = {:verbose => true }
6num_fname="tmp/num.txt"
7template_fname="tmp/script-area.txt"
8tmp_fname="tmp/tmp.txt"
9to_fname="index.html"
10
11num = File.read(num_fname).to_i
12#puts num
13File.write(num_fname , num + 1)
14
15lines=File.readlines("index.html").map{|x| x.chomp!}
16
17parts = [[],[],[]]
18index = 0
19first_delimitor = %r@<!-- AREA-START -->@
20second_delimitor = %r@<!-- AREA-END -->@
21
22lines.map{ |x|
23       if x =~ first_delimitor
24         parts[ index ] << x
25         index += 1
26       elsif x =~ second_delimitor
27         index += 1
28         parts[ index ] << x
29       else
30         parts[ index ] << x
31       end
32}
33
34content = File.read(template_fname)
35erb = ERB.new(content)
36new_content = erb.result_with_hash({num: num})
37parts[1] = [new_content]
38
39File.write( tmp_fname,  parts.flatten.join("\n") )
40FileUtils.cp( tmp_fname , to_fname, options )
41
Note: See TracBrowser for help on using the repository browser.