start of feed and profile integration

This commit is contained in:
Kyle Drake 2014-04-29 00:03:48 -07:00
parent d23ffc3b17
commit 44311e4008
10 changed files with 386 additions and 22 deletions

34
app.rb
View file

@ -31,7 +31,7 @@ error do
EmailWorker.perform_async({ EmailWorker.perform_async({
from: 'web@neocities.org', from: 'web@neocities.org',
to: 'errors@neocities.org', to: 'errors@neocities.org',
subject: "[NeoCities Error] #{env['sinatra.error'].class}: #{env['sinatra.error'].message}", subject: "[Neocities Error] #{env['sinatra.error'].class}: #{env['sinatra.error'].message}",
body: "#{request.request_method} #{request.path}\n\n" + body: "#{request.request_method} #{request.path}\n\n" +
(current_site ? "Site: #{current_site.username}\nEmail: #{current_site.email}\n\n" : '') + (current_site ? "Site: #{current_site.username}\nEmail: #{current_site.email}\n\n" : '') +
env['sinatra.error'].backtrace.join("\n") env['sinatra.error'].backtrace.join("\n")
@ -63,7 +63,14 @@ get '/edit_mockup' do
end end
get '/profile_mockup' do get '/profile_mockup' do
erb :'profile_mockup' require_login
erb :'profile_mockup', locals: {site: current_site}
end
get '/profile/:sitename' do |sitename|
@title = "#{sitename}.neocities.org"
site = Site[username: sitename]
erb :'profile', locals: {site: site}
end end
get '/tags_mockup' do get '/tags_mockup' do
@ -83,6 +90,11 @@ get '/stats_mockup' do
end end
get '/?' do get '/?' do
if current_site
require_login
halt erb :'home', locals: {site: current_site}
end
if SimpleCache.expired?(:sites_count) if SimpleCache.expired?(:sites_count)
@sites_count = SimpleCache.store :sites_count, Site.count.roundup(100), 600 # 10 Minutes @sites_count = SimpleCache.store :sites_count, Site.count.roundup(100), 600 # 10 Minutes
else else
@ -116,7 +128,7 @@ post '/plan/create' do
from: 'web@neocities.org', from: 'web@neocities.org',
reply_to: current_site.email, reply_to: current_site.email,
to: 'contact@neocities.org', to: 'contact@neocities.org',
subject: "[NeoCities] You've become a supporter!", subject: "[Neocities] You've become a supporter!",
body: Tilt.new('./views/templates/email_subscription.erb', pretty: true).render(self, plan_name: plan_name) body: Tilt.new('./views/templates/email_subscription.erb', pretty: true).render(self, plan_name: plan_name)
}) })
end end
@ -263,7 +275,7 @@ post '/create' do
end end
session[:id] = @site.id session[:id] = @site.id
redirect '/dashboard' redirect '/'
else else
@site.errors.add :captcha, 'You must type in the two words correctly! Try again.' if !recaptcha_is_valid @site.errors.add :captcha, 'You must type in the two words correctly! Try again.' if !recaptcha_is_valid
@ -299,7 +311,7 @@ post '/signin' do
end end
session[:id] = site.id session[:id] = site.id
redirect '/dashboard' redirect '/'
else else
flash[:error] = 'Invalid login.' flash[:error] = 'Invalid login.'
flash[:username] = params[:username] flash[:username] = params[:username]
@ -614,7 +626,7 @@ post '/send_password_reset' do
end end
body = <<-EOT body = <<-EOT
Hello! This is the NeoCities cat, and I have received a password reset request for your e-mail address. Purrrr. Hello! This is the Neocities cat, and I have received a password reset request for your e-mail address. Purrrr.
Go to this URL to reset your password: http://neocities.org/password_reset_confirm?token=#{token} Go to this URL to reset your password: http://neocities.org/password_reset_confirm?token=#{token}
@ -625,7 +637,7 @@ Token: #{token}
If you didn't request this reset, you can ignore it. Or hide under a bed. Or take a nap. Your call. If you didn't request this reset, you can ignore it. Or hide under a bed. Or take a nap. Your call.
Meow, Meow,
the NeoCities Cat the Neocities Cat
EOT EOT
body.strip! body.strip!
@ -633,12 +645,12 @@ the NeoCities Cat
EmailWorker.perform_async({ EmailWorker.perform_async({
from: 'web@neocities.org', from: 'web@neocities.org',
to: params[:email], to: params[:email],
subject: '[NeoCities] Password Reset', subject: '[Neocities] Password Reset',
body: body body: body
}) })
end end
flash[:success] = 'If your email was valid (and used by a site), the NeoCities Cat will send an e-mail to your account with password reset instructions.' flash[:success] = 'If your email was valid (and used by a site), the Neocities Cat will send an e-mail to your account with password reset instructions.'
redirect '/' redirect '/'
end end
@ -712,7 +724,7 @@ post '/contact' do
from: 'web@neocities.org', from: 'web@neocities.org',
reply_to: params[:email], reply_to: params[:email],
to: 'contact@neocities.org', to: 'contact@neocities.org',
subject: "[NeoCities Contact]: #{params[:subject]}", subject: "[Neocities Contact]: #{params[:subject]}",
body: params[:body] body: params[:body]
}) })
@ -863,7 +875,7 @@ def current_site
end end
def title def title
out = "NeoCities" out = "Neocities"
return out if request.path == '/' return out if request.path == '/'
return "#{out} - #{@title}" if @title return "#{out} - #{@title}" if @title
"#{out} - #{request.path.gsub('/', '').capitalize}" "#{out} - #{request.path.gsub('/', '').capitalize}"

