From 44311e400835a443ac1c6588938576ec2427f9d1 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Tue, 29 Apr 2014 00:03:48 -0700 Subject: [PATCH] start of feed and profile integration --- app.rb | 34 +++++++---- models/site.rb | 17 +++++- tests/acceptance_tests.rb | 6 +- views/_follows.erb | 12 ++++ views/_profile_news.erb | 94 +++++++++++++++++++++++++++++ views/_tags.erb | 10 ++++ views/home.erb | 122 ++++++++++++++++++++++++++++++++++++++ views/home_mockup.erb | 2 +- views/profile.erb | 92 ++++++++++++++++++++++++++++ views/profile_mockup.erb | 19 ++++-- 10 files changed, 386 insertions(+), 22 deletions(-) create mode 100644 views/_follows.erb create mode 100644 views/_profile_news.erb create mode 100644 views/_tags.erb create mode 100644 views/home.erb create mode 100644 views/profile.erb diff --git a/app.rb b/app.rb index 95e47c33..602489b2 100644 --- a/app.rb +++ b/app.rb @@ -31,7 +31,7 @@ error do EmailWorker.perform_async({ from: 'web@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" + (current_site ? "Site: #{current_site.username}\nEmail: #{current_site.email}\n\n" : '') + env['sinatra.error'].backtrace.join("\n") @@ -63,7 +63,14 @@ get '/edit_mockup' do end 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 get '/tags_mockup' do @@ -83,6 +90,11 @@ get '/stats_mockup' do end get '/?' do + if current_site + require_login + halt erb :'home', locals: {site: current_site} + end + if SimpleCache.expired?(:sites_count) @sites_count = SimpleCache.store :sites_count, Site.count.roundup(100), 600 # 10 Minutes else @@ -116,7 +128,7 @@ post '/plan/create' do from: 'web@neocities.org', reply_to: current_site.email, 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) }) end @@ -263,7 +275,7 @@ post '/create' do end session[:id] = @site.id - redirect '/dashboard' + redirect '/' else @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 session[:id] = site.id - redirect '/dashboard' + redirect '/' else flash[:error] = 'Invalid login.' flash[:username] = params[:username] @@ -614,7 +626,7 @@ post '/send_password_reset' do end 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} @@ -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. Meow, -the NeoCities Cat +the Neocities Cat EOT body.strip! @@ -633,12 +645,12 @@ the NeoCities Cat EmailWorker.perform_async({ from: 'web@neocities.org', to: params[:email], - subject: '[NeoCities] Password Reset', + subject: '[Neocities] Password Reset', body: body }) 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 '/' end @@ -712,7 +724,7 @@ post '/contact' do from: 'web@neocities.org', reply_to: params[:email], to: 'contact@neocities.org', - subject: "[NeoCities Contact]: #{params[:subject]}", + subject: "[Neocities Contact]: #{params[:subject]}", body: params[:body] }) @@ -863,7 +875,7 @@ def current_site end def title - out = "NeoCities" + out = "Neocities" return out if request.path == '/' return "#{out} - #{@title}" if @title "#{out} - #{request.path.gsub('/', '').capitalize}" diff --git a/models/site.rb b/models/site.rb index d5c95d5d..cc691d79 100644 --- a/models/site.rb +++ b/models/site.rb @@ -52,8 +52,8 @@ class Site < Sequel::Model LOSSLESS_IMAGE_REGEX = /png|bmp|gif/ LOSSY_IMAGE_REGEX = /jpg|jpeg/ HTML_REGEX = /htm|html/ - - SCREENSHOT_RESOLUTIONS = ['235x141', '105x63', '270x162'] + + SCREENSHOT_RESOLUTIONS = ['235x141', '105x63', '270x162', '37x37', '146x88', '302x182', '90x63', '82x62'] THUMBNAIL_RESOLUTIONS = ['105x63'] many_to_one :server @@ -91,6 +91,11 @@ class Site < Sequel::Model end end + def tip_amount + return '0.00' if tips_dataset.count == 0 + '31.337' + end + def username=(val) super val.downcase end @@ -373,9 +378,17 @@ class Site < Sequel::Model 'Supporter Plan' end + def latest_events + events_dataset.order(:id.desc).limit(10).all + end + def title values[:title] || values[:username] end + + def hits_english + values[:hits].to_s.reverse.gsub(/...(?=.)/,'\&,').reverse + end def screenshots_delete(filename) SCREENSHOT_RESOLUTIONS.each do |res| diff --git a/tests/acceptance_tests.rb b/tests/acceptance_tests.rb index 9c5922f3..3e0f8ca5 100644 --- a/tests/acceptance_tests.rb +++ b/tests/acceptance_tests.rb @@ -38,7 +38,7 @@ describe 'signup' do it 'succeeds with valid data' do fill_in_valid click_button 'Create Home Page' - page.must_have_content 'My Website' + page.must_have_content 'Your Feed' assert_equal( true, 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 fill_in_valid click_button 'Create Home Page' - page.must_have_content 'My Website' + page.must_have_content 'Your Feed' Capybara.reset_sessions! visit_signup fill_in 'username', with: @site[:username] @@ -138,6 +138,6 @@ describe 'signin' do fill_in 'username', with: site[:username] fill_in 'password', with: site[:password] click_button 'Sign In' - page.must_have_content 'My Website' + page.must_have_content 'Your Feed' end end \ No newline at end of file diff --git a/views/_follows.erb b/views/_follows.erb new file mode 100644 index 00000000..29fe8cf9 --- /dev/null +++ b/views/_follows.erb @@ -0,0 +1,12 @@ +<% if (!is_current_site && site.followings_dataset.count > 0) || is_current_site %> +

Following

+
+ <% if site.followings_dataset.count == 0 %> +

You are not following any sites yet. Add some by browsing sites or looking at your tags. + <% else %> + <% site.followings.each do |following| %> + + <% end %> + <% end %> +

+<% end %> \ No newline at end of file diff --git a/views/_profile_news.erb b/views/_profile_news.erb new file mode 100644 index 00000000..5d5016aa --- /dev/null +++ b/views/_profile_news.erb @@ -0,0 +1,94 @@ +
+
+
+ Derp followed Foo's website7h +
+
+ +
+ +
+ +
+ +
+ +
+
+
+ Derp followed victoria's websiteApr 7 +
+
+ +
+
+
+ Derp made an update Apr 7 +
+
+
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+ Foo + Apr 7 +
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.
+
+
+ +
+
+ + victoria Indeed, it's great!Apr 7 + +
+
+
+
+ +
+ +
+ +
+
+
+ victoria tipped .01 BTC + Apr 7 +
Hey, this looks great!
+
+ +
\ No newline at end of file diff --git a/views/_tags.erb b/views/_tags.erb new file mode 100644 index 00000000..909809f8 --- /dev/null +++ b/views/_tags.erb @@ -0,0 +1,10 @@ +<% if is_current_site %> +

Tags

+ <% if site.tags_dataset.count == 0 %> +

You don't have any tags yet. Add some! + <% else %> + <% site.tags.each do |tag| %> + <%= tag.name %> + <% end %> + <% end %> +<% end %> \ No newline at end of file diff --git a/views/home.erb b/views/home.erb new file mode 100644 index 00000000..49794c8e --- /dev/null +++ b/views/home.erb @@ -0,0 +1,122 @@ +

+
+ +
+

Your Website

+ Edit Site +
+
+
+ +
+
+
+
+ <% if current_site.followings_dataset.count == 0 %> +
+

Welcome to your Neocities news feed!

+

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 check out all the sites on Neocities!

+
+ + + + + + + + + + + + + <% end %> +
+ +
+

http://<%= site.username %>.neocities.org

+
+
+ <% if site.updated_at %> + Last updated
<%= site.updated_at.ago %> + <% else %> + Your new site!
Start Building + <% end %> +
+
+
<%= site.hits_english %> hits
+
<%= site.follows_dataset.count %> followers
+
<%= site.tips_dataset.count %> tips ($<%= site.tip_amount %>)
+
+
+ + + + + + <%== 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} %> +
+
+
+
\ No newline at end of file diff --git a/views/home_mockup.erb b/views/home_mockup.erb index b2756420..23c1e8f1 100644 --- a/views/home_mockup.erb +++ b/views/home_mockup.erb @@ -245,7 +245,7 @@

http://<%= current_site.username %>.neocities.org

-
Last updated
<%= current_site.updated_at.ago %>
+
Last updated
<%= current_site.updated_at ? current_site.updated_at.ago : '' %>
<%= current_site.hits.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse %> hits
24 followers
diff --git a/views/profile.erb b/views/profile.erb new file mode 100644 index 00000000..7ced9e15 --- /dev/null +++ b/views/profile.erb @@ -0,0 +1,92 @@ +
+
+ +
+

Derp's Website <% if site.supporter? && !site.ended_supporter? %> <% end %>

+

http://<%= site.username %>.neocities.org

+
+
<%= site.hits_english %> hits
+
<%= site.follows_dataset.count %> followers
+
<%= site.tips_dataset.count %> tips
+
+
+ <% if site != current_site %> + + Tip + <% end %> + +
+
+
+
+ +
+
+
+ +
+ + Post +
+ + <% if site.latest_events.empty? %> +
+

No activity yet.

+
+ <% else %> + <%= erb :'_profile_news', layout: false, locals: {events: events} %> + <% end %> + +
+ +
+

Website Stats

+
+
+ Last updated + + <% if site.updated_at.nil? %> + Just Created + <% else %> + <%= site.updated_at.ago.downcase %> + <% end %> + +
+
Total updates<%= site.changed_count %>
+
Created<%= site.created_at.strftime('%B %-d, %Y') %>
+
+ +

Archives

+
+ + + + + See all versions +
+ + <% if site.followings_dataset.count < 0 %> +

Following

+
+ <% site.followings.each do |following| %> + + <% end %> +
+ <% 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} %> + +
+ Report | Block +
+
+
+
\ No newline at end of file diff --git a/views/profile_mockup.erb b/views/profile_mockup.erb index 821bf045..415b53bb 100644 --- a/views/profile_mockup.erb +++ b/views/profile_mockup.erb @@ -9,7 +9,7 @@

Derp's Website

-

http://<%= current_site.username %>.neocities.org

+

http://<%= site.username %>.neocities.org

23.5K visitors
342 followers
@@ -133,11 +133,20 @@

Website Stats

-
Last updated<%= current_site.updated_at.ago %>
-
Total updates265
-
CreatedDecember 4, 2013
+
+ Last updated + + <% if site.updated_at.nil? %> + Just Created + <% else %> + <%= site.updated_at.ago.downcase %> + <% end %> + +
+
Total updates<%= site.changed_count %>
+
Created<%= site.created_at.strftime('%B %-d, %Y') %>
- +

Archives