class MyOutline
Attributes
md[RW]
outline[R]
Public Class Methods
new(source, debug: false, allsorted: true, autoupdate: true, topic_url: '$topic', md_path: '.', default_md: 'main.md')
click to toggle source
# File lib/myoutline.rb, line 124 def initialize(source, debug: false, allsorted: true, autoupdate: true, topic_url: '$topic', md_path: '.', default_md: 'main.md') @debug, @topic_url = debug, topic_url @md_path = md_path @default_md = default_md @allsorted, @autoupdate = allsorted, autoupdate @outline = Outline.new(source, debug: debug, allsorted: allsorted, autoupdate: autoupdate) end
Public Instance Methods
fetch(uri)
click to toggle source
# File lib/myoutline.rb, line 137 def fetch(uri) s, remaining = @outline.locate(uri) puts 'fetch() s: ' + s.inspect if @debug redirect = s =~ /^\[r\] +/i return s if redirect s ||= @default_md; remaining ||= '' f = File.join(@md_path, s) puts 'f: ' + f.inspect if @debug @md = MdEdit.new f, debug: @debug r = edit(remaining.sub(/^\//,'').gsub(/\//,' > ')) puts 'fetch() r: ' + r.inspect if @debug @md.update r r end
rebuild(s)
click to toggle source
# File lib/myoutline.rb, line 156 def rebuild(s) @outline = Outline.new s end
to_html()
click to toggle source
# File lib/myoutline.rb, line 189 def to_html() @outline.build_html do |e| e.attributes[:href] = @topic_url.sub(/\$topic/, e.text)\ .sub(/\$id/, e.attributes[:id]).sub(/\$trail/, e.attributes[:trail])\ .to_s.gsub(/ +/,'-') end end
to_s()
click to toggle source
# File lib/myoutline.rb, line 201 def to_s() @outline end
update(section)
click to toggle source
# File lib/myoutline.rb, line 160 def update(section) @md.update section end
update_tree(s)
click to toggle source
# File lib/myoutline.rb, line 164 def update_tree(s) mo2 = Outline.new(s, debug: @debug, allsorted: @allsorted, autoupdate: @autoupdate) h = @outline.links.to_h links = mo2.links mo2.links.to_h.each do |title, file| if @debug then puts 'title: ' + title.inspect puts 'h[title]: ' + h[title].inspect end links.link(title).url = h[title] if h[title] end puts 'before Outline.new: ' + links.to_s(header: false).inspect if @debug @outline = Outline.new(links.to_s(header: false), debug: @debug, allsorted: @allsorted, autoupdate: @autoupdate) @outline.autosave end
Private Instance Methods
edit(s)
click to toggle source
# File lib/myoutline.rb, line 208 def edit(s) r = @md.find s return r if r a = s.split(/ *> */) if a.length > 1 then heading = a.pop.capitalize r2 = edit(a.join(' > ')) n = r2.scan(/^#+/).last.length r2 + ("\n%s %s\n" % [('#' * (n+1)), heading]) end end