diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..d4948a0 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,7 @@ +class HomeController < ApplicationController + def index + @tracks = LastFM::Chart.getTopTracks 25 + @artists = LastFM::Chart.getTopArtists 10 + end + +end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000..23de56a --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml new file mode 100644 index 0000000..85085a2 --- /dev/null +++ b/app/views/home/index.html.haml @@ -0,0 +1,47 @@ +#home + = image_tag "cnt/9minutes-is-a-mashup-of-lastfm-and-youtube.png", :class=>"right" + = link_to image_tag("cnt/sign-up.png", :class=>"left"), '#' + %br.clean + %br + %br + .right + %h2.headline.small + %span.left Top Tracks + .navigate + %a.left + %a.right + %ul.songs.short{:count=>"5"} + - @tracks.track.each_with_index do |track, i| + %li + = image_tag "ico/play.png", :class=>"play" + = image_tag "ico/add.png", :class=>"add" + %span + %span= (i+1).to_s+"." + = track.name + =raw " by " + = link_to trimString(track.artist.name, 50), :controller=>"artists",:action=>"show",:id=>CGI.escape(track.artist.name) + .left + %h2.headline.small + %span.left Top Artists + .navigate + %a.left + %a.right + %ul.artists.big{:count=>"2"} + - @artists.artist.each do |artist| + %li + = link_to :controller=>:artists,:action=>:show,:id=>CGI.escape(artist.name) do + = image_tag validate_img_url(artist.image, "artist", :extralarge) + %p + = trimString(artist.name, 30) + %br>< + =raw "#{artist.listeners} Listeners, #{artist.playcount} Plays" + %br.clean + .bottom + %hr + %p.left + =raw "©2011 by 9minutes" + = link_to "Home", "#" + = link_to "Terms of Service", "#" + = link_to "Contact", "#" + = link_to "About", "#" + \ No newline at end of file diff --git a/config/initializers/lastfm_api_key.rb b/config/initializers/lastfm_api_key.rb index 5c268fe..8dd9b36 100644 --- a/config/initializers/lastfm_api_key.rb +++ b/config/initializers/lastfm_api_key.rb @@ -2,5 +2,6 @@ require 'LastFM/LastFMRequest' require 'LastFM/Artist' require 'LastFM/Album' require 'LastFM/Track' +require 'LastFM/Chart' LastFM::LastFMRequest::api_key = '4c32e360f68553ec8fdca3711456b4f9' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5ba63ff..5f85ada 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,8 @@ Nineminutes::Application.routes.draw do + resources :artists, :constraints => { :id => /.*/ } resources :search + resources :home # The priority is based upon order of creation: # first created -> highest priority. @@ -50,7 +52,7 @@ Nineminutes::Application.routes.draw do # You can have the root of your site routed with "root" # just remember to delete public/index.html. - # root :to => "welcome#index" + root :to => "home#index" # See how all your routes lay out with "rake routes" diff --git a/lib/LastFM/Chart.rb b/lib/LastFM/Chart.rb new file mode 100644 index 0000000..aaff786 --- /dev/null +++ b/lib/LastFM/Chart.rb @@ -0,0 +1,12 @@ +module LastFM + class Chart < LastFMRequest + def self.getTopArtists limit = nil, page = nil + chart_request "getTopArtists", "artists", limit, page + end + + def self.getTopTracks limit = nil, page = nil + chart_request "getTopTracks", "tracks", limit, page + end + end + +end \ No newline at end of file diff --git a/lib/LastFM/LastFMRequest.rb b/lib/LastFM/LastFMRequest.rb index 2e34199..3a1451e 100644 --- a/lib/LastFM/LastFMRequest.rb +++ b/lib/LastFM/LastFMRequest.rb @@ -45,6 +45,10 @@ module LastFM def self.track_request method, node, q, artist = nil, limit = nil, page = nil prepare_result method, node, get('/', :query => { :method => "track.#{method.to_s}", :track => q, :artist => artist, :limit => limit, :page => page }) end + + def self.chart_request method, node, limit = nil, page = nil + prepare_result method, node, get('/', :query => { :method => "chart.#{method.to_s}", :limit => limit, :page => page }) + end private diff --git a/public/images/cnt/9minutes-is-a-mashup-of-lastfm-and-youtube.png b/public/images/cnt/9minutes-is-a-mashup-of-lastfm-and-youtube.png new file mode 100644 index 0000000..c2e753f Binary files /dev/null and b/public/images/cnt/9minutes-is-a-mashup-of-lastfm-and-youtube.png differ diff --git a/public/images/cnt/sign-up.png b/public/images/cnt/sign-up.png new file mode 100644 index 0000000..536734f Binary files /dev/null and b/public/images/cnt/sign-up.png differ diff --git a/public/images/ico/navigate.png b/public/images/ico/navigate.png new file mode 100644 index 0000000..a5addc2 Binary files /dev/null and b/public/images/ico/navigate.png differ diff --git a/public/index.html b/public/index.html deleted file mode 100644 index 75d5edd..0000000 --- a/public/index.html +++ /dev/null @@ -1,239 +0,0 @@ - - - - Ruby on Rails: Welcome aboard - - - - -
- - -
- - - - -
-

