1 class Speech < Peta::Element
3 belongs_to :speech_balloon
4 belongs_to :speech_balloon_template
5 belongs_to :writing_format
7 validates :speech_balloon_id, :numericality => {:allow_blank => true}
8 validates :speech_balloon_template_id, :presence => true, :numericality => true, :existence => {:both => false}
9 validates :speech_balloon_template_classname, :presence => true, :length => {:maximum => 50}
10 validates :writing_format_id, :presence => true, :numericality => true, :existence => {:both => false}
11 validates :writing_format_classname, :presence => true, :length => {:maximum => 50}
12 validates :font_size, :presence => true, :numericality => {:only_integer => false}
13 validates :text_align, :presence => true, :numericality => true, :inclusion => { :in => 0..3 }
14 validates :fore_color, :presence => true, :numericality => {:greater_than_or_equal_to => 0, :less_than => 0x1000000}
15 validates :x, :presence => true, :numericality => true
16 validates :y, :presence => true, :numericality => true
17 validates :width, :presence => true, :numericality => true, :natural_number => true
18 validates :height, :presence => true, :numericality => true, :natural_number => true
19 validates :quotes, :length => {:maximum => 15}, :quotes_even => true
20 validates :speech_balloon_template_settings, :boost => {:resource_name => :speech_balloon_template}
21 #validates :writing_format_settings
23 @@text_align_texts = ['left', 'left', 'right', 'center']
33 self.speech_balloon.speech_balloon_template.symbol_option
38 'top' => self.y, 'left' => self.x,
39 'width' => self.width, 'height' => self.height
45 'font-size' => self.font_size.to_s + 'em',
46 'text-align' => self.text_align_text,
47 'color' => '#' + format("%06x", self.fore_color)
52 @@text_align_texts[self.text_align]
55 def self.public_list_where
60 'speeches.updated_at desc'
63 def self.by_author_list_includes
74 {:speech_balloon => {:panel => {:author => {}}, :balloon => {}, :speech_balloon_template => {}} }
77 def self.list_json_opt
78 {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech_balloon_template => {} }}}}
82 {:include => {:speech_balloon => {:panel => {:author => {}}, :balloon => {}, :speech_balloon_template => {} }}}
85 def self.show_json_opt
86 {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech_balloon_template => {} }}}}
92 r.delete 'speech_balloon_id'
98 def self.panelize speech_attributes
99 {'speech_attributes' => speech_attributes}
102 def writing_format_engine_model
103 self.writing_format.engine_model
107 self.writing_format_engine_model.render self.content
115 ERB::Util.html_escape(self.content)