View file

@ -53,7 +53,7 @@ class Site < Sequel::Model
LOSSY_IMAGE_REGEX = /jpg|jpeg/ LOSSY_IMAGE_REGEX = /jpg|jpeg/
HTML_REGEX = /htm|html/ HTML_REGEX = /htm|html/
SCREENSHOT_RESOLUTIONS = ['235x141', '105x63', '270x162'] SCREENSHOT_RESOLUTIONS = ['235x141', '105x63', '270x162', '37x37', '146x88', '302x182', '90x63', '82x62']
THUMBNAIL_RESOLUTIONS = ['105x63'] THUMBNAIL_RESOLUTIONS = ['105x63']
many_to_one :server many_to_one :server
@ -91,6 +91,11 @@ class Site < Sequel::Model
end end
end end
def tip_amount
return '0.00' if tips_dataset.count == 0
'31.337'
end
def username=(val) def username=(val)
super val.downcase super val.downcase
end end
@ -373,10 +378,18 @@ class Site < Sequel::Model
'Supporter Plan' 'Supporter Plan'
end end
def latest_events
events_dataset.order(:id.desc).limit(10).all
end
def title def title
values[:title] || values[:username] values[:title] || values[:username]
end end
def hits_english
values[:hits].to_s.reverse.gsub(/...(?=.)/,'\&,').reverse
end
def screenshots_delete(filename) def screenshots_delete(filename)
SCREENSHOT_RESOLUTIONS.each do |res| SCREENSHOT_RESOLUTIONS.each do |res|
begin begin

View file

