Module: Tidtools::Tiddler2texts

Defined in:
lib/tidtools/tiddler2texts.rb

Class Method Summary collapse

Class Method Details

.escape(src) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/tidtools/tiddler2texts.rb', line 17

def escape(src)
  r = src
  r.gsub!(/\//, "")
  r.gsub!(/:/, "")
  r.gsub!(/>/, "")
  r.gsub!(/"/, "")
  r
end

.output(filename, output_dir) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tidtools/tiddler2texts.rb', line 26

def output(filename, output_dir)
  filename = File.expand_path filename
  
  FileUtils.mkdir_p output_dir

  data = Tiddle.parse(filename)

  data.each do |tiddler|
    # OSX
    filename = output_dir + '/' + escape(tiddler.title)
    # win
    # filename = output_dir + '/' + escape(tiddler.title.kconv(Kconv::SJIS))

    next if (File.exist?(filename) and File.read(filename) == tiddler.content)
    
    open(filename, 'w') do |f|
      puts "#{filename}"
      f.write tiddler.content
    end
  end
end