From 74f7e30d359708cbe027113f35599a1b3d2f79a2 Mon Sep 17 00:00:00 2001 From: optikfluffel Date: Tue, 4 Aug 2015 15:48:30 +0200 Subject: [PATCH 1/5] add elixir-rss dependency --- mix.exs | 3 ++- mix.lock | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 2765482..8c5ac14 100644 --- a/mix.exs +++ b/mix.exs @@ -35,7 +35,8 @@ defmodule ElixirJobs.Mixfile do {:exrethinkdb, github: "hamiltop/exrethinkdb", ref: "55fb5b5ed892f28b7ae8ee1b2f8e54fb651bd611"}, {:timex, "~> 0.13.4"}, {:earmark, "~> 0.1.17"}, - {:comeonin, "~> 1.0"} + {:comeonin, "~> 1.0"}, + {:rss, "~> 0.2.1"} ] end end diff --git a/mix.lock b/mix.lock index 42c8f35..16d81bd 100644 --- a/mix.lock +++ b/mix.lock @@ -10,4 +10,5 @@ "plug": {:hex, :plug, "0.14.0"}, "poison": {:hex, :poison, "1.4.0"}, "ranch": {:hex, :ranch, "1.1.0"}, + "rss": {:hex, :rss, "0.2.1"}, "timex": {:hex, :timex, "0.13.5"}} From 85e3d1ae31716ae31c749f95f6f9ac8567b11656 Mon Sep 17 00:00:00 2001 From: optikfluffel Date: Tue, 4 Aug 2015 15:48:58 +0200 Subject: [PATCH 2/5] cleanup routes and add /feed --- web/router.ex | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/web/router.ex b/web/router.ex index 08873f3..4de16bf 100644 --- a/web/router.ex +++ b/web/router.ex @@ -8,34 +8,34 @@ defmodule ElixirJobs.Router do plug :protect_from_forgery end - pipeline :api do - plug :accepts, ["json"] + pipeline :rss do + plug :accepts, ["rss"] end scope "/", ElixirJobs do pipe_through :browser # Use the default browser stack - # resources "/", PageController - get "/", PageController, :index - get "/job/new", PageController, :new - get "/job/:id", PageController, :show + get "/", PageController, :index + get "/job/new", PageController, :new + get "/job/:id", PageController, :show post "/job", PageController, :create - get "/users/login", UserController, :login + get "/users/login", UserController, :login post "/users/process_login", UserController, :process_login + get "/users/logout", UserController, :logout + post "/users", UserController, :create - get "/users/new_profile", UserController, :new_profile - get "/users/edit_profile", UserController, :edit_profile + get "/users/new_profile", UserController, :new_profile + get "/users/edit_profile", UserController, :edit_profile post "/users/profile", UserController, :create_profile post "/users/edit_profile", UserController, :update_profile - get "/users/logout", UserController, :logout - - get "/dev/:id", DevController, :show + get "/dev/:id", DevController, :show end - # Other scopes may use custom stacks. - # scope "/api", ElixirJobs do - # pipe_through :api - # end + scope "/feed", ElixirJobs do + pipe_through :rss # Use the rss stack + + get "/", FeedController, :index + end end From d4e388fcc7c647450c6389d4865dbe8e1e1f54c2 Mon Sep 17 00:00:00 2001 From: optikfluffel Date: Tue, 4 Aug 2015 17:28:19 +0200 Subject: [PATCH 3/5] add FeedController --- web/controllers/feed_controller.ex | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 web/controllers/feed_controller.ex diff --git a/web/controllers/feed_controller.ex b/web/controllers/feed_controller.ex new file mode 100644 index 0000000..abfa6ad --- /dev/null +++ b/web/controllers/feed_controller.ex @@ -0,0 +1,48 @@ +defmodule ElixirJobs.FeedController do + use ElixirJobs.Web, :controller + use Timex + + alias Exrethinkdb.Query + alias ElixirJobs.Repo + + @title "ElixirDose Jobs" + @baseurl "http://jobs.elixirdose.com" + @description "Elixir Jobs is the best place to find, list jobs and developer community space specifically for Elixir Programming Language." + @lang "en-us" + + defp format_rfc(date) do + date |> DateFormat.format!("%a, %d %b %Y %H:%M:%S %z", :strftime) + end + + defp job_to_rss_item(job) do + date = job["date_created"] |> Date.from(:secs, :epoch) + |> format_rfc + + RSS.item( + job["title"], + job["description"], + date, + "#{@baseurl}/job/#{job["id"]}", + job["id"] + ) + end + + def index(conn, _params) do + date = Date.now |> format_rfc + + channel = RSS.channel( + @title, + @baseurl, + @description, + date, + "lang (#{@lang})" + ) + + items = Query.table("jobs") |> Repo.run + |> Map.get(:data) + |> Enum.map(&job_to_rss_item(&1)) + + conn |> put_resp_content_type("application/xml") + |> text(RSS.feed(channel, items)) + end +end From c83f8de2a2dd31574e4b36eebe8e18ac2be0b0b2 Mon Sep 17 00:00:00 2001 From: optikfluffel Date: Tue, 4 Aug 2015 17:38:02 +0200 Subject: [PATCH 4/5] add feed url to app.html.eex --- web/templates/layout/app.html.eex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/templates/layout/app.html.eex b/web/templates/layout/app.html.eex index 4d0f8d7..06b0f94 100644 --- a/web/templates/layout/app.html.eex +++ b/web/templates/layout/app.html.eex @@ -10,6 +10,8 @@ + From 8fe4c232befa382b61582f1c73527f740e0ee8f9 Mon Sep 17 00:00:00 2001 From: optikfluffel Date: Tue, 4 Aug 2015 18:14:02 +0200 Subject: [PATCH 5/5] tweak .gitignore I overlooked the images and fonts in /priv/static in an earlier commit, this only ignores js and css generated from brunch --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 589be5d..f863c1c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,8 @@ erl_crash.dump # Since we are building assets from web/static, # we ignore priv/static. You may want to comment # this depending on your deployment strategy. -/priv/static/ +/priv/static/css +/priv/static/js # The config/prod.secret.exs file by default contains sensitive # data and you should not commit it into version control.