OSDN Git Service

t#31653:add scenario
authoryasushiito <yas@pen-chan.jp>
Wed, 10 Jul 2013 10:20:01 +0000 (19:20 +0900)
committeryasushiito <yas@pen-chan.jp>
Wed, 10 Jul 2013 10:20:01 +0000 (19:20 +0900)
app/models/speech.rb
app/views/panels/_form.html.erb
config/locales/ja.yml
db/migrate/20130709074533_add_quotes_on_speeches.rb [new file with mode: 0644]
lib/validators/quotes_even_validator.rb [new file with mode: 0644]
spec/models/speech_spec.rb

index 134c038..5c5cdcd 100644 (file)
@@ -6,12 +6,13 @@ class Speech < ActiveRecord::Base
   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
@@ -131,4 +132,8 @@ class Speech < ActiveRecord::Base
     self.content + "\n"
   end
   
+  def feed
+    ERB::Util.html_escape(self.content)
+  end
+  
 end
index 7b945e8..f99dd66 100644 (file)
     <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>
index 2a201d4..f61767f 100644 (file)
@@ -126,6 +126,7 @@ ja:
       resize: はサイズを変更できません。
       reverse: は反転できません。
       sync_vh: は縦横比を変更できません。
+      quotes_even: はカッコの開きと閉じを空白区切りのペアで入力してください。
     template:
       body: 次の項目を確認してください。
       header:
diff --git a/db/migrate/20130709074533_add_quotes_on_speeches.rb b/db/migrate/20130709074533_add_quotes_on_speeches.rb
new file mode 100644 (file)
index 0000000..f514507
--- /dev/null
@@ -0,0 +1,9 @@
+class AddQuotesOnSpeeches < ActiveRecord::Migration
+  def up
+    add_column :speeches, :quotes, :string, :limit => 15, :default => "' '"
+  end
+
+  def down
+    remove_column :speeches, :quotes
+  end
+end
diff --git a/lib/validators/quotes_even_validator.rb b/lib/validators/quotes_even_validator.rb
new file mode 100644 (file)
index 0000000..0c60d5f
--- /dev/null
@@ -0,0 +1,6 @@
+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
index 489a9a2..dfeb35b 100644 (file)
@@ -31,6 +31,7 @@ describe Speech do
         @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
@@ -38,6 +39,7 @@ describe Speech do
         @speech.y = 99999\r
         @speech.width = 99999\r
         @speech.height = 99999\r
+        @speech.quotes = '[ ] [ ] [ ] [ ]'\r
         @speech.should be_valid\r
       end\r
     end\r
@@ -127,6 +129,16 @@ describe Speech do
         @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
@@ -147,6 +159,15 @@ describe Speech do
       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