diff --git a/Gemfile b/Gemfile index 2419a1a..ef60484 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,7 @@ gem 'sinatra-mongoid', :require => 'sinatra/mongoid' gem "bson_ext" gem "omniauth" gem "omniauth-facebook" +gem "time-ago-in-words", "~> 0.1.2" group :development do gem "awesome_print" diff --git a/Gemfile.lock b/Gemfile.lock index 4af5db5..7683ebc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,6 +87,7 @@ GEM eventmachine (>= 0.12.6) rack (>= 1.0.0) tilt (1.3.3) + time-ago-in-words (0.1.2) tzinfo (0.3.32) xpath (0.1.4) nokogiri (~> 1.3) @@ -108,4 +109,5 @@ DEPENDENCIES sinatra-mongoid slim thin + time-ago-in-words (~> 0.1.2) yard diff --git a/app.rb b/app.rb index 21e22d0..dc4f283 100644 --- a/app.rb +++ b/app.rb @@ -3,6 +3,7 @@ require 'omniauth-facebook' require 'slim' require 'mongoid' +require 'time-ago-in-words' require_relative 'routes/init' require_relative 'helpers/init' diff --git a/assets/application.sass b/assets/application.sass index b4d18ae..8af051c 100644 --- a/assets/application.sass +++ b/assets/application.sass @@ -1,8 +1,14 @@ +* + box-sizing: border-box + body - padding-top: 40px + padding-top: 50px #header color: #444 + position: fixed + box-shadow: 0px 1px 3px 3px #CCC + h2 text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25) float: left @@ -20,10 +26,38 @@ body border: #AAA solid 1px #new-post - margin: 10px 20px text-align: center textarea width: 99% button width: 100% +#posts + span + color: #666 + img + height: 25px + display: inline + border: #CCC solid 1px + margin-right: 5px + p + border-bottom: 1px solid rgba(200, 200, 200, 0.4) + -webkit-box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.1) + -moz-box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.1) + box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.1) + -webkit-border-radius: 5px + -moz-border-radius: 5px + border-radius: 5px + font-size: 1.2em + margin: 10px 25px + padding: 20px + color: #666 + .timestamp + float: right + font-size: 0.7em + hr + display: block + clear: both + height: 0 + border-top: 1px solid #CCC + border-bottom: 1px solid #DDD diff --git a/helpers/helper1.rb b/helpers/helper1.rb deleted file mode 100644 index a41c90b..0000000 --- a/helpers/helper1.rb +++ /dev/null @@ -1,29 +0,0 @@ -def clear; '
' end - -def update_session - session[:path] = params['project'] - - comma = params['project'] =~ /,/ - if comma - session[:project] = params['project'].slice(0,comma) - else - session[:project] = params['project'] - end -end - -# return string of kerberos user or false -def authenticate - if ENV['RACK_ENV'] == 'development' or ENV['RACK_ENV'] == 'qa' - return settings.user - end - - user = request.env["HTTP_AUTHORIZATION"] - - if user - user = Base64.decode64(user[6,user.length-6])[/\w+/] - return user - end - - return false -end - diff --git a/helpers/init.rb b/helpers/init.rb index a8df151..d567c1a 100644 --- a/helpers/init.rb +++ b/helpers/init.rb @@ -1 +1 @@ -require_relative 'helper1' +# require_relative 'time' diff --git a/models/init.rb b/models/init.rb index f38ee53..2d666ab 100644 --- a/models/init.rb +++ b/models/init.rb @@ -1,2 +1,2 @@ require_relative 'user' -require_relative 'picture' +require_relative 'post' diff --git a/models/post.rb b/models/post.rb index 66f0138..abfa101 100644 --- a/models/post.rb +++ b/models/post.rb @@ -1,5 +1,6 @@ class Post include Mongoid::Document + include Mongoid::Timestamps field :body, type: String - embeds :user + embeds_one :user end diff --git a/models/user.rb b/models/user.rb index 08ca5be..0cd21f8 100644 --- a/models/user.rb +++ b/models/user.rb @@ -2,6 +2,5 @@ class User include Mongoid::Document field :uid, type: String field :name, type: String - field :image_url, type: String embedded_in :Post end diff --git a/public/css/application.css b/public/css/application.css index cafc984..be56905 100644 --- a/public/css/application.css +++ b/public/css/application.css @@ -1,8 +1,13 @@ +* { + box-sizing: border-box; } + body { - padding-top: 40px; } + padding-top: 50px; } #header { - color: #444444; } + color: #444444; + position: fixed; + box-shadow: 0px 1px 3px 3px #cccccc; } #header h2 { text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); float: left; } @@ -13,15 +18,44 @@ body { text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); font-size: 1.1em; top: 3px; - position: relative; } + position: relative; + margin-right: 5px; } #header .user-info img { height: 23px; border: #aaaaaa solid 1px; } #new-post { - margin: 10px 20px; text-align: center; } #new-post textarea { width: 99%; } #new-post button { width: 100%; } + +#posts span { + color: #666666; } +#posts img { + height: 25px; + display: inline; + border: #cccccc solid 1px; + margin-right: 5px; } +#posts p { + border-bottom: 1px solid rgba(200, 200, 200, 0.4); + -webkit-box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.1); + -moz-box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.1); + box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.1); + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + border-radius: 5px; + font-size: 1.2em; + margin: 10px 25px; + padding: 20px; + color: #666666; } +#posts .timestamp { + float: right; + font-size: 0.7em; } +#posts hr { + display: block; + clear: both; + height: 0; + border-top: 1px solid #cccccc; + border-bottom: 1px solid #dddddd; } diff --git a/routes/posts.rb b/routes/posts.rb index de196d9..ddf812a 100644 --- a/routes/posts.rb +++ b/routes/posts.rb @@ -1,12 +1,14 @@ class MyApp < Sinatra::Base get '/posts' do - puts session[:uid] + @posts = Post.all(sort: [[ :created_at, :desc ]]) slim :post_index end post '/posts' do - p params + user = session['user'].merge({:uid=>session[:uid]}) + @post = Post.create(:body=>params["post"], :user=>user) + redirect '/posts' end end diff --git a/views/post_index.slim b/views/post_index.slim index 6cad307..4157c58 100644 --- a/views/post_index.slim +++ b/views/post_index.slim @@ -2,6 +2,17 @@ form action='/posts' method='POST' textarea type='text' name='post' button.btn.btn-primary SHARE -= session[:uid] -p = session[:user].to_json +#posts + - @posts.each do |post| + .post + span + image src="#{post.user.image}" + = "#{post.user.name} said " + i = post.created_at.ago_in_words + p.post + = post.body + span.timestamp + = post.created_at + .clearfix + hr