OSDN Git Service

左ペインの表示を実装
authorcake <cake@users.sourceforge.jp>
Sun, 26 Sep 2010 13:24:45 +0000 (22:24 +0900)
committercake <cake@users.sourceforge.jp>
Sun, 26 Sep 2010 13:24:45 +0000 (22:24 +0900)
app/helpers/songs_helper.rb
app/models/song.rb
app/views/songs/edit.html.erb
app/views/songs/show.html.erb
config/environment.rb
spec/models/song_spec.rb
spec/spec_helper.rb
spec/support/blueprints.rb [new file with mode: 0644]

index e3cdcfe..503e618 100644 (file)
@@ -27,7 +27,7 @@ module SongsHelper
     end.join " "
   end
 
-  def format_words(song)
-    song.ruby.gsub("\n"){ "<br />" }.gsub("^( )+"){ "&nbsp;" * $1.length }
+  def format_words(str)
+    str.gsub("\n"){ "<br />" }.gsub("^( )+"){ "&nbsp;" * $1.length }
   end
 end
index 54db88f..34118e1 100644 (file)
@@ -34,8 +34,12 @@ class Song < ActiveRecord::Base
     strip_ruby_base(words)
   end
 
+  def kanji
+    strip_ruby_text(words)
+  end
+
   def ruby
-    markup_html_ruby_tag(words)
+    markup_html_ruby_tag(ERB::Util.h words)
   end
 
   # 慈(いつく)しみ
@@ -45,7 +49,8 @@ class Song < ActiveRecord::Base
       to_s.
       gsub(RUBY_KANJI_HIRA)  { ruby_tag_template($1, $2) }.
       gsub(RUBY_ENGLISH_KANA){ ruby_tag_template($1, $2) }.
-      gsub(RUBY_KANA_HIRA)   { ruby_tag_template($1, $2) }
+      gsub(RUBY_KANA_HIRA)   { ruby_tag_template($1, $2) }.
+      yourself
   end
 
   def ruby_tag_template(base, text)
@@ -53,6 +58,16 @@ class Song < ActiveRecord::Base
   end
 
   def strip_ruby_base(str)
-    str.gsub(RUBY_KANJI_HIRA){ $2 }.gsub(RUBY_ENGLISH_KANA){ $2 }.gsub(RUBY_KANA_HIRA){ $2 }
+    str.gsub(RUBY_KANJI_HIRA){ $2 }.
+      gsub(RUBY_ENGLISH_KANA){ $2 }.
+      gsub(RUBY_KANA_HIRA){ $2 }.
+      yourself
+  end
+
+  def strip_ruby_text(str)
+    str.gsub(RUBY_KANJI_HIRA){ $1 }.
+      gsub(RUBY_ENGLISH_KANA){ $1 }.
+      gsub(RUBY_KANA_HIRA){ $1 }.
+      yourself
   end
 end
index 4a81626..4acd2d5 100644 (file)
@@ -18,6 +18,6 @@
 [<%= link_to_function "リセット", "reset()" %>]
 
 <hr />
-<div id="song_preview" style="font-size:18pt; width:20em;border:solid gray 1px">
-<%= format_words(@song) %>
+<div id="song_preview" style="font-size:18pt; width:20em; border:solid gray 1px">
+<%= format_words(@song.ruby) %>
 </div>
index c978687..ceda830 100644 (file)
@@ -8,7 +8,7 @@ Event.observe(window, 'load', function() {
 </script>
 <%- end -%>
 <div id="fixed"> 
- <pre id="smallWindow"><%= render :partial => 'fixed' %></pre>
+ <pre id="smallWindow"><%= format_words(@song.kanji) %></pre>
  <table id="panel">
  <tr>
    <th rowspan="2">文字の大きさの調整&nbsp;</th>
@@ -29,5 +29,5 @@ Event.observe(window, 'load', function() {
  </table>
 </div> 
 <div id="scroll"> 
- <pre id="song"><%= render :partial => 'scroll' %></pre>
+ <pre id="song"><%= format_words(@song.ruby) %></pre>
 </div>
index 93944c0..748ffbf 100644 (file)
@@ -40,3 +40,5 @@ Rails::Initializer.run do |config|
   # config.i18n.default_locale = :de
   config.i18n.default_locale = :ja
 end
+
+require 'object_ext'
index c7d4755..6294b5b 100644 (file)
@@ -10,5 +10,7 @@ describe Song do
 
   subject { @song }
 
-  its(:kana) {should == "いつくしみふかい ともなるイエスは"}
+  its(:kana) { should == "いつくしみふかい ともなるイエスは" }
+
+  its(:kanji) { should == "慈しみ深い 友なるイエスは" }
 end
index 1f72de0..c126e39 100644 (file)
@@ -19,6 +19,7 @@ Spec::Runner.configure do |config|
   config.use_transactional_fixtures = true
   config.use_instantiated_fixtures  = false
   config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
+  config.before(:each) { Machinist.reset_before_test }
 
   # == Fixtures
   #
diff --git a/spec/support/blueprints.rb b/spec/support/blueprints.rb
new file mode 100644 (file)
index 0000000..8278b82
--- /dev/null
@@ -0,0 +1,14 @@
+require 'machinist/active_record'
+
+Program.blueprint do
+  name { "a program" }
+  note { "a note about this program..." }
+  play_on { Date.today }
+end
+
+Song.blueprint do
+  code { "C" }
+  title { "a title of song" }
+  copyright { "blah blah blah, ..." }
+  font_size { 2 }
+end