Created
July 19, 2014 16:23
-
-
Save alekhinen/1ff79e4342404a88d21c to your computer and use it in GitHub Desktop.
Index page for views/blog/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.page-content-container | |
%h1.big blog | |
.padder100 | |
.metaPostsContainer | |
///////////////////////////////////////////////////////////////////////////// | |
// Pull each post out of @posts ///////////////////////////////////////////// | |
- @posts.each do |post| | |
// Set variables. ///////////////////////////////////// | |
- @type = post["type"] # the type of post | |
- @noteCount = post["note_count"] # the note count | |
- @url = post["post_url"] # the url for the post | |
- @currentTime = Time.now | |
- @postTime = Time.at(post["timestamp"]) | |
- @elapsedTime = (@currentTime - @postTime) | |
- mm, ss = @elapsedTime.divmod(60) | |
- hh, mm = mm.divmod(60) | |
- dd, hh = hh.divmod(24) | |
/////////////////////////////////////////////////////////////////////////// | |
// Photo ////////////////////////////////////////////////////////////////// | |
- if @type == "photo" | |
// Set variables //////////////////////////////////// | |
- @photos = post["photos"] # the array of photos | |
- @caption = post["caption"] # the caption of the post | |
.postContainer.photoContainer | |
/////////////////////////////////////////////////// | |
// Pull each photo from @photos /////////////////// | |
- @photos.each do |photo| | |
// Set variables //////////////////////////////// | |
- @photoURL = photo["original_size"]["url"] | |
%img{:src => "#{@photoURL}"} | |
.infoSection | |
// sanitize removes any html tags embedded in @caption | |
%p #{sanitize @caption} | |
// displays note count and time of post | |
%a{:href => "#{@url}"} | |
- if dd > 0 | |
- if dd == 1 | |
#{dd} day ago | |
- else | |
#{dd} days ago | |
- elsif hh > 0 | |
- if hh == 1 | |
#{hh} hour ago | |
- else | |
#{hh} hours ago | |
- elsif mm > 0 | |
- if mm == 1 | |
#{mm} minute ago | |
- else | |
#{mm} minutes ago | |
- else | |
#{ss.round} seconds ago | |
- if @noteCount == 1 | |
\/ #{@noteCount} note | |
- if @noteCount != 1 | |
\/ #{@noteCount} notes | |
///////////////////////////////////////////////////////////////////////// | |
// Text ///////////////////////////////////////////////////////////////// | |
- if @type == "text" | |
- @title = post["title"] | |
- @body = post["body"] | |
.postContainer.textContainer | |
%a.heady{:href => "#{@url}"} #{@title} | |
#{@body.html_safe} | |
.infoSection | |
// displays note count and time of post | |
%a{:href => "#{@url}"} | |
- if dd > 0 | |
- if dd == 1 | |
#{dd} day ago | |
- else | |
#{dd} days ago | |
- elsif hh > 0 | |
- if hh == 1 | |
#{hh} hour ago | |
- else | |
#{hh} hours ago | |
- elsif mm > 0 | |
- if mm == 1 | |
#{mm} minute ago | |
- else | |
#{mm} minutes ago | |
- else | |
#{ss.round} seconds ago | |
- if @noteCount == 1 | |
\/ #{@noteCount} note | |
- if @noteCount != 1 | |
\/ #{@noteCount} notes | |
= paginate @posts | |
.padder100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your article has helped me a lot to get started with the Tumblr API, thanks! I keep getting stuck on this one problem though. I get this error with all the variables: "no implicit conversion of String into Integer". I've tried a lot of stuff but can't seem to get around this. Can you help?