life-story 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +56 -0
  3. data/Gemfile +21 -0
  4. data/Gemfile.lock +136 -0
  5. data/LICENSE +21 -0
  6. data/README.md +40 -0
  7. data/Rakefile +8 -0
  8. data/app/controllers/application_controller.rb +31 -0
  9. data/app/controllers/story_controller.rb +101 -0
  10. data/app/controllers/user_controller.rb +59 -0
  11. data/app/models/.gitkeep +0 -0
  12. data/app/models/category.rb +4 -0
  13. data/app/models/concerns/slugifiable.rb +13 -0
  14. data/app/models/story.rb +8 -0
  15. data/app/models/user.rb +12 -0
  16. data/app/models/user_story.rb +4 -0
  17. data/app/views/layout.erb +42 -0
  18. data/app/views/stories/edit.erb +51 -0
  19. data/app/views/stories/new.erb +47 -0
  20. data/app/views/stories/show.erb +46 -0
  21. data/app/views/stories/show_by_category.erb +27 -0
  22. data/app/views/stories/show_by_date.erb +27 -0
  23. data/app/views/stories/show_by_users.erb +29 -0
  24. data/app/views/users/signup.erb +36 -0
  25. data/app/views/welcome.erb +51 -0
  26. data/config.ru +10 -0
  27. data/config/environment.rb +12 -0
  28. data/db/development.sqlite +0 -0
  29. data/db/migrate/20200118192302_create_users.rb +9 -0
  30. data/db/migrate/20200118192313_create_categories.rb +7 -0
  31. data/db/migrate/20200118192321_create_stories.rb +10 -0
  32. data/db/migrate/20200118201120_create_user_stories.rb +8 -0
  33. data/db/schema.rb +38 -0
  34. data/db/seeds.rb +39 -0
  35. data/development.sqlite +0 -0
  36. data/lib/.gitkeep +0 -0
  37. data/life-story.gemspec +46 -0
  38. data/public/favicon.ico +0 -0
  39. data/public/images/.gitkeep +0 -0
  40. data/public/images/life-story.png +0 -0
  41. data/public/javascripts/.gitkeep +0 -0
  42. data/public/stylesheets/main.css +246 -0
  43. metadata +204 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 49969ea35d8d2b17f0988bb2f417099a545aa44b03c12a4dade747540e3d5e06
