diff --git a/Gemfile b/Gemfile index b494e47..2c68a54 100644 --- a/Gemfile +++ b/Gemfile @@ -4,12 +4,15 @@ source 'https://rubygems.org' gem 'rails', '4.2.5.2' # Use sqlite3 as the database for Active Record gem 'sqlite3' +gem 'will_paginate' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views - +gem 'bootstrap-sass' +# for external api calls +gem 'httparty' # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks diff --git a/Gemfile.lock b/Gemfile.lock index b580227..029f547 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,6 +39,8 @@ GEM arel (6.0.3) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) + bootstrap-sass (3.2.0.0) + sass (~> 3.2) builder (3.2.2) byebug (8.2.2) coffee-rails (4.1.1) @@ -54,6 +56,9 @@ GEM execjs (2.6.0) globalid (0.3.6) activesupport (>= 4.1.0) + httparty (0.13.7) + json (~> 1.8) + multi_xml (>= 0.5.2) i18n (0.7.0) jbuilder (2.4.1) activesupport (>= 3.0.0, < 5.1) @@ -71,6 +76,7 @@ GEM mini_portile2 (2.0.0) minitest (5.8.4) multi_json (1.11.2) + multi_xml (0.5.5) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) rack (1.6.4) @@ -136,12 +142,15 @@ GEM binding_of_caller (>= 0.7.2) railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) + will_paginate (3.1.0) PLATFORMS ruby DEPENDENCIES + bootstrap-sass byebug + httparty jbuilder (~> 2.0) jquery-rails rails (= 4.2.5.2) @@ -151,6 +160,4 @@ DEPENDENCIES turbolinks uglifier (>= 1.3.0) web-console (~> 2.0) - -BUNDLED WITH - 1.11.2 + will_paginate diff --git a/app/assets/javascripts/movies.js b/app/assets/javascripts/movies.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/movies.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/static_pages.js b/app/assets/javascripts/static_pages.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/static_pages.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/custom.css.scss b/app/assets/stylesheets/custom.css.scss new file mode 100644 index 0000000..c60a3d4 --- /dev/null +++ b/app/assets/stylesheets/custom.css.scss @@ -0,0 +1,98 @@ +@import "bootstrap-sprockets"; +@import "bootstrap"; + +/* mixins, variables, etc. */ + +$gray-medium-light: #eaeaea; + +/* universal */ + +body { + padding-top: 60px; +} + +section { + overflow: auto; +} + +textarea { + resize: vertical; +} + +.center { + text-align: center; + h1 { + margin-bottom: 10px; + } +} + +/* typography */ + +h1, h2, h3, h4, h5, h6 { + line-height: 1; +} + +h1 { + font-size: 3em; + letter-spacing: -2px; + margin-bottom: 30px; + text-align: center; +} + +h2 { + font-size: 1.2em; + letter-spacing: -1px; + margin-bottom: 30px; + text-align: center; + font-weight: normal; + color: $gray-light; +} + +p { + font-size: 1.1em; + line-height: 1.7em; +} + + +/* header */ + +#logo { + float: left; + margin-right: 10px; + font-size: 1.7em; + color: white; + text-transform: uppercase; + letter-spacing: -1px; + padding-top: 9px; + font-weight: bold; + &:hover { + color: white; + text-decoration: none; + } +} + +/* footer */ + +footer { + margin-top: 45px; + padding-top: 5px; + border-top: 1px solid $gray-medium-light; + color: $gray-light; + a { + color: $gray; + &:hover { + color: $gray-darker; + } + } + small { + float: left; + } + ul { + float: right; + list-style: none; + li { + float: left; + margin-left: 15px; + } + } +} diff --git a/app/assets/stylesheets/movies.scss b/app/assets/stylesheets/movies.scss new file mode 100644 index 0000000..b86dfed --- /dev/null +++ b/app/assets/stylesheets/movies.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Movies controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/static_pages.scss b/app/assets/stylesheets/static_pages.scss new file mode 100644 index 0000000..d55836c --- /dev/null +++ b/app/assets/stylesheets/static_pages.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the StaticPages controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb new file mode 100644 index 0000000..85bba87 --- /dev/null +++ b/app/controllers/movies_controller.rb @@ -0,0 +1,10 @@ +class MoviesController < ApplicationController + def index + @movies = Movie.paginate(page: params[:page]) + end + + def show + @movie = Movie.find(params[:id]) + end + +end diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb new file mode 100644 index 0000000..8c01578 --- /dev/null +++ b/app/controllers/static_pages_controller.rb @@ -0,0 +1,10 @@ +class StaticPagesController < ApplicationController + def home + end + + def about + end + + def contact + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..bc9cec4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,10 @@ module ApplicationHelper + def full_title(page_title = '') + base_title = "Filmci" + if page_title.empty? + base_title + else + "#{page_title} - #{base_title} " + end + end end diff --git a/app/helpers/movies_helper.rb b/app/helpers/movies_helper.rb new file mode 100644 index 0000000..493eee5 --- /dev/null +++ b/app/helpers/movies_helper.rb @@ -0,0 +1,2 @@ +module MoviesHelper +end diff --git a/app/helpers/static_pages_helper.rb b/app/helpers/static_pages_helper.rb new file mode 100644 index 0000000..2d63e79 --- /dev/null +++ b/app/helpers/static_pages_helper.rb @@ -0,0 +1,2 @@ +module StaticPagesHelper +end diff --git a/app/models/movie.rb b/app/models/movie.rb new file mode 100644 index 0000000..49198a7 --- /dev/null +++ b/app/models/movie.rb @@ -0,0 +1,2 @@ +class Movie < ActiveRecord::Base +end diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb new file mode 100644 index 0000000..c1903f5 --- /dev/null +++ b/app/views/layouts/_footer.html.erb @@ -0,0 +1,12 @@ + diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb new file mode 100644 index 0000000..12b3081 --- /dev/null +++ b/app/views/layouts/_header.html.erb @@ -0,0 +1,13 @@ + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 2fb82d3..53cb9fb 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,14 +1,16 @@ - Filmci +<%= full_title(yield(:title)) %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> - +<%= render 'layouts/header' %> +
<%= yield %> - +<%= render 'layouts/footer' %> +
diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb new file mode 100644 index 0000000..4c866ef --- /dev/null +++ b/app/views/movies/index.html.erb @@ -0,0 +1,14 @@ +

