Sha256: 752c1e41300125c5efcfa4916d37e0e4ea87c9a5f73afd3c7b543c6ff59a2c7a
Contents?: true
Size: 1.38 KB
Versions: 3
Compression:
Stored size: 1.38 KB
Contents
#!/usr/bin/env ruby require 'soywiki' # Takes any wiki link that stands alone on a line and expands it WIKI_LINK_PATTERN = /^\s*(([a-z]\w+\.)?[A-Z][a-z]+[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 2 # 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 =~ /^\./ # 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) else puts indent("#{link} [[no file found]]", 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.0.4 | bin/soywiki-expand |
soywiki-0.0.3 | bin/soywiki-expand |
soywiki-0.0.2 | bin/soywiki-expand |