Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Parsing JSP files and adding a Line
donald dapp
3/20/2006 6:21:00 PM
Basically, I'm still pretty much freshmeat when it comes to Ruby, but
I'm intrigued by the language and wanted to start playing around w/ it
for the J2EE project that I'm on.
I wrote some Ruby Code that would find all the jsp's in our project
(around 200) and look for a XML-Tag and after this tag it would insert a
new line w/ another tag... Some basic scripting. But I doubt I'm doing
it the most efficient way.
Another problem I have is if within the original JSP file, a Tag carries
over onto the next line. I would ideally like to find a Xml-Tag and
insert another block after the end of it. What would be the best way of
doing so? Thanks.
Here's the relevant code:
def insertStr(fname, str, regexpr, isHeader)
notAdded = true
File.open(fname, 'r+') do |f| # open file for update
lines = f.readlines # read into array of lines
lines.each do |line| # modify lines
if notAdded
if line =~ regexpr # If the tag is found
if isHeader # insert include string
line << str + "\n"
else
line.replace(str + "\n" + line)
end
notAdded = false # make sure nothing else can be
inserted
end
end
end
f.pos = 0 # back to start
f.print lines # write out modified lines
f.truncate(f.pos) # truncate to new length
end # file is automatically closed
return !notAdded
end
--
Posted via
http://www.ruby-...
.
1 Answer
Guest
3/21/2006 3:35:00 PM
0
A Xml-Parser might be able to help?
donald dapp wrote:
> Another problem I have is if within the original JSP file, a Tag carries
> over onto the next line. I would ideally like to find a Xml-Tag and
> insert another block after the end of it. What would be the best way of
> doing so? Thanks.
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Parsing JSP files and adding a Line
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password