diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/images/Twitter_Logo_Blue.png | bin | 0 -> 4298 bytes | |||
-rw-r--r-- | app/assets/stylesheets/application.scss | 1 | ||||
-rw-r--r-- | app/assets/stylesheets/twitter.scss | 72 | ||||
-rw-r--r-- | app/helpers/twitter_helper.rb | 46 | ||||
-rw-r--r-- | app/views/home/_content.html.haml | 31 | ||||
-rw-r--r-- | app/views/twitter/_index.html.erb | 26 |
6 files changed, 164 insertions, 12 deletions
diff --git a/app/assets/images/Twitter_Logo_Blue.png b/app/assets/images/Twitter_Logo_Blue.png Binary files differnew file mode 100644 index 0000000..b5eebc8 --- /dev/null +++ b/app/assets/images/Twitter_Logo_Blue.png 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..b2233d0 --- /dev/null +++ b/app/assets/stylesheets/twitter.scss @@ -0,0 +1,72 @@ +.twitter { + position: relative; +} + +.twitter_header { + font-size: 16px; + text-align: left; + margin-bottom: 55px; + padding: 10px 8px; +} + +.twitter_id { + position: absolute; +} + +.twitter_image_frame { + display: block; + width: 40px; + height: 40px; + overflow: hidden; + position: absolute; + left: 0; + top: 0; + } + +.twitter_image_frame > img { + display: block; + position: absolute; + top: 0; + bottom: 0; + left: 30; + width: 100%; + margin: auto; + } + +.twitter_name { + padding-left: 55px; + line-height: 20px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + font-size: 16px; +} + +// Body = displays tweets +.twitter_list { + box-sizing: border-box; +} + +.tweet { + border-top-style: solid; + border-color: lightgrey; + padding: 10px 8px; +} + +.tweet_text { +box-sizing: border-box; +} + +.tweet_text_date { + text-align: right; + padding-top: 4px; + font-size: 12px ; +} + +.twitter_footer { + border-top-style: solid; + border-color: lightgrey; + padding: 10px 8px; + font-style: italic; + font-size: 12px; +} diff --git a/app/helpers/twitter_helper.rb b/app/helpers/twitter_helper.rb new file mode 100644 index 0000000..f824a03 --- /dev/null +++ b/app/helpers/twitter_helper.rb @@ -0,0 +1,46 @@ +module TwitterHelper + def twitter_enabled + if Rails.application.secrets.twitter + Rails.application.secrets.twitter['enabled'] == true + end + end + + def twitter_client + Twitter::REST::Client.new do |config| + config.bearer_token = Rails.application.secrets.twitter['bearer_token'] + end + end + + def twitter_handle + Rails.application.secrets.twitter['twitter_handle'] + end + + def twitter_user_info + $twitter_user_info ||= [] + end + + def update_twitter_info + twitter_user_info[0] = Time.now + twitter_user_info[1] = twitter_client.user(twitter_handle).name + twitter_user_info[2] = twitter_client.user_timeline(twitter_handle).select{ |tweet| tweet.text.start_with?('RT','@')==false}.take(3) + end + + def cached_info + if twitter_user_info[0] == nil + update_twitter_info + else + if Time.now > twitter_user_info[0] + 15.minutes + update_twitter_info + end + end + twitter_user_info + end + + def twitter_name + cached_info[1] + end + + def tweets + cached_info[2] + end +end diff --git a/app/views/home/_content.html.haml b/app/views/home/_content.html.haml index 67e4533..5341189 100644 --- a/app/views/home/_content.html.haml +++ b/app/views/home/_content.html.haml @@ -1,12 +1,19 @@ -.row - %h1= t(:welcome, :provider => APP_CONFIG[:domain]) - .p=t(:welcome_message_html) - -.row - = home_page_buttons - - - if Rails.env == 'development' - .row - %hr - %p - = link_to "make donation", new_payment_path if APP_CONFIG[:payment].present? +.col-md-8 + .row + %h1= t(:welcome, :provider => APP_CONFIG[:domain]) + .p=t(:welcome_message_html) + + .row + = home_page_buttons + +.col-md-1 + +.col-md-3 + .row + = render 'twitter/index' + + - if Rails.env == 'development' + .row + %hr + %p + = 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 new file mode 100644 index 0000000..a7ebd1b --- /dev/null +++ b/app/views/twitter/_index.html.erb @@ -0,0 +1,26 @@ +<% if twitter_enabled == true %> + <div class="twitter"> + + <div class="twitter_header"> + <div class="twitter_id"> + <div class="twitter_image_frame"><%= image_tag("Twitter_Logo_Blue.png") %></div> + <div class="twitter_name"><%= twitter_name%><br><a href="https://twitter.com/loadtocode">@<%= twitter_handle %></a></div> + </div> + </div> + + <div class="twitter_list"> + <% tweets.each do |e| %> + <div class="tweet"> + <div class="tweet_text"><%= " #{e.text}" %> + </div> + <div class="tweet_text_date">tweeted on <% t = e.created_at%> <%= t.strftime("%m/%d/%y").to_s %> + </div> + </div> + <% end %> + </div> + + <div class="twitter_footer"> + <p>This feed uses a Ruby interface to access the Twitter API. Within LEAP Twitter does not track you.</p> + </div> +</div> +<% end %> |