Skip to content
Browse files

Add retweeted functional.

  • Loading branch information...
1 parent adcc315 commit 32aba77e5a43707ac337b483a3e1db068c796df4 @paulmillr paulmillr committed
Showing with 45 additions and 29 deletions.
  1. +9 −1 app/lib/view_helper.coffee
  2. +4 −5 app/models/tweets.coffee
  3. +4 −2 app/styles/main.styl
  4. +28 −21 app/views/templates/tweet.hbs
View
10 app/lib/view_helper.coffee
@@ -52,6 +52,14 @@ Handlebars.registerHelper 'with_user', (options) ->
context = mediator.user.toJSON() or {}
Handlebars.helpers.with.call(this, context, options)
+Handlebars.registerHelper 'transform_if_retweeted', (options) ->
+ if this.retweeted_status
+ data = _.clone(this.retweeted_status)
+ data.retweeter = this.user
+ options.fn(data)
+ else
+ options.fn(this)
+
Handlebars.registerHelper 'auto_link', (options) ->
new Handlebars.SafeString twttr.txt.autoLink options.fn this
@@ -59,6 +67,6 @@ Handlebars.registerHelper 'format_date', (options) ->
date = new Date options.fn this
new Handlebars.SafeString moment(date).fromNow()
-Handlebars.registerHelper 'unless_source_is_web', (source, options) ->
+Handlebars.registerHelper 'unless_is_web', (source, options) ->
string = if source is 'web' then '' else options.fn this
new Handlebars.SafeString string
View
9 app/models/tweets.coffee
@@ -29,15 +29,14 @@ module.exports = class Tweets extends Collection
provider.T.currentUser.homeTimeline @processTweets
processTweets: (response) =>
- console.debug 'Tweets#processTweets', response
-
- # Trigger before updating the collection to hide the loading spinner
- @trigger 'load'
-
tweets = if response?.array
_(response.array).map (tweet) => tweet.attributes
else
[]
+
+ console.debug 'Tweets#processTweets', tweets
+ # Trigger before updating the collection to hide the loading spinner
+ @trigger 'load'
# Update the collection
@reset tweets
View
6 app/styles/main.styl
@@ -172,5 +172,7 @@ h1
&-footer
overflow: hidden
color: $gray
- a, a:visited
- color: $gray
+ &-created-at, &-source > a
+ color: $gray
+ &-retweeter
+ margin-bottom: 0
View
49 app/views/templates/tweet.hbs
@@ -1,21 +1,28 @@
-<div class="tweet-content">
- <header class="tweet-header">
- <a href="https://twitter.com/{{user.screen_name}}">
- <img class="avatar" src="{{user.profile_image_url}}" alt="Paul Miller" />
- <strong class="tweet-author-full-name">
- {{user.name}}
- </strong>
- </a>
- </header>
- <p class="tweet-text">{{#auto_link}}{{text}}{{/auto_link}}</p>
- <footer class="tweet-footer">
- <a href="http://twitter.com/{{user.screen_name}}/status/{{id_str}}">
- <time datetime="{{created_at}}">
- {{#format_date}}{{created_at}}{{/format_date}}
- </time>
- </a>
- {{#unless_source_is_web source}}
- via <span class="tweet-client">{{{source}}}</span>
- {{/unless_source_is_web}}
- </footer>
-</div>
+{{#transform_if_retweeted}}
+ <div class="tweet-content">
+ <header class="tweet-header">
+ <a href="https://twitter.com/{{user.screen_name}}">
+ <img class="avatar" src="{{user.profile_image_url}}" alt="" />
+ <strong class="tweet-author-full-name">
+ {{user.name}}
+ </strong>
+ </a>
+ </header>
+ <p class="tweet-text">{{#auto_link}}{{text}}{{/auto_link}}</p>
+ <footer class="tweet-footer">
+ <a href="http://twitter.com/{{user.screen_name}}/status/{{id_str}}">
+ <time class="tweet-created-at" datetime="{{created_at}}">
+ {{#format_date}}{{created_at}}{{/format_date}}
+ </time>
+ </a>
+ {{#unless_is_web source}}
+ via <span class="tweet-source">{{{source}}}</span>
+ {{/unless_is_web}}
+ {{#if retweeter}}
+ <p class="tweet-retweeter">
+ Retweeted by <a class="tweet-retweeter-username" href="https://twitter.com/{{retweeter.screen_name}}">{{retweeter.screen_name}}</a>
+ </p>
+ {{/if}}
+ </footer>
+ </div>
+{{/transform_if_retweeted}}

0 comments on commit 32aba77

Please sign in to comment.
Something went wrong with that request. Please try again.