Sha256: b93b75210e24e055bbf463b3e86c63a87a9b7460381ee3a80ac2c65a787ee74c
Contents?: true
Size: 1.56 KB
Versions: 3
Compression:
Stored size: 1.56 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-z]\w+\.)?[A-Z][a-z]+[A-Z]\w*\s*$/ PROCESSED_FILES = [] def indent(text, level, mode) return text if mode == 'seamless' return text if level == 0 (':' * level) + ' ' + text 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' puts '.' * 10 end expand(link.to_file_path, mode, level + 1) # recursive call if mode == 'seamful' puts '.' * 10 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
soywiki-0.2.2 | bin/soywiki-expand |
soywiki-0.2.1 | bin/soywiki-expand |
soywiki-0.2.0 | bin/soywiki-expand |