1 class Speech < Peta::Content
3 include Peta::ElementPart
4 belongs_to :speech_balloon
5 belongs_to :writing_format
7 validates :speech_balloon_id, :numericality => {:allow_blank => true}
8 validates :writing_format_id, :presence => true, :numericality => true, :existence => {:both => false}
9 validates :font_size, :presence => true, :numericality => {:only_integer => false}
10 validates :text_align, :presence => true, :numericality => true, :inclusion => { :in => 0..3 }
11 validates :fore_color, :presence => true, :numericality => {:greater_than_or_equal_to => 0, :less_than => 0x1000000}
12 validates :x, :presence => true, :numericality => true
13 validates :y, :presence => true, :numericality => true
14 validates :width, :presence => true, :numericality => true, :natural_number => true
15 validates :height, :presence => true, :numericality => true, :natural_number => true
16 validates :quotes, :length => {:maximum => 15}, :quotes_even => true
17 validates :settings, :extend_speech => true
19 @@text_align_texts = ['left', 'left', 'right', 'center']
21 def self.colum_structures
22 @@colum_structures ||= {
24 :helper => 'panels/color_helper'
36 def visible? operators
37 return false unless super
38 self.owner_model.visible? operators
42 self.get_parent.speech_balloon_template.symbol_option
46 self.speech_balloon || @new_parent
49 def tag_element_part_type
54 @@text_align_texts[self.text_align]
62 'speeches.updated_at desc'
66 {:speech_balloon => {:panel => {:author => {}}, :balloon => {}, :speech_balloon_template => {}} }
69 def self.list_json_opt
70 {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech_balloon_template => {} }}}}
74 {:include => {:speech_balloon => {:panel => {:author => {}}, :balloon => {}, :speech_balloon_template => {} }}}
77 def self.show_json_opt
78 {:include => {:speech_balloon => {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech_balloon_template => {} }}}}
84 r.delete 'speech_balloon_id'
90 def self.panelize speech_attributes
91 {'speech_attributes' => speech_attributes}
94 def writing_format_engine_model
95 self.writing_format.engine_model
99 self.writing_format_engine_model.render self.content
107 ERB::Util.html_escape(self.content)