From fecc0e9e1985be2d3767664453d4776ac20897c0 Mon Sep 17 00:00:00 2001 From: luca-marie Date: Thu, 25 Aug 2016 20:50:12 +0200 Subject: Twitter controller now as helper, some more styling in CSS, bug fix --- app/assets/stylesheets/twitter.scss | 21 ++++++++++++-------- app/controllers/home_controller.rb | 17 ----------------- app/helpers/twitter_helper.rb | 22 +++++++++++++++++++++ app/views/home/_content.html.haml | 13 +++++++------ app/views/twitter/_index.html.erb | 38 ++++++++++++++++++------------------- config/routes.rb | 2 -- 6 files changed, 60 insertions(+), 53 deletions(-) diff --git a/app/assets/stylesheets/twitter.scss b/app/assets/stylesheets/twitter.scss index 1d54785..6b74cf7 100644 --- a/app/assets/stylesheets/twitter.scss +++ b/app/assets/stylesheets/twitter.scss @@ -1,5 +1,5 @@ .twitter { - // position: fixed; + position: relative; // top: 0; // right: 10px; // bottom: 0; @@ -11,13 +11,18 @@ height: 30px; font-size: 20px ; text-align: center; + margin-bottom: 20px; +} + +.twitter_list { + position: relative; } -.tweets:hover { +.tweet:hover { background-color: #ccf2ff; } -.tweets { +.tweet { border-bottom-style: solid; border-color: #bfbfbf; // display: inline; @@ -27,7 +32,7 @@ // text-align: center; } -.tweets_pic { +.tweet_pic { display: block; float: left; width: 28px; @@ -37,7 +42,7 @@ // background: hsl(0, 0%, 30%); } -.tweets_name { +.tweet_name { padding-left: 45px; padding-top: 16px; // border-bottom-style: solid; @@ -49,7 +54,7 @@ padding-top: 15px; } -.text_date { +.tweet_text_date { text-align: right; padding-top: 4px; font-size: 12px ; @@ -58,14 +63,14 @@ padding-top: 8px; } -.twitter-image-frame { +.twitter_image_frame { width: 40px; height: 40px; overflow: hidden; position: relative; } -.twitter-image-frame > img { +.twitter_image_frame > img { display: block; position: absolute; top: 0; diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 49471ff..86c36e9 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -4,25 +4,8 @@ class HomeController < ApplicationController respond_to :html def index - unless Rails.application.secrets.twitter['enabled'] == false - twitter_handle = Rails.application.secrets.twitter['twitter_handle'] - @twitter_screen_name = twitter_handle - @twitter_name = twitter_client.user(twitter_handle).name - @tweets = twitter_client.user_timeline(twitter_handle).select{ |tweet| tweet.text.start_with?('RT','@')==false} - @tweet_time = "tweeted on" - end - if logged_in? redirect_to current_user end end - - def twitter_client - Twitter::REST::Client.new do |config| - config.consumer_key = Rails.application.secrets.twitter['consumer_key'] - config.consumer_secret = Rails.application.secrets.twitter['consumer_secret'] - config.bearer_token = Rails.application.secrets.twitter['bearer_token'] - end - end - end diff --git a/app/helpers/twitter_helper.rb b/app/helpers/twitter_helper.rb index bb3ed2d..9fd4ffd 100644 --- a/app/helpers/twitter_helper.rb +++ b/app/helpers/twitter_helper.rb @@ -1,2 +1,24 @@ module TwitterHelper + + def twitter_client + Twitter::REST::Client.new do |config| + config.consumer_key = Rails.application.secrets.twitter['consumer_key'] + config.consumer_secret = Rails.application.secrets.twitter['consumer_secret'] + config.bearer_token = Rails.application.secrets.twitter['bearer_token'] + end + end + + def twitter_handle + Rails.application.secrets.twitter['twitter_handle'] + end + + def twitter_name + twitter_client.user(twitter_handle).name + end + + def tweets + twitter_client.user_timeline(twitter_handle).select{ |tweet| tweet.text.start_with?('RT','@')==false} + end end + +# unless Rails.application.secrets.twitter['enabled'] == false diff --git a/app/views/home/_content.html.haml b/app/views/home/_content.html.haml index 725c391..6efd2d0 100644 --- a/app/views/home/_content.html.haml +++ b/app/views/home/_content.html.haml @@ -1,14 +1,15 @@ -.left.column +.row %h1= t(:welcome, :provider => APP_CONFIG[:domain]) .p=t(:welcome_message_html) - = home_page_buttons - -.right.column - = render :partial => 'twitter/index' +.row + .col-md-9 + = home_page_buttons + .col-md-3 + = render 'twitter/index' - if Rails.env == 'development' .row %hr %p - = link_to "make donation", new_payment_path if APP_CONFIG[:payment].present? += link_to "make donation", new_payment_path if APP_CONFIG[:payment].present? diff --git a/app/views/twitter/_index.html.erb b/app/views/twitter/_index.html.erb index 9825afa..3dab567 100644 --- a/app/views/twitter/_index.html.erb +++ b/app/views/twitter/_index.html.erb @@ -1,26 +1,24 @@ -<% unless Rails.application.secrets.twitter['enabled'] == false %> -
+