OSDN Git Service

add seigas controller
authornomeu <nomeu@users.sourceforge.jp>
Sun, 3 Feb 2013 03:32:50 +0000 (12:32 +0900)
committernomeu <nomeu@users.sourceforge.jp>
Sun, 3 Feb 2013 03:32:50 +0000 (12:32 +0900)
app/controllers/seigas_controller.rb [new file with mode: 0644]
app/controllers/welcome_controller.rb
app/helpers/seigas_helper.rb [new file with mode: 0644]
app/models/seiga.rb
app/views/layouts/arcs.html.erb
app/views/seigas/index.html.erb [new file with mode: 0644]
app/views/seigas/show.html.erb [new file with mode: 0644]
app/views/welcome/index.html.erb
config/locales/translation_ja.yml
config/routes.rb

diff --git a/app/controllers/seigas_controller.rb b/app/controllers/seigas_controller.rb
new file mode 100644 (file)
index 0000000..4cb5888
--- /dev/null
@@ -0,0 +1,27 @@
+class SeigasController < ApplicationController
+  layout 'arcs'
+  before_filter :login_required, :only => [ :new, :edit, :create, :update, :destroy ]
+
+  # GET /seigas
+  # GET /seigas.xml
+  def index
+    @search = Seiga::Search.new(params[:search])
+    @seigas = Seiga.search(@search).paginate([ '_id' ], :size => 30, :page => params[:page])
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.xml  { render :xml => @seigas }
+    end
+  end
+
+  # GET /seigas/1
+  # GET /seigas/1.xml
+  def show
+    @seiga = Seiga.find(params[:id])
+
+    respond_to do |format|
+      format.html # show.html.erb
+      format.xml  { render :xml => @seiga }
+    end
+  end
+end
index 4369683..8997a40 100644 (file)
@@ -10,6 +10,7 @@ class WelcomeController < ApplicationController
       @vmds = Vmd.select { |rec| rec.updated_at > time }.paginate([ :key => 'updated_at', :order => :desc ], :size => 15)
       @xes = X.select { |rec| rec.updated_at > time }.paginate([ :key => 'updated_at', :order => :desc ], :size => 15)
       @thumbs = Thumb.select { |rec| rec.updated_at > time }.paginate([ :key => 'updated_at', :order => :desc ], :size => 15)
+      @seigas = Seiga.select { |rec| rec.updated_at > time }.paginate([ :key => 'updated_at', :order => :desc ], :size => 15)
     else
       @arc_search = Arc::Search.new(params[:search])
       @arcs = Arc.search(@arc_search).paginate([ 'site', '_key' ], :size => 15, :page => params[:page])
@@ -21,6 +22,8 @@ class WelcomeController < ApplicationController
       @xes = X.search(@x_search).paginate([ '_id' ], :size => 15, :page => params[:page])
       @thumb_search = Thumb::Search.new(params[:search])
       @thumbs = Thumb.search(@thumb_search).paginate([ '_id' ], :size => 15, :page => params[:page])
+      @seiga_search = Seiga::Search.new(params[:search])
+      @seigas = Seiga.search(@seiga_search).paginate([ '_id' ], :size => 15, :page => params[:page])
     end
   end
 
diff --git a/app/helpers/seigas_helper.rb b/app/helpers/seigas_helper.rb
new file mode 100644 (file)
index 0000000..1029d0b
--- /dev/null
@@ -0,0 +1,5 @@
+module SeigasHelper
+  def nico_seiga(image_id)
+    content_tag 'iframe', '', :src => "http://ext.seiga.nicovideo.jp/thumb/" + u(image_id), :width => 312, :height => 176, :scrolling => "no", :frameborder => 0
+  end
+end
index e099399..5812c70 100644 (file)
@@ -1,2 +1,27 @@
 class Seiga < ActiveGroonga::Base
+  def self.search(search)
+    if search.text.blank?
+      all
+    else
+      select { |rec|
+        rec.match(search.text) { |mat|
+          (mat.title * 1) | (mat.description * 1)
+        }
+      }
+    end
+  end
+
+  def image_id
+    key
+  end
+
+  class Search
+    attr_accessor :text
+
+    def initialize(attributes)
+      attributes.each do |name, value|
+        send("#{name}=", value)
+      end if attributes
+    end
+  end
 end
