Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gitpod config #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM gitpod/workspace-full

USER gitpod

# Install custom tools, runtime, etc. using apt-get
# For example, the command below would install "bastet" - a command line tetris clone:
#
# RUN sudo apt-get -q update && # sudo apt-get install -yq bastet && # sudo rm -rf /var/lib/apt/lists/*
#
# More information: https://www.gitpod.io/docs/config-docker/
6 changes: 6 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tasks:
- init: echo "Replace me with a build script for the project."
command: echo "Replace me with omething that should run on every start, or just
remove me entirely."
image:
file: .gitpod.Dockerfile
11 changes: 7 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# A sample Gemfile
source "https://rubygems.org"

gem 'rake'
gem 'activesupport'
gem 'activerecord', '~> 4.2.0'

gem 'sinatra'
gem 'sinatra-contrib'
gem 'sinatra-activerecord'

gem 'puma'
gem 'tux'
gem 'pry'

group :development, :test do
gem 'pry'
gem 'shotgun'
gem 'sqlite3', '~> 1.3.6'
gem 'sqlite3'
end

group :production do
gem 'pg'
gem 'rails_12factor'
end
102 changes: 102 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
GEM
remote: https://rubygems.org/
specs:
activemodel (4.2.11.1)
activesupport (= 4.2.11.1)
builder (~> 3.1)
activerecord (4.2.11.1)
activemodel (= 4.2.11.1)
activesupport (= 4.2.11.1)
arel (~> 6.0)
activesupport (4.2.11.1)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.4)
backports (3.16.1)
bond (0.5.1)
builder (3.2.4)
coderay (1.1.2)
concurrent-ruby (1.1.6)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
method_source (0.9.2)
minitest (5.14.0)
multi_json (1.14.1)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
nio4r (2.5.2)
pg (1.2.3)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
puma (4.3.2)
nio4r (~> 2.0)
rack (2.2.2)
rack-protection (2.0.8.1)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.5)
rake (13.0.1)
ripl (0.7.1)
bond (~> 0.5.1)
ripl-multi_line (0.3.1)
ripl (>= 0.3.6)
ripl-rack (0.2.1)
rack (>= 1.0)
rack-test (~> 0.6.2)
ripl (>= 0.7.0)
ruby2_keywords (0.0.2)
shotgun (0.9.2)
rack (>= 1.0)
sinatra (2.0.8.1)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.8.1)
tilt (~> 2.0)
sinatra-activerecord (2.0.14)
activerecord (>= 3.2)
sinatra (>= 1.0)
sinatra-contrib (2.0.8.1)
backports (>= 2.8.2)
multi_json
mustermann (~> 1.0)
rack-protection (= 2.0.8.1)
sinatra (= 2.0.8.1)
tilt (~> 2.0)
sqlite3 (1.3.13)
thread_safe (0.3.6)
tilt (2.0.10)
tux (0.3.0)
ripl (>= 0.3.5)
ripl-multi_line (>= 0.2.4)
ripl-rack (>= 0.2.0)
sinatra (>= 1.2.1)
tzinfo (1.2.6)
thread_safe (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
activesupport
pg
pry
puma
rails_12factor
rake
shotgun
sinatra
sinatra-activerecord
sinatra-contrib
sqlite3
tux

BUNDLED WITH
2.1.4
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/lighthouse-labs/finstagram)

# finstagram


Expand Down
91 changes: 91 additions & 0 deletions app/actions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
helpers do
def current_user
User.find_by(id: session[:user_id])
end
end

get '/' do
@finstagram_posts = FinstagramPost.order(created_at: :desc)
erb(:index)
end

get '/signup' do
@user = User.new
erb(:signup)
end

post '/signup' do
email = params[:email]
avatar_url = params[:avatar_url]
username = params[:username]
password = params[:password]

@user = User.new({ email: email, avatar_url: avatar_url, username: username, password: password })

if @user.save
redirect to('/login')
else
erb(:signup)
end
end

get '/login' do # when a GET request comes into /login
erb(:login) # render app/views/login.erb
end

post '/login' do
username = params[:username]
password = params[:password]

user = User.find_by(username: username)

if user && user.password == password
session[:user_id] = user.id
redirect to('/')
else
@error_message = "Login failed."
erb(:login)
end
end

get '/logout' do
session[:user_id] = nil
redirect to('/')
end

get '/finstagram_posts/new' do
@finstagram_post = FinstagramPost.new
erb(:"finstagram_posts/new")
end