Movies

+<% if @movies.count == 0 %> +

We do not have any movie! Come back later!

+<%else%> + <%= will_paginate %> + + <%= will_paginate %> +<%end%> + + diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb new file mode 100644 index 0000000..00b9858 --- /dev/null +++ b/app/views/movies/show.html.erb @@ -0,0 +1,7 @@ +<% provide(:title, @movie.title) %> +

<%= @movie.title %>

+

Director: <%= @movie.director %> | + Year: <%= @movie.year %> | + Country: <%= @movie.country %> +

+

<%= @movie.description %>

diff --git a/app/views/static_pages/about.html.erb b/app/views/static_pages/about.html.erb new file mode 100644 index 0000000..edb477d --- /dev/null +++ b/app/views/static_pages/about.html.erb @@ -0,0 +1,3 @@ +<%= provide(:title, 'About') %> +

About Page

+

This is about page!!

diff --git a/app/views/static_pages/contact.html.erb b/app/views/static_pages/contact.html.erb new file mode 100644 index 0000000..6e0e0be --- /dev/null +++ b/app/views/static_pages/contact.html.erb @@ -0,0 +1,3 @@ +<%= provide(:title, 'Contact') %> +

Contact Page

+

This is contact page!!

diff --git a/app/views/static_pages/home.html.erb b/app/views/static_pages/home.html.erb new file mode 100644 index 0000000..674cce0 --- /dev/null +++ b/app/views/static_pages/home.html.erb @@ -0,0 +1,2 @@ +

Home Page

+

This is home page!!

