Sha256: 36b719e472a5d10521bd84fcf4d0275a3b8849cc92a93bda02e4dc2145341dc3

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

#!/usr/bin/env ruby

cur=0
opts={mode: :default, to: ""}

##p ARGV

while ["--dir","--mode","--from","--to","--help","--ext"].include? ARGV[cur]
  ##p [:cur,ARGV[cur]]
  case ARGV[cur]
  when "--dir","--help"
    opts[ARGV[cur].to_sym]=true
    cur += 1
  when "--mode"
    opts[:mode]==ARGV[cur+1].to_sym if ["default","href"].include? ARGV[cur+1]
    cur += 2
  when "--from","--to"
    opts[ARGV[cur][2..-1].to_sym]=ARGV[cur+1]
    cur += 2
  when "--ext"
    opts[ARGV[cur].to_sym]=ARGV[cur+1]
    cur += 2
  end
end

file=ARGV[cur]
opts[:help]=true unless file
if opts[:help]
  puts "rebase_url [--dir] [--from <from_path>] [--to <to_path>] [--ext <extension>] file"
else
  ext=opts[:ext] ? "."+opts[:ext]  : ""
  files=opts[:"--dir"] ? Dir[File.join(file,"*"+ext)] : [file]
  ##p files
  ##p opts
  files.each do |filename|
    content=File.read(filename)
    File.open(filename,"w") do |f|
      case opts[:mode]
      when :href
        f << content.gsub(/\ href="#{opts[:from]}/," href=\""+opts[:to])
      else
        f << content.gsub(/#{opts[:from]}/,opts[:to])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dyndoc-ruby-1.4.6 bin/dyn-rebase-url