From df4ba480ad74c1c30d785877f748b2a46ebf4024 Mon Sep 17 00:00:00 2001 From: Takafumi Yoshida Date: Tue, 7 Nov 2017 15:52:26 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=E3=83=A2=E3=83=90=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E7=89=88=E3=81=AEDojo=E4=B8=80=E8=A6=A7=E3=82=92=E5=9C=B0?= =?UTF-8?q?=E5=9F=9F=E3=81=94=E3=81=A8=E3=81=AB=E3=82=A2=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=87=E3=82=A3=E3=82=AA=E3=83=B3=E3=81=AB=E3=81=BE=E3=81=A8?= =?UTF-8?q?=E3=82=81=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #174 --- Gemfile | 2 ++ Gemfile.lock | 5 ++++ app/controllers/application_controller.rb | 5 ++++ app/controllers/static_pages_controller.rb | 3 ++- app/views/static_pages/_dojo.html.erb | 14 ++++++++++ .../static_pages/_dojos_by_region.html.erb | 20 ++++++++++++++ app/views/static_pages/home.html.erb | 27 ++++++------------- 7 files changed, 56 insertions(+), 20 deletions(-) create mode 100644 app/views/static_pages/_dojo.html.erb create mode 100644 app/views/static_pages/_dojos_by_region.html.erb diff --git a/Gemfile b/Gemfile index 7ada2bdfb..461da6964 100644 --- a/Gemfile +++ b/Gemfile @@ -33,6 +33,8 @@ gem 'faraday_middleware', '0.10' gem 'koala' +gem 'rack-user_agent' + group :development do gem 'web-console' gem 'spring' diff --git a/Gemfile.lock b/Gemfile.lock index 6136d19e6..ecb4b0b7d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -155,6 +155,9 @@ GEM rack rack-test (0.7.0) rack (>= 1.0, < 3) + rack-user_agent (0.5.2) + rack (>= 1.5) + woothee (>= 1.0.0) rails (5.1.4) actioncable (= 5.1.4) actionmailer (= 5.1.4) @@ -294,6 +297,7 @@ GEM websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) + woothee (1.7.0) xpath (2.1.0) nokogiri (~> 1.3) @@ -316,6 +320,7 @@ DEPENDENCIES pg pry-rails rack-host-redirect + rack-user_agent rails (= 5.1.4) rails-controller-testing rake diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bc64cff4a..94e28d714 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,6 +6,8 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception include SessionsHelper + before_action :set_request_variant + private def store_location @@ -16,4 +18,7 @@ def login_page_access? %w(login_page sessions).include? self.controller_name end + def set_request_variant + request.variant = request.device_variant + end end diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 10b40ec56..c048f19e4 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -1,6 +1,7 @@ class StaticPagesController < ApplicationController def home - @dojos = Dojo.all + @dojo_count = Dojo.count + @regions_and_dojos = Dojo.includes(:prefecture).group_by { |dojo| dojo.prefecture.region } end def letsencrypt diff --git a/app/views/static_pages/_dojo.html.erb b/app/views/static_pages/_dojo.html.erb new file mode 100644 index 000000000..14ff32092 --- /dev/null +++ b/app/views/static_pages/_dojo.html.erb @@ -0,0 +1,14 @@ +
  • +
    + + + <%= dojo.name %> + +
    + +

    <%= dojo.description %>

    +
  • \ No newline at end of file diff --git a/app/views/static_pages/_dojos_by_region.html.erb b/app/views/static_pages/_dojos_by_region.html.erb new file mode 100644 index 000000000..6c309a5b5 --- /dev/null +++ b/app/views/static_pages/_dojos_by_region.html.erb @@ -0,0 +1,20 @@ +
    + + <% @regions_and_dojos.each_with_index do |(region, dojos), index| %> +
    + +
    " class="panel-collapse collapse" role="tabpanel"> +
    + <%= render partial: 'dojo', collection: dojos %> +
    +
    +
    + <% end %> + +
    \ No newline at end of file diff --git a/app/views/static_pages/home.html.erb b/app/views/static_pages/home.html.erb index 91973e80d..23d40a362 100644 --- a/app/views/static_pages/home.html.erb +++ b/app/views/static_pages/home.html.erb @@ -9,7 +9,7 @@
    -

    CoderDojo は7〜17歳の子どもを対象にしたプログラミング道場です。2011年にアイルランドで始まり、世界では<%= Dojo::NUM_OF_COUNTRIES %>カ国・<%= Dojo::NUM_OF_WHOLE_DOJOS %>の道場、日本では全国に<%= @dojos.count %>以上の道場があります。これまでに<%= Dojo::NUM_OF_WHOLE_EVENTS %>回以上のイベントが開催されました。

    +

    CoderDojo は7〜17歳の子どもを対象にしたプログラミング道場です。2011年にアイルランドで始まり、世界では<%= Dojo::NUM_OF_COUNTRIES %>カ国・<%= Dojo::NUM_OF_WHOLE_DOJOS %>の道場、日本では全国に<%= @dojo_count %>以上の道場があります。これまでに<%= Dojo::NUM_OF_WHOLE_EVENTS %>回以上のイベントが開催されました。

    CoderDojo で学べる内容は道場ごとに異なります。例えば、次の内容を学べる道場があります。

    From 3f38f51e5e31ab26b486ac8202168e81562b7c43 Mon Sep 17 00:00:00 2001 From: Takafumi Yoshida Date: Tue, 7 Nov 2017 17:24:06 +0900 Subject: [PATCH 2/3] =?UTF-8?q?variant=E3=82=92=E4=BD=BF=E3=81=A3=E3=81=A6?= =?UTF-8?q?view=E3=81=8B=E3=82=89=E3=83=AD=E3=82=B8=E3=83=83=E3=82=AF?= =?UTF-8?q?=E3=82=92=E6=8E=92=E9=99=A4=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...s_by_region.html.erb => _dojos.html+smartphone.erb} | 0 app/views/static_pages/_dojos.html.erb | 3 +++ app/views/static_pages/home.html.erb | 10 +++------- 3 files changed, 6 insertions(+), 7 deletions(-) rename app/views/static_pages/{_dojos_by_region.html.erb => _dojos.html+smartphone.erb} (100%) create mode 100644 app/views/static_pages/_dojos.html.erb diff --git a/app/views/static_pages/_dojos_by_region.html.erb b/app/views/static_pages/_dojos.html+smartphone.erb similarity index 100% rename from app/views/static_pages/_dojos_by_region.html.erb rename to app/views/static_pages/_dojos.html+smartphone.erb diff --git a/app/views/static_pages/_dojos.html.erb b/app/views/static_pages/_dojos.html.erb new file mode 100644 index 000000000..d177703e0 --- /dev/null +++ b/app/views/static_pages/_dojos.html.erb @@ -0,0 +1,3 @@ +
      + <%= render partial: 'dojo', collection: @regions_and_dojos.values.flatten %> +
    \ No newline at end of file diff --git a/app/views/static_pages/home.html.erb b/app/views/static_pages/home.html.erb index 23d40a362..50ab8feab 100644 --- a/app/views/static_pages/home.html.erb +++ b/app/views/static_pages/home.html.erb @@ -84,13 +84,9 @@

    全国の道場


    - <% if request.from_smartphone? %> - <%= render 'dojos_by_region', locals: { regions_and_dojos: @regions_and_dojos } %> - <% else %> -
      - <%= render partial: 'dojo', collection: @regions_and_dojos.values.flatten %> -
    - <% end %> + + <%= render 'dojos' %> +
    From 4defaa59f95bd5cec8cc1238ecbbc3d16bdae5fd Mon Sep 17 00:00:00 2001 From: Takafumi Yoshida Date: Thu, 9 Nov 2017 11:19:27 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E3=82=AD=E3=83=A3=E3=83=AC=E3=83=83?= =?UTF-8?q?=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/static_pages.coffee | 5 +++++ app/views/static_pages/_dojos.html+smartphone.erb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/static_pages.coffee diff --git a/app/assets/javascripts/static_pages.coffee b/app/assets/javascripts/static_pages.coffee new file mode 100644 index 000000000..f50a8f580 --- /dev/null +++ b/app/assets/javascripts/static_pages.coffee @@ -0,0 +1,5 @@ +$ -> + $('.collapse').on 'shown.bs.collapse', -> + $(this).parent().find(".fa-chevron-right").removeClass("fa-chevron-right").addClass("fa-chevron-down") + $('.collapse').on 'hidden.bs.collapse', -> + $(this).parent().find(".fa-chevron-down").removeClass("fa-chevron-down").addClass("fa-chevron-right") diff --git a/app/views/static_pages/_dojos.html+smartphone.erb b/app/views/static_pages/_dojos.html+smartphone.erb index 6c309a5b5..5fec9dfe9 100644 --- a/app/views/static_pages/_dojos.html+smartphone.erb +++ b/app/views/static_pages/_dojos.html+smartphone.erb @@ -5,7 +5,8 @@