From e1e98d0229b8b79de2105515f0312903a23dc335 Mon Sep 17 00:00:00 2001 From: luca-marie Date: Wed, 24 Aug 2016 15:23:07 +0200 Subject: Update with Twitter --- app/assets/stylesheets/application.scss | 1 + app/assets/stylesheets/twitter.scss | 76 +++++++++++++++++++++++++++++++++ app/controllers/home_controller.rb | 17 ++++++++ app/controllers/twitter_controller.rb | 19 +++++++++ app/helpers/twitter_helper.rb | 2 + app/views/home/_content.html.haml | 6 ++- app/views/home/index.html.haml | 3 +- app/views/twitter/_index.html.erb | 26 +++++++++++ 8 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 app/assets/stylesheets/twitter.scss create mode 100644 app/controllers/twitter_controller.rb create mode 100644 app/helpers/twitter_helper.rb create mode 100644 app/views/twitter/_index.html.erb (limited to 'app') diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 856a559..f42044b 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,6 +16,7 @@ // LEAP web app specific overrides // @import "leap"; +@import "twitter"; // And finally bootswatch style itself // @import "bootswatch/cerulean/bootswatch"; diff --git a/app/assets/stylesheets/twitter.scss b/app/assets/stylesheets/twitter.scss new file mode 100644 index 0000000..1d54785 --- /dev/null +++ b/app/assets/stylesheets/twitter.scss @@ -0,0 +1,76 @@ +.twitter { + // position: fixed; + // top: 0; + // right: 10px; + // bottom: 0; + // overflow: auto; + // width: 250px; +} +.twitter_header { + padding-top: 8px; + height: 30px; + font-size: 20px ; + text-align: center; +} + +.tweets:hover { + background-color: #ccf2ff; + } + +.tweets { + border-bottom-style: solid; + border-color: #bfbfbf; + // display: inline; + // height: 32px; + // width: 100%; + // position: absolute; + // text-align: center; +} + +.tweets_pic { + display: block; + float: left; + width: 28px; + height: 33px; + padding-left: 8px; + padding-top: 8px; + // background: hsl(0, 0%, 30%); +} + +.tweets_name { + padding-left: 45px; + padding-top: 16px; + // border-bottom-style: solid; + // border-color: #00bfff; +} + +.tweet_text { + padding-left: 8px; + padding-top: 15px; +} + +.text_date { + text-align: right; + padding-top: 4px; + font-size: 12px ; +} +.twitter_footer { + padding-top: 8px; +} + +.twitter-image-frame { + width: 40px; + height: 40px; + overflow: hidden; + position: relative; +} + +.twitter-image-frame > img { + display: block; + position: absolute; + top: 0; + bottom: 0; + left: 0; + width: 100%; + margin: auto; +} diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 86c36e9..49471ff 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -4,8 +4,25 @@ 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/controllers/twitter_controller.rb b/app/controllers/twitter_controller.rb new file mode 100644 index 0000000..0f6a773 --- /dev/null +++ b/app/controllers/twitter_controller.rb @@ -0,0 +1,19 @@ +class TwitterController < ApplicationController + 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 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 + end +end diff --git a/app/helpers/twitter_helper.rb b/app/helpers/twitter_helper.rb new file mode 100644 index 0000000..bb3ed2d --- /dev/null +++ b/app/helpers/twitter_helper.rb @@ -0,0 +1,2 @@ +module TwitterHelper +end diff --git a/app/views/home/_content.html.haml b/app/views/home/_content.html.haml index 67e4533..725c391 100644 --- a/app/views/home/_content.html.haml +++ b/app/views/home/_content.html.haml @@ -1,10 +1,12 @@ -.row +.left.column %h1= t(:welcome, :provider => APP_CONFIG[:domain]) .p=t(:welcome_message_html) -.row = home_page_buttons +.right.column + = render :partial => 'twitter/index' + - if Rails.env == 'development' .row %hr diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 147cacd..7f07460 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -3,7 +3,8 @@ #main .container-fluid = render 'home/content' + #push -# #push is used for sticky footer in bootstrap 2. remove when upgrading to bootstrap 3 #footer - = render 'layouts/footer' \ No newline at end of file + = render 'layouts/footer' diff --git a/app/views/twitter/_index.html.erb b/app/views/twitter/_index.html.erb new file mode 100644 index 0000000..9825afa --- /dev/null +++ b/app/views/twitter/_index.html.erb @@ -0,0 +1,26 @@ +<% unless Rails.application.secrets.twitter['enabled'] == false %> +
+ + + <% @tweets.each do |e| %> +
+ + +
+ @<%= @twitter_screen_name %> +
+
+ <%= " #{e.text}" %> +
+
+ <%= @tweet_time %> <% t = e.created_at%> <%="#{t.strftime("%m/%d/%Y")}"%> +
+
+ <% end %> + +
+ <% end %> -- cgit v1.2.3