Class: TDiary::IO::Base
- Inherits:
-
Object
- Object
- TDiary::IO::Base
- Defined in:
- lib/tdiary/io/base.rb
Direct Known Subclasses
Instance Method Summary collapse
- #cache_dir ⇒ Object
- #cache_path ⇒ Object
- #calendar ⇒ Object
- #diary_factory(date, title, body, style_name = 'tDiary') ⇒ Object
-
#initialize(tdiary) ⇒ Base
constructor
A new instance of Base.
- #load_styles ⇒ Object
- #style(s) ⇒ Object
- #transaction(date) ⇒ Object
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_dir ⇒ Object
29 30 31 |
# File 'lib/tdiary/io/base.rb', line 29 def cache_dir raise StandardError, 'not implemented' end |
#cache_path ⇒ Object
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 |
#calendar ⇒ Object
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_styles ⇒ Object
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.['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
21 22 23 |
# File 'lib/tdiary/io/base.rb', line 21 def transaction(date) raise StandardError, 'not implemented' end |