3 class HatedaThema < ActiveRecord::Base
4 include ActionView::Helpers::TextHelper
5 include ActionView::Helpers::TagHelper
6 include ApplicationHelper
12 self.upload_at = Time.now if self.name
17 self.upload_at.strftime('%Y/%m/%d %H:%M:%S')
24 "[道徳経][テーマ]#{self.thema.caption}"
28 sections = Section.find(:all, :include => :thema_sections,
29 :conditions => ['thema_sections.thema_id = ?', self.thema.id]
31 ERB.new(open(RAILS_ROOT + '/lib/hateda_thema.rhtml').read.untaint, nil, '-').result(binding)
34 def self.upload(htn, ht)
35 if ht.name.to_s.empty?
36 entry = Atom::Entry.new(
37 :updated => Time.parse('2010/1/10') + (ht.thema.id - 1).day,
38 :title => ht.title(htn),
39 :content => ht.content(htn)
41 ht.name = htn.create(entry)
43 entry = htn.entry(ht.name)
44 entry.title = ht.title(htn)
45 entry.content = ht.content(htn)
46 htn.update(ht.name, entry)
52 def self.remove(htn, ht)
61 def self.upload_one(un, pass, thema_id)
62 htn = Hatena.new(un, pass)
63 thema = Thema.find(thema_id)
64 self.upload(htn, thema.hateda_thema)
67 def self.upload_modified(un, pass)
68 htn = Hatena.new(un, pass)
69 themas = Thema.find(:all, :include => [:hateda_thema],
70 :conditions => ['hateda_themas.name is null or hateda_themas.upload_at < themas.update_at']
72 themas.each do |thema|
73 self.upload(htn, thema.hateda_thema)
77 def self.remove_one(htn, thema_id)
78 thema = Thema.find(thema_id)
79 self.remove(htn, thema.hateda_thema)
82 def self.remove_all(un, pass)
83 htn = Hatena.new(un, pass)
84 themas = Thema.find(:all, :include => [:hateda_thema],
85 :conditions => ['hateda_themas.name is not null']
87 themas.each do |thema|
88 self.remove(htn, thema.hateda_thema)