Skip to content

Commit

Permalink
Merging Gemfile.lock
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpettus committed Jul 19, 2015
2 parents 90ccde2 + 16c0235 commit cdc7611
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
!/log/.keep
/tmp
/coverage
Gemfile.lock
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ gem 'autoprefixer-rails'

gem 'nokogiri'
gem 'fastimage'
gem 'image_info'
gem 'open_uri_redirections'
gem 'mechanize'
gem 'image_info'

gem 'text'

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# evening-edition
# Evening-Edition ![travis-ci](https://travis-ci.org/jasonpettus/evening-edition.svg?branch=master) [![Coverage Status](https://coveralls.io/repos/jasonpettus/evening-edition/badge.svg?branch=master&service=github)](https://coveralls.io/github/jasonpettus/evening-edition?branch=master)
17 changes: 17 additions & 0 deletions app/assets/stylesheets/evening-edition.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,20 @@ p {
padding: 0.75em;
border-radius: 15px 15px 0 0;
}

.form_box {
text-align: center;
margin: auto;
padding: 4em;
}

.form_box input {
font-family: 'Lusitana', serif;
font-size: 1.25em;
width: 40%;
}

.login_box input {
font-family: 'Lusitana', serif;
font-size: 12px;
}
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :reset_login_error

private

def reset_login_error
session['login_error'] = false
end

def user_logged_in?
!session['user_id'].nil?
end
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class UsersController < ApplicationController

def login
user = User.find_by(username: params['username'])
user = User.find_by(email: params['email'])
if user.authenticate(params['password'])
login_user(user)
redirect_to :back
else
session['login_error'] = true
render :back
end
end
Expand All @@ -18,16 +19,16 @@ def logout
def create
@user = User.new(user_params)
if @user.save

login_user(@user)
redirect_to root_path
redirect_to new_section_path
else
render 'new'
end
end

def new
@user = User.new
@page_name = "Create Account"
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ def user_logged_in?
end

def current_user
user_logged_in ? nil : User.find(session['user_id'])
user_logged_in? ? User.find(session['user_id']) : nil
end
end
33 changes: 21 additions & 12 deletions app/models/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,38 @@ def get_articles
@entries.map! do |entry|
Article.new(set_article: entry)
end
@entries.each { |entry| self.articles << entry }
@entries.each { |entry| self.articles << entry }
end

def get_feature_imgs(articles) # => Takes 13s for 20 articles from "http://rss.nytimes.com/services/xml/rss/nyt/Science.xml" feed
feature_imgs = [] # => holds feature img srcs
articles.map do |article|
articles.map do |article|
all_img_urls = [] # => holds img srcs
img_areas = [] # => holds dimensions
response = Net::HTTP.get_response(URI.parse(article.url))
puts ">" * 50 + response.code
if response.code.match(/30\d/)
if response.code.match(/30\d/)
article_url = response.header['location']
else
article_url = article.url
end

agent = Mechanize.new
page = agent.get(article_url).images.each do |img|
all_img_urls << img.src
dimensions = FastImage.size(img.src)
dimensions ? area = dimensions.reduce(1) { |length, width| length * width } : area = 0
img_areas << area
p ">" * 25
p img
p ">" * 25
img_src = img.src
if img_src
all_img_urls << img_src
img = ImageInfo.from(img_src)[0]
img ? area = img.size.reduce(1) { |length, width| length * width } : area = 0
img_areas << area
else
all_img_urls << "NONE"
img_areas << 0
end

end

largest = img_areas.index(img_areas.max)
Expand All @@ -56,17 +66,16 @@ def get_feature_imgs(articles) # => Takes 13s for 20 articles from "http://rss.n
private
def save_articles
strip_ads
get_feature_imgs(self.articles)
get_feature_imgs(self.articles)
self.articles.each { |article| article.save }
end

def strip_ads
self.articles.each do |article|
p article.summary.nil?
unless article.summary.nil?
no_images = article.summary.gsub!(/<img.*?>/,"")
no_links = no_images.gsub!(/<a.*?<\/a>/,"")
no_links.gsub!(/<br.*?>/,"")
article.summary.gsub!(/<img.*?>/,"")
article.summary.gsub!(/<a.*?<\/a>/,"")
article.summary.gsub!(/<br.*?>/,"")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/application/_drawerbanner.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
</div>

