Class: TDiary::IO::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tdiary/io/base.rb

Direct Known Subclasses

Default

Instance Method Summary collapse

Constructor Details

#initialize(tdiary) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
# File 'lib/tdiary/io/base.rb', line 11

def initialize( tdiary )
  @tdiary = tdiary
  @data_path = @tdiary.conf.data_path if @tdiary.conf.data_path
  load_styles
end

Instance Method Details

#cache_dirObject

Raises:

  • (StandardError)


29
30
31
# File 'lib/tdiary/io/base.rb', line 29

def cache_dir
  raise StandardError, 'not implemented'
end

#cache_pathObject



33
34
35
36
37
# File 'lib/tdiary/io/base.rb', line 33

def cache_path
  @_cache_path ||= cache_dir
  FileUtils.mkdir_p(@_cache_path)
  @_cache_path
end

#calendarObject

Raises:

  • (StandardError)


17
18
19
# File 'lib/tdiary/io/base.rb', line 17

def calendar
  raise StandardError, 'not implemented'
end

#diary_factory(date, title, body, style_name = 'tDiary') ⇒ Object



25
26
27
# File 'lib/tdiary/io/base.rb', line 25

def diary_factory(date, title, body, style_name = 'tDiary')
  style(style_name.downcase).new(date, title, body)
end

#load_stylesObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/tdiary/io/base.rb', line 39

def load_styles
  @styles = {}
  paths = @tdiary.conf.options['style.path'] ||
    [TDiary::PATH, TDiary.server_root].map {|base| "#{base}/tdiary/style" }
  [paths].flatten.uniq.each do |path|
    path = path.sub(/\/+$/, '')
    Dir.glob("#{path}/*.rb") {|style_file| require style_file }
  end
  TDiary::Style.constants(false).each do |name|
    prefix = name.slice(/\A(.*)Diary\z/, 1)
    if prefix && /\A(Base|Categorizable|Uncategorizable)\z/ !~ prefix
      klass = TDiary::Style.const_get(name)
      klass.send(:include, TDiary::Style::BaseDiary)
      klass.send(:include, TDiary::Style::CategorizableDiary)
      section_class_name = "#{prefix}Section"
      if TDiary::Style.const_defined?(section_class_name)
        TDiary::Style.const_get(section_class_name).send(:include, TDiary::Style::BaseSection)
      end
      @styles[prefix.downcase] = klass
    end
  end
end

#style(s) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/tdiary/io/base.rb', line 62

def style(s)
  unless @styles
    raise BadStyleError, "styles are not loaded"
  end
  r = @styles[s.downcase]
  unless r
    raise BadStyleError, "bad style: #{s}"
  end
  r
end

#transaction(date) ⇒ Object

Raises:

  • (StandardError)


21
22
23
# File 'lib/tdiary/io/base.rb', line 21

def transaction(date)
  raise StandardError, 'not implemented'
end