post '/finstagram_posts' do
photo_url = params[:photo_url]

@finstagram_post = FinstagramPost.new({ photo_url: photo_url, user_id: current_user.id })

if @finstagram_post.save
redirect(to('/'))
else
erb(:"finstagram_posts/new")
end
end

get '/finstagram_posts/:id' do
@finstagram_post = FinstagramPost.find(params[:id]) # find the finstagram post with the ID from the URL
erb(:"finstagram_posts/show") # render app/views/finstagram_posts/show.erb
end

post '/comments' do
# point values from params to variables
text = params[:text]
finstagram_post_id = params[:finstagram_post_id]

# instantiate a comment with those values & assign the comment to the `current_user`
comment = Comment.new({ text: text, finstagram_post_id: finstagram_post_id, user_id: current_user.id })

# save the comment
comment.save

# `redirect` back to wherever we came from
redirect(back)
end
10 changes: 10 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Comment < ActiveRecord::Base

# Associations from a previous exercise
belongs_to :user
belongs_to :finstagram_post

# New validation code
validates_presence_of :text, :user, :finstagram_post

end
28 changes: 28 additions & 0 deletions app/models/finstagram_post.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class FinstagramPost < ActiveRecord::Base

belongs_to :user
has_many :comments
has_many :likes

validates :photo_url, :user, presence: true

def humanized_time_ago
time_ago_in_seconds = Time.now - self.created_at
time_ago_in_minutes = time_ago_in_seconds / 60

if time_ago_in_minutes >= 60
"#{(time_ago_in_minutes / 60).to_i} hours ago"
else
"#{time_ago_in_minutes.to_i} minutes ago"
end
end

def like_count
self.likes.size
end

def comment_count
self.comments.size
end

end
6 changes: 6 additions & 0 deletions app/models/like.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Like < ActiveRecord::Base

belongs_to :user
belongs_to :finstagram_post

end
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class User < ActiveRecord::Base

has_many :finstagram_posts
has_many :comments
has_many :likes
validates :email, :username, uniqueness: true
validates :email, :avatar_url, :username, :password, presence: true
end
31 changes: 31 additions & 0 deletions app/views/HTML_class.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Very First Site</title>
</head>
<body>

<header>
<h1>Welcome Welcome!</h1>
<h2>Ramen</h2>
</header>

<main>

<section>
<h3>Some Aricle</h3>

<p>
We all think that celebrities are rich and famous. Take one look at their social media or see them walk a red carpet, and you’ll quickly realize that they’re loaded. But no one seems to really know exactly how much money a celebrity is worth.

Yes, we know that Maria Sharapova has won a bunch of tennis tournaments and has a ton of ad partnerships, but exactly how much money has she made from that? And what about Dolly Parton, the Queen of Country? Check out the list below to be blown away by some of the insane net worths of the biggest celebrities in the world.
</p>

<a href="http://google.com"> Take me to Hongkong!</a>

<img src="https://www.moneypop.com/wp-content/uploads/2019/03/GettyImages-51648919-84084.jpg" width="587" height="617"> alt="Hey!">
</section>
</main>

</body>
</html>
13 changes: 13 additions & 0 deletions app/views/Practice_2d1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>

<title>Document</title>

</head>
<body>

<a class="btn btn-primary btn-activity-complete-status-no-code-review" data-toggle="modal" data-target="#new-activity-submission-modal" href="#"><i class="fa fa-check"></i>&nbsp;Mark Completed</a>

</body>
</html>
File renamed without changes.
32 changes: 32 additions & 0 deletions app/views/finstagram_posts/new.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<h2>New Post</h2>
<ul class="errors">
<% @finstagram_post.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
<form action="/finstagram_posts" method="POST">
<div class="form-group">
<label for="photo_url">Photo URL</label>
<input type="text" id="photo_url" name="photo_url">
</div>
<div class="form-group">
<button class="button" type="submit">Post</button>
</div>
</form>

<img id="preview" style="display: none; max-width: 200px;" src="">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#photo_url").on("blur", function(event) {
var photo_url = $(this).val();
var preview = $("#preview");
if(photo_url) {
preview.attr("src", photo_url);
preview.fadeIn(1000);
} else {
preview.hide();
}
});
});
</script>
1 change: 1 addition & 0 deletions app/views/finstagram_posts/show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= erb(:"shared/finstagram_post", { locals: { finstagram_post: @finstagram_post, allow_new_comment: true }}) %>
Loading