<header class="mdl-layout__header mdl-color--orange-300">
<span id="banner" class="mdl-typography--display-3">World</span>
<span id="banner" class="mdl-typography--display-3"><%= page_name %></span>
</header>
8 changes: 8 additions & 0 deletions app/views/application/_login.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="form_box">
<%= form_tag("/users/login", method: 'POST') do %>
<p><%= text_field_tag "email", placeholder: "Email" %></p>
<p><%= text_field_tag "password", placeholder: "Password" %></p>
<p><%= text_field_tag "password_confirmation", placeholder: 'Password Confirmation' %></p>
<p><%= submit_tag "Login" %></p>
<% end %>
</div>
7 changes: 4 additions & 3 deletions app/views/application/_masthead.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
<div class="login mdl-color--orange-900">
<span class="mdl-typography--caption">
<% if user_logged_in? %>
<%= link_to "Log out", users_logout_path %>
Personalized for <%= current_user.email %> / <%= link_to "Log out", users_logout_path %>
<% else %>
Members receive personalized subscriptions,
personalized sections, and personalized delivery times.<br>
<%= link_to "Create a free account", users_new_path %> or <%= link_to "log in", users_login_path %> now.
personalized sections, and personalized delivery times.
<%= link_to "Create a free account now.", users_new_path %><br>
<%= render 'login' %>
<% end %>
</span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<body>

<%= render "application/masthead" %>
<%= render "application/drawerbanner" %>
<%= render partial: "application/drawerbanner", locals: {page_name: @page_name} %>
<main class="mdl-layout__content">
<div class="page-content mdl-color--blue-grey">
<%= yield %>
Expand Down
Binary file added app/views/users/.DS_Store
Binary file not shown.
13 changes: 7 additions & 6 deletions app/views/users/_login.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<%= form_tag("/users/login", method: 'POST') do %>
<%= text_field_tag "email", placeholder: "Email" %>
<%= text_field_tag "password", placeholder: "Password" %>
<%= text_field_tag "password_confirmation", placeholder: 'Password Confirmation' %>
<%= submit_tag "Login" %>
<% end %>
<div class="login_box">
<%= form_tag("/users/login", method: 'POST') do %>
<%= text_field_tag 'email', nil, placeholder: 'Email' %>
<%= text_field_tag 'password', nil, placeholder: 'Password' %>
<%= submit_tag 'Login' %>
<% end %>
</div>
9 changes: 3 additions & 6 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<% if @user.errors.any? %>
<ul>
<% @user.errors.full_messages.each do |error_message| %>
<li><%= error_message %></li>
<% end %>
</ul>
<% if session['login_error'] %>
<p><%= Incorrect Email or Password %></p>
<% end %>
<%= form_for @user do |f| %>
<%= f.text_field :email, placeholder: 'email' %>
<%= f.text_field :password, placeholder: 'password' %>
<%= f.text_field "password_confirmation", placeholder: 'Password Confirmation' %>
<%= f.submit value: 'Create Account' %>
<% end %>
1 change: 1 addition & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

8 changes: 4 additions & 4 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)

default_section = Section.new(title: Default)
default_section = Section.create!(title: 'Default9')

default_section.subscriptions.build(set_feed: 'http://america.aljazeera.com/content/ajam/articles.rss', title: 'Al Jazeera America')
default_section.subscriptions.build(set_feed: 'http://feeds.bbci.co.uk/news/rss.xml', title: 'BBC Top Stories')
default_section.subscriptions.build(set_feed: 'http://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml', title: 'NYTimes US')
default_section.subscriptions.create(set_feed: 'http://america.aljazeera.com/content/ajam/articles.rss', name: 'Al Jazeera America')
# default_section.subscriptions.create!(set_feed: 'http://feeds.bbci.co.uk/news/rss.xml', name: 'BBC Top Stories')
default_section.subscriptions.create!(set_feed: 'http://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml', name: 'NYTimes US')

59 changes: 59 additions & 0 deletions defaultfeeds.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
New York Times: Front Page
http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml

BBC: Top Stories
http://feeds.bbci.co.uk/news/rss.xml

CNN: Top Stories
http://rss.cnn.com/rss/cnn_topstories.rss

Al Jazeera: All Articles
http://america.aljazeera.com/content/ajam/articles.rss

Los Angeles Times: All Articles
http://www.latimes.com/rss2.0.xml

Chicago Tribune: Front Page
http://www.chicagotribune.com/rss2.0.xml

TIME
http://newsfeed.time.com/feed/&t1=

Newsweek
http://www.newsweek.com/rss

The Economist
http://www.economist.com/rss/the_world_this_week_rss.xml

Wall Street Journal
http://www.wsj.com/xml/rss/3_7085.xml

The Daily Beast
http://feeds.feedburner.com/thedailybeast/articles

The Huffington Post
http://www.huffingtonpost.com/feeds/index.xml

Sports Illustrated
http://www.si.com/rss/si_topstories.rss

WIRED
http://feeds.wired.com/wired/index

Chicagoist
http://chicagoist.com/index.xml

Politico
http://www.politico.com/rss/magazine.xml

The Week
http://theweek.com/rss.xml

Council on Foreign Relations
http://feeds.cfr.org/cfr_main

Boing Boing
http://boingboing.net/feed

AV Club
http://www.avclub.com/feed/rss/

0 comments on commit cdc7611

Please sign in to comment.