Class: TDiary::IO::Base

Inherits:
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.



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

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)


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

def cache_dir
	raise StandardError, 'not implemented'
end

#cache_pathObject



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

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

#calendarObject

Raises:

  • (StandardError)


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

def calendar
	raise StandardError, 'not implemented'
end

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



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

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

#load_stylesObject



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

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(/\/+$/, '').untaint
		Dir.glob("#{path}/*.rb") {|style_file| require style_file.untaint }
	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



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

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)


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

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