class TiddlyWikiUtils
file: tiddlywikiutils.rb
Attributes
tiddlers[R]
Public Class Methods
new(filepath=nil, debug: false)
click to toggle source
# File lib/tiddlywikiutils.rb, line 10 def initialize(filepath=nil, debug: false) @debug = debug import_html(filepath) if filepath end
Public Instance Methods
add(title: '', tags: '', body: '', type: 'text/x-markdown')
click to toggle source
# File lib/tiddlywikiutils.rb, line 17 def add(title: '', tags: '', body: '', type: 'text/x-markdown') time = Time.now.strftime('%Y%M%d%H%M%S%3N') tiddler = "<div created='%s' modified='%s' tags='%s' title='%s' \ type='%s'>\n<pre>%s</pre>\n</div>" % \ [time, time, tags, title, type, body] id = @tiddlers.last[/(?<=created=")\d+/] pos = @s =~ /#{id}/ pos2 = @s[pos..-1] =~ /<\/div>/ puts [id, pos, pos2].inspect if @debug puts 'tiddler: ' + tiddler.inspect if @debug @s.insert((pos + pos2 + 6), tiddler) :added end
import_html(filepath)
click to toggle source
# File lib/tiddlywikiutils.rb, line 37 def import_html(filepath) @s = File.read filepath a = @s.split(/.*(?=<div created)/) a.shift a.reject! {|x| x =~ / title="\$/} @tiddlers = a[0..-2] @tiddlers << a.last.split(/<\/div>/,2).first end
to_html()
click to toggle source
# File lib/tiddlywikiutils.rb, line 48 def to_html() @s end