index 6644fb1..2f2f59f 100644 (file)
@@ -22,6 +22,7 @@
         <li><%= link_menu_to _("x"), xes_path %></li>
         <li><%= link_menu_to _("site"), sites_path %></li>
         <li><%= link_menu_to _("thumb"), thumbs_path %></li>
+        <li><%= link_menu_to _("seiga"), seigas_path %></li>
         <li><%= link_menu_to _("about"), welcome_about_path %></li>
       </ul>
     </div>
diff --git a/app/views/seigas/index.html.erb b/app/views/seigas/index.html.erb
new file mode 100644 (file)
index 0000000..538d707
--- /dev/null
@@ -0,0 +1,28 @@
+<%=form_for(@search, :as => :search, :url => seigas_path, :html => { :method => :get }) do |f| %>
+  <p>
+    <%= _'Seiga|Title' %> or <%= _'Seiga|Description' %><br />
+    <%= f.text_field :text %>
+    <%= f.submit t("search") %>
+  </p>
+<% end %>
+<table class="list seigas">
+  <thead>
+  <tr>
+    <th><%= _'Seiga|Image' %></th>
+    <th><%= _'Seiga|Title' %></th>
+    <th><%= _'Seiga|Description' %></th>
+  </tr>
+  </thead>
+
+  <tbody>
+<% @seigas.each do |seiga| %>
+  <tr class="<%= cycle('odd', 'even') %>">
+    <td><%=link_to seiga.image_id, seiga_path(seiga) %></td>
+    <td><%= seiga.title %></td>
+    <td><%= truncate(seiga.description) %></td>
+  </tr>
+<% end %>
+  </tbody>
+</table>
+
+<%= paginate(@seigas) %>
diff --git a/app/views/seigas/show.html.erb b/app/views/seigas/show.html.erb
new file mode 100644 (file)
index 0000000..6955401
--- /dev/null
@@ -0,0 +1,16 @@
+<p>
+  <b><%= _'Seiga|Image' %>:</b>
+  <%= @seiga.image_id %>
+</p>
+
+<p>
+  <b><%= _'Seiga|Title' %>:</b>
+  <%= @seiga.title %>
+</p>
+
+<p>
+  <b><%= _'Seiga|Description' %>:</b>
+  <%= @seiga.description %>
+</p>
+
+<%= nico_seiga(@seiga.image_id) %>
index 57878fc..05a3911 100644 (file)
   <%= link_to t('and_more'), thumbs_path(:search => params[:search]) %>
 </div>
 <%-end-%>
+
+<%-if @seigas.count != 0-%>
+<p>
+  <b><%= _'seiga' %>:</b>
+</p>
+<table class="list seigas">
+  <thead>
+  <tr>
+    <th><%= _'Seiga|Image' %></th>
+    <th><%= _'Seiga|Title' %></th>
+    <th><%= _'Seiga|Description' %></th>
+  </tr>
+  </thead>
+
+  <tbody>
+<% for seiga in @seigas %>
+  <tr class="<%= cycle('odd', 'even') %>">
+    <td><%=link_to seiga.image_id, seiga_path(seiga) %></td>
+    <td><%= seiga.title %></td>
+    <td><%= truncate(seiga.description) %></td>
+  </tr>
+<% end %>
+  </tbody>
+</table>
+<div class="pagination">
+  <%= link_to t('and_more'), seigas_path(:search => params[:search]) %>
+</div>
+<%-end-%>
index b0f5f3f..f79f6f7 100644 (file)
@@ -7,6 +7,7 @@ ja:
       site: "ロダ"
       pmd: "モデル"
       thumb: "動画"
+      seiga: "静画"
       user: "User"
       vmd: "モーション"
       x: "アクセサリ"
@@ -52,6 +53,11 @@ ja:
         arcs: Arcs
         arc_thumbs: "書庫動画関連"
 
+      seiga:
+        image: "No."
+        title: "タイトル"
+        description: "説明文"
+
       user:
         login: "ログイン"
         password: "パスワード"
index 83bf6a9..6aa5572 100644 (file)
@@ -6,6 +6,7 @@ Nimono::Application.routes.draw do
   resources :vmds, :only => :index
   resources :xes, :only => :index
   resources :thumbs, :only => [ :index, :show ]
+  resources :seigas, :only => [ :index, :show ]
   resource :session
   root :to => 'welcome#index'
   get 'welcome/about'