diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ebccf18..aea8ad2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,18 @@ class ApplicationController < ActionController::Base + before_action :set_locale + def default_url_options - { host: ENV["DOMAIN"] || "localhost:3000" } + { + host: ENV["DOMAIN"] || "localhost:3000", + locale: I18n.locale, + } + end + + def set_locale + I18n.locale = params[:locale] || I18n.default_locale + end + + def locale + default_url_options[:locale] end end diff --git a/app/controllers/guideline_categories_controller.rb b/app/controllers/guideline_categories_controller.rb new file mode 100644 index 0000000..a9ecbc8 --- /dev/null +++ b/app/controllers/guideline_categories_controller.rb @@ -0,0 +1,9 @@ +class GuidelineCategoriesController < ApplicationController + def index + @category = + end + + def fetch_categories + GuidelinesPresenter.new(locale).categories + end +end diff --git a/app/controllers/guidelines_controller.rb b/app/controllers/guidelines_controller.rb new file mode 100644 index 0000000..4347607 --- /dev/null +++ b/app/controllers/guidelines_controller.rb @@ -0,0 +1,5 @@ +class GuidelinesController < ApplicationController + def index + @guidelines = GuidelinesPresenter.new(locale) + end +end diff --git a/app/models/guideline_category.rb b/app/models/guideline_category.rb new file mode 100644 index 0000000..ee19fc2 --- /dev/null +++ b/app/models/guideline_category.rb @@ -0,0 +1,24 @@ +class GuidelineCategory + attr_reader :slug, :position, :title, :description, :svg_filename, :articles + def initialize(dir_path, metadata) + @dir_path = dir_path + @slug = extract_slug + @position = extract_position + @title = metadata[:title] + @description = metadata[:description] + @svg_filename = metadata[:svg_filename] + @articles = [] + end + + private + + def extract_slug + dir_path.match(/\d+-(\w.*)$/)[1] + end + + def extract_position + dir_path.match(/(\d+)(?!.*\d)/)[1]&.to_i + end + + attr_reader :dir_path +end diff --git a/app/presenters/guidelines_presenter.rb b/app/presenters/guidelines_presenter.rb new file mode 100644 index 0000000..c02368e --- /dev/null +++ b/app/presenters/guidelines_presenter.rb @@ -0,0 +1,45 @@ +class GuidelinesPresenter + ROOT_PATH = Rails.root.join("lib/markdown").freeze + METADATA_FILE_NAME = "metadata.yml".freeze + + def initialize(locale) + @locale = locale + end + + def categories + guideline_dir_paths.map do |dir_path| + GuidelineCategory.new( + dir_path.to_s, + metadata(dir_path), + ) + end + end + + def title + metadata(guidelines_path)[:title] + end + + def description + metadata(guidelines_path)[:description] + end + + def metadata(dir_path) + YAML::load_file(File.join(dir_path, METADATA_FILE_NAME)).symbolize_keys! + end + + private + + def guideline_dir_paths + Pathname.new(guidelines_path).children.select(&:directory?) + end + + def guidelines_path + root_path("guidelines") + end + + def root_path(dir_name) + "#{ROOT_PATH}/#{locale}/#{dir_name}" + end + + attr_reader :locale +end diff --git a/app/views/guideline_categories/index.html.erb b/app/views/guideline_categories/index.html.erb new file mode 100644 index 0000000..275d4c6 --- /dev/null +++ b/app/views/guideline_categories/index.html.erb @@ -0,0 +1,5 @@ +<%= render partial: "shared/guideline_index", locals: { + title: @category.title, + description: @category.description, + children: @categories.articles, +} %> diff --git a/app/views/guidelines/index.html.erb b/app/views/guidelines/index.html.erb new file mode 100644 index 0000000..13c0e4c --- /dev/null +++ b/app/views/guidelines/index.html.erb @@ -0,0 +1,5 @@ +<%= render partial: "shared/guideline_index", locals: { + title: @guidelines.title, + description: @guidelines.description, + children: @guidelines.categories, +} %> diff --git a/app/views/shared/_guideline_card.html.erb b/app/views/shared/_guideline_card.html.erb new file mode 100644 index 0000000..f59fb3c --- /dev/null +++ b/app/views/shared/_guideline_card.html.erb @@ -0,0 +1,25 @@ + <%= link_to "/guidelines/#{slug}" do %> +
+ +
+
+
+ <%= inline_svg_tag "graphics/home/#{svg_filename}.svg", + size: "200", + class: "m-auto" + %> +
+
+

