Class: WikiMindCardsDirectory

Inherits:
Object
  • Object
show all
Includes:
RXFReadWriteModule
Defined in:
lib/wikimindcards_directory.rb

Defined Under Namespace

Classes: Card, MindWordsX, PxLinks

Instance Method Summary collapse

Constructor Details

#initialize(dir: '.', dxpath: nil, debug: false) ⇒ WikiMindCardsDirectory

the directory being read should be the root directory of the project data store



258
259
260
261
262
263
264
265
266
267
268
# File 'lib/wikimindcards_directory.rb', line 258

def initialize(dir: '.', dxpath: nil, debug: false)

  @dir = dir
  @dxpath = dxpath
  @debug = debug

  # attempt to read the mindwords and outline (polyrex-links) files
  #
  read()

end

Instance Method Details

#edit(type = :mindwords, title = nil) ⇒ Object



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/wikimindcards_directory.rb', line 270

def edit(type=:mindwords, title=nil)

  case type
  when :link
    @pl.linkedit(title)
  when :mindwords
    @mw.edit()
  when :outline
    @pl.outlinefile_edit()
  when :tree
    @pl.tree_edit()
  when :card
    cardedit(title)
  end

end

#import_mindwords(s) ⇒ Object



287
288
289
290
291
292
# File 'lib/wikimindcards_directory.rb', line 287

def import_mindwords(s)

  @mw = MindWordsX.new(@dir, s)
  @pl = PxLinks.new(@dir, @mw.to_outline)

end

#read(path = '') ⇒ Object



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/wikimindcards_directory.rb', line 294

def read(path='')

  data_dir = File.join(@dir, *path.split('/'), 'data')

  # open the file if it exists
  mindwords_file = File.join(data_dir, 'mindwords.txt')

  if FileX.exists? mindwords_file then

    @mw = MindWordsX.new(@dir, mindwords_file)

    # create the activeoutline document if it doesn't already exist
    outline_txt = File.join(data_dir, 'outline.txt')
    @outline_xml = File.join(data_dir, 'outline.xml')

    if not FileX.exists? outline_txt then

      s = "<?polyrex-links?>\n\n" + @mw.to_outline
      FileX.write outline_txt, s

    end

    @pl = PxLinks.new(@dir, outline_txt)

  end

  self

end

#update(type, title = nil, s) ⇒ Object



324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/wikimindcards_directory.rb', line 324

def update(type, title=nil, s)

  case type
  when :mindwords
    mindwords_update(s)
  when :link
    @pl.linkupdate(title, s)
  when :card
    cardupdate(title, s)
  when :outline
    @pl = PxLinks.new @dir, s
  end

end

#view(type = :mindwords, title: nil, base_url: '') ⇒ Object

options: :mindwords, :tree, :link, :card



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/wikimindcards_directory.rb', line 341

def view(type=:mindwords, title: nil, base_url: '')

  puts 'inside view' if @debug
  case type
  when :mindwords
    @mw.to_s
  when :mindwords_tree
    @mw.to_outline
  when :tree
    @pl.treeview()
  when :index
    @pl.indexview(base_url)
  when :card
    cardview(title)
  end

end