diff --git a/lib/librarix/application.rb b/lib/librarix/application.rb index cd38207..af680a4 100644 --- a/lib/librarix/application.rb +++ b/lib/librarix/application.rb @@ -1,6 +1,7 @@ require 'librarix/filter' require 'librarix/menu' require 'librarix/the_movie_db' +require 'librarix/helpers' require 'sinatra/base' require 'sinatra/content_for' @@ -21,12 +22,10 @@ module Librarix helpers Librarix::TheMovieDB helpers Librarix::Menu::Helper + helpers Librarix::Helpers get '/' do - slim :index, locals: { - compact: params.key?('compact'), - movies: Librarix::Filter.new(params).movies - } + slim :index, locals: {movies: Librarix::Filter.new(params).movies} end get '/search' do diff --git a/lib/librarix/helpers.rb b/lib/librarix/helpers.rb new file mode 100644 index 0000000..c98da80 --- /dev/null +++ b/lib/librarix/helpers.rb @@ -0,0 +1,7 @@ +module Librarix + module Helpers + def compact? + params.key?('compact') + end + end +end diff --git a/lib/librarix/views/index.slim b/lib/librarix/views/index.slim index 9281a63..6343e8e 100644 --- a/lib/librarix/views/index.slim +++ b/lib/librarix/views/index.slim @@ -1,12 +1,16 @@ - content_for(:title) { 'Index' } form method="get" action="/" id="filter" - input type="text" name="title" value="#{params['title']}" autocomplete="off" - select name="view_state" - option value="all" selected=(params['view_state'].nil? || params['view_state'] == '' || params['view_state'] == 'all') All movies - option value="viewed" selected=(params['view_state'] == 'viewed') Only viewed - option value="not_viewed" selected=(params['view_state'] == 'not_viewed') Not viewed - input type="submit" value="Filter" + div id="search-main" + input type="text" name="title" value="#{params['title']}" autocomplete="off" + input type="submit" value="Filter" + div id="search-more" + select name="view_state" + option value="all" selected=(params['view_state'].nil? || params['view_state'] == '' || params['view_state'] == 'all') All movies + option value="viewed" selected=(params['view_state'] == 'viewed') Only viewed + option value="not_viewed" selected=(params['view_state'] == 'not_viewed') Not viewed + input type="checkbox" name="compact" id="compact" checked=(params['compact']) + label for="compact" Compact view -== slim :list, locals: {compact: compact, movies: movies} +== slim :list, locals: {movies: movies} diff --git a/lib/librarix/views/list.slim b/lib/librarix/views/list.slim index 62a3787..2062ac1 100644 --- a/lib/librarix/views/list.slim +++ b/lib/librarix/views/list.slim @@ -1,4 +1,4 @@ ul#movies - movies.each do |movie| li - == slim :movie, locals: {compact: locals.key?('compact') ? compact : false, movie: movie} + == slim :movie, locals: {movie: movie} diff --git a/lib/librarix/views/movie.slim b/lib/librarix/views/movie.slim index ce6b35e..656c93f 100644 --- a/lib/librarix/views/movie.slim +++ b/lib/librarix/views/movie.slim @@ -1,12 +1,12 @@ .movie data-id="#{movie.id}" .poster - if movie.poster_path - img src="#{poster_url(movie.poster_path, compact ? 'w92' : 'w154')}" + img src="#{poster_url(movie.poster_path, compact? ? 'w92' : 'w154')}" .informations h2 a href="https://www.themoviedb.org/movie/#{movie.id}" #{movie.original_title} p = movie.release_date - - unless compact + - unless compact? p = movie.overview .actions - if movie.added?