diff --git a/config/routes.rb b/config/routes.rb index 3f66539..af3abc8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,56 +1,7 @@ Rails.application.routes.draw do - # The priority is based upon order of creation: first created -> highest priority. - # See how all your routes lay out with "rake routes". - # You can have the root of your site routed with "root" - # root 'welcome#index' - - # Example of regular route: - # get 'products/:id' => 'catalog#view' - - # Example of named route that can be invoked with purchase_url(id: product.id) - # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - - # Example resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Example resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Example resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Example resource route with more complex sub-resources: - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', on: :collection - # end - # end - - # Example resource route with concerns: - # concern :toggleable do - # post 'toggle' - # end - # resources :posts, concerns: :toggleable - # resources :photos, concerns: :toggleable - - # Example resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end + root 'static_pages#home' + get 'about' => 'static_pages#about' + get 'contact' => 'static_pages#contact' + resources :movies end diff --git a/db/migrate/20160314152249_create_movies.rb b/db/migrate/20160314152249_create_movies.rb new file mode 100644 index 0000000..f181790 --- /dev/null +++ b/db/migrate/20160314152249_create_movies.rb @@ -0,0 +1,13 @@ +class CreateMovies < ActiveRecord::Migration + def change + create_table :movies do |t| + t.string :title + t.text :description + t.string :director + t.string :country + t.integer :year + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..f579a1a --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,26 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20160314152249) do + + create_table "movies", force: :cascade do |t| + t.string "title" + t.text "description" + t.string "director" + t.string "country" + t.integer "year" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/lib/assets/movielist.txt b/lib/assets/movielist.txt new file mode 100644 index 0000000..af1d12b --- /dev/null +++ b/lib/assets/movielist.txt @@ -0,0 +1,250 @@ +The Shawshank Redemption,1994 +The Godfather,1972 +The Godfather: Part II,1974 +The Dark Knight,2008 +Pulp Fiction,1994 +Schindler's List,1993 +12 Angry Men,1957 +The Lord of the Rings: The Return of the King,2003 +The Good, the Bad and the Ugly,1966 +Fight Club,1999 +The Lord of the Rings: The Fellowship of the Ring,2001 +Star Wars: Episode V - The Empire Strikes Back,1980 +Forrest Gump,1994 +Inception,2010 +The Lord of the Rings: The Two Towers,2002 +One Flew Over the Cuckoo's Nest,1975 +Goodfellas,1990 +The Matrix,1999 +Seven Samurai,1954 +Star Wars: Episode IV - A New Hope,1977 +City of God,2002 +Se7en,1995 +The Silence of the Lambs,1991 +It's a Wonderful Life,1946 +The Usual Suspects,1995 +Life Is Beautiful,1997 +Léon: The Professional,1994 +Once Upon a Time in the West,1968 +Spirited Away,2001 +Saving Private Ryan,1998 +Interstellar,2014 +Casablanca,1942 +American History X,1998 +City Lights,1931 +Psycho,1960 +Raiders of the Lost Ark,1981 +Rear Window,1954 +The Intouchables,2011 +Modern Times,1936 +The Green Mile,1999 +Terminator 2: Judgment Day,1991 +The Pianist,2002 +The Departed,2006 +Whiplash,2014 +Back to the Future,1985 +Memento,2000 +Gladiator,2000 +Apocalypse Now,1979 +Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb,1964 +The Prestige,2006 +Sunset Blvd.,1950 +The Lion King,1994 +Alien,1979 +The Great Dictator,1940 +The Lives of Others,2006 +Cinema Paradiso,1988 +Django Unchained,2012 +The Shining,1980 +Paths of Glory,1957 +Deadpool,2016 +The Dark Knight Rises,2012 +Grave of the Fireflies,1988 +WALL·E,2008 +American Beauty,1999 +Aliens,1986 +Princess Mononoke,1997 +Old Boy,2003 +Citizen Kane,1941 +North by Northwest,1959 +Vertigo,1958 +Érase una vez en América,1984 +Das Boot,1981 +Star Wars: Episode VI - Return of the Jedi,1983 +M,1931 +Witness for the Prosecution,1957 +Amélie,2001 +Reservoir Dogs,1992 +Braveheart,1995 +Requiem for a Dream,2000 +A Clockwork Orange,1971 +Taxi Driver,1976 +Toy Story 3,2010 +Double Indemnity,1944 +To Kill a Mockingbird,1962 +Lawrence of Arabia,1962 +Star Wars: Episode VII - The Force Awakens,2015 +Eternal Sunshine of the Spotless Mind,2004 +Full Metal Jacket,1987 +Amadeus,1984 +The Sting,1973 +Singin' in the Rain,1952 +Bicycle Thieves,1948 +2001: A Space Odyssey,1968 +Snatch.,2000 +Monty Python and the Holy Grail,1975 +Toy Story,1995 +The Kid,1921 +Inglourious Basterds,2009 +L.A. Confidential,1997 +Rashomon,1950 +For a Few Dollars More,1965 +The Apartment,1960 +All About Eve,1950 +Nader y Simin, una separación,2011 +Indiana Jones and the Last Crusade,1989 +Scarface,1983 +Metrópolis,1927 +The Treasure of the Sierra Madre,1948 +Yojimbo,1961 +Inside Out,2015 +Batman Begins,2005 +Some Like It Hot,1959 +3 Idiots,2009 +The Third Man,1949 +Unforgiven,1992 +The Hunt,2012 +Up,2009 +Good Will Hunting,1997 +Raging Bull,1980 +Downfall,2004 +Die Hard,1988 +Chinatown,1974 +The Great Escape,1963 +Heat,1995 +On the Waterfront,1954 +Pan's Labyrinth,2006 +La habitación,2015 +Sunrise,1927 +My Neighbor Totoro,1988 +Mr. Smith Goes to Washington,1939 +Ikiru,1952 +The Bridge on the River Kwai,1957 +The Gold Rush,1925 +Ran,1985 +The Seventh Seal,1957 +The Secret in Their Eyes,2009 +Blade Runner,1982 +Lock, Stock and Two Smoking Barrels,1998 +The General,1926 +Wild Strawberries,1957 +Howl's Moving Castle,2004 +Casino,1995 +The Elephant Man,1980 +Warrior,2011 +The Wolf of Wall Street,2013 +V for Vendetta,2005 +The Revenant,2015 +Judgment at Nuremberg,1961 +A Beautiful Mind,2001 +Gran Torino,2008 +The Big Lebowski,1998 +Rebecca,1940 +The Deer Hunter,1978 +Incendies,2010 +Gone with the Wind,1939 +Cool Hand Luke,1967 +Fargo,1996 +How to Train Your Dragon,2010 +Trainspotting,1996 +Dial M for Murder,1954 +The Sixth Sense,1999 +Into the Wild,2007 +Finding Nemo,2003 +It Happened One Night,1934 +The Thing,1982 +No Country for Old Men,2007 +Mary and Max,2009 +Gone Girl,2014 +Mad Max: Fury Road,2015 +Kill Bill: Vol. 1,2003 +Spotlight,2015 +Rush,2013 +The Maltese Falcon,1941 +Life of Brian,1979 +Hotel Rwanda,2004 +Platoon,1986 +There Will Be Blood,2007 +The Wages of Fear,1953 +Network,1976 +Butch Cassidy and the Sundance Kid,1969 +The 400 Blows,1959 +Stand by Me,1986 +Persona,1966 +En el nombre del padre,1993 +12 Years a Slave,2013 +The Grand Budapest Hotel,2014 +The Princess Bride,1987 +Amores Perros,2000 +Touch of Evil,1958 +Shutter Island,2010 +Million Dollar Baby,2004 +Annie Hall,1977 +Ben-Hur,1959 +The Grapes of Wrath,1940 +Relatos salvajes,2014 +Hachi: A Dog's Tale,2009 +Nausicaä of the Valley of the Wind,1984 +Stalker,1979 +Diabolique,1955 +Jurassic Park,1993 +Gandhi,1982 +8½,1963 +The Bourne Ultimatum,2007 +Donnie Darko,2001 +Before Sunrise,1995 +The Wizard of Oz,1939 +The Best Years of Our Lives,1946 +The Martian,2015 +Sin City,2005 +Rocky,1976 +Memories of Murder,2003 +Strangers on a Train,1951 +The Terminator,1984 +The Truman Show,1998 +Twelve Monkeys,1995 +Harry Potter and the Deathly Hallows: Part 2,2011 +Groundhog Day,1993 +Monsters, Inc.,2001 +Infernal Affairs,2002 +The Battle of Algiers,1966 +Jaws,1975 +Barry Lyndon,1975 +La Haine,1995 +Fanny and Alexander,1982 +The Avengers,2012 +Dog Day Afternoon,1975 +Ip Man,2008 +Prisoners,2013 +Throne of Blood,1957 +The Imitation Game,2014 +The King's Speech,2010 +La Grande Illusion,1937 +Guardians of the Galaxy,2014 +Pirates of the Caribbean: The Curse of the Black Pearl,2003 +High Noon,1952 +A Fistful of Dollars,1964 +The Help,2011 +Castle in the Sky,1986 +Roman Holiday,1953 +Catch Me If You Can,2002 +Notorious,1946 +Gangs of Wasseypur,2012 +Who's Afraid of Virginia Woolf?,1966 +Underground,1995 +Beauty and the Beast,1991 +Spring, Summer, Fall, Winter... and Spring,2003 +Anatomy of a Murder,1959 +In the Mood for Love,2000 +Before Sunset,2004 +Akira,1988 diff --git a/lib/tasks/populate_movies_table.rake b/lib/tasks/populate_movies_table.rake new file mode 100644 index 0000000..f23123f --- /dev/null +++ b/lib/tasks/populate_movies_table.rake @@ -0,0 +1,37 @@ +task :populate_movies_table => :environment do + file_path = Rails.root + 'lib/assets/movielist.txt' + fh = File.open(file_path) + while (line = fh.gets) != nil + line.chomp! + line = line.force_encoding("ISO-8859-1").encode("utf-8", replace: nil) + arr = line.split(',') + # puts arr.inspect + response = query_omdb(arr[0], arr[1]) + # puts response + if response.include? "Error" + puts "Error for #{arr[0]}" + else + hash = JSON.parse response.body + add_movie hash + end + end +end + +def add_movie(params) + movie = Movie.new + movie.title = params["Title"] + movie.description = params["Plot"] + movie.director = params["Director"] + movie.country = params["Country"] + movie.year = params["Year"] + if movie.save + puts "#{movie.title} added successfully!" + end +end + +def query_omdb(movie, year) + omdb_url = "http://www.omdbapi.com/" + # example URL: http://www.omdbapi.com/?t=city+of+god&y=&plot=short&r=json + options = { query: { t: movie, y: year, plot: "long", r: "json"} } + return HTTParty.get(omdb_url, options) +end