Skip to content

sotechsha でコンテンツ一覧を表示する #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/so_tech_sha_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class SoTechShaController < ApplicationController
def quiz
quiz = params[:quiz]
redirect_to "/#{quiz}"
redirect_to "/sotechsha-#{quiz}"
end
end
22 changes: 22 additions & 0 deletions app/controllers/so_tech_sha_overview_page_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class SoTechShaOverviewPageController < CmsController
POSTS_PER_PAGE = 10

def index
offset = params[:offset].to_i

sts_posts_query = BlogPostPage.where(:_permalink, :starts_with, 'sotechsha-').order(created: :asc)
sts_posts_query.batch_size(POSTS_PER_PAGE).offset(offset)
@sts_posts = sts_posts_query.take(POSTS_PER_PAGE)

total = sts_posts_query.size

if offset > 0
@previous_page = scrivito_path(@obj, offset: offset - POSTS_PER_PAGE)
end

if total > offset + POSTS_PER_PAGE
@next_page = scrivito_path(@obj, offset: offset + POSTS_PER_PAGE)
end
end

end
5 changes: 5 additions & 0 deletions app/models/so_tech_sha_overview_page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class SoTechShaOverviewPage < Obj
attribute :title, :string
attribute :body, :widgetlist
attribute :child_order, :referencelist
end
2 changes: 1 addition & 1 deletion app/views/blog_overview_page/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class ="row">
<div class="col-lg-12">
<h1 class="page-header">Page Overview </h1>
<h1 class="page-header">Page Overview</h1>
</div>
</div>
<% @blog_posts.each do |blog_post| %>
Expand Down
5 changes: 5 additions & 0 deletions app/views/so_tech_sha_overview_page/details.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= scrivito_medium_dialog do %>
<%= scrivito_details_for "Title" do %>
<%= scrivito_tag :div, @obj, :title %>
<% end %>
<% end %>
21 changes: 21 additions & 0 deletions app/views/so_tech_sha_overview_page/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class ="row">
<div class="col-lg-12">
<h1 class="page-header">「Scratchでつくる! たのしむ! プログラミング道場」Webコンテンツ</h1>
</div>
</div>
<% @sts_posts.each do |sts_post| %>
<div class="row">
<div class="col-md-7">
<%= scrivito_image_tag(scrivito_value(sts_post.image), :class => "img-responsive") %>
</div>
<div class="col-md-5">
<h3><%= link_to(scrivito_value(sts_post.title), scrivito_path(sts_post)) %></h3>
<%= content_tag(:p, scrivito_value(sts_post.abstract)) %>
<%= link_to("もっと読む", scrivito_path(sts_post), :class => "btn btn-primary") %>
</div>
</div>
<hr>
<% end %>

<%= link_to("previous page", @previous_page) if @previous_page %>
<%= link_to("next page", @next_page) if @next_page %>
1 change: 1 addition & 0 deletions app/views/so_tech_sha_overview_page/thumbnail.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= scrivito_thumbnail SoTechShaOverviewPage.description_for_editor, :content %>
5 changes: 3 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Rails.application.routes.draw do
# Accsess from CoderDojo Book
get '/sotechsha', to: 'so_tech_sha_overview_page#index'
get '/sotechsha/:quiz', to: 'so_tech_sha#quiz'

# Default Scrivito routes. Adapt them to change the routing of CMS objects.
# See the documentation of 'scrivito_route' for a detailed description.
scrivito_route '/', using: 'homepage'
scrivito_route '/', using: 'homepage'
scrivito_route '(/)(*slug-):id', using: 'slug_id'
scrivito_route '/*permalink', using: 'permalink', format: false
scrivito_route '/*permalink', using: 'permalink', format: false
end
Binary file modified db/test
Binary file not shown.
12 changes: 12 additions & 0 deletions test/integration/blog_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'test_helper'

class BlogTest < ActionDispatch::IntegrationTest
def setup
end

test "Bloglink should be rendered" do
get "/blog"
assert_template "blog_overview_page/index"
assert_select "h1.page-header","Page Overview"
end
end
16 changes: 15 additions & 1 deletion test/integration/so_tech_sha_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@ def setup
test "Quizzes should be redirected" do
@quizzes.each do |num|
get "/sotechsha/#{num}"
assert_redirected_to "/#{num}"
assert_redirected_to "/sotechsha-#{num}"
end
end

test "Gazoulink should be redirected" do
get "/sotechsha/gazou"
assert_redirected_to "/sotechsha-gazou"
end

test "SoTechShalink should be rendered" do
get "/sotechsha"
assert_template "so_tech_sha_overview_page/index"
assert_select "h1.page-header","「Scratchでつくる! たのしむ! プログラミング道場」Webコンテンツ"
assert_select "a[href]", count:14
# Error
# assert_select "a[href=?]", /sotechsha-/ , count:14
end
end