class Wikisys::Pages
Attributes
entries[RW]
mw[RW]
Public Class Methods
new(filepath='.', debug: false)
click to toggle source
# File lib/wikisys.rb, line 318 def initialize(filepath='.', debug: false) @filepath, @debug = filepath, debug entries_file = File.join(@filepath, 'entries.txt') if File.exists?(entries_file) then @entries = DxLite.new(entries_file) else @entries = DxLite.new('entries/entry(title, tags)') @entries.save entries_file end # check for the mindwords raw document file mindwords_file = File.join(@filepath, 'mindwords.txt') if File.exists?(mindwords_file) then @mw = MindWords.new(mindwords_file) else @mw = MindWords.new @mw.filepath = mindwords_file end @pg = Wiki.new @filepath, entries: @entries, debug: @debug #scan_md_files() end
Public Instance Methods
new_pg(filename)
click to toggle source
# File lib/wikisys.rb, line 347 def new_pg(filename) @pg.new_build(filename) @entries.save update_mw(@pg.title, @pg.tags) @mw.save if @mw.lines.any? build_html(filename) end
update_pg(filename)
click to toggle source
# File lib/wikisys.rb, line 359 def update_pg(filename) @pg.modify_build(filename) @entries.save update_mw(@pg.title, @pg.tags) @mw.save if @mw.lines.any? build_html(filename) end
Private Instance Methods
build_html(filename)
click to toggle source
# File lib/wikisys.rb, line 373 def build_html(filename) xml_file = filename.sub(/\.md$/,'.xml') filepath = File.join(@filepath, 'xml', xml_file) s = @pg.read_file filepath title = Rexle.new(s).root.text('heading') puts 'about to search title: ' + title.inspect if @debug found = @mw.search(title) if found then links = found.breadcrumb.map do |x| [x, x.gsub(/ +/,'-') + '.html'] end @pg.create_breadcrumb(filepath, links) end @pg.write_html xml_file end
scan_md_files()
click to toggle source
Check if any of the md files have been modified or newly created
# File lib/wikisys.rb, line 398 def scan_md_files() filepath = File.join(@filepath, 'md') puts 'about to scan ' + filepath.inspect if @debug dir = DirToXML.new(filepath, index: 'dir.json', debug: @debug) h = dir.activity puts 'h: ' + h.inspect if @debug return if (h[:new] + h[:modified]).empty? h[:new].each {|filename| new_pg(filename) } h[:modified].each {|filename| update_pg(filename) } @mw.save if @mw.lines.any? outline_filepath = File.join(@filepath, 'myoutline.txt') File.write outline_filepath, @mw.to_outline (h[:new] + h[:modified]).each do |filename| build_html filename end @entries.save end
update_mw(title, line_tags)
click to toggle source
# File lib/wikisys.rb, line 427 def update_mw(title, line_tags) # read the file tags = line_tags.reject {|x| x =~ /#{title.strip}/i} puts 'tags: ' + tags.inspect if @debug puts 'title: ' + title.inspect if @debug return if tags.empty? line = title + ' ' + tags.map {|x| "#" + x }.join(' ') + "\n" puts 'line: ' + line.inspect if @debug # does the tagsline contain the topic hashtag? #if tagsline =~ /#/ # not yet implemented # check if the title already exists found = @mw.lines.grep(/^#{title} +(?=#)/i) if found.any? then found_tags = found.first.scan(/(?<=#)\w+/) if @debug then puts 'tags: ' + tags.inspect puts 'found_tags: ' + found_tags.inspect end new_tags = tags - found_tags # add the new tags to the mindwords line hashtags = (found_tags + new_tags).map {|x| '#' + x }.join(' ') i = @mw.lines.index(found.first) @mw.lines[i] = line else @mw.lines << line end end
view_file(file='index.html')
click to toggle source
# File lib/wikisys.rb, line 478 def view_file(file='index.html') @hc.read(file) { File.read(file) } end