+ + <%= title %> + +

+

+ <%= description %> +

+
+
+
+
+ <% end %> diff --git a/app/views/shared/_guideline_index.html.erb b/app/views/shared/_guideline_index.html.erb new file mode 100644 index 0000000..645f026 --- /dev/null +++ b/app/views/shared/_guideline_index.html.erb @@ -0,0 +1,16 @@ +
+

+ <%= title %> +

+

+ <%= description %> +

+ <% children.each do |child| %> + <%= render partial: "shared/guideline_card", locals: { + title: child.title, + description: child.description, + slug: child.slug, + svg_filename: child.svg_filename, + } %> + <% end %> +
diff --git a/config/routes.rb b/config/routes.rb index eda0f93..6a4bc42 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,4 +15,9 @@ get '/hospitals', to: 'hospitals#index' get '/privacy', to: 'pages#privacy' + + scope "(:locale)", locale: /en|ja/ do + resources :guidelines, only: %I(index) + get "/guidelines/:category_name", to: "guideline_categories#index" + end end diff --git a/lib/markdown/en/guidelines/00-elderly-crews/00-role-definition.md b/lib/markdown/en/guidelines/00-elderly-crews/00-role-definition.md new file mode 100644 index 0000000..ec8644d --- /dev/null +++ b/lib/markdown/en/guidelines/00-elderly-crews/00-role-definition.md @@ -0,0 +1,12 @@ +# Role Definition +> What elderly crews is all about. + +Elderly crews are crucial parts of the Pandemic Volunteers team who go around to retirement homes and elderly individuals’ homes to check up on them and bring them essential needs such as food and clothes so that they do not have to leave the home and risk catching COVID-19. + +This is an especially important job because it targets the elderly, those who are at most risk of dying from or hurting themselves permanently if they do catch the virus, so volunteers are supposed to be even more careful than normal because of their added vulnerabilities. + +Volunteers must also know how to reach out to their local elderly individuals, how to sterilize groceries and PPE, nonviolent communication and have to avoid the most amount of contact possible. If one is interested in this position and does not think they have the required skills, they can always follow the following knowledgebase articles to learn more and hopefully be qualified enough to be able to carry out such a job efficiently, and, more importantly, safely. + +Elderly crew volunteers have the choice of being assigned targets by Coordination Crew meetings, and joining an action crew to listen in and know what those targets are, or they can find targets individually and help those in need as soon as they know about them. + +They must also remember not to treat elderly individuals like children, or patronize them in any way: they may not be necessarily dependent on outside groups for support most of the time, and in a time of crisis such as this one it is only right that they do what is best for their health without any judgment. diff --git a/lib/markdown/en/guidelines/00-elderly-crews/metadata.yml b/lib/markdown/en/guidelines/00-elderly-crews/metadata.yml new file mode 100644 index 0000000..edf251c --- /dev/null +++ b/lib/markdown/en/guidelines/00-elderly-crews/metadata.yml @@ -0,0 +1,3 @@ +title: Elderly Crews +description: Guidelines for elderly crews. +svg_filename: undraw_collab_8oes_modified diff --git a/lib/markdown/en/guidelines/metadata.yml b/lib/markdown/en/guidelines/metadata.yml new file mode 100644 index 0000000..8c3c9a9 --- /dev/null +++ b/lib/markdown/en/guidelines/metadata.yml @@ -0,0 +1,3 @@ +title: Guidelines +description: Pandemic Volunteers guidelines +svg_filename: undraw_reading_0re1 diff --git a/spec/models/guideline_category_spec.rb b/spec/models/guideline_category_spec.rb new file mode 100644 index 0000000..ee12bb7 --- /dev/null +++ b/spec/models/guideline_category_spec.rb @@ -0,0 +1,70 @@ +require "rails_helper" + +RSpec.describe GuidelineCategory do + it "returns a slug" do + dir_path = "/foo/bar/00-bar-baz" + presenter = described_class.new(dir_path, {}) + expect(presenter.slug).to eq("bar-baz") + end + + it "returns a position" do + dir_path = "/foo/bar/00-bar-baz" + presenter = described_class.new(dir_path, {}) + expect(presenter.position).to eq(0) + end + + it "returns a title" do + dir_path = "/foo/bar/00-bar-baz" + + metadata = { + title: "foo", + description: "bar", + svg_filename: "baz", + } + + presenter = described_class.new(dir_path, metadata) + expect(presenter.title).to eq("foo") + end + + it "returns a description" do + dir_path = + "/pandemic-volunteers/lib/markdown/en/guidelines/00-elderly-crews" + + metadata = { + title: "foo", + description: "bar", + svg_filename: "baz", + } + + presenter = described_class.new(dir_path, metadata) + expect(presenter.description).to eq("bar") + end + + it "returns an svg_filename" do + dir_path = "/foo/bar/00-bar-baz" + + metadata = { + title: "foo", + description: "bar", + svg_filename: "baz", + } + + presenter = described_class.new(dir_path, metadata) + expect(presenter.svg_filename).to eq("baz") + end + + it "returns articles" do + pending "TODO: add articles" + dir_path = + "/pandemic-volunteers/lib/markdown/en/guidelines/00-elderly-crews" + + metadata = { + title: "foo", + description: "bar", + svg_filename: "baz", + } + + presenter = described_class.new(dir_path, metadata) + expect(presenter.articles).not_to be_empty + end +end diff --git a/spec/presenters/guidelines_presenter_spec.rb b/spec/presenters/guidelines_presenter_spec.rb new file mode 100644 index 0000000..69c1455 --- /dev/null +++ b/spec/presenters/guidelines_presenter_spec.rb @@ -0,0 +1,34 @@ +require "rails_helper" + +RSpec.describe GuidelinesPresenter do + it "returns a list of guidelines based on locale" do + expect(presenter.categories).not_to be_empty + end + + it "returns a list of guidelines with slugs" do + expect(presenter.categories.first.slug).not_to be_empty + end + + it "parses metadata" do + allow(GuidelineCategory).to receive(:new) + presenter.categories + expect(GuidelineCategory).to have_received(:new).with( + instance_of(String), + instance_of(Hash), + ) + end + + it "returns a title" do + expect(presenter.title).not_to be_empty + end + + it "returns a description" do + expect(presenter.description).not_to be_empty + end + + private + + def presenter + described_class.new(:en) + end +end diff --git a/spec/requests/guideline_categories_request_spec.rb b/spec/requests/guideline_categories_request_spec.rb new file mode 100644 index 0000000..929f377 --- /dev/null +++ b/spec/requests/guideline_categories_request_spec.rb @@ -0,0 +1,27 @@ +require "rails_helper" + +RSpec.describe "/guidelines", type: :request do + let(:locale) { :en } + it "returns a 200 " do + get "/#{locale}/guidelines" + + expect(response.status).to eq(200) + end + + it "returns page metadata" do + locale = :en + presenter = GuidelinesPresenter.new(locale) + get "/#{locale}/guidelines" + + expect(response.body).to include presenter.title + expect(response.body).to include presenter.description + end + + it "returns a list of guidelines" do + locale = :en + categories = GuidelinesPresenter.new(locale).categories + get "/#{locale}/guidelines" + + expect(response.body).to include categories.first.title + end +end