OSDN Git Service

fix:new elm
[pettanr/pettanr.git] / app / models / speech.rb
1 class Speech < Peta::Element
2   load_manifest
3   belongs_to :speech_balloon
4   belongs_to :speech_balloon_template
5   belongs_to :writing_format
6   
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_module_name, :presence => true, :length => {:maximum => 50}
10   validates :writing_format_id, :presence => true, :numericality => true, :existence => {:both => false}
11   validates :writing_format_module_name, :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 => {:boost_name => :speech_balloon_template}
21   #validates :writing_format_settings
22   
23   @@text_align_texts = ['left', 'left', 'right', 'center']
24   
25   def y
26     self.attributes['y']
27   end
28   
29   def supply_default
30     self.x = 0
31     self.y = 0
32     self.width = 100
33     self.height = 100
34     self.fore_color = 0
35   end
36   
37   def symbol_option
38     self.speech_balloon.speech_balloon_template.symbol_option
39   end
40   
41   def outer_style
42     {
43       'top' => self.y, 'left' => self.x, 
44       'width' => self.width, 'height' => self.height
45     }
46   end
47   
48   def inner_style
49     {
50       'font-size' => self.font_size.to_s + 'em',
51       'text-align' => self.text_align_text, 
52       'color' => '#' + format("%06x", self.fore_color)
53     }
54   end
55   
56   def text_align_text
57     @@text_align_texts[self.text_align]
58   end
59   
60   def self.public_list_where list
61     'panels.publish > 0'
62   end
63   
64   def self.by_author_list_includes
65     {
66       :speech_balloon => {
67         :panel => {
68           :author => {}
69         }
70       }
71     }
72   end
73   
74   def self.show_opt
75     {:include => {:speech_balloon => {:panel => {:author => {}}, :balloon => {}, :speech_balloon_template => {} }}}
76   end
77   
78   def self.panelize speech_attributes
79     {'speech_attributes' => speech_attributes}
80   end
81   
82   def scenario
83     self.boosts 'read'
84     self.render
85   end
86   
87   def plain_scenario
88     self.content + "\n"
89   end
90   
91   def feed
92     ERB::Util.html_escape(self.content)
93   end
94   
95 end