|
Last change
on this file since 75 was
28,
checked in by anonymous, 6 years ago
|
|
replace new value with index.html
|
|
File size:
921 bytes
|
| Rev | Line | |
|---|
| [28] | 1 | require 'erb' |
|---|
| 2 | require 'fileutils' |
|---|
| 3 | #options = {:noop => true } |
|---|
| 4 | #options = {} |
|---|
| 5 | options = {:verbose => true } |
|---|
| 6 | num_fname="tmp/num.txt" |
|---|
| 7 | template_fname="tmp/script-area.txt" |
|---|
| 8 | tmp_fname="tmp/tmp.txt" |
|---|
| 9 | to_fname="index.html" |
|---|
| 10 | |
|---|
| 11 | num = File.read(num_fname).to_i |
|---|
| 12 | #puts num |
|---|
| 13 | File.write(num_fname , num + 1) |
|---|
| 14 | |
|---|
| 15 | lines=File.readlines("index.html").map{|x| x.chomp!} |
|---|
| 16 | |
|---|
| 17 | parts = [[],[],[]] |
|---|
| 18 | index = 0 |
|---|
| 19 | first_delimitor = %r@<!-- AREA-START -->@ |
|---|
| 20 | second_delimitor = %r@<!-- AREA-END -->@ |
|---|
| 21 | |
|---|
| 22 | lines.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 | |
|---|
| 34 | content = File.read(template_fname) |
|---|
| 35 | erb = ERB.new(content) |
|---|
| 36 | new_content = erb.result_with_hash({num: num}) |
|---|
| 37 | parts[1] = [new_content] |
|---|
| 38 | |
|---|
| 39 | File.write( tmp_fname, parts.flatten.join("\n") ) |
|---|
| 40 | FileUtils.cp( tmp_fname , to_fname, options ) |
|---|
| 41 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.