OSDN Git Service

t#31222:add feed
authoryasushiito <yas@pen-chan.jp>
Sat, 4 May 2013 00:36:55 +0000 (09:36 +0900)
committeryasushiito <yas@pen-chan.jp>
Sat, 4 May 2013 00:36:55 +0000 (09:36 +0900)
app/controllers/comics_controller.rb
app/models/comic.rb
app/views/comics/index.atom.builder [new file with mode: 0644]
app/views/comics/index.rss.builder [new file with mode: 0644]
app/views/comics/show.atom.builder [new file with mode: 0644]
app/views/comics/show.rss.builder [new file with mode: 0644]

index 0539fe5..e7a071d 100644 (file)
@@ -23,6 +23,8 @@ class ComicsController < ApplicationController
     respond_to do |format|
       format.html # index.html.erb
       format.json { render json: @comics.to_json(Comic.list_json_opt) }
+      format.atom 
+      format.rss
     end
   end
 
@@ -32,6 +34,8 @@ class ComicsController < ApplicationController
     respond_to do |format|
       format.html # show.html.erb
       format.json { render json: @comic.to_json(Comic.show_json_opt) }
+      format.atom 
+      format.rss 
     end
   end
 
index dd78a40..fe58760 100644 (file)
@@ -133,4 +133,16 @@ class Comic < ActiveRecord::Base
     res
   end
   
+  def scenario
+    panels.map {|panel|
+      panel.scenario
+    }.join
+  end
+  
+  def plain_scenario
+    panels.map {|panel|
+      panel.plain_scenario
+    }.join
+  end
+  
 end
diff --git a/app/views/comics/index.atom.builder b/app/views/comics/index.atom.builder
new file mode 100644 (file)
index 0000000..ddf8c87
--- /dev/null
@@ -0,0 +1,25 @@
+atom_feed(
+  :language => 'ja-JP',
+  :root_url => root_url,
+  :url => root_url(:format => :atom),
+  :id => root_url
+) do |feed|
+  feed.title MagicNumber['profile']['users']['caption']
+  feed.subtitle sanitize(MagicNumber['profile']['users']['description'], :tags => %w(a p img br))
+  feed.updated Time.now
+  feed.author {|author| author.name(MagicNumber['profile']['web_master'])}
+
+  @comics.each do |comic|
+    feed.entry(
+      comic,
+      :url => comic_url(comic),
+      :id => comic_url(comic),
+      :published => comic.updated_at,
+      :updated => comic.updated_at
+    ) do |item|
+      item.title(comic.title)
+      item.content(comic.title, :type => 'html')
+      item.author {|author| author.name(comic.author.name)}
+    end
+  end
+end
diff --git a/app/views/comics/index.rss.builder b/app/views/comics/index.rss.builder
new file mode 100644 (file)
index 0000000..abbf1c3
--- /dev/null
@@ -0,0 +1,24 @@
+xml.instruct!
+xml.rss("version"    => "2.0",
+        "xmlns:dc"   => "http://purl.org/dc/elements/1.1/",
+        "xmlns:atom" => "http://www.w3.org/2005/Atom") do
+  xml.channel do
+    xml.title       MagicNumber['profile']['users']['caption']
+    xml.link        root_url
+    xml.pubDate     Time.now.rfc822
+    xml.description sanitize(MagicNumber['profile']['users']['description'], :tags => %w(a p img br))
+    xml.atom :link, "href" => @rss_url, "rel" => "self", "type" => "application/rss+xml"
+    @comics.each do |comic|
+      xml.item do
+        xml.title        comic.title
+        xml.link         comic_url(comic)
+        xml.guid         comic_url(comic)
+        xml.description  comic.title
+        xml.pubDate      comic.updated_at.to_formatted_s(:rfc822)
+        xml.dc :creator, comic.author.name
+      end
+    end
+  end
+end
diff --git a/app/views/comics/show.atom.builder b/app/views/comics/show.atom.builder
new file mode 100644 (file)
index 0000000..6f5c967
--- /dev/null
@@ -0,0 +1,25 @@
+atom_feed(
+  :language => 'ja-JP',
+  :root_url => root_url,
+  :url => root_url(:format => :atom),
+  :id => root_url
+) do |feed|
+  feed.title MagicNumber['profile']['users']['caption']
+  feed.subtitle sanitize(MagicNumber['profile']['users']['description'], :tags => %w(a p img br))
+  feed.updated Time.now
+  feed.author {|author| author.name(MagicNumber['profile']['web_master'])}
+
+  @comic.stories.each do |story|
+    feed.entry(
+      story.panel,
+      :url => panel_url(story.panel),
+      :id => panel_url(story.panel),
+      :published => story.panel.updated_at,
+      :updated => story.panel.updated_at
+    ) do |item|
+      item.title(story.panel.caption)
+      item.content(story.panel.scenario, :type => 'html')
+      item.author {|author| author.name(story.panel.author.name)}
+    end
+  end
+end
diff --git a/app/views/comics/show.rss.builder b/app/views/comics/show.rss.builder
new file mode 100644 (file)
index 0000000..553f344
--- /dev/null
@@ -0,0 +1,24 @@
+xml.instruct!
+xml.rss("version"    => "2.0",
+        "xmlns:dc"   => "http://purl.org/dc/elements/1.1/",
+        "xmlns:atom" => "http://www.w3.org/2005/Atom") do
+  xml.channel do
+    xml.title       MagicNumber['profile']['users']['caption']
+    xml.link        root_url
+    xml.pubDate     Time.now.rfc822
+    xml.description sanitize(MagicNumber['profile']['users']['description'], :tags => %w(a p img br))
+    xml.atom :link, "href" => @rss_url, "rel" => "self", "type" => "application/rss+xml"
+  @comic.stories.each do |story|
+      xml.item do
+        xml.title        story.panel.caption
+        xml.link         panel_url(story.panel)
+        xml.guid         panel_url(story.panel)
+        xml.description  story.panel.plain_scenario
+        xml.pubDate      story.panel.updated_at.to_formatted_s(:rfc822)
+        xml.dc :creator, story.panel.author.name
+      end
+    end
+  end
+end