@ -38,7 +38,7 @@ describe 'signup' do
it 'succeeds with valid data' do it 'succeeds with valid data' do
fill_in_valid fill_in_valid
click_button 'Create Home Page' click_button 'Create Home Page'
page.must_have_content 'My Website' page.must_have_content 'Your Feed'
assert_equal( assert_equal(
true, true,
File.exist?(File.join(Site::SITE_FILES_ROOT, @site[:username], 'index.html')) File.exist?(File.join(Site::SITE_FILES_ROOT, @site[:username], 'index.html'))
@ -48,7 +48,7 @@ describe 'signup' do
it 'fails to create for existing site' do it 'fails to create for existing site' do
fill_in_valid fill_in_valid
click_button 'Create Home Page' click_button 'Create Home Page'
page.must_have_content 'My Website' page.must_have_content 'Your Feed'
Capybara.reset_sessions! Capybara.reset_sessions!
visit_signup visit_signup
fill_in 'username', with: @site[:username] fill_in 'username', with: @site[:username]
@ -138,6 +138,6 @@ describe 'signin' do
fill_in 'username', with: site[:username] fill_in 'username', with: site[:username]
fill_in 'password', with: site[:password] fill_in 'password', with: site[:password]
click_button 'Sign In' click_button 'Sign In'
page.must_have_content 'My Website' page.must_have_content 'Your Feed'
end end
end end

12
views/_follows.erb Normal file
View file

@ -0,0 +1,12 @@
<% if (!is_current_site && site.followings_dataset.count > 0) || is_current_site %>
<h3>Following</h3>
<div class="following">
<% if site.followings_dataset.count == 0 %>
<p>You are not following any sites yet. Add some by <a href="/browse">browsing sites</a> or looking at your tags.
<% else %>
<% site.followings.each do |following| %>
<a href="#"><img src="<%= site.screenshot_path 'index.html', '37x37' %>" class="avatar"></a>
<% end %>
<% end %>
</div>
<% end %>

94
views/_profile_news.erb Normal file
View file

@ -0,0 +1,94 @@
<div class="news-item follow">
<div class="title">
<div class="icon"></div>
<a href="" class="user">Derp</a> followed <a href="" class="user">Foo's</a> website<span class="date">7h</span>
</div>
</div>
<div class="news-item tip">
<div class="title">
<div class="icon"></div>
<a href="" class="user">Derp</a> tipped <a href="" class="user">Foo's</a> website: <a href="" class="comment">Wow, great work here! Please keep updating :)</a><span class="date">Apr 23</span>
</div>
</div>
<div class="news-item comment">
<div class="title">
<div class="icon"></div>
<a href="" class="user">Derp</a> commented on <a href="" class="user">victoria's</a> website: <a href="" class="comment">I had a question - how did you make it so that the...</a>
<span class="date">Apr 20</span>
</div>
</div>
<div class="news-item follow">
<div class="title">
<div class="icon"></div>
<a href="" class="user">Derp</a> followed <a href="" class="user">victoria's</a> website<span class="date">Apr 7</span>
</div>
</div>
<div class="news-item update">
<div class="title">
<div class="icon"></div>
<a href="" class="user">Derp</a> made an update <span class="date">Apr 7</span>
</div>
<div class="content">
<div class="files">
<div class="file">
<div class="html-thumbnail misc"><a href=""><span class="misc-icon">css</span><span class="title">styles.css</span></a></div>
</div>
<div class="file">
<div class="html-thumbnail html"><a href=""><img src="http://neocities.org/site_screenshots/codeventurer.jpg"><span class="title">styles.css</span></a></div>
</div>
<div class="file">
<div class="html-thumbnail misc"><a href=""><span class="misc-icon">js</span><span class="title">styles.css</span></a></div>
</div>
<div class="file">
<div class="html-thumbnail image"><a href=""><img src="/site_thumbnails/victoria/constructioncat2.png.105x63.png"><span class="title">cat.jpg</span></a></div>
</div>
<div class="file">
<div class="html-thumbnail misc"><a href=""><span class="misc-icon">js</span><span class="title">styles.css</span></a></div>
</div>
</div>
<div class="actions"><a href="">Like (1)</a> <a href="">Reply</a></div>
</div>
</div>
<div class="news-item comment for-me">
<div class="title">
<div class="icon" style="background-image:url(https://neocities.org/site_screenshots/codeventurer.jpg);"></div>
<a href="" class="user">Foo</a>
<span class="date">Apr 7</span>
<div class="comment">Your site is amazing. Very helpful information. Would love to see more updates if you have time. Your site is amazing. Very helpful information. Would love to see more updates if you have time. </div>
</div>
<div class="content">
<div class="actions"><a href="">Like (1)</a> <a href="">Reply</a></div>
<div class="comments">
<div class="comment">
<img class="avatar" src="https://neocities.org/site_screenshots/victoria.jpg">
<a href="" class="user">victoria</a> Indeed, it's great!<span class="date">Apr 7</span>
<div class="actions"><a href="">Like (1)</a></div>
</div>
</div>
</div>
</div>
<div class="news-item comment">
<div class="title">
<div class="icon"></div>
<a href="" class="user">Derp</a> commented on <a href="" class="user">Foo's</a> website: <a href="" class="comment">I had a question - how did you make it so that the...</a>
<span class="date">Apr 7</span>
</div>
</div>
<div class="news-item tip for-me">
<div class="title">
<div class="icon" style="background-image:url(https://neocities.org/site_screenshots/victoria.jpg);"></div>
<a href="" class="user">victoria</a> tipped .01 BTC
<span class="date">Apr 7</span>
<div class="comment">Hey, this looks great!</div>
</div>
<div class="content">
<div class="actions"><a href="">Like (1)</a> <a href="">Reply</a></div>
</div>
</div>

10
views/_tags.erb Normal file
View file

@ -0,0 +1,10 @@
<% if is_current_site %>
<h3>Tags</h3>
<% if site.tags_dataset.count == 0 %>
<p>You don't have any tags yet. <a href="#">Add some!</a>
<% else %>
<% site.tags.each do |tag| %>
<a class="tag" href="//neocities.org/tags/<%= tag.name %>"><%= tag.name %></a>
<% end %>
<% end %>
<% end %>

122
views/home.erb Normal file
View file

@ -0,0 +1,122 @@
<div class="header-Outro with-columns">
<div class="row content">
<div class="col col-66">
<h3>Your Feed</h3>
<div class="feed-filter"><a href="">All Activity</a> <a href="">Activity on your profile</a></div>
</div>
<div class="col col-32">
<h3>Your Website</h3>
<a href="/dashboard" class="btn-Action edit">Edit Site</a>
</div>
</div>
</div>
<div class="container">
<div class="content misc-page columns right-col">
<div class="col-left">
<div class="col col-66">
<% if current_site.followings_dataset.count == 0 %>
<div class="welcome">
<h4>Welcome to your Neocities news feed!</h4>
<p>You aren't following any websites yet! Once you do, updates will show up here and you can like and comment on them. Here are some website suggestions based on your tags, or <a href="/browse">check out all the sites on Neocities!</a></p>
</div>
<div class="site-suggestion">
<div class="site-portrait">
<a href="http://dragonquest.neocities.org">
<img src="http://neocities.org/site_screenshots/dragonquest.jpg">
<span class="caption">dragonquest</span>
</a>
</div>
<a class="tag" href="http://neocities.org">Games</a>
<a class="tag" href="http://neocities.org">Anime</a>
<a class="tag" href="http://neocities.org">Art</a>
<a class="tag" href="http://neocities.org">Cooking</a>
</div>
<div class="site-suggestion">
<div class="site-portrait">
<a href="http://dragonquest.neocities.org">
<img src="http://neocities.org/site_screenshots/dragonquest.jpg">
<span class="caption">dragonquest</span>
</a>
</div>
<a class="tag" href="http://neocities.org">Games</a>
<a class="tag" href="http://neocities.org">Anime</a>
<a class="tag" href="http://neocities.org">Art</a>
</div>
<div class="site-suggestion">
<div class="site-portrait">
<a href="http://dragonquest.neocities.org">
<img src="http://neocities.org/site_screenshots/dragonquest.jpg">
<span class="caption">dragonquest</span>
</a>
</div>
<a class="tag" href="http://neocities.org">Games</a>
<a class="tag" href="http://neocities.org">Anime</a>
</div>
<div class="site-suggestion">
<div class="site-portrait">
<a href="http://dragonquest.neocities.org">
<img src="http://neocities.org/site_screenshots/dragonquest.jpg">
<span class="caption">dragonquest</span>
</a>
</div>
<a class="tag" href="http://neocities.org">Games</a>
</div>
<div class="site-suggestion">
<div class="site-portrait">
<a href="http://dragonquest.neocities.org">
<img src="http://neocities.org/site_screenshots/dragonquest.jpg">
<span class="caption">dragonquest</span>
</a>
</div>
<a class="tag" href="http://neocities.org">Games</a>
<a class="tag" href="http://neocities.org">Anime</a>
</div>
<div class="site-suggestion">
<div class="site-portrait">
<a href="http://dragonquest.neocities.org">
<img src="http://neocities.org/site_screenshots/dragonquest.jpg">
<span class="caption">dragonquest</span>
</a>
</div>
<a class="tag" href="http://neocities.org">Games</a>
</div>
<% end %>
</div>
<div class="col col-33">
<p class="site-url"><a href="http://<%= site.username %>.neocities.org" target="_blank">http://<%= site.username %>.neocities.org</a></p>
<div class="stats">
<div class="col col-50">
<% if site.updated_at %>
Last updated<br><strong><%= site.updated_at.ago %></strong>
<% else %>
Your new site!<br><strong><a href="/dashboard">Start Building</a></strong>
<% end %>
</div>
<div class="col col-50">
<div><strong><%= site.hits_english %></strong> hits</div>
<div><strong><%= site.follows_dataset.count %></strong> followers</div>
<div><strong><%= site.tips_dataset.count %></strong> tips ($<%= site.tip_amount %>)</div>
</div>
</div>
<a href=""><img src="http://neocities.org/site_screenshots/codeventurer.jpg" style="width:340px" class="large-portrait"></a>
<div style="margin-top: 20px; margin-bottom: 20px" class="txt-Center">
<a href="/profile/<%= site.username %>" class="btn-Action">View Site Profile</a>
</div>
<%== erb :'_follows', layout: false, locals: {site: site, is_current_site: site == current_site} %>
<%== erb :'_tags', layout: false, locals: {site: site, is_current_site: site == current_site} %>
</div>
</div>
</div>
</div>

View file

@ -245,7 +245,7 @@
<div class="col col-33"> <div class="col col-33">
<p class="site-url"><a href="http://<%= current_site.username %>.neocities.org" target="_blank">http://<%= current_site.username %>.neocities.org</a></p> <p class="site-url"><a href="http://<%= current_site.username %>.neocities.org" target="_blank">http://<%= current_site.username %>.neocities.org</a></p>
<div class="stats"> <div class="stats">
<div class="col col-50">Last updated<br><strong><%= current_site.updated_at.ago %></strong></div> <div class="col col-50">Last updated<br><strong><%= current_site.updated_at ? current_site.updated_at.ago : '' %></strong></div>
<div class="col col-50"> <div class="col col-50">
<div><strong><%= current_site.hits.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse %></strong> hits</div> <div><strong><%= current_site.hits.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse %></strong> hits</div>
<div><strong>24</strong> followers</div> <div><strong>24</strong> followers</div>

92
views/profile.erb Normal file
View file

@ -0,0 +1,92 @@
<div class="header-Outro with-site-image">
<div class="row content">
<div class="col col-50 signup-Area large">
<div class="signup-Form">
<fieldset class="content">
<img class="screenshot" src="http://neocities.org/site_screenshots/codeventurer.jpg" style="width: 358px;height: 215px;">
</fieldset>
</div>
</div>
<div class="col col-50">
<h2 class="eps title-with-badge"><span>Derp's Website</span> <% if site.supporter? && !site.ended_supporter? %><a href="/plan" class="supporter-badge" title="Neocities Supporter"></a> <% end %></h2>
<p class="site-url"><a href="http://<%= site.username %>.neocities.org" target="_blank">http://<%= site.username %>.neocities.org</a></p>
<div class="stats">
<div class="stat"><strong><%= site.hits_english %></strong> <span>hits</span></div>
<div class="stat"><strong><%= site.follows_dataset.count %></strong> <span>followers</span></div>
<div class="stat tips"><strong><%= site.tips_dataset.count %></strong> <span>tips</span></div>
</div>
<div class="actions">
<% if site != current_site %>
<a href="" class="btn-Action follow"><span>Follow</span></a>
<a href="" class="btn-Action tip"><span>Tip</span></a>
<% end %>
<a href="" class="btn-Action share"><span>Share</span></a>
</div>
</div>
</div>
</div>
<div class="container">
<div class="content misc-page columns right-col"><div class="col-left">
<div class="col col-66">
<div class="post-comment">
<input class="" type="text" placeholder="Post on Derp's profile...">
<a href="" class="btn-Action">Post</a>
</div>
<% if site.latest_events.empty? %>
<div>
<p>No activity yet.</p>
</div>
<% else %>
<%= erb :'_profile_news', layout: false, locals: {events: events} %>
<% end %>
</div>
<div class="col col-33">
<h3>Website Stats</h3>
<div class="stats">
<div class="stat">
<span>Last updated</span>
<strong>
<% if site.updated_at.nil? %>
Just Created
<% else %>
<%= site.updated_at.ago.downcase %>
<% end %>
</strong>
</div>
<div class="stat"><span>Total updates</span><strong><%= site.changed_count %></strong></div>
<div class="stat"><span>Created</span><strong><%= site.created_at.strftime('%B %-d, %Y') %></strong></div>
</div>
<h3>Archives</h3>
<div class="archives">
<a href=""><img src="http://neocities.org/site_screenshots/codeventurer.jpg"></a>
<a href=""><img src="http://neocities.org/site_screenshots/codeventurer.jpg"></a>
<a href=""><img src="http://neocities.org/site_screenshots/codeventurer.jpg"></a>
<a href=""><img src="http://neocities.org/site_screenshots/codeventurer.jpg"></a>
<a href="" class="more">See all versions</a>
</div>
<% if site.followings_dataset.count < 0 %>
<h3>Following</h3>
<div class="following">
<% site.followings.each do |following| %>
<a href="#"><img src="<%= site.screenshot_path 'index.html', '37x37' %>" class="avatar"></a>
<% end %>
</div>
<% end %>
<%== erb :'_follows', layout: false, locals: {site: site, is_current_site: site == current_site} %>
<%== erb :'_tags', layout: false, locals: {site: site, is_current_site: site == current_site} %>
<div class="report">
<a href="">Report</a> | <a href="">Block</a>
</div>
</div>
</div></div>
</div>

View file

@ -9,7 +9,7 @@
</div> </div>
<div class="col col-50"> <div class="col col-50">
<h2 class="eps title-with-badge"><span>Derp's Website</span><a href="/plan" class="supporter-badge" title="Neocities Supporter"></a></h2> <h2 class="eps title-with-badge"><span>Derp's Website</span><a href="/plan" class="supporter-badge" title="Neocities Supporter"></a></h2>
<p class="site-url" style="margin-top: -9px;"><a href="http://<%= current_site.username %>.neocities.org" target="_blank">http://<%= current_site.username %>.neocities.org</a></p> <p class="site-url" style="margin-top: -9px;"><a href="http://<%= site.username %>.neocities.org" target="_blank">http://<%= site.username %>.neocities.org</a></p>
<div class="stats"> <div class="stats">
<div class="stat"><strong>23.5K</strong> <span>visitors</span></div> <div class="stat"><strong>23.5K</strong> <span>visitors</span></div>
<div class="stat"><strong>342</strong> <span>followers</span></div> <div class="stat"><strong>342</strong> <span>followers</span></div>
@ -133,9 +133,18 @@
<div class="col col-33"> <div class="col col-33">
<h3>Website Stats</h3> <h3>Website Stats</h3>
<div class="stats"> <div class="stats">
<div class="stat"><span>Last updated</span><strong><%= current_site.updated_at.ago %></strong></div> <div class="stat">
<div class="stat"><span>Total updates</span><strong>265</strong></div> <span>Last updated</span>
<div class="stat"><span>Created</span><strong>December 4, 2013</strong></div> <strong>
<% if site.updated_at.nil? %>
Just Created
<% else %>
<%= site.updated_at.ago.downcase %>
<% end %>
</strong>
</div>
<div class="stat"><span>Total updates</span><strong><%= site.changed_count %></strong></div>
<div class="stat"><span>Created</span><strong><%= site.created_at.strftime('%B %-d, %Y') %></strong></div>
</div> </div>
<h3>Archives</h3> <h3>Archives</h3>