Sha256: c6a91dad0642f228bd4d932db153c0924a07770c57e61bbf71960688cbada32f
Contents?: true
Size: 1.59 KB
Versions: 8
Compression:
Stored size: 1.59 KB
Contents
#!/usr/bin/env ruby require 'soywiki' # Takes any wiki link that stands alone on a line and expands it # this is different from Soywiki::WIKI_WORD in that it requires ^\s* before the # first letter WIKI_LINK_PATTERN = /^\s*([a-z0-9]\w+\.)?[A-Z][a-z]+[A-Z0-9]\w*\s*$/ PROCESSED_FILES = [] def indent(text, level, mode) return text if mode == 'seamless' return text if level == 0 ('|' * level) + ' ' + text end def divider puts '+' + '-' * 78 + '+' end def expand(file, mode, level=0) PROCESSED_FILES << file lines = File.readlines(file) if mode == 'seamless' lines.shift # strips title end lines = lines.join.strip.split("\n") lines.each do |line| # note that the wiki link must be alone on the line to be expanded if line =~ WIKI_LINK_PATTERN link = line.strip if link =~ /(\A|\s)[A-Z]/ # short link in namespace (relative link) namespace = file.namespace link = [namespace, link].join('.') end if File.file?(link.to_file_path) && !PROCESSED_FILES.include?(link.to_file_path) if mode == 'seamful' divider end expand(link.to_file_path, mode, level + 1) # recursive call if mode == 'seamful' divider end elsif PROCESSED_FILES.include?(link) puts indent("#{link} [[already expanded]]", level, mode) elsif !File.file?(link.to_file_path) puts indent("#{link} [[no file found]]", level, mode) else puts indent("#{link}", level, mode) end else puts indent(line, level, mode) end end end mode, file = *ARGV expand(file, mode)
Version data entries
8 entries across 8 versions & 1 rubygems