Sha256: 3f84e290070c2b7085af376f747394afd914cf190206fc7f00d873affa455782

Contents?: true

Size: 882 Bytes

Versions: 1

Compression:

Stored size: 882 Bytes

Contents

#!/usr/bin/env ruby

# takes any wiki link that stands alone on a line and expands it
#
WIKI_LINK_PATTERN =  /^\s*(([a-z]+\.)?[A-Z][a-z]+[A-Z]\w*|\.[A-Z][a-z]+[A-Z]\w*)\s*$/

PROCESSED_FILES = []
def unfurl(file)
  PROCESSED_FILES << file
  lines = File.readlines(file)
  lines.shift 2
  lines = lines.join.strip.split("\n")
  lines.each do |line|
    if line =~ WIKI_LINK_PATTERN 
      link = line.strip
      if link =~ /^\./ # short link in namespace (relative link)
        namespace = file.split(".")[0]
        link = [namespace, link].join
      end
      if File.file?(link) && !PROCESSED_FILES.include?(link) 
        unfurl link # recursive
      elsif PROCESSED_FILES.include?(link) 
        puts "#{link} [already expanded]"
      else
        puts "#{link} [no file found]"
      end
    else
      puts line
    end
  end
end

ARGV.each do |file|
  unfurl(file)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
soywiki-0.0.1 bin/soywiki-unfurl