Method: TD2Planet::Formatter#initialize

Defined in:
lib/td2planet/formatter.rb

#initialize(config) ⇒ Formatter

Returns a new instance of Formatter.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/td2planet/formatter.rb', line 50

def initialize(config)
  @config = config
  @config['title'] ||= '(no title Planet)'
  @config['tdiary_theme_path'] ||= '/tdiary/theme'
  @config['tdiary_theme'] ||= 'default'
  @config['date_strftime_format'] ||= '%Y-%m-%d'
  @config['sanchor_strftime_format'] ||= '%H:%M:%S'
  @base_uri = URI.parse(@config['base_uri'])
  @config['templates_path'] ||= []
  @config['templates_path'].push(default_templates_dir)
  ERB_METHODS.each do |method_name, basename|
    @config['templates_path'].find do |dir|
      fname = File.expand_path(basename, dir)
      if File.exist?(fname)
        puts "use template #{basename}: #{fname}"
        erb = ERB.new(File.read(fname), nil, '-')
        eval("def self.#{method_name}\n#{erb.src}\nend\n", binding, fname, 0)
        true
      else
        false
      end
    end
  end
end