validates :y, :presence => true, :numericality => true
validates :width, :presence => true, :numericality => true, :natural_number => true
validates :height, :presence => true, :numericality => true, :natural_number => true
+ validates :quotes, :length => {:maximum => 15}, :quotes_even => true
# validates :settings, :presence => true
before_validation :valid_encode
def valid_encode
- ['content', 'settings'].each do |a|
+ ['content', 'quotes', 'settings'].each do |a|
next if attributes[a] == nil
raise Pettanr::BadRequest unless attributes[a].valid_encoding?
end
self.content + "\n"
end
+ def feed
+ ERB::Util.html_escape(self.content)
+ end
+
end
<div id="<%= @panel.tag_id -%>scenario" class="scenario" panel_id="<%= @panel.tag_panel_id -%>">
<% @panel.panel_elements.each do |elm| %>
<div panel_id="<%= elm.tag_panel_id -%>" element_id="<%= elm.tag_element_id -%>" element_type="<%= elm.tag_element_type -%>">
- <%= h elm.plain_scenario -%>
+ <% case elm.class.to_s %>
+ <% when 'PanelPicture' %>
+ <%= render 'panel_pictures/scenario', :panel_picture => elm %>
+ <% when 'SpeechBalloon' %>
+ <%= render elm.speech_balloon_template.engine_name + '/speech_balloons/scenario', :speech_balloon => elm %>
+ <% when 'GroundPicture' %>
+ <%= render 'ground_pictures/scenario', :ground_picture => elm %>
+ <% when 'GroundColor' %>
+ <%= render 'ground_colors/scenario', :ground_color => elm %>
+ <% end %>
</div>
<% end %>
</div>
resize: はサイズを変更できません。
reverse: は反転できません。
sync_vh: は縦横比を変更できません。
+ quotes_even: はカッコの開きと閉じを空白区切りのペアで入力してください。
template:
body: 次の項目を確認してください。
header:
--- /dev/null
+class AddQuotesOnSpeeches < ActiveRecord::Migration
+ def up
+ add_column :speeches, :quotes, :string, :limit => 15, :default => "' '"
+ end
+
+ def down
+ remove_column :speeches, :quotes
+ end
+end
--- /dev/null
+class QuotesEvenValidator < ActiveModel::EachValidator\r
+ def validate_each(record, attribute, value)\r
+ record.errors[attribute] << (options[:message] || I18n.t('activerecord.errors.messages.quotes_even')) if value.to_s.split(/ /).size.odd?\r
+ end\r
+end\r
+\r
@speech.y = 0\r
@speech.width = 1\r
@speech.height = 1\r
+ @speech.quotes = ''\r
@speech.should be_valid\r
end\r
it '上限データが通る' do\r
@speech.y = 99999\r
@speech.width = 99999\r
@speech.height = 99999\r
+ @speech.quotes = '[ ] [ ] [ ] [ ]'\r
@speech.should be_valid\r
end\r
end\r
@speech.should_not be_valid\r
end\r
end\r
+ context 'quotesを検証するとき' do\r
+ it '奇数なら失敗する' do\r
+ @speech.quotes = '[ ] ['\r
+ @speech.should_not be_valid\r
+ end\r
+ it '16文字以上なら失敗する' do\r
+ @speech.quotes = '[ ] [ ] [ ] [ ] [ ]'\r
+ @speech.should_not be_valid\r
+ end\r
+ end\r
context 'settingsを検証するとき' do\r
end\r
end\r
end\r
end\r
\r
+ context 'quotesを検証するとき' do\r
+ it 'Shift JISなら失敗する' do\r
+ @speech.quotes = "\x83G \x83r \x83 ]\x83D"\r
+ lambda{\r
+ @speech.valid_encode\r
+ }.should raise_error(Pettanr::BadRequest)\r
+ end\r
+ end\r
+ \r
context 'settingsを検証するとき' do\r
it 'Shift JISなら失敗する' do\r
@speech.settings = "\x83G\x83r\x83]\x83D"\r