Refactor app in to its own slice
This commit is contained in:
21
slices/main/views/posts/archive.rb
Normal file
21
slices/main/views/posts/archive.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
module Main
|
||||
module Views
|
||||
module Posts
|
||||
class Archive< Main::View
|
||||
include Deps["repos.post_repo"]
|
||||
|
||||
expose :year do |year:|
|
||||
year
|
||||
end
|
||||
|
||||
expose :posts do |year:|
|
||||
post_repo.by_year(year: year).map { |post| Decorators::Posts::Decorator.new(post) }
|
||||
end
|
||||
|
||||
expose :post_years do
|
||||
post_repo.post_years.map { |py| py[:year].to_i }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
slices/main/views/posts/index.rb
Normal file
31
slices/main/views/posts/index.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
module Main
|
||||
module Views
|
||||
module Posts
|
||||
class Index< Main::View
|
||||
include Deps["repos.post_repo"]
|
||||
|
||||
expose :posts do |post_query|
|
||||
post_query.map do |post|
|
||||
Decorators::Posts::Decorator.new(post)
|
||||
end
|
||||
end
|
||||
|
||||
private_expose :post_query do |query|
|
||||
if query
|
||||
post_repo.search(term: query)
|
||||
else
|
||||
post_repo.post_listing
|
||||
end
|
||||
end
|
||||
|
||||
expose :query do |query:|
|
||||
(query == "") ? nil : query
|
||||
end
|
||||
|
||||
expose :post_years do
|
||||
post_repo.post_years.map { |py| py[:year].to_i }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
41
slices/main/views/posts/show.rb
Normal file
41
slices/main/views/posts/show.rb
Normal file
@@ -0,0 +1,41 @@
|
||||
require "time_math"
|
||||
|
||||
module Main
|
||||
module Views
|
||||
module Posts
|
||||
class Show< Main::View
|
||||
include Deps["repos.post_repo", "repos.movie_repo"]
|
||||
|
||||
expose :post do |slug:|
|
||||
Decorators::Posts::Decorator.new(post_repo.fetch!(slug))
|
||||
end
|
||||
|
||||
expose :past_posts do |post|
|
||||
start_date = TimeMath.week.floor(post.published_at)
|
||||
end_date = TimeMath.week.ceil(post.published_at)
|
||||
posts = post_repo.from_the_archives(start_date: start_date, end_date: end_date)
|
||||
posts.map { |p| Decorators::Posts::Decorator.new(p) }
|
||||
end
|
||||
|
||||
expose :past_movies do |post|
|
||||
start_date = TimeMath.week.floor(post.published_at)
|
||||
end_date = TimeMath.week.ceil(post.published_at)
|
||||
movies = movie_repo.from_the_archives(start_date: start_date, end_date: end_date)
|
||||
movies.map { |p| Decorators::Movies::Decorator.new(p) }
|
||||
end
|
||||
|
||||
expose :text_posts do |past_posts|
|
||||
past_posts.reject(&:photos?)
|
||||
end
|
||||
|
||||
expose :photo_posts do |past_posts|
|
||||
past_posts.select(&:photos?)
|
||||
end
|
||||
|
||||
expose :trip do |post|
|
||||
post.trips.first
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
21
slices/main/views/posts/top_tracks.rb
Normal file
21
slices/main/views/posts/top_tracks.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
module Main
|
||||
module Views
|
||||
module Posts
|
||||
class TopTracks< Main::View
|
||||
config.layout = false
|
||||
|
||||
expose :name do |track:|
|
||||
track.name
|
||||
end
|
||||
|
||||
expose :artist do |track:|
|
||||
track.artist
|
||||
end
|
||||
|
||||
expose :url do |track:|
|
||||
track.url
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user