Getting started

-

Here’s how to get rolling:

- -
    -
  1. -

    Use rails generate to create your models and controllers

    -

    To see all available options, run it without parameters.

    -
  2. - -
  3. -

    Set up a default route and remove or rename this file

    -

    Routes are set up in config/routes.rb.

    -
  4. - -
  5. -

    Create your database

    -

    Run rake db:migrate to create your database. If you're not using SQLite (the default), edit config/database.yml with your username and password.

    -
  6. -
-
-
- - -
- - diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 3cb2f3d..832152a 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -10,6 +10,9 @@ $(document).ready(function(){ initPictureOverlay(); initArtistDescription(); + + initTopMusic(); + navigateTopMusic(); }); $(window).load(function() { @@ -48,6 +51,38 @@ function initPictureOverlay(){ } +function initTopMusic(){ + $('#home .songs li').each(function(){ + if($(this).parent().children().index(this)>=5) $(this).hide(); + }); + $('#home .artists li').each(function(){ + if($(this).parent().children().index(this)>=2) $(this).hide(); + }); +} + +function navigateTopMusic(){ + $('#home .navigate a').live('click', function(){ + $selector = $(this).closest("h2").next("ul"); + $id = $selector.children("li:visible").first(); + $start = $id.parent().children().index($id); + $count = parseInt($selector.attr("count")); + $size = $selector.children().size(); + + if($(this).hasClass("left")) { + $start -= $count; + if($start < 0) return; + } + else { + $start += $count; + if($start >= $size) return; + } + + $selector.children().hide(); + for($i=$start;$i<$start+$count;$i++) + $selector.children("li:eq("+$i+")").show(); + }); +} + function ajj(){ /* $('#myajax').load('/artists', function() { diff --git a/public/stylesheets/layout.css b/public/stylesheets/layout.css index b10164b..d556a53 100644 --- a/public/stylesheets/layout.css +++ b/public/stylesheets/layout.css @@ -66,13 +66,13 @@ a { text-decoration: none; color: #7d8791; } margin: 0 auto; } #head { height: 140px; } -#head h1 { padding-top: 60px; float: left; } +#head h1 { padding-top: 55px; float: left; } #search_form { position: relative; } #search_form .wrap { width: 400px; /* 300 + 28*/ height: 38px; - margin-top: 60px; + margin-top: 50px; border: 1px solid #dfe4e8; border-radius: 7px; -moz-border-radius: 7px; @@ -108,7 +108,7 @@ a { text-decoration: none; color: #7d8791; } #search_form .selection { position: absolute; - right: 50px; top: 65px; + right: 50px; top: 55px; font-family: AauxNextBold, "Segoe UI", Arial, sans-serif; font-size: 14px; color: #868f98; @@ -119,6 +119,7 @@ a { text-decoration: none; color: #7d8791; } width: 65px; height: 29px; line-height: 29px; display: block; + opacity: 0.85; } #search_form .selection > span { text-transform: uppercase;} #search_form .box @@ -182,8 +183,10 @@ a { text-decoration: none; color: #7d8791; } .headline { - color: #7d8791; + color: #363d3f; font-size: 32px; + overflow: hidden; + vertical-align: middle; } .headline, .headline span { @@ -539,4 +542,52 @@ div[wheel] > div { display: none; opacity: 0.0; position: relative; } } .overlay.album .mid li span { color: White; font-family: AauxNextMedium, "Segoe UI", Arial, sans-serif;} .overlay.album .mid li:first-child { border-top: 0; } -.overlay.album .mid li:last-child { border-bottom: 0; } \ No newline at end of file +.overlay.album .mid li:last-child { border-bottom: 0; } + + + + + + + + +.navigate +{ + width: 44px; + height: 20px; + float: left; + margin-top: 5px; + padding-left: 10px; +} +.navigate .left, .navigate .right +{ + width: 20px; + height: 20px; + background: url('../images/ico/navigate.png') 0 0; + cursor: pointer; +} +.navigate .right { background-position: -24px 0;} +.blocked +{ + opacity: 0.5; + cursor: default!important; +} + +#home .bottom hr +{ + margin-top: 40px; + background: White; + height: 1px; + border: 0; +} +#home .bottom { font-size: 12px; } +#home .bottom a +{ + margin-left: 10px; + color: #cbd3d9; +} +#home .bottom a:first-child { margin-left: 20px;} +#home .bottom a:hover +{ + color: #40474c; +} \ No newline at end of file diff --git a/test/functional/home_controller_test.rb b/test/functional/home_controller_test.rb new file mode 100644 index 0000000..0d9bb47 --- /dev/null +++ b/test/functional/home_controller_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class HomeControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + end + +end diff --git a/test/unit/helpers/home_helper_test.rb b/test/unit/helpers/home_helper_test.rb new file mode 100644 index 0000000..4740a18 --- /dev/null +++ b/test/unit/helpers/home_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class HomeHelperTest < ActionView::TestCase +end