4
+ data.tar.gz: dc39d6c1e51a14bf7ed40564f2725062cc2f43c9e3285d2bcd4073bbdcaf3449
5
+ SHA512:
6
+ metadata.gz: 4416e6f4727e3a8c7b1da1a6156d3f9f09b130b4c56402e4fd25a6a80d6eac41580795a359dd7a91951458d980945ec317e76a74c6bb6bbe752d7010c13f2c45
7
+ data.tar.gz: 42a058db5cc3637d840428629bd16d62e4dd444c01b57d19ebb051e745b9953af1d62a6e7acde25cea26805e2438ecbc907a40f37b2cf0e03f0da4de1132211d
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'sinatra'
4
+ gem 'activerecord', '~> 4.2', '>= 4.2.6', :require => 'active_record'
5
+ gem 'sinatra-activerecord', :require => 'sinatra/activerecord'
6
+ gem 'rake'
7
+ gem 'require_all'
8
+ gem 'sqlite3', '~> 1.3.6'
9
+ gem 'thin'
10
+ gem 'shotgun'
11
+ gem 'pry'
12
+ gem 'bcrypt'
13
+ gem 'tux'
14
+ gem 'sinatra-flash'
15
+
16
+ group :test do
17
+ gem 'rspec'
18
+ gem 'capybara'
19
+ gem 'rack-test'
20
+ gem 'database_cleaner', git: 'https://github.com/bmabey/database_cleaner.git'
21
+ end
@@ -0,0 +1,136 @@
1
+ GIT
2
+ remote: https://github.com/bmabey/database_cleaner.git
3
+ revision: 16b4f7d8df83b9445d701c731ce60cdaa687c03e
4
+ specs:
5
+ database_cleaner (1.8.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (4.2.11.1)
11
+ activesupport (= 4.2.11.1)
12
+ builder (~> 3.1)
13
+ activerecord (4.2.11.1)
14
+ activemodel (= 4.2.11.1)
15
+ activesupport (= 4.2.11.1)
16
+ arel (~> 6.0)
17
+ activesupport (4.2.11.1)
18
+ i18n (~> 0.7)
19
+ minitest (~> 5.1)
20
+ thread_safe (~> 0.3, >= 0.3.4)
21
+ tzinfo (~> 1.1)
22
+ addressable (2.7.0)
23
+ public_suffix (>= 2.0.2, < 5.0)
24
+ arel (6.0.4)
25
+ bcrypt (3.1.13)
26
+ bond (0.5.1)
27
+ builder (3.2.4)
28
+ capybara (3.30.0)
29
+ addressable
30
+ mini_mime (>= 0.1.3)
31
+ nokogiri (~> 1.8)
32
+ rack (>= 1.6.0)
33
+ rack-test (>= 0.6.3)
34
+ regexp_parser (~> 1.5)
35
+ xpath (~> 3.2)
36
+ coderay (1.1.2)
37
+ concurrent-ruby (1.1.5)
38
+ daemons (1.3.1)
39
+ diff-lcs (1.3)
40
+ eventmachine (1.2.7)
41
+ i18n (0.9.5)
42
+ concurrent-ruby (~> 1.0)
43
+ method_source (0.9.2)
44
+ mini_mime (1.0.2)
45
+ mini_portile2 (2.4.0)
46
+ minitest (5.14.0)
47
+ mustermann (1.1.1)
48
+ ruby2_keywords (~> 0.0.1)
49
+ nokogiri (1.10.7)
50
+ mini_portile2 (~> 2.4.0)
51
+ pry (0.12.2)
52
+ coderay (~> 1.1.0)
53
+ method_source (~> 0.9.0)
54
+ public_suffix (4.0.3)
55
+ rack (2.1.1)
56
+ rack-protection (2.0.8.1)
57
+ rack
58
+ rack-test (1.1.0)
59
+ rack (>= 1.0, < 3)
60
+ rake (13.0.1)
61
+ regexp_parser (1.6.0)
62
+ require_all (3.0.0)
63
+ ripl (0.7.1)
64
+ bond (~> 0.5.1)
65
+ ripl-multi_line (0.3.1)
66
+ ripl (>= 0.3.6)
67
+ ripl-rack (0.2.0)
68
+ rack (>= 1.0)
69
+ rack-test (>= 0.5)
70
+ ripl (>= 0.3.5)
71
+ rspec (3.9.0)
72
+ rspec-core (~> 3.9.0)
73
+ rspec-expectations (~> 3.9.0)
74
+ rspec-mocks (~> 3.9.0)
75
+ rspec-core (3.9.1)
76
+ rspec-support (~> 3.9.1)
77
+ rspec-expectations (3.9.0)
78
+ diff-lcs (>= 1.2.0, < 2.0)
79
+ rspec-support (~> 3.9.0)
80
+ rspec-mocks (3.9.1)
81
+ diff-lcs (>= 1.2.0, < 2.0)
82
+ rspec-support (~> 3.9.0)
83
+ rspec-support (3.9.2)
84
+ ruby2_keywords (0.0.2)
85
+ shotgun (0.9.2)
86
+ rack (>= 1.0)
87
+ sinatra (2.0.8.1)
88
+ mustermann (~> 1.0)
89
+ rack (~> 2.0)
90
+ rack-protection (= 2.0.8.1)
91
+ tilt (~> 2.0)
92
+ sinatra-activerecord (2.0.14)
93
+ activerecord (>= 3.2)
94
+ sinatra (>= 1.0)
95
+ sinatra-flash (0.3.0)
96
+ sinatra (>= 1.0.0)
97
+ sqlite3 (1.3.13)
98
+ thin (1.7.2)
99
+ daemons (~> 1.0, >= 1.0.9)
100
+ eventmachine (~> 1.0, >= 1.0.4)
101
+ rack (>= 1, < 3)
102
+ thread_safe (0.3.6)
103
+ tilt (2.0.10)
104
+ tux (0.3.0)
105
+ ripl (>= 0.3.5)
106
+ ripl-multi_line (>= 0.2.4)
107
+ ripl-rack (>= 0.2.0)
108
+ sinatra (>= 1.2.1)
109
+ tzinfo (1.2.6)
110
+ thread_safe (~> 0.1)
111
+ xpath (3.2.0)
112
+ nokogiri (~> 1.8)
113
+
114
+ PLATFORMS
115
+ ruby
116
+
117
+ DEPENDENCIES
118
+ activerecord (~> 4.2, >= 4.2.6)
119
+ bcrypt
120
+ capybara
121
+ database_cleaner!
122
+ pry
123
+ rack-test
124
+ rake
125
+ require_all
126
+ rspec
127
+ shotgun
128
+ sinatra
129
+ sinatra-activerecord
130
+ sinatra-flash
131
+ sqlite3 (~> 1.3.6)
132
+ thin
133
+ tux
134
+
135
+ BUNDLED WITH
136
+ 2.0.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 sophieqgu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # Life Story
2
+
3
+ Welcome to Life Story™, a place where important memories are kept.
4
+
5
+ This Sinatra app allows you to write stories recorded that are meaningful in various aspects of life. Record things that matter to you at that moment. Read later to reflect on what is really important in life. Browse by date, category and users to see what others have been through. Visualize your life and those that are connected to you in a single app.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'life-story'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install life-story
23
+
24
+ ## Development
25
+
26
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
27
+
28
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/'sophieqgu'/play_GOT. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
37
+
38
+ ## Code of Conduct
39
+
40
+ Everyone interacting in the PlayGOT project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/'sophieqgu'/play_GOT/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,8 @@
1
+ ENV["SINATRA_ENV"] ||= "development"
2
+
3
+ require_relative './config/environment'
4
+ require 'sinatra/activerecord/rake'
5
+
6
+ task :console do
7
+ Pry.start
8
+ end
@@ -0,0 +1,31 @@
1
+ require './config/environment'
2
+ require 'sinatra/base'
3
+ require 'sinatra/flash'
4
+
5
+ class ApplicationController < Sinatra::Base
6
+
7
+ configure do
8
+ set :public_folder, 'public'
9
+ set :views, Proc.new { File.join(root, "../views/") }
10
+ enable :sessions
11
+ set :session_secret, "my_life_story"
12
+ register Sinatra::Flash
13
+ end
14
+
15
+
16
+ helpers do
17
+ def logged_in?
18
+ !!session[:user_id]
19
+ end
20
+
21
+ def current_user
22
+ User.find(session[:user_id])
23
+ end
24
+ end
25
+
26
+
27
+ get '/' do
28
+ erb :welcome
29
+ end
30
+
31
+ end
@@ -0,0 +1,101 @@
1
+ class StoryController < ApplicationController
2
+
3
+ get '/new' do
4
+ if logged_in?
5
+ erb :'stories/new'
6
+ else
7
+ flash[:error] = "You must log in to open Life Story."
8
+ redirect '/'
9
+ end
10
+ end
11
+
12
+
13
+ post '/' do
14
+ @story = Story.create(summary: params[:summary], date: params[:date], description: params[:description])
15
+ @story.category = Category.find(params[:category])
16
+ @story.users << current_user
17
+ if !params[:users].nil?
18
+ params[:users].each do |user_id|
19
+ @story.users << User.find(user_id)
20
+ end
21
+ end
22
+ @story.save
23
+ flash[:success] = "Story published successfully."
24
+ redirect '/'
25
+ end
26
+
27
+
28
+ get '/stories/:id' do
29
+ if logged_in?
30
+ @story = Story.find(params[:id])
31
+ erb :'stories/show'
32
+ else
33
+ flash[:error] = "You must log in to open Life Story."
34
+ redirect '/'
35
+ end
36
+ end
37
+
38
+
39
+ get '/stories/:id/edit' do
40
+ @story = Story.find(params[:id])
41
+ if !logged_in?
42
+ flash[:error] = "You must log in to open Life Story."
43
+ redirect '/'
44
+ elsif !@story.user_ids.include?(current_user.id)
45
+ flash[:error] = "You cannot edit other people's Life Story."
46
+ redirect "/stories/#{@story.id}"
47
+ else
48
+ erb :'stories/edit'
49
+ end
50
+ end
51
+
52
+
53
+ patch '/stories/:id' do
54
+ @story = Story.find(params[:id])
55
+ @story.update(summary: params[:summary], date: params[:date], description: params[:description])
56
+ @story.category = Category.find(params[:category])
57
+ @story.users.clear
58
+ @story.users << current_user
59
+ if !params[:users].nil?
60
+ params[:users].each do |user_id|
61
+ @story.users << User.find(user_id)
62
+ end
63
+ end
64
+ @story.save
65
+ flash[:success] = "Story updated successfully."
66
+ redirect "/stories/#{@story.id}"
67
+ end
68
+
69
+
70
+ delete '/stories/:id' do
71
+ @story = Story.find(params[:id])
72
+ @story.destroy
73
+ flash[:message] = "Story successfully deleted."
74
+ redirect '/'
75
+ end
76
+
77
+
78
+ get '/dates/:date' do
79
+ if logged_in?
80
+ @date = Date.parse(params[:date])
81
+ erb :'stories/show_by_date'
82
+ else
83
+ flash[:error] = "You must log in to open Life Story."
84
+ redirect '/'
85
+ end
86
+ end
87
+
88
+
89
+ get '/categories/:category' do
90
+ if logged_in?
91
+ @category = Category.find_by(name: params[:category])
92
+ erb :'stories/show_by_category'
93
+ else
94
+ flash[:error] = "You must log in to open Life Story."
95
+ redirect '/'
96
+ end
97
+ end
98
+
99
+
100
+
101
+ end
@@ -0,0 +1,59 @@
1
+ class UserController < ApplicationController
2
+
3
+ get '/signup' do
4
+ if !logged_in?
5
+ erb :'users/signup'
6
+ else
7
+ redirect '/'
8
+ end
9
+ end
10
+
11
+
12
+ post '/signup' do
13
+ if User.exists?(email: params[:email]) || User.exists?(username: params[:username])
14
+ flash[:error] = "Username or email already exists. Please try another or log in."
15
+ redirect '/signup'
16
+ else
17
+ user = User.create(params)
18
+ flash[:success] = "Signed up successfully. Logging you in.."
19
+ session[:user_id] = user.id
20
+ redirect '/'
21
+ end
22
+ end
23
+
24
+
25
+ post '/login' do
26
+ user = User.find_by(username: params[:username])
27
+
28
+ if user && user.authenticate(params[:password])
29
+ session[:user_id] = user.id
30
+ flash[:success] = "Logged in successfully."
31
+ redirect '/'
32
+ else
33
+ flash[:error] = "Username or password is incorrect. Please try again or create a new account."
34
+ redirect '/signup'
35
+ end
36
+ end
37
+
38
+
39
+ get '/logout' do
40
+ if logged_in?
41
+ session.clear
42
+ flash[:success] = "Logged out successfully. Directing you to homepage.."
43
+ end
44
+ redirect '/'
45
+ end
46
+
47
+
48
+ get '/users/:slug' do
49
+ if logged_in?
50
+ @user = User.find_by_slug(params[:slug])
51
+ erb :'stories/show_by_users'
52
+ else
53
+ flash[:error] = "You must log in to open Life Story."
54
+ redirect '/'
55
+ end
56
+ end
57
+
58
+
59
+ end