Sha256: 6259d0c5701f259d8575b0f1af817399950f01e20db211c9ed638760c599adb0

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 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

8 entries across 8 versions & 1 rubygems

Version Path
dyndoc-ruby-1.4.5 bin/dyn-rebase-url
dyndoc-ruby-1.4.2 bin/dyn-rebase-url
dyndoc-ruby-1.4.1 bin/dyn-rebase-url
dyndoc-ruby-1.4.0 bin/dyn-rebase-url
dyndoc-ruby-1.3.9 bin/dyn-rebase-url
dyndoc-ruby-1.3.6 bin/dyn-rebase-url
dyndoc-ruby-1.3.4 bin/dyn-rebase-url
dyndoc-ruby-1.3.2 bin/dyn-rebase-url