Skip to content

Commit 6a0b276

Browse files
authored
Merge pull request #20 from yasslab/add-index-page
sotechsha でコンテンツ一覧を表示する
2 parents b13e424 + 164f3d6 commit 6a0b276

File tree

10 files changed

+86
-5
lines changed

10 files changed

+86
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class SoTechShaController < ApplicationController
22
def quiz
33
quiz = params[:quiz]
4-
redirect_to "/#{quiz}"
4+
redirect_to "/sotechsha-#{quiz}"
55
end
66
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class SoTechShaOverviewPageController < CmsController
2+
POSTS_PER_PAGE = 10
3+
4+
def index
5+
offset = params[:offset].to_i
6+
7+
sts_posts_query = BlogPostPage.where(:_permalink, :starts_with, 'sotechsha-').order(created: :asc)
8+
sts_posts_query.batch_size(POSTS_PER_PAGE).offset(offset)
9+
@sts_posts = sts_posts_query.take(POSTS_PER_PAGE)
10+
11+
total = sts_posts_query.size
12+
13+
if offset > 0
14+
@previous_page = scrivito_path(@obj, offset: offset - POSTS_PER_PAGE)
15+
end
16+
17+
if total > offset + POSTS_PER_PAGE
18+
@next_page = scrivito_path(@obj, offset: offset + POSTS_PER_PAGE)
19+
end
20+
end
21+
22+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class SoTechShaOverviewPage < Obj
2+
attribute :title, :string
3+
attribute :body, :widgetlist
4+
attribute :child_order, :referencelist
5+
end

app/views/blog_overview_page/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class ="row">
22
<div class="col-lg-12">
3-
<h1 class="page-header">Page Overview </h1>
3+
<h1 class="page-header">Page Overview</h1>
44
</div>
55
</div>
66
<% @blog_posts.each do |blog_post| %>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<%= scrivito_medium_dialog do %>
2+
<%= scrivito_details_for "Title" do %>
3+
<%= scrivito_tag :div, @obj, :title %>
4+
<% end %>
5+
<% end %>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<div class ="row">
2+
<div class="col-lg-12">
3+
<h1 class="page-header">「Scratchでつくる! たのしむ! プログラミング道場」Webコンテンツ</h1>
4+
</div>
5+
</div>
6+
<% @sts_posts.each do |sts_post| %>
7+
<div class="row">
8+
<div class="col-md-7">
9+
<%= scrivito_image_tag(scrivito_value(sts_post.image), :class => "img-responsive") %>
10+
</div>
11+
<div class="col-md-5">
12+
<h3><%= link_to(scrivito_value(sts_post.title), scrivito_path(sts_post)) %></h3>
13+
<%= content_tag(:p, scrivito_value(sts_post.abstract)) %>
14+
<%= link_to("もっと読む", scrivito_path(sts_post), :class => "btn btn-primary") %>
15+
</div>
16+
</div>
17+
<hr>
18+
<% end %>
19+
20+
<%= link_to("previous page", @previous_page) if @previous_page %>
21+
<%= link_to("next page", @next_page) if @next_page %>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= scrivito_thumbnail SoTechShaOverviewPage.description_for_editor, :content %>

config/routes.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
Rails.application.routes.draw do
22
# Accsess from CoderDojo Book
3+
get '/sotechsha', to: 'so_tech_sha_overview_page#index'
34
get '/sotechsha/:quiz', to: 'so_tech_sha#quiz'
45

56
# Default Scrivito routes. Adapt them to change the routing of CMS objects.
67
# See the documentation of 'scrivito_route' for a detailed description.
7-
scrivito_route '/', using: 'homepage'
8+
scrivito_route '/', using: 'homepage'
89
scrivito_route '(/)(*slug-):id', using: 'slug_id'
9-
scrivito_route '/*permalink', using: 'permalink', format: false
10+
scrivito_route '/*permalink', using: 'permalink', format: false
1011
end

test/integration/blog_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'test_helper'
2+
3+
class BlogTest < ActionDispatch::IntegrationTest
4+
def setup
5+
end
6+
7+
test "Bloglink should be rendered" do
8+
get "/blog"
9+
assert_template "blog_overview_page/index"
10+
assert_select "h1.page-header","Page Overview"
11+
end
12+
end

test/integration/so_tech_sha_test.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,21 @@ def setup
99
test "Quizzes should be redirected" do
1010
@quizzes.each do |num|
1111
get "/sotechsha/#{num}"
12-
assert_redirected_to "/#{num}"
12+
assert_redirected_to "/sotechsha-#{num}"
1313
end
1414
end
15+
16+
test "Gazoulink should be redirected" do
17+
get "/sotechsha/gazou"
18+
assert_redirected_to "/sotechsha-gazou"
19+
end
20+
21+
test "SoTechShalink should be rendered" do
22+
get "/sotechsha"
23+
assert_template "so_tech_sha_overview_page/index"
24+
assert_select "h1.page-header","「Scratchでつくる! たのしむ! プログラミング道場」Webコンテンツ"
25+
assert_select "a[href]", count:14
26+
# Error
27+
# assert_select "a[href=?]", /sotechsha-/ , count:14
28+
end
1529
end

0 commit comments

Comments
 (0)