From d7ba65d35289217e2c89ffa9a352ee1e36e0f442 Mon Sep 17 00:00:00 2001 From: Cyrus Stoller Date: Fri, 30 Dec 2016 17:24:03 -0800 Subject: [PATCH] Initial commit --- .env.example | 1 + .gitignore | 24 + Capfile | 41 ++ Gemfile | 63 ++ Gemfile.lock | 264 ++++++++ Guardfile | 44 ++ LICENSE | 21 + Procfile | 1 + README.md | 52 ++ Rakefile | 6 + app/assets/config/manifest.js | 3 + app/assets/images/.keep | 0 app/assets/images/avatar-social.png | Bin 0 -> 7309 bytes app/assets/images/title-logo.svg | 1 + app/assets/javascripts/application.js | 19 + app/assets/javascripts/cable.js | 13 + app/assets/javascripts/channels/.keep | 0 .../javascripts/channels/conversation.coffee | 155 +++++ app/assets/javascripts/chat.coffee | 3 + app/assets/javascripts/static.coffee | 3 + app/assets/javascripts/topics.coffee | 3 + app/assets/stylesheets/_settings.scss | 621 ++++++++++++++++++ app/assets/stylesheets/application.css | 17 + app/assets/stylesheets/chat.scss | 79 +++ .../stylesheets/foundation_and_overrides.scss | 53 ++ app/assets/stylesheets/static.scss | 31 + app/assets/stylesheets/topics.scss | 3 + app/channels/application_cable/channel.rb | 4 + app/channels/application_cable/connection.rb | 11 + app/channels/conversation_channel.rb | 67 ++ app/controllers/application_controller.rb | 3 + app/controllers/chat_controller.rb | 26 + app/controllers/concerns/.keep | 0 app/controllers/static_controller.rb | 17 + app/controllers/topics_controller.rb | 82 +++ app/helpers/application_helper.rb | 34 + app/helpers/chat_helper.rb | 2 + app/helpers/static_helper.rb | 2 + app/helpers/topics_helper.rb | 2 + app/jobs/application_job.rb | 2 + app/mailers/application_mailer.rb | 4 + app/models/application_record.rb | 3 + app/models/concerns/.keep | 0 app/models/topic.rb | 11 + app/services/conversation.rb | 63 ++ app/services/matcher.rb | 55 ++ app/services/message_formatter.rb | 13 + app/views/chat/_instructions.html.erb | 5 + app/views/chat/_loading.html.erb | 3 + app/views/chat/_message.html.erb | 7 + app/views/chat/index.html.erb | 42 ++ app/views/layouts/_flash_message.html.erb | 6 + app/views/layouts/_flash_messages.html.erb | 5 + app/views/layouts/_footer.html.erb | 25 + app/views/layouts/_header.html.erb | 7 + app/views/layouts/application.html.erb | 34 + app/views/layouts/empty.html.erb | 21 + app/views/layouts/mailer.html.erb | 13 + app/views/layouts/mailer.text.erb | 1 + app/views/shared/_error_messages.html.erb | 15 + app/views/shared/_google_analytics.html.erb | 10 + app/views/shared/_social_meta.html.erb | 13 + app/views/static/about.html.erb | 54 ++ .../static/community_guidelines.html.erb | 51 ++ app/views/static/faq.html.erb | 40 ++ app/views/static/welcome.html.erb | 20 + app/views/topics/_form.html.erb | 17 + app/views/topics/_topic.json.jbuilder | 2 + app/views/topics/edit.html.erb | 11 + app/views/topics/index.html.erb | 33 + app/views/topics/index.json.jbuilder | 1 + app/views/topics/new.html.erb | 9 + app/views/topics/show.html.erb | 12 + app/views/topics/show.json.jbuilder | 1 + bin/bundle | 3 + bin/rails | 9 + bin/rake | 9 + bin/setup | 34 + bin/spring | 16 + bin/update | 29 + config.ru | 5 + config/application.rb | 17 + config/boot.rb | 3 + config/cable.yml | 14 + config/database.yml | 85 +++ config/deploy.rb | 42 ++ config/deploy/production.rb | 65 ++ config/deploy/staging.rb | 63 ++ config/deploy/templates/nginx_conf.erb | 116 ++++ config/deploy/templates/puma.rb.erb | 42 ++ config/environment.rb | 5 + config/environments/development.rb | 57 ++ config/environments/production.rb | 87 +++ config/environments/test.rb | 42 ++ .../application_controller_renderer.rb | 6 + config/initializers/assets.rb | 11 + config/initializers/backtrace_silencers.rb | 7 + config/initializers/cookies_serializer.rb | 5 + .../initializers/filter_parameter_logging.rb | 4 + config/initializers/inflections.rb | 16 + config/initializers/mime_types.rb | 4 + config/initializers/new_framework_defaults.rb | 24 + config/initializers/redis.rb | 3 + config/initializers/session_store.rb | 3 + config/initializers/wrap_parameters.rb | 14 + config/locales/en.yml | 23 + config/puma.rb | 49 ++ config/routes.rb | 13 + config/secrets.yml | 22 + config/spring.rb | 6 + db/migrate/20161211085923_create_topics.rb | 12 + db/schema.rb | 26 + db/seeds.rb | 7 + lib/assets/.keep | 0 lib/capistrano/.gitkeep | 0 lib/capistrano/tasks/.gitkeep | 0 lib/capistrano/tasks/env.rake | 29 + lib/capistrano/tasks/helper.rb | 3 + lib/capistrano/tasks/setup.rake | 51 ++ lib/capistrano/tasks/uptime.rake | 6 + lib/capistrano/templates/.gitkeep | 0 lib/capistrano/templates/env.example | 6 + lib/capistrano/templates/monit.conf.erb | 7 + .../templates/puma_log_rotate.conf.erb | 31 + lib/tasks/.keep | 0 log/.keep | 0 public/404.html | 67 ++ public/422.html | 67 ++ public/500.html | 66 ++ public/apple-touch-icon-precomposed.png | 0 public/apple-touch-icon.png | 0 public/favicon.ico | Bin 0 -> 5430 bytes public/robots.txt | 5 + test/controllers/.keep | 0 test/controllers/chat_controller_test.rb | 31 + test/controllers/static_controller_test.rb | 27 + test/controllers/topics_controller_test.rb | 59 ++ test/fixtures/.keep | 0 test/fixtures/files/.keep | 0 test/fixtures/topics.yml | 9 + test/helpers/.keep | 0 test/helpers/application_helper_test.rb | 35 + test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/models/topic_test.rb | 31 + test/test_helper.rb | 10 + tmp/.keep | 0 vendor/assets/javascripts/.keep | 0 vendor/assets/stylesheets/.keep | 0 150 files changed, 3918 insertions(+) create mode 120000 .env.example create mode 100644 .gitignore create mode 100644 Capfile create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Guardfile create mode 100644 LICENSE create mode 100644 Procfile create mode 100644 README.md create mode 100644 Rakefile create mode 100644 app/assets/config/manifest.js create mode 100644 app/assets/images/.keep create mode 100644 app/assets/images/avatar-social.png create mode 100644 app/assets/images/title-logo.svg create mode 100644 app/assets/javascripts/application.js create mode 100644 app/assets/javascripts/cable.js create mode 100644 app/assets/javascripts/channels/.keep create mode 100644 app/assets/javascripts/channels/conversation.coffee create mode 100644 app/assets/javascripts/chat.coffee create mode 100644 app/assets/javascripts/static.coffee create mode 100644 app/assets/javascripts/topics.coffee create mode 100644 app/assets/stylesheets/_settings.scss create mode 100644 app/assets/stylesheets/application.css create mode 100644 app/assets/stylesheets/chat.scss create mode 100644 app/assets/stylesheets/foundation_and_overrides.scss create mode 100644 app/assets/stylesheets/static.scss create mode 100644 app/assets/stylesheets/topics.scss create mode 100644 app/channels/application_cable/channel.rb create mode 100644 app/channels/application_cable/connection.rb create mode 100644 app/channels/conversation_channel.rb create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/chat_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/controllers/static_controller.rb create mode 100644 app/controllers/topics_controller.rb create mode 100644 app/helpers/application_helper.rb create mode 100644 app/helpers/chat_helper.rb create mode 100644 app/helpers/static_helper.rb create mode 100644 app/helpers/topics_helper.rb create mode 100644 app/jobs/application_job.rb create mode 100644 app/mailers/application_mailer.rb create mode 100644 app/models/application_record.rb create mode 100644 app/models/concerns/.keep create mode 100644 app/models/topic.rb create mode 100644 app/services/conversation.rb create mode 100644 app/services/matcher.rb create mode 100644 app/services/message_formatter.rb create mode 100644 app/views/chat/_instructions.html.erb create mode 100644 app/views/chat/_loading.html.erb create mode 100644 app/views/chat/_message.html.erb create mode 100644 app/views/chat/index.html.erb create mode 100644 app/views/layouts/_flash_message.html.erb create mode 100644 app/views/layouts/_flash_messages.html.erb create mode 100644 app/views/layouts/_footer.html.erb create mode 100644 app/views/layouts/_header.html.erb create mode 100644 app/views/layouts/application.html.erb create mode 100644 app/views/layouts/empty.html.erb create mode 100644 app/views/layouts/mailer.html.erb create mode 100644 app/views/layouts/mailer.text.erb create mode 100644 app/views/shared/_error_messages.html.erb create mode 100644 app/views/shared/_google_analytics.html.erb create mode 100644 app/views/shared/_social_meta.html.erb create mode 100644 app/views/static/about.html.erb create mode 100644 app/views/static/community_guidelines.html.erb create mode 100644 app/views/static/faq.html.erb create mode 100644 app/views/static/welcome.html.erb create mode 100644 app/views/topics/_form.html.erb create mode 100644 app/views/topics/_topic.json.jbuilder create mode 100644 app/views/topics/edit.html.erb create mode 100644 app/views/topics/index.html.erb create mode 100644 app/views/topics/index.json.jbuilder create mode 100644 app/views/topics/new.html.erb create mode 100644 app/views/topics/show.html.erb create mode 100644 app/views/topics/show.json.jbuilder create mode 100755 bin/bundle create mode 100755 bin/rails create mode 100755 bin/rake create mode 100755 bin/setup create mode 100755 bin/spring create mode 100755 bin/update create mode 100644 config.ru create mode 100644 config/application.rb create mode 100644 config/boot.rb create mode 100644 config/cable.yml create mode 100644 config/database.yml create mode 100644 config/deploy.rb create mode 100644 config/deploy/production.rb create mode 100644 config/deploy/staging.rb create mode 100644 config/deploy/templates/nginx_conf.erb create mode 100644 config/deploy/templates/puma.rb.erb create mode 100644 config/environment.rb create mode 100644 config/environments/development.rb create mode 100644 config/environments/production.rb create mode 100644 config/environments/test.rb create mode 100644 config/initializers/application_controller_renderer.rb create mode 100644 config/initializers/assets.rb create mode 100644 config/initializers/backtrace_silencers.rb create mode 100644 config/initializers/cookies_serializer.rb create mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/initializers/inflections.rb create mode 100644 config/initializers/mime_types.rb create mode 100644 config/initializers/new_framework_defaults.rb create mode 100644 config/initializers/redis.rb create mode 100644 config/initializers/session_store.rb create mode 100644 config/initializers/wrap_parameters.rb create mode 100644 config/locales/en.yml create mode 100644 config/puma.rb create mode 100644 config/routes.rb create mode 100644 config/secrets.yml create mode 100644 config/spring.rb create mode 100644 db/migrate/20161211085923_create_topics.rb create mode 100644 db/schema.rb create mode 100644 db/seeds.rb create mode 100644 lib/assets/.keep create mode 100644 lib/capistrano/.gitkeep create mode 100644 lib/capistrano/tasks/.gitkeep create mode 100644 lib/capistrano/tasks/env.rake create mode 100644 lib/capistrano/tasks/helper.rb create mode 100644 lib/capistrano/tasks/setup.rake create mode 100644 lib/capistrano/tasks/uptime.rake create mode 100644 lib/capistrano/templates/.gitkeep create mode 100644 lib/capistrano/templates/env.example create mode 100644 lib/capistrano/templates/monit.conf.erb create mode 100644 lib/capistrano/templates/puma_log_rotate.conf.erb create mode 100644 lib/tasks/.keep create mode 100644 log/.keep create mode 100644 public/404.html create mode 100644 public/422.html create mode 100644 public/500.html create mode 100644 public/apple-touch-icon-precomposed.png create mode 100644 public/apple-touch-icon.png create mode 100644 public/favicon.ico create mode 100644 public/robots.txt create mode 100644 test/controllers/.keep create mode 100644 test/controllers/chat_controller_test.rb create mode 100644 test/controllers/static_controller_test.rb create mode 100644 test/controllers/topics_controller_test.rb create mode 100644 test/fixtures/.keep create mode 100644 test/fixtures/files/.keep create mode 100644 test/fixtures/topics.yml create mode 100644 test/helpers/.keep create mode 100644 test/helpers/application_helper_test.rb create mode 100644 test/integration/.keep create mode 100644 test/mailers/.keep create mode 100644 test/models/.keep create mode 100644 test/models/topic_test.rb create mode 100644 test/test_helper.rb create mode 100644 tmp/.keep create mode 100644 vendor/assets/javascripts/.keep create mode 100644 vendor/assets/stylesheets/.keep diff --git a/.env.example b/.env.example new file mode 120000 index 0000000..efd7fa1 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +lib/capistrano/templates/env.example \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..02aff9b --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore Byebug command history file. +.byebug_history + +.DS_Store +.env* +!.env.example + +lib/capistrano/templates/env.* +!lib/capistrano/templates/env.example diff --git a/Capfile b/Capfile new file mode 100644 index 0000000..59a7af4 --- /dev/null +++ b/Capfile @@ -0,0 +1,41 @@ +# Load DSL and set up stages +require "capistrano/setup" + +# Include default deployment tasks +require "capistrano/deploy" + +# Load the SCM plugin appropriate to your project: +# +# require "capistrano/scm/hg" +# install_plugin Capistrano::SCM::Hg +# or +# require "capistrano/scm/svn" +# install_plugin Capistrano::SCM::Svn +# or +require "capistrano/scm/git" +install_plugin Capistrano::SCM::Git + +# Include tasks from other gems included in your Gemfile +# +# For documentation on these, see for example: +# +# https://github.com/capistrano/rvm +# https://github.com/capistrano/rbenv +# https://github.com/capistrano/chruby +# https://github.com/capistrano/bundler +# https://github.com/capistrano/rails +# https://github.com/capistrano/passenger +# +# require "capistrano/rvm" +require "capistrano/rbenv" +# require "capistrano/chruby" +require "capistrano/bundler" +require "capistrano/rails/assets" +require "capistrano/rails/migrations" +# require "capistrano/passenger" +require 'capistrano/puma' +require 'capistrano/puma/nginx' # if you want to upload a nginx site template +require 'capistrano/puma/monit' + +# Load custom tasks from `lib/capistrano/tasks` if you have any defined +Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..a570924 --- /dev/null +++ b/Gemfile @@ -0,0 +1,63 @@ +source 'https://rubygems.org' + + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5.0.1' +# Use postgresql as the database for Active Record +gem 'pg', '~> 0.18' +# Use Puma as the app server +gem 'puma', '~> 3.0' +# Use SCSS for stylesheets +gem 'sass-rails', '~> 5.0' +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' +# Use CoffeeScript for .coffee assets and views +gem 'coffee-rails', '~> 4.2' +# See https://github.com/rails/execjs#readme for more supported runtimes +# gem 'therubyracer', platforms: :ruby + +# Use jquery as the JavaScript library +gem 'jquery-rails' +# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks +gem 'turbolinks', '~> 5' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.5' +# Use Redis adapter to run Action Cable in production +gem 'redis', '~> 3.0' +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' +gem 'foundation-rails', '~> 6.3.0.0' +gem 'rinku', '~> 2.0.2' +gem 'will_paginate', '~> 3.1.5' +gem 'will_paginate-foundation', '~> 6.2.0' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development +gem 'dotenv-rails' + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platform: :mri +end + +group :development do + # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. + gem 'web-console' + gem 'listen', '~> 3.0.5' + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' + + gem 'guard' + gem 'guard-minitest' + install_if -> { RUBY_PLATFORM =~ /darwin/ } do + gem 'terminal-notifier-guard', '~> 1.7.0', require: false + end + gem 'foreman' + gem 'capistrano-rails', '~> 1.1' + gem 'capistrano-rbenv', require: false + gem 'capistrano3-puma' +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..842f97b --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,264 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.0.1) + actionpack (= 5.0.1) + nio4r (~> 1.2) + websocket-driver (~> 0.6.1) + actionmailer (5.0.1) + actionpack (= 5.0.1) + actionview (= 5.0.1) + activejob (= 5.0.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.0.1) + actionview (= 5.0.1) + activesupport (= 5.0.1) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.0.1) + activesupport (= 5.0.1) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (5.0.1) + activesupport (= 5.0.1) + globalid (>= 0.3.6) + activemodel (5.0.1) + activesupport (= 5.0.1) + activerecord (5.0.1) + activemodel (= 5.0.1) + activesupport (= 5.0.1) + arel (~> 7.0) + activesupport (5.0.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + airbrussh (1.1.1) + sshkit (>= 1.6.1, != 1.7.0) + arel (7.1.4) + babel-source (5.8.35) + babel-transpiler (0.7.0) + babel-source (>= 4.0, < 6) + execjs (~> 2.0) + builder (3.2.2) + byebug (9.0.6) + capistrano (3.7.1) + airbrussh (>= 1.0.0) + capistrano-harrow + i18n + rake (>= 10.0.0) + sshkit (>= 1.9.0) + capistrano-bundler (1.2.0) + capistrano (~> 3.1) + sshkit (~> 1.2) + capistrano-harrow (0.5.3) + capistrano-rails (1.2.1) + capistrano (~> 3.1) + capistrano-bundler (~> 1.1) + capistrano-rbenv (2.1.0) + capistrano (~> 3.1) + sshkit (~> 1.3) + capistrano3-puma (1.2.1) + capistrano (~> 3.0) + puma (>= 2.6) + coderay (1.1.1) + coffee-rails (4.2.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.2.x) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.12.2) + concurrent-ruby (1.0.4) + debug_inspector (0.0.2) + dotenv (2.1.1) + dotenv-rails (2.1.1) + dotenv (= 2.1.1) + railties (>= 4.0, < 5.1) + erubis (2.7.0) + execjs (2.7.0) + ffi (1.9.14) + foreman (0.82.0) + thor (~> 0.19.1) + formatador (0.2.5) + foundation-rails (6.3.0.0) + railties (>= 3.1.0) + sass (>= 3.3.0, < 3.5) + sprockets-es6 (>= 0.9.0) + globalid (0.3.7) + activesupport (>= 4.1.0) + guard (2.14.0) + formatador (>= 0.2.4) + listen (>= 2.7, < 4.0) + lumberjack (~> 1.0) + nenv (~> 0.1) + notiffany (~> 0.0) + pry (>= 0.9.12) + shellany (~> 0.0) + thor (>= 0.18.1) + guard-compat (1.2.1) + guard-minitest (2.4.6) + guard-compat (~> 1.2) + minitest (>= 3.0) + i18n (0.7.0) + jbuilder (2.6.1) + activesupport (>= 3.0.0, < 5.1) + multi_json (~> 1.2) + jquery-rails (4.2.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + listen (3.0.8) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + loofah (2.0.3) + nokogiri (>= 1.5.9) + lumberjack (1.0.10) + mail (2.6.4) + mime-types (>= 1.16, < 4) + method_source (0.8.2) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.1.0) + minitest (5.10.1) + multi_json (1.12.1) + nenv (0.3.0) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-ssh (4.0.0) + nio4r (1.2.1) + nokogiri (1.6.8.1) + mini_portile2 (~> 2.1.0) + notiffany (0.1.1) + nenv (~> 0.1) + shellany (~> 0.0) + pg (0.19.0) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + puma (3.6.2) + rack (2.0.1) + rack-test (0.6.3) + rack (>= 1.0) + rails (5.0.1) + actioncable (= 5.0.1) + actionmailer (= 5.0.1) + actionpack (= 5.0.1) + actionview (= 5.0.1) + activejob (= 5.0.1) + activemodel (= 5.0.1) + activerecord (= 5.0.1) + activesupport (= 5.0.1) + bundler (>= 1.3.0, < 2.0) + railties (= 5.0.1) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.1) + activesupport (>= 4.2.0, < 6.0) + nokogiri (~> 1.6.0) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (5.0.1) + actionpack (= 5.0.1) + activesupport (= 5.0.1) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.0.0) + rb-fsevent (0.9.8) + rb-inotify (0.9.7) + ffi (>= 0.5.0) + redis (3.3.2) + rinku (2.0.2) + sass (3.4.23) + sass-rails (5.0.6) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + shellany (0.0.1) + slop (3.6.0) + spring (2.0.0) + activesupport (>= 4.2) + spring-watcher-listen (2.0.1) + listen (>= 2.7, < 4.0) + spring (>= 1.2, < 3.0) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-es6 (0.9.2) + babel-source (>= 5.8.11) + babel-transpiler + sprockets (>= 3.0.0) + sprockets-rails (3.2.0) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sshkit (1.11.5) + net-scp (>= 1.1.2) + net-ssh (>= 2.8.0) + terminal-notifier-guard (1.7.0) + thor (0.19.4) + thread_safe (0.3.5) + tilt (2.0.5) + turbolinks (5.0.1) + turbolinks-source (~> 5) + turbolinks-source (5.0.0) + tzinfo (1.2.2) + thread_safe (~> 0.1) + uglifier (3.0.4) + execjs (>= 0.3.0, < 3) + web-console (3.4.0) + actionview (>= 5.0) + activemodel (>= 5.0) + debug_inspector + railties (>= 5.0) + websocket-driver (0.6.4) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) + will_paginate (3.1.5) + will_paginate-foundation (6.2.0) + will_paginate (>= 3.0.3) + +PLATFORMS + ruby + +DEPENDENCIES + byebug + capistrano-rails (~> 1.1) + capistrano-rbenv + capistrano3-puma + coffee-rails (~> 4.2) + dotenv-rails + foreman + foundation-rails (~> 6.3.0.0) + guard + guard-minitest + jbuilder (~> 2.5) + jquery-rails + listen (~> 3.0.5) + pg (~> 0.18) + puma (~> 3.0) + rails (~> 5.0.1) + redis (~> 3.0) + rinku (~> 2.0.2) + sass-rails (~> 5.0) + spring + spring-watcher-listen (~> 2.0.0) + terminal-notifier-guard (~> 1.7.0) + turbolinks (~> 5) + tzinfo-data + uglifier (>= 1.3.0) + web-console + will_paginate (~> 3.1.5) + will_paginate-foundation (~> 6.2.0) + +BUNDLED WITH + 1.12.5 diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..71eda03 --- /dev/null +++ b/Guardfile @@ -0,0 +1,44 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +## Uncomment and set this to only include directories you want to watch +# directories %w(app lib config test spec features) \ +# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")} + +## Note: if you are using the `directories` clause above and you are not +## watching the project directory ('.'), then you will want to move +## the Guardfile to a watched dir and symlink it back, e.g. +# +# $ mkdir config +# $ mv Guardfile config/ +# $ ln -s config/Guardfile . +# +# and, you'll have to watch "config/Guardfile" instead of "Guardfile" + +guard :minitest, spring: "bin/rails test" do + notification :terminal_notifier, app_name: "EchoRemix ::", activate: 'com.googlecode.iTerm2' if `uname` =~ /Darwin/ + + # with Minitest::Unit + # watch(%r{^test/(.*)\/?test_(.*)\.rb$}) + # watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" } + # watch(%r{^test/test_helper\.rb$}) { 'test' } + + # with Minitest::Spec + # watch(%r{^spec/(.*)_spec\.rb$}) + # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } + # watch(%r{^spec/spec_helper\.rb$}) { 'spec' } + + # Rails 4 + watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" } + watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' } + watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" } + watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" } + watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" } + watch(%r{^test/.+_test\.rb$}) + watch(%r{^test/test_helper\.rb$}) { 'test' } + + # Rails < 4 + # watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" } + # watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" } + # watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" } +end diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c698d9a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Cyrus Stoller and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..8365868 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: bundle exec puma -e $RAILS_ENV -p 5000 -C config/puma.rb diff --git a/README.md b/README.md new file mode 100644 index 0000000..89e61fb --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# EchoRemix + +Thank you for participating in this experiment. +EchoRemix is a project that facilitates anonymous one-on-one +text-conversations about controversial political topics. + +I'm sharing this code so that you can have confidence that +the messages being sent are not being stored on the server. + +## Contributing + +### Bugs / Issues + +If you find a bug or something that could improve the user experience, please file an issue on this github project, so +contributors/maintainers can get started fixing them. :-) + +### Submitting Pull Requests + +- Fork this project +- Make a feature branch git checkout -b feature +- Make your changes and commit them to your feature branch +- Submit a pull request + +## Getting started with development + +Be sure to have Ruby 2.3.1, Postgresql, and Redis installed on a Mac or Linux machine. + +```bash +$ cp .env.example .env +$ bundle install +$ rake db:create +$ rake db:migrate +$ rails s +``` + +## Deploying EchoRemix + +The server has been setup using the Puppet manifests found at https://github.com/cyrusstoller/gardenbed + +Then if you're going to leave SSL enabled, be sure to install an SSL certificate using +[LetsEncrypt](https://letsencrypt.org/). You can find instructions [here](https://certbot.eff.org/). + +Once the server has been provisioned, be sure to change the `server` +and `ssl_cert_domain` in `config/deploy/production.rb`. + +Create `lib/capistrano/templates/env.production` with the appropriate environment variables, +then run the following commands. + +```bash +$ cap production setup +$ cap production deploy +``` diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..e85f913 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 0000000..b16e53d --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/images/avatar-social.png b/app/assets/images/avatar-social.png new file mode 100644 index 0000000000000000000000000000000000000000..087fbd385e95adafd7160523ca7c560cec5a09b6 GIT binary patch literal 7309 zcmZ{J2{_c<`}fQsgP0ikhYN-SFxmX;KiA=!+ZDc@q$46d$2eV2!{hEWc}X)1c881DA2zO5Eu-C z!vSsoPeCMtKu{>?U&VjRII8`(jHB9r%Q&k2|70{!{M2)O`GLnGPBuKP9y}~yFfoi< zG7ODg{`q5blWqYb#{gXn_n1p>y)Y+2?6mv>1S3HWdB?+dw_((ee(FdcH(>aI(P7iX zqj>1ia6C#sh6rlNF+E(XUq&lWDk9*Zo!_@U{<@?O^sIH;dGM^Fz%>njz70n}ASjEh*tfpzQi(v@y$9)a zJes?_aL{X?cOn@iz|MG|;@02Sk3?INHTSCXK2Gjv_n8TD90^*+)TAhY!DPt5bt*>a zNEVw7`-HOqMJ_Gc7?{>!uzOp`q}u!zp8@d9UF$&E+*SG}@HZ%|!vupk8W0p>J`pTH z!S=J5;6REHUt!8>u~(BJ4n+SP*K268G7U7-yl7oQKdXAnW8tgZn^RxwJwUie!6!k=WT%2Pk`6=AUkJa)1+!w3(jm!VpW@ z!(K~vu2-)gdR}Y;w@Zd4Z}PR-_NXf9>NmFajmolk|8mIMM^eZvmWI`)4(cYRaLaR2 zQYTdm1etiuG*J!{W;EXt;C!KEHjE9HZ;|PCTm!wJ4?Ni^iK$2y_-fgcZNWh@P+r{) zv9}%%BOKR2N$R=SWsy^BTfgX@Q|3$5=$>zh_eOANpv-G?!>iNEP#7Qnq%p%O7JM{` zRg6qZUmL!fLw=*d|4woEbcfp%N#cUO6Q^O3ddAwYrBSvDx)D6tW_C{S?#}X=w*}8v z*%9BpYK7kB>6|jz)6On3=DYswy$}D4PpG$cCIa>=q&UU|Aq$F^x?ulHg0mFvPh zY`GVmpSpTEi%Yc##bfx%RvByM#n%sOLMt`HrhPDCNmZE>D0KWW8ovnv_Ip8=Sk>%h zIFEjQhMAxqH`IhMQbVy)JY^(>(3Ki;__3Sgs^MDatq<->^jx?8{?cUd0JoWk}qO= z&ZP%jMhL3We=i(|e^R zQ_`B5?`ht2ma{jqJ))t|^Y5>}XsI>a2Ij98*spK2*FPz9EQVwAFih0U+Ji^$c7Bqj zDYdyy;kWW=*jbcDSB-#n*8NBDfbD#qq6K2N)Hb2jw398eBk<`WDb+QE@E9y)W-ZiJnvv9D7(*%(4wP%*l-;~< z;J9j6rFSY44*w<5q&)F+N{M3iFags2HbHO2UC(c<+6&Gd_cT>8?)o_D_c5l!xGK~KNH zaVItV(wJ?r++Pk)u%l0k_#WY<7P4Wu`5|COn2g*!mx?g_u+e3RX&_9y&uWs`_bg5B z&7qNiVv@DK`k1Um{SMx-Rj0HQd;Tw6)6z=!cMe3`A{`)FJd51{X|18oXG%rsmZNzh zKZlI7N9y(++9b%22lV-$k8jaCf>Y@%T7P!Davp0@%8!CQTcg35QTOvW=p)1x{(#?DFM^KZo58u>(BRz0Dc05+u^RzfOMj z){7JOtlB4oFvaXKSJ)QRsR7F)ALaO9S8boctf_t(Bb2hqA7|v!*QD;ea@`&tO(DE# zanY!*NVD2}k5x-YK*2`6Otm>Gj?`ry%(9>c~BSiYWUh$RZ5p7D8HP&FGvc*^x;%)MMTLQ6|a@@HZ;$8dc1 zZhHJ~Gw0)-DGO4;r|#v&Dw5+@UEKJ|^c$V@Wz&upIBb)7YVg(2?v8y=K5c(am?PUG z@WRf!VDUSXy;3Ar+DN7;=EN-QC9t(dv8yvHUDv~h(wmD{N4~Qci*kS$ev^u&Rb}dl zBi}JY-%8qv`OO4si0FhImUdpKdj6OgAV$5>bD<*x4qM9qt@~QV?u;!@YZfg6`%|b( z?`EzEu9~~uwj%`&J7_PYy(sL}aAg|{?h5}SeMtXGHcv;=X!Hby2P;0fw{ePQF_r{ zKyPtrZPEHyhPW^1Cyq-Ve`z3ho5x7v`E_`d^+Oj;UISEkvH_=&iIUm{EW@gx%Ft_UMs3-b!#iMv za^ysmE&PpTe|X?Y_#2=5Ov%CbR_a?NYc0I+7jR9awg&xa7A6WAS)-cQbbt5aa4+w8 z!k3kkgKX){Ao`ng*?^g`GzEGzfprfnzg}&-b)YUK`m4jj8{cy*WqvHqMSKBMEO!4A z_PJo7DV7xXb&Pdy<+c>EzES2)Ze|F@l4)L)cjPGI+4Ff4y6($tn-Efll41~snG%%y zMpYrvyf8-NtL9{cVWF#rGSh*Tmu~3dV1OlYvc~~Mh$GdP z_z07W4~RS&Yq=rnJ?qGq@30P6-DceTv*K2w2&{_+oiYVIQ>~dchxgKG!SrY%oN{QV zHTvYdjjTELv8Kuhc_)1D!z}N(tdWMmF9YUHJ#O;W6P%9ukE^Autn~);3~s@AJi+U$ zob?#%p?~d3i52M>!I*Em}tbBqCy*a)BSG4+06;g$$$d*JAl+Y%s z0y;lVB#(A{8cb@%^{6u6$xpYhXPDZDgyml3H-SK;5i(y*k8dGhi+SHovBthNH%Gb# zjA91PyVURQ8+Xc_FP9KU5u&rIYrc>PF#^fh9-&fzOi~@QX0%;h#bPL9N$e2;kT;QIhSftoHgY;`=Gzi>8?Iw?AjgZg8n?rQws^ zgScHad6N~{dBLSjhC$G*-e^s6dyt82__{(=oqR{5p-Fv@j?E*1od3Y*hA zGnAz%j-<1&vQqSEUl%vTiz;s2zKPa!8XMq5IPhScA~Ioa;3pDtkm4Dug&|NVl=2s%IAqXoUAE)}+3)+W9 z@@|NuP(J*y!GyS!PDE$l%-y_#;w%C?6l&Yztc#6$h`+P&DNI>HsKLba`My~4`|;LKQf&#Gq^`56IM!9rBVX$g24td&T(R*`m&OAbl3O8TQfce=|=YJuzJ zG88IDZ$3~)BZHf zOOqltf&paxEselWtpohRC6V!mTh*-;C#zuPP)WEm`T}lk9|%=ckwuK+piM6CpE>3o zb{fj{R?hKl9y;s*F5Zz8iS|>MZ!s=_Pfa%a2Vw4rwkz~4asSFIrrlo=H^-4$BZ7Oi zX5HY)C!Ka(a{prfQcLulzKDAlj15Yec~izIi!?FECpgE}Ga1^tq~%RfaAVF?F+63a z=&@!ZUVNdnRcGJ#+kn}UW)vEo>!9$)t4WDmmcAL8KN*v}y*WRl4!rx5&$L1SxZA1l zECtvls@`A&RPhJrU|$q)?uyug*(zdpb4-Hdq=44^%PJE}({6AWdL1qN@)>}H;?Iag z-yR57oIu!PJxAdWNwsFK3yVN@fcGLc$RwbuPGXdhiV(@ajHcQg*k&9-?h8q+H+o>j z`f8g5y0ZImadZl6#H`yp&QF)rl~oJgR4S4QJFhJLE9&tR$U(R2GopWaN8O+p;Cd2T zJLu6>JPcj^EuAg-2(X<|_P*dH$OZMva)~5@i+j4w%Qdir2b$6Hv#*nPJmQLISPM~u z+{{qQC=*9EwgRY7m~3T`Tq9e_WsWo#u%?y*NeHHtNY;?6M9(V7Zu+o4LjXm z#Ih$#F3#@*hV*!-A9EEeh@k6hFiFh5bXpH1X+H{;*|#eFg9Noi}shh zqmo^;o?90&kR$GA4ve%>_w%p*Zs~au2tfid3-`@mmX+j&+Xt<`kNN%DFC7s+BNN|0 z9};LUsa65+jXyDY#|H@S(T|99L{imYR1D$Ujh>#F9%~f=rg@jnTtDkZ_R9ms_PnNh zL4ST{XOa|HcGYQ#Mkc=*)*~YFA%z|)^qB3Mi?G%fViVEYKfC-(swx&J%tSYUH zP^o$Ltd4@e>Zi%D#z(IOBWq73#SgiL<-7Vl20ZG)P;s`=R?oWo*@>cd2Tg(jN&&BD z>1ZJG<_|Q|O$TjL@w05jhp(kv9=UR94%-=jjLzzemQm~e_RyCB-Y<8bP4AC;<8sQ( zdK;Msc95RPWN|7t@9LYF*R>QTCDGdKG?645;lzx` zz-a~Y1d-W`!6f{zGpaReo~Bltp}gZMlC}EuR$}HALml<9ofac|YmYeQ>6Yiv!C=`t zAA;5t{EImgL=|+g@C0Wd74Q<=uJHziBtb_SRUo>p<<#+-hpj3?ai{b#xx{y$B+IGm zwME7m6ZFR!uJij4S@!O+s;^qK=w`R`8_zYQXQ*k|G9E z4sBv&EfNl=5Lukk*U)1}9{tDrQC}}43r-&*8mZWr`bSRgRB;Y0>$OJgv49g4F&XbB zH%*kr+t<@KW&%|gRghii5+ww&EL-hdIZCaLV?2-6O{L1{&F-?n+p`%E|#(Z}u%g&2T&oyyKO9-`7sT zxHyZIxyJTWjrHFg!O89dj2Yx%>xOKfO%@xPL43bF`e{-l zbk|WwfDudyR7XV2f&ro{7>;1&r8oqW%TJIK2QK)04jX##goI*}Lb(Eg#2_`dkhWcX zV?tLS9*?Ssp5wo2>(w_}T04Ci4rq51(uCAI)a+V3GnaY-5xI@9d9dzqogG-K@q)h5 zdgsPxgRAoZiRZPI z2f7tXJGTGIyb*W9#)@ zghNdraw&~V%RmghvT?6U-OQ4R(t4al@q9O&goBdypDhEq3_iwWnBgo{`{5N^g5B8# zyLl#{=_SXiQcb%S&H^8_-`#P(3K8yu507X@$G7z|hTk?hal8$CQ}nRGt=iUbuZhx7 zTFT*HTB>`Fhvz7@=A0{0M>53}w#3HOR^)K8y!cD{;-9~dB|PBeVLpl$k0jy*pI5+I(QgY>rVP^we6Fc>AMs?%6Vo)PpeH>1`(Rt_WRgc((BP2Dwav0)<^DB@{`zX8ESG?~|j+n2p@LmTK%kAnv3S$EsIZ@$9)1 zA`fVAe~fnB>YPk&Ny!PahmjbsmTQH(l=fSpyHE4U)6`jx`ngcVOb{lFm1eqh#o~wD zDPjBH=4CKhLX?gc&Nl6EcK+9SM`K^=+bim`)P10l&pBK5#B-I}=?ovkFeGcQ8@-@; z_}=4md}QqE>e8g_uwT#jd?JaqNSuCnn`3oZ{*+t|n^L1fy|Alk>Ils6nPSFTKXt`S zam7X>w#`{tQK`LCCrc%yhE^`Ia300ATOU(FE!&k845i{e>SkqTE*-*CGjv=|zP^j^ z3B-k7Yr39;!)6;U9acFu2@|edR#vT;7>m6{C0J3%j;1x;T<@eEE4iP%c~gfCt85Nd zfAnz$*l9W`w^tW4r>L7jm?y_raXpmwyq}Bm=ju6cWpEZP16&H0%M@C0ZYYT!Rj8>+^H;&CW6+!(x+OlzOE{FZtm5`fp(-fHhqt>9$*}9i#lECTC*<30|q68o{tTb zm61Ru;y^Kt8H*POlVXS6JG#9^k>n~X@;Rwvjoxkw$!@P6B zEON#p=`_$WseD7s6G%*eFlRiN6GyNRLL@H5E*qj7Fz1QoTUxP!1+LE@6BHp}a%GrQ zH;_mGC?9ignmlM zEmjEVEg_sUVcGDA9vbrEeR91MV08vR75}{s4Pb4*iy_rVOd8`f2(3?aqe+aXG(QN+^X8)qu{vpi%MY91ij%xo5{#WteY}-FFa4!!9+T`m#<&jG) QK)}c7;wAl}3l35L1G(<&-T(jq literal 0 HcmV?d00001 diff --git a/app/assets/images/title-logo.svg b/app/assets/images/title-logo.svg new file mode 100644 index 0000000..e1407a1 --- /dev/null +++ b/app/assets/images/title-logo.svg @@ -0,0 +1 @@ +Asset 4 \ No newline at end of file diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 0000000..32980d9 --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,19 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. JavaScript code in this file should be added after the last require_* statement. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require jquery_ujs +//= require foundation +//= require turbolinks +//= require_tree . + +$(function(){ $(document).foundation(); }); diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js new file mode 100644 index 0000000..71ee1e6 --- /dev/null +++ b/app/assets/javascripts/cable.js @@ -0,0 +1,13 @@ +// Action Cable provides the framework to deal with WebSockets in Rails. +// You can generate new channels where WebSocket features live using the rails generate channel command. +// +//= require action_cable +//= require_self +//= require_tree ./channels + +(function() { + this.App || (this.App = {}); + + App.cable = ActionCable.createConsumer(); + +}).call(this); diff --git a/app/assets/javascripts/channels/.keep b/app/assets/javascripts/channels/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/channels/conversation.coffee b/app/assets/javascripts/channels/conversation.coffee new file mode 100644 index 0000000..c34c905 --- /dev/null +++ b/app/assets/javascripts/channels/conversation.coffee @@ -0,0 +1,155 @@ +App.conversation = App.cable.subscriptions.create "ConversationChannel", + connected: -> + # Called when the subscription is ready for use on the server + if window.location.pathname == '/chat' + App.conversation.egress() + + disconnected: -> + # Called when the subscription has been terminated by the server + reset_conversation() + + received: (data) -> + # Called when there's incoming data on the websocket for this channel + enable_chat(data) + place_message(data) + place_links(data) + place_topic(data) + show_typing(data) + scroll_bottom('#chat-container') + scroll_bottom('#links-container') + color_my_nickname() + back_in_waiting_pool(data) + # console.log data + + message: (str) -> + @perform 'message', message: str + + typing: -> + @perform 'typing' + + egress: (get_next = true) -> + @perform 'egress', get_next: get_next + +# manipulating the dom + +nickname = () -> + $('#chat-instructions').data('nickname') + +submit_message = () -> + $('#chat-message').on 'keydown', (event) -> + if event.keyCode == 13 && !event.shiftKey + str = event.target.value + # console.log "Submitted string: #{str}" + + blank_regex = /^\s*$/g + unless blank_regex.test str + App.conversation.message str + + event.target.value = "" + event.preventDefault() + +scroll_bottom = (sel) -> + $(sel).scrollTop($(sel)[0].scrollHeight) + +reset_conversation = () -> + $('#chat-history').html('') + $('#links-shared li').not('.none-yet').remove() + $('.none-yet').removeClass('hide') + $('#chat-message').val('') + $('#typing-indicator').html('') + $('#chat-topic').html('Waiting for a topic...') + disable_chat() + +disable_chat = () -> + disable_next() + disable_messages() + $('#chat-loading').removeClass('hide') + +enable_chat = (data) -> + enable_next() + enable_messages() + $('#chat-loading').addClass('hide') + $('#chat-message').focus() + +disable_next = () -> + $('#chat-next').addClass('disabled') + $('#chat-next').attr('disabled', true) + +enable_next = () -> + $('#chat-next').removeClass('disabled') + $('#chat-next').attr('disabled', false) + +disable_messages = () -> + $('#chat-message').attr('disabled', true) + +enable_messages = () -> + $('#chat-message').attr('disabled', false) + +setup_chat_next = () -> + $('#chat-next').click (e) -> + if confirm("Are you sure you want to leave this conversation?") + App.conversation.egress() + reset_conversation() + e.preventDefault() + $('#chat-message').focus() + +add_link = (partial) -> + # assumes that it's an 'li a' + $('.none-yet').addClass('hide') + $('#links-shared').append("
  • " + partial + "
  • ") + +add_message = (partial) -> + # assumes that it's a 'div' + $('#chat-history').append(partial) + +color_my_nickname = () -> + $('span.label[data-nickname=\'' + nickname() + '\']').addClass("alert") + +place_message = (data) -> + if data.message + add_message data.message + $('#typing-indicator').html('') + +place_links = (data) -> + if data.message + for link in $(data.message).find('a') + add_link(link.outerHTML) + return + +place_topic = (data) -> + if data.topic + $('#chat-topic').html(data.topic) + +back_in_waiting_pool = (data) -> + if data.waiting_pool + reset_conversation() + +typing_interval = 1000 +send_typing_indicator = () -> + past_val = "" + setInterval () -> + current_val = $('#chat-message').val() + if current_val && (past_val != current_val) && (current_val != "") + past_val = current_val + # console.log "typing" + App.conversation.typing() + , typing_interval + +typing_indicator = 0 +show_typing = (data) -> + if data.typing + $('#typing-indicator').html(data.nickname + " is typing ...") + clearTimeout(typing_indicator) + typing_indicator = setTimeout () -> + $('#typing-indicator').html('') + , typing_interval + +$(document).on 'turbolinks:load', -> + submit_message() + reset_conversation() + setup_chat_next() + send_typing_indicator() + + if window.location.pathname == '/chat' + $("a[target!='_window']").click -> + App.conversation.egress(false) diff --git a/app/assets/javascripts/chat.coffee b/app/assets/javascripts/chat.coffee new file mode 100644 index 0000000..fad9c6c --- /dev/null +++ b/app/assets/javascripts/chat.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ \ No newline at end of file diff --git a/app/assets/javascripts/static.coffee b/app/assets/javascripts/static.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/static.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/topics.coffee b/app/assets/javascripts/topics.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/topics.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/_settings.scss b/app/assets/stylesheets/_settings.scss new file mode 100644 index 0000000..47db289 --- /dev/null +++ b/app/assets/stylesheets/_settings.scss @@ -0,0 +1,621 @@ +// Foundation for Sites Settings +// ----------------------------- +// +// Table of Contents: +// +// 1. Global +// 2. Breakpoints +// 3. The Grid +// 4. Base Typography +// 5. Typography Helpers +// 6. Abide +// 7. Accordion +// 8. Accordion Menu +// 9. Badge +// 10. Breadcrumbs +// 11. Button +// 12. Button Group +// 13. Callout +// 14. Card +// 15. Close Button +// 16. Drilldown +// 17. Dropdown +// 18. Dropdown Menu +// 19. Forms +// 20. Label +// 21. Media Object +// 22. Menu +// 23. Meter +// 24. Off-canvas +// 25. Orbit +// 26. Pagination +// 27. Progress Bar +// 28. Responsive Embed +// 29. Reveal +// 30. Slider +// 31. Switch +// 32. Table +// 33. Tabs +// 34. Thumbnail +// 35. Title Bar +// 36. Tooltip +// 37. Top Bar + +@import 'util/util'; + +// 1. Global +// --------- + +$global-font-size: 100%; +$global-width: rem-calc(1200); +$global-lineheight: 1.5; +$foundation-palette: ( + primary: #2199e8, + secondary: #767676, + success: #3adb76, + warning: #ffae00, + alert: #ec5840, +); +$light-gray: #e6e6e6; +$medium-gray: #cacaca; +$dark-gray: #8a8a8a; +$black: #0a0a0a; +$white: #fefefe; +$body-background: $white; +$body-font-color: $black; +$body-font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; +$body-antialiased: true; +$global-margin: 1rem; +$global-padding: 1rem; +$global-weight-normal: normal; +$global-weight-bold: bold; +$global-radius: 0; +$global-text-direction: ltr; +$global-flexbox: false; +$print-transparent-backgrounds: true; + +@include add-foundation-colors; + +// 2. Breakpoints +// -------------- + +$breakpoints: ( + small: 0, + medium: 640px, + large: 1024px, + xlarge: 1200px, + xxlarge: 1440px, +); +$print-breakpoint: large; +$breakpoint-classes: (small medium large); + +// 3. The Grid +// ----------- + +$grid-row-width: $global-width; +$grid-column-count: 12; +$grid-column-gutter: ( + small: 20px, + medium: 30px, +); +$grid-column-align-edge: true; +$block-grid-max: 8; + +// 4. Base Typography +// ------------------ + +$header-font-family: $body-font-family; +$header-font-weight: $global-weight-normal; +$header-font-style: normal; +$font-family-monospace: Consolas, 'Liberation Mono', Courier, monospace; +$header-color: inherit; +$header-lineheight: 1.4; +$header-margin-bottom: 0.5rem; +$header-styles: ( + small: ( + 'h1': ('font-size': 24), + 'h2': ('font-size': 20), + 'h3': ('font-size': 19), + 'h4': ('font-size': 18), + 'h5': ('font-size': 17), + 'h6': ('font-size': 16), + ), + medium: ( + 'h1': ('font-size': 48), + 'h2': ('font-size': 40), + 'h3': ('font-size': 31), + 'h4': ('font-size': 25), + 'h5': ('font-size': 20), + 'h6': ('font-size': 16), + ), +); +$header-text-rendering: optimizeLegibility; +$small-font-size: 80%; +$header-small-font-color: $medium-gray; +$paragraph-lineheight: 1.6; +$paragraph-margin-bottom: 1rem; +$paragraph-text-rendering: optimizeLegibility; +$code-color: $black; +$code-font-family: $font-family-monospace; +$code-font-weight: $global-weight-normal; +$code-background: $light-gray; +$code-border: 1px solid $medium-gray; +$code-padding: rem-calc(2 5 1); +$anchor-color: $primary-color; +$anchor-color-hover: scale-color($anchor-color, $lightness: -14%); +$anchor-text-decoration: none; +$anchor-text-decoration-hover: none; +$hr-width: $global-width; +$hr-border: 1px solid $medium-gray; +$hr-margin: rem-calc(20) auto; +$list-lineheight: $paragraph-lineheight; +$list-margin-bottom: $paragraph-margin-bottom; +$list-style-type: disc; +$list-style-position: outside; +$list-side-margin: 1.25rem; +$list-nested-side-margin: 1.25rem; +$defnlist-margin-bottom: 1rem; +$defnlist-term-weight: $global-weight-bold; +$defnlist-term-margin-bottom: 0.3rem; +$blockquote-color: $dark-gray; +$blockquote-padding: rem-calc(9 20 0 19); +$blockquote-border: 1px solid $medium-gray; +$cite-font-size: rem-calc(13); +$cite-color: $dark-gray; +$cite-pseudo-content: '\2014 \0020'; +$keystroke-font: $font-family-monospace; +$keystroke-color: $black; +$keystroke-background: $light-gray; +$keystroke-padding: rem-calc(2 4 0); +$keystroke-radius: $global-radius; +$abbr-underline: 1px dotted $black; + +// 5. Typography Helpers +// --------------------- + +$lead-font-size: $global-font-size * 1.25; +$lead-lineheight: 1.6; +$subheader-lineheight: 1.4; +$subheader-color: $dark-gray; +$subheader-font-weight: $global-weight-normal; +$subheader-margin-top: 0.2rem; +$subheader-margin-bottom: 0.5rem; +$stat-font-size: 2.5rem; + +// 6. Abide +// -------- + +$abide-inputs: true; +$abide-labels: true; +$input-background-invalid: get-color(alert); +$form-label-color-invalid: get-color(alert); +$input-error-color: get-color(alert); +$input-error-font-size: rem-calc(12); +$input-error-font-weight: $global-weight-bold; + +// 7. Accordion +// ------------ + +$accordion-background: $white; +$accordion-plusminus: true; +$accordion-title-font-size: rem-calc(12); +$accordion-item-color: $primary-color; +$accordion-item-background-hover: $light-gray; +$accordion-item-padding: 1.25rem 1rem; +$accordion-content-background: $white; +$accordion-content-border: 1px solid $light-gray; +$accordion-content-color: $body-font-color; +$accordion-content-padding: 1rem; + +// 8. Accordion Menu +// ----------------- + +$accordionmenu-arrows: true; +$accordionmenu-arrow-color: $primary-color; +$accordionmenu-arrow-size: 6px; + +// 9. Badge +// -------- + +$badge-background: $primary-color; +$badge-color: $white; +$badge-color-alt: $white; +$badge-palette: $foundation-palette; +$badge-padding: 0.3em; +$badge-minwidth: 2.1em; +$badge-font-size: 0.6rem; + +// 10. Breadcrumbs +// --------------- + +$breadcrumbs-margin: 0 0 $global-margin 0; +$breadcrumbs-item-font-size: rem-calc(11); +$breadcrumbs-item-color: $primary-color; +$breadcrumbs-item-color-current: $black; +$breadcrumbs-item-color-disabled: $medium-gray; +$breadcrumbs-item-margin: 0.75rem; +$breadcrumbs-item-uppercase: true; +$breadcrumbs-item-slash: true; + +// 11. Button +// ---------- + +$button-padding: 0.85em 1em; +$button-margin: 0 0 $global-margin 0; +$button-fill: solid; +$button-background: $primary-color; +$button-background-hover: scale-color($button-background, $lightness: -15%); +$button-color: $white; +$button-color-alt: $white; +$button-radius: $global-radius; +$button-sizes: ( + tiny: 0.6rem, + small: 0.75rem, + default: 0.9rem, + large: 1.25rem, +); +$button-palette: $foundation-palette; +$button-opacity-disabled: 0.25; +$button-background-hover-lightness: -20%; +$button-hollow-hover-lightness: -50%; +$button-transition: background-color 0.25s ease-out, color 0.25s ease-out; + +// 12. Button Group +// ---------------- + +$buttongroup-margin: 1rem; +$buttongroup-spacing: 1px; +$buttongroup-child-selector: '.button'; +$buttongroup-expand-max: 6; +$buttongroup-radius-on-each: true; + +// 13. Callout +// ----------- + +$callout-background: $white; +$callout-background-fade: 85%; +$callout-border: 1px solid rgba($black, 0.25); +$callout-margin: 0 0 1rem 0; +$callout-padding: 1rem; +$callout-font-color: $body-font-color; +$callout-font-color-alt: $body-background; +$callout-radius: $global-radius; +$callout-link-tint: 30%; + +// 14. Card +// -------- + +$card-background: $white; +$card-font-color: $body-font-color; +$card-divider-background: $light-gray; +$card-border: 1px solid $light-gray; +$card-shadow: none; +$card-border-radius: $global-radius; +$card-padding: $global-padding; +$card-margin: $global-margin; + +// 15. Close Button +// ---------------- + +$closebutton-position: right top; +$closebutton-offset-horizontal: ( + small: 0.66rem, + medium: 1rem, +); +$closebutton-offset-vertical: ( + small: 0.33em, + medium: 0.5rem, +); +$closebutton-size: ( + small: 1.5em, + medium: 2em, +); +$closebutton-lineheight: 1; +$closebutton-color: $dark-gray; +$closebutton-color-hover: $black; + +// 16. Drilldown +// ------------- + +$drilldown-transition: transform 0.15s linear; +$drilldown-arrows: true; +$drilldown-arrow-color: $primary-color; +$drilldown-arrow-size: 6px; +$drilldown-background: $white; + +// 17. Dropdown +// ------------ + +$dropdown-padding: 1rem; +$dropdown-background: $body-background; +$dropdown-border: 1px solid $medium-gray; +$dropdown-font-size: 1rem; +$dropdown-width: 300px; +$dropdown-radius: $global-radius; +$dropdown-sizes: ( + tiny: 100px, + small: 200px, + large: 400px, +); + +// 18. Dropdown Menu +// ----------------- + +$dropdownmenu-arrows: true; +$dropdownmenu-arrow-color: $anchor-color; +$dropdownmenu-arrow-size: 6px; +$dropdownmenu-min-width: 200px; +$dropdownmenu-background: $white; +$dropdownmenu-border: 1px solid $medium-gray; + +// 19. Forms +// --------- + +$fieldset-border: 1px solid $medium-gray; +$fieldset-padding: rem-calc(20); +$fieldset-margin: rem-calc(18 0); +$legend-padding: rem-calc(0 3); +$form-spacing: rem-calc(16); +$helptext-color: $black; +$helptext-font-size: rem-calc(13); +$helptext-font-style: italic; +$input-prefix-color: $black; +$input-prefix-background: $light-gray; +$input-prefix-border: 1px solid $medium-gray; +$input-prefix-padding: 1rem; +$form-label-color: $black; +$form-label-font-size: rem-calc(14); +$form-label-font-weight: $global-weight-normal; +$form-label-line-height: 1.8; +$select-background: $white; +$select-triangle-color: $dark-gray; +$select-radius: $global-radius; +$input-color: $black; +$input-placeholder-color: $medium-gray; +$input-font-family: inherit; +$input-font-size: rem-calc(16); +$input-font-weight: $global-weight-normal; +$input-background: $white; +$input-background-focus: $white; +$input-background-disabled: $light-gray; +$input-border: 1px solid $medium-gray; +$input-border-focus: 1px solid $dark-gray; +$input-shadow: inset 0 1px 2px rgba($black, 0.1); +$input-shadow-focus: 0 0 5px $medium-gray; +$input-cursor-disabled: not-allowed; +$input-transition: box-shadow 0.5s, border-color 0.25s ease-in-out; +$input-number-spinners: true; +$input-radius: $global-radius; +$form-button-radius: $global-radius; + +// 20. Label +// --------- + +$label-background: $primary-color; +$label-color: $white; +$label-color-alt: $white; +$label-palette: $foundation-palette; +$label-font-size: 0.8rem; +$label-padding: 0.33333rem 0.5rem; +$label-radius: $global-radius; + +// 21. Media Object +// ---------------- + +$mediaobject-margin-bottom: $global-margin; +$mediaobject-section-padding: $global-padding; +$mediaobject-image-width-stacked: 100%; + +// 22. Menu +// -------- + +$menu-margin: 0; +$menu-margin-nested: 1rem; +$menu-item-padding: 0.7rem 1rem; +$menu-item-color-active: $white; +$menu-item-background-active: get-color(primary); +$menu-icon-spacing: 0.25rem; +$menu-item-background-hover: $light-gray; +$menu-border: $light-gray; + +// 23. Meter +// --------- + +$meter-height: 1rem; +$meter-radius: $global-radius; +$meter-background: $medium-gray; +$meter-fill-good: $success-color; +$meter-fill-medium: $warning-color; +$meter-fill-bad: $alert-color; + +// 24. Off-canvas +// -------------- + +$offcanvas-size: 250px; +$offcanvas-vertical-size: 250px; +$offcanvas-background: $light-gray; +$offcanvas-shadow: 0 0 10px rgba($black, 0.7); +$offcanvas-push-zindex: 1; +$offcanvas-overlap-zindex: 10; +$offcanvas-reveal-zindex: 1; +$offcanvas-transition-length: 0.5s; +$offcanvas-transition-timing: ease; +$offcanvas-fixed-reveal: true; +$offcanvas-exit-background: rgba($white, 0.25); +$maincontent-class: 'off-canvas-content'; + +// 25. Orbit +// --------- + +$orbit-bullet-background: $medium-gray; +$orbit-bullet-background-active: $dark-gray; +$orbit-bullet-diameter: 1.2rem; +$orbit-bullet-margin: 0.1rem; +$orbit-bullet-margin-top: 0.8rem; +$orbit-bullet-margin-bottom: 0.8rem; +$orbit-caption-background: rgba($black, 0.5); +$orbit-caption-padding: 1rem; +$orbit-control-background-hover: rgba($black, 0.5); +$orbit-control-padding: 1rem; +$orbit-control-zindex: 10; + +// 26. Pagination +// -------------- + +$pagination-font-size: rem-calc(14); +$pagination-margin-bottom: $global-margin; +$pagination-item-color: $black; +$pagination-item-padding: rem-calc(3 10); +$pagination-item-spacing: rem-calc(1); +$pagination-radius: $global-radius; +$pagination-item-background-hover: $light-gray; +$pagination-item-background-current: $primary-color; +$pagination-item-color-current: $white; +$pagination-item-color-disabled: $medium-gray; +$pagination-ellipsis-color: $black; +$pagination-mobile-items: false; +$pagination-mobile-current-item: false; +$pagination-arrows: false; + +// 27. Progress Bar +// ---------------- + +$progress-height: 1rem; +$progress-background: $medium-gray; +$progress-margin-bottom: $global-margin; +$progress-meter-background: $primary-color; +$progress-radius: $global-radius; + +// 28. Responsive Embed +// -------------------- + +$responsive-embed-margin-bottom: rem-calc(16); +$responsive-embed-ratios: ( + default: 4 by 3, + widescreen: 16 by 9, +); + +// 29. Reveal +// ---------- + +$reveal-background: $white; +$reveal-width: 600px; +$reveal-max-width: $global-width; +$reveal-padding: $global-padding; +$reveal-border: 1px solid $medium-gray; +$reveal-radius: $global-radius; +$reveal-zindex: 1005; +$reveal-overlay-background: rgba($black, 0.45); + +// 30. Slider +// ---------- + +$slider-width-vertical: 0.5rem; +$slider-transition: all 0.2s ease-in-out; +$slider-height: 0.5rem; +$slider-background: $light-gray; +$slider-fill-background: $medium-gray; +$slider-handle-height: 1.4rem; +$slider-handle-width: 1.4rem; +$slider-handle-background: $primary-color; +$slider-opacity-disabled: 0.25; +$slider-radius: $global-radius; + +// 31. Switch +// ---------- + +$switch-background: $medium-gray; +$switch-background-active: $primary-color; +$switch-height: 2rem; +$switch-height-tiny: 1.5rem; +$switch-height-small: 1.75rem; +$switch-height-large: 2.5rem; +$switch-radius: $global-radius; +$switch-margin: $global-margin; +$switch-paddle-background: $white; +$switch-paddle-offset: 0.25rem; +$switch-paddle-radius: $global-radius; +$switch-paddle-transition: all 0.25s ease-out; + +// 32. Table +// --------- + +$table-background: $white; +$table-color-scale: 5%; +$table-border: 1px solid smart-scale($table-background, $table-color-scale); +$table-padding: rem-calc(8 10 10); +$table-hover-scale: 2%; +$table-row-hover: darken($table-background, $table-hover-scale); +$table-row-stripe-hover: darken($table-background, $table-color-scale + $table-hover-scale); +$table-is-striped: true; +$table-striped-background: smart-scale($table-background, $table-color-scale); +$table-stripe: even; +$table-head-background: smart-scale($table-background, $table-color-scale / 2); +$table-head-row-hover: darken($table-head-background, $table-hover-scale); +$table-foot-background: smart-scale($table-background, $table-color-scale); +$table-foot-row-hover: darken($table-foot-background, $table-hover-scale); +$table-head-font-color: $body-font-color; +$table-foot-font-color: $body-font-color; +$show-header-for-stacked: false; + +// 33. Tabs +// -------- + +$tab-margin: 0; +$tab-background: $white; +$tab-color: $primary-color; +$tab-background-active: $light-gray; +$tab-active-color: $primary-color; +$tab-item-font-size: rem-calc(12); +$tab-item-background-hover: $white; +$tab-item-padding: 1.25rem 1.5rem; +$tab-expand-max: 6; +$tab-content-background: $white; +$tab-content-border: $light-gray; +$tab-content-color: $body-font-color; +$tab-content-padding: 1rem; + +// 34. Thumbnail +// ------------- + +$thumbnail-border: solid 4px $white; +$thumbnail-margin-bottom: $global-margin; +$thumbnail-shadow: 0 0 0 1px rgba($black, 0.2); +$thumbnail-shadow-hover: 0 0 6px 1px rgba($primary-color, 0.5); +$thumbnail-transition: box-shadow 200ms ease-out; +$thumbnail-radius: $global-radius; + +// 35. Title Bar +// ------------- + +$titlebar-background: $black; +$titlebar-color: $white; +$titlebar-padding: 0.5rem; +$titlebar-text-font-weight: bold; +$titlebar-icon-color: $white; +$titlebar-icon-color-hover: $medium-gray; +$titlebar-icon-spacing: 0.25rem; + +// 36. Tooltip +// ----------- + +$has-tip-font-weight: $global-weight-bold; +$has-tip-border-bottom: dotted 1px $dark-gray; +$tooltip-background-color: $black; +$tooltip-color: $white; +$tooltip-padding: 0.75rem; +$tooltip-font-size: $small-font-size; +$tooltip-pip-width: 0.75rem; +$tooltip-pip-height: $tooltip-pip-width * 0.866; +$tooltip-radius: $global-radius; + +// 37. Top Bar +// ----------- + +$topbar-padding: 0.5rem; +$topbar-background: $light-gray; +$topbar-submenu-background: $topbar-background; +$topbar-title-spacing: 0.5rem 1rem 0.5rem 0; +$topbar-input-width: 200px; +$topbar-unstack-breakpoint: medium; + diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000..d89149d --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,17 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + *= require_tree . + *= require_self + *= require foundation_and_overrides + + */ diff --git a/app/assets/stylesheets/chat.scss b/app/assets/stylesheets/chat.scss new file mode 100644 index 0000000..3762139 --- /dev/null +++ b/app/assets/stylesheets/chat.scss @@ -0,0 +1,79 @@ +// Place all the styles related to the chat controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +$top-header-height: 50px; +$chat-message-height: 100px; +$message-box-height: $chat-message-height + 30px; + +.title-logo.small{ + width: 150px; + padding: 20px 0; +} + +#chat-container { + height: calc(100vh - 220px); + margin-bottom: 0px; + padding-bottom: 0px; + overflow-y: auto; +} + +#links-container { + max-height: 50vh; + overflow-y: auto; +} + +#links-shared { + margin-bottom: 0; +} + +.message { + padding-bottom: 7px; +} + +body { + height: 100vh; +} + +.full-height { + height: 100%; +} + +.vertical-table { + display:table; +} + +.vertical-table-row { + display: table-row; +} + +.vertical-table-row.message-box{ + height: $message-box-height; +} + +.vertical-table-row.header{ + height: $top-header-height; +} + +.vertical-table-spacing { + padding-top: 20px; + padding-bottom: 20px; +} + +@media all and (min-width: 640px) { + #chat-topic-box { + margin-top: 63px; + } +} + +#chat-topic { + font-weight: bold; +} + +#chat-message { + height: $chat-message-height; +} + +#typing-indicator { + padding-bottom: 20px; +} diff --git a/app/assets/stylesheets/foundation_and_overrides.scss b/app/assets/stylesheets/foundation_and_overrides.scss new file mode 100644 index 0000000..2066155 --- /dev/null +++ b/app/assets/stylesheets/foundation_and_overrides.scss @@ -0,0 +1,53 @@ +@charset 'utf-8'; + +@import 'settings'; +@import 'foundation'; + +// If you'd like to include motion-ui the foundation-rails gem comes prepackaged with it, uncomment the 3 @imports, if you are not using the gem you need to install the motion-ui sass package. +// +// @import 'motion-ui/motion-ui'; + +// We include everything by default. To slim your CSS, remove components you don't use. + +@include foundation-global-styles; +@include foundation-grid; +@include foundation-typography; +@include foundation-button; +@include foundation-forms; +@include foundation-visibility-classes; +@include foundation-float-classes; +@include foundation-accordion; +@include foundation-accordion-menu; +@include foundation-badge; +@include foundation-breadcrumbs; +@include foundation-button-group; +@include foundation-callout; +@include foundation-card; +@include foundation-close-button; +@include foundation-drilldown-menu; +@include foundation-dropdown; +@include foundation-dropdown-menu; +@include foundation-responsive-embed; +@include foundation-label; +@include foundation-media-object; +@include foundation-menu; +@include foundation-menu-icon; +@include foundation-off-canvas; +@include foundation-orbit; +@include foundation-pagination; +@include foundation-progress-bar; +@include foundation-slider; +@include foundation-sticky; +@include foundation-reveal; +@include foundation-switch; +@include foundation-table; +@include foundation-tabs; +@include foundation-thumbnail; +@include foundation-title-bar; +@include foundation-tooltip; +@include foundation-top-bar; + +// If you'd like to include motion-ui the foundation-rails gem comes prepackaged with it, uncomment the 3 @imports, if you are not using the gem you need to install the motion-ui sass package. +// +// @include motion-ui-transitions; +// @include motion-ui-animations; diff --git a/app/assets/stylesheets/static.scss b/app/assets/stylesheets/static.scss new file mode 100644 index 0000000..7cc241b --- /dev/null +++ b/app/assets/stylesheets/static.scss @@ -0,0 +1,31 @@ +// Place all the styles related to the static controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +.title-logo { + width: 300px; + padding: 40px 0; +} + +footer { + padding-bottom: 20px; +} + +.flash-message { + border: none; +} + +.no-bottom { + margin-bottom: 0; +} + +.faq-question { + font-weight: 500; + font-size: 130%; + margin-bottom: 0px; +} + +.static-header { + font-size: 31px; + font-weight: 500; +} diff --git a/app/assets/stylesheets/topics.scss b/app/assets/stylesheets/topics.scss new file mode 100644 index 0000000..9c30683 --- /dev/null +++ b/app/assets/stylesheets/topics.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the topics controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 0000000..d672697 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 0000000..704a88b --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,11 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + identified_by :user_id, :nickname + + def connect + uuid = cookies.signed['uuid'] || SecureRandom.uuid + self.user_id = "user_#{uuid}" + self.nickname = cookies.signed['nickname'] + end + end +end diff --git a/app/channels/conversation_channel.rb b/app/channels/conversation_channel.rb new file mode 100644 index 0000000..cd7f0d0 --- /dev/null +++ b/app/channels/conversation_channel.rb @@ -0,0 +1,67 @@ +# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading. +class ConversationChannel < ApplicationCable::Channel + def subscribed + stream_from user_id + end + + def unsubscribed + # Any cleanup needed when channel is unsubscribed + disconnect_from_conversation + + # Make sure that this user isn't matched with anyone else + Matcher.remove(user_id) + end + + def message(data) + message = data['message'] + Conversation.broadcast_from_user(user_id, nickname, message) + end + + def typing + Conversation.broadcast_typing_from_user(user_id, nickname) + end + + # Also called when the user first lands on the chat page + def egress(data) + disconnect_from_conversation + + if data['get_next'] and not nickname.blank? + Matcher.create_chat(user_id) + end + end + + private + + def disconnect_from_conversation + other_user_ids = Matcher.conversation_ended_by_user(user_id) + other_user_ids.each do |u_id| + # Put the other users into the waiting pool + Matcher.create_chat(u_id) + end + end + + # FILTER out the message so that it is not stored in the logs + + def transmit(data, via: nil) # :doc: + transmitted_data = data.dup + unless transmitted_data["message"].nil? + transmitted_data["message"] = "[FILTERED]" + end + + logger.info "#{self.class.name} transmitting #{transmitted_data.inspect.truncate(300)}".tap { |m| m << " (via #{via})" if via } + + payload = { channel_class: self.class.name, data: data, via: via } + ActiveSupport::Notifications.instrument("transmit.action_cable", payload) do + connection.transmit identifier: @identifier, message: data + end + end + + def action_signature(action, data) + "#{self.class.name}##{action}".tap do |signature| + if (arguments = data.except("action")).any? + arguments["message"] = "[FILTERED]" + signature << "(#{arguments.inspect})" + end + end + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..1c07694 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,3 @@ +class ApplicationController < ActionController::Base + protect_from_forgery with: :exception +end diff --git a/app/controllers/chat_controller.rb b/app/controllers/chat_controller.rb new file mode 100644 index 0000000..47df6eb --- /dev/null +++ b/app/controllers/chat_controller.rb @@ -0,0 +1,26 @@ +class ChatController < ApplicationController + def index + @title = "Chat" + @logo_class = "small" + @no_footer = true + @nickname = cookies.signed['nickname'] + if @nickname.blank? + redirect_to root_path + else + render layout: 'empty' + end + end + + def create + nickname = params[:nickname].to_s + + if nickname =~ /system/i + flash[:error] = "You cannot call yourself 'System'" + redirect_to root_path + else + cookies.signed[:nickname] = nickname + cookies.signed[:uuid] = SecureRandom.uuid + redirect_to action: "index" + end + end +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb new file mode 100644 index 0000000..323d329 --- /dev/null +++ b/app/controllers/static_controller.rb @@ -0,0 +1,17 @@ +class StaticController < ApplicationController + def welcome + @title = "Welcome" + end + + def about + @title = "About" + end + + def community_guidelines + @title = "Community Guidelines" + end + + def faq + @title = "FAQ" + end +end diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb new file mode 100644 index 0000000..a98d164 --- /dev/null +++ b/app/controllers/topics_controller.rb @@ -0,0 +1,82 @@ + class TopicsController < ApplicationController + before_action :set_topic, only: [:show, :edit, :update, :destroy] + before_action :http_basic_authentication + + # GET /topics + # GET /topics.json + def index + @topics = Topic.priority.paginate(page: params[:page]) + @topic = Topic.new(weight: 1) + end + + # GET /topics/1 + # GET /topics/1.json + def show + end + + # GET /topics/new + def new + @topic = Topic.new(weight: 1) + end + + # GET /topics/1/edit + def edit + end + + # POST /topics + # POST /topics.json + def create + @topic = Topic.new(topic_params) + + respond_to do |format| + if @topic.save + format.html { redirect_to topics_path, notice: 'Topic was successfully created.' } + format.json { render :show, status: :created, location: @topic } + else + format.html { render :new } + format.json { render json: @topic.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /topics/1 + # PATCH/PUT /topics/1.json + def update + respond_to do |format| + if @topic.update(topic_params) + format.html { redirect_to @topic, notice: 'Topic was successfully updated.' } + format.json { render :show, status: :ok, location: @topic } + else + format.html { render :edit } + format.json { render json: @topic.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /topics/1 + # DELETE /topics/1.json + def destroy + @topic.destroy + respond_to do |format| + format.html { redirect_to topics_url, notice: 'Topic was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_topic + @topic = Topic.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def topic_params + params.require(:topic).permit(:text, :weight) + end + + def http_basic_authentication + authenticate_or_request_with_http_basic do |user, password| + user == ENV['ADMIN_USER'] && password == ENV['ADMIN_PASSWORD'] + end + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..8146100 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,34 @@ +module ApplicationHelper + def title + if @title.blank? + "EchoRemix" + else + "EchoRemix | #{@title}" + end + end + + def social_description + "Anonymous one-on-one conversations about topics that matter." + end + + def logo_class + if @logo_class.blank? + "title-logo" + else + "title-logo #{@logo_class}" + end + end + + def alert_type(type) + case type + when :error, "error" + "alert" + when :notice, "notice" + "warning" + when :success, "success" + "success" + else + type.to_s + end + end +end diff --git a/app/helpers/chat_helper.rb b/app/helpers/chat_helper.rb new file mode 100644 index 0000000..a020368 --- /dev/null +++ b/app/helpers/chat_helper.rb @@ -0,0 +1,2 @@ +module ChatHelper +end diff --git a/app/helpers/static_helper.rb b/app/helpers/static_helper.rb new file mode 100644 index 0000000..8cfc9af --- /dev/null +++ b/app/helpers/static_helper.rb @@ -0,0 +1,2 @@ +module StaticHelper +end diff --git a/app/helpers/topics_helper.rb b/app/helpers/topics_helper.rb new file mode 100644 index 0000000..488eed5 --- /dev/null +++ b/app/helpers/topics_helper.rb @@ -0,0 +1,2 @@ +module TopicsHelper +end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000..a009ace --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..286b223 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..10a4cba --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/topic.rb b/app/models/topic.rb new file mode 100644 index 0000000..b6a9adb --- /dev/null +++ b/app/models/topic.rb @@ -0,0 +1,11 @@ +class Topic < ApplicationRecord + validates_presence_of :text + validates_uniqueness_of :text + validates_presence_of :weight + + scope :priority, -> { order(weight: :desc, text: :asc) } + + def self.random + order("RANDOM()").first.text rescue "Waiting for new topics ..." + end +end diff --git a/app/services/conversation.rb b/app/services/conversation.rb new file mode 100644 index 0000000..8f2b202 --- /dev/null +++ b/app/services/conversation.rb @@ -0,0 +1,63 @@ +class Conversation + def initialize(*user_ids) + @user_ids = user_ids + end + + def create + @c_id = "conversation_" + SecureRandom.uuid + + REDIS.sadd @c_id, @user_ids + + # set the user_id values to the c_id + @user_ids.each do |u_id| + REDIS.set u_id, @c_id + end + + self.class.broadcast(@c_id, "System", message: "You've been matched!", topic: Topic.random) + end + + def self.broadcast(conversation_id, nickname, opts = {}) + user_ids = REDIS.smembers conversation_id + payload = { nickname: nickname } + + if opts[:message] + payload[:message] = format_message(nickname, opts[:message]) + end + + if opts[:topic] + payload[:topic] = opts[:topic] + end + + user_ids.each do |u_id| + ActionCable.server.logger.silence do + ActionCable.server.broadcast u_id, payload + end + end + end + + def self.broadcast_from_user(user_id, nickname, message) + c_id = REDIS.get user_id + broadcast(c_id, nickname, message: message) + end + + def self.broadcast_typing_from_user(user_id, nickname) + c_id = REDIS.get user_id + user_ids = REDIS.smembers c_id + + user_ids.each do |u_id| + unless u_id == user_id + ActionCable.server.logger.silence do + ActionCable.server.broadcast u_id, { nickname: nickname, typing: true } + end + end + end + end + + def self.format_message(nickname, message) + messsage_formatter = MessageFormatter.new(message) + message_with_markup = messsage_formatter.markup + + res = ChatController.render partial: 'message', locals: { nickname: nickname, message: message_with_markup } + res.squish + end +end diff --git a/app/services/matcher.rb b/app/services/matcher.rb new file mode 100644 index 0000000..2729e94 --- /dev/null +++ b/app/services/matcher.rb @@ -0,0 +1,55 @@ +class Matcher + WAITING_POOL = "chat_waiting_pool" + + def self.create_chat(user_id) + partner = REDIS.spop(WAITING_POOL) + prev_partners = [] + + # cycle throught the waiting pool until you find a partner + while (REDIS.sismember "#{user_id}:recent", partner) do + prev_partners << partner + partner = REDIS.spop(WAITING_POOL) + end + + if partner + conversation = Conversation.new(user_id, partner) + conversation.create + else + REDIS.sadd(WAITING_POOL, user_id) + unless prev_partners.empty? + REDIS.sadd(WAITING_POOL, prev_partners) + end + end + end + + def self.remove(uuid) + REDIS.srem(WAITING_POOL, uuid) + end + + def self.remove_all + REDIS.del(WAITING_POOL) + end + + def self.conversation_ended_by_user(user_id) + c_id = REDIS.get user_id + user_ids = REDIS.smembers c_id + + user_ids.each do |u_id| + REDIS.del u_id + REDIS.sadd "#{u_id}:recent", user_ids + REDIS.expire "#{u_id}:recent", 15 + put_in_waiting(u_id) + end + + REDIS.del c_id + + # Return all of the user_ids except the one that I entered + user_ids.select { |u_id| u_id != user_id } + end + + def self.put_in_waiting(user_id) + ActionCable.server.logger.silence do + ActionCable.server.broadcast user_id, { waiting_pool: true } + end + end +end diff --git a/app/services/message_formatter.rb b/app/services/message_formatter.rb new file mode 100644 index 0000000..55e661f --- /dev/null +++ b/app/services/message_formatter.rb @@ -0,0 +1,13 @@ +require "uri" + +class MessageFormatter + def initialize(text) + @text = CGI::escapeHTML text + end + + # in case I want to add markdown parsing + def markup + res = Rinku.auto_link @text, :urls, "target='_window'", ["a", "pre", "code", "kbd", "script", "img"] + res.html_safe + end +end diff --git a/app/views/chat/_instructions.html.erb b/app/views/chat/_instructions.html.erb new file mode 100644 index 0000000..7c5f6f1 --- /dev/null +++ b/app/views/chat/_instructions.html.erb @@ -0,0 +1,5 @@ +<%= content_tag :div, id: 'chat-instructions', data: { nickname: nickname } do %> + <%= render 'message', nickname: 'System', message: "Start with where you're from and what occupies most of your time + (e.g. your occupation, seeking employment, or taking care of your kids / parents)." %> + <%= render 'message', nickname: 'System', message: "When possible share URLs to help others understand your point of view." %> +<% end %> diff --git a/app/views/chat/_loading.html.erb b/app/views/chat/_loading.html.erb new file mode 100644 index 0000000..f7b1ee7 --- /dev/null +++ b/app/views/chat/_loading.html.erb @@ -0,0 +1,3 @@ +
    + Please wait to be assigned to a conversation ... +
    diff --git a/app/views/chat/_message.html.erb b/app/views/chat/_message.html.erb new file mode 100644 index 0000000..58eeb65 --- /dev/null +++ b/app/views/chat/_message.html.erb @@ -0,0 +1,7 @@ +<% label_class = 'label' %> +<% label_class += ' secondary' if nickname =~ /System/i %> + +
    + <%= content_tag :span, class: label_class, data: { nickname: nickname } do; nickname; end %> + <%= message %> +
    diff --git a/app/views/chat/index.html.erb b/app/views/chat/index.html.erb new file mode 100644 index 0000000..3f103cd --- /dev/null +++ b/app/views/chat/index.html.erb @@ -0,0 +1,42 @@ +
    +
    +
    +
    + <%= render "layouts/header" %> +
    + +
    +
    + <%= render partial: "instructions", locals: { nickname: @nickname } %> + <%= render partial: "loading" %> +
    +
    +
    +
    + +
    +
    + +
    +
    +
    +
    + +
    +
    + Consider discussing:
    + +
    + + <%= button_tag "Next Conversation", id: "chat-next", class: "button warning expanded" %> + +
    Links shared
    + + + <%= render partial: "layouts/footer" %> +
    +
    diff --git a/app/views/layouts/_flash_message.html.erb b/app/views/layouts/_flash_message.html.erb new file mode 100644 index 0000000..869f316 --- /dev/null +++ b/app/views/layouts/_flash_message.html.erb @@ -0,0 +1,6 @@ +
    + <%= message %> + +
    diff --git a/app/views/layouts/_flash_messages.html.erb b/app/views/layouts/_flash_messages.html.erb new file mode 100644 index 0000000..a054566 --- /dev/null +++ b/app/views/layouts/_flash_messages.html.erb @@ -0,0 +1,5 @@ +
    + <% flash.each do |type, message| %> + <%= render "layouts/flash_message", type: type, message: message %> + <% end %> +
    diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb new file mode 100644 index 0000000..aff61fe --- /dev/null +++ b/app/views/layouts/_footer.html.erb @@ -0,0 +1,25 @@ +<% + opts = {} + if @no_footer + opts = { target: "_window" } + end +%> + +
    + +
    +
    +
    + + + + Made by <%= link_to "Cyrus Stoller", "http://www.cyrusstoller.com/?ref=echoremix", target: "_window" %> + © <%= Time.now.year %> + +
    +
    +
    diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb new file mode 100644 index 0000000..1411c41 --- /dev/null +++ b/app/views/layouts/_header.html.erb @@ -0,0 +1,7 @@ +
    +
    + <%= link_to root_path do %> + <%= image_tag "title-logo.svg", class: logo_class %> + <% end %> +
    +
    \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..d5f5f03 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,34 @@ + + + + + + + <%= title %> + + <%= stylesheet_link_tag 'application', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + <%= render partial: 'shared/google_analytics' %> + <%= render partial: 'shared/social_meta' %> + <%= csrf_meta_tags %> + <%= action_cable_meta_tag %> + <%= yield :header %> + + + + <%= render partial: 'layouts/flash_messages' %> + <%= render partial: 'layouts/header' %> + + <%= yield :unbound %> + +
    +
    + <%= yield %> +
    +
    + + <% unless @no_footer %> + <%= render partial: 'layouts/footer' %> + <% end %> + + diff --git a/app/views/layouts/empty.html.erb b/app/views/layouts/empty.html.erb new file mode 100644 index 0000000..da69815 --- /dev/null +++ b/app/views/layouts/empty.html.erb @@ -0,0 +1,21 @@ + + + + + + + <%= title %> + + <%= stylesheet_link_tag 'application', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + <%= render partial: 'shared/google_analytics' %> + <%= render partial: 'shared/social_meta' %> + <%= csrf_meta_tags %> + <%= action_cable_meta_tag %> + <%= yield :header %> + + + + <%= yield %> + + diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000..cbd34d2 --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000..37f0bdd --- /dev/null +++ b/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/app/views/shared/_error_messages.html.erb b/app/views/shared/_error_messages.html.erb new file mode 100644 index 0000000..8a86f8a --- /dev/null +++ b/app/views/shared/_error_messages.html.erb @@ -0,0 +1,15 @@ +<% if object.errors.any? %> +
    +
    +

    + <%= pluralize(object.errors.count, "error") %> + prohibited this <%= object.class.to_s.underscore.humanize.downcase %> from being saved: +

    +
      + <% object.errors.full_messages.each do |m| %> +
    • <%= m %>
    • + <% end %> +
    +
    +
    +<% end %> diff --git a/app/views/shared/_google_analytics.html.erb b/app/views/shared/_google_analytics.html.erb new file mode 100644 index 0000000..b95028b --- /dev/null +++ b/app/views/shared/_google_analytics.html.erb @@ -0,0 +1,10 @@ + diff --git a/app/views/shared/_social_meta.html.erb b/app/views/shared/_social_meta.html.erb new file mode 100644 index 0000000..474b68c --- /dev/null +++ b/app/views/shared/_social_meta.html.erb @@ -0,0 +1,13 @@ + + + + + +" /> + + + + + + +" /> diff --git a/app/views/static/about.html.erb b/app/views/static/about.html.erb new file mode 100644 index 0000000..86e1b7e --- /dev/null +++ b/app/views/static/about.html.erb @@ -0,0 +1,54 @@ +
    +
    +

    About

    + +

    + 2016 has been a year that's highlighted deep divisions in society. + Sadly, instead of reaching out to those we disagree with to help + them understand our points of view and to help us to understand theirs, + we've retreated to the comfort of echo chambers on social media and + mainstream news of our choosing. + By limiting our exposure to the opinions of those who agree with us, + we've lost empathy for each other. + The fact that many people are saying, "I don't care that I don't + have empathy for them", epitomizes this. +

    + +
    + +
    +

    + + EchoRemix is a platform to respectfully and anonymously discuss + political issues with people who live outside our immediate communities. + +

    +
    + +
    + +

    + Ideally, this website will provide us with an opportunity to talk with + people who might have a different point of view. + My sincere hope is that people choosing to use this website + will come to each conversation with an open mind and a willingness + to listen. +

    + +

    + To help keep conversations candid, participants will be invited to + engage in anonymous one-on-one text-chat sessions on a + controversial topic (e.g. "Healthcare Reform" or "Gun Control"). +

    + +

    + Once you feel like the conversation has reached its conclusion, + hit the next button and you'll be assigned to a new + conversation. + If you have questions about how this works, + take a look at the <%= link_to "FAQs", faq_path %> and the + <%= link_to "community guidelines", community_guidelines_path %> + that users are asked to abide by. +

    +
    +
    diff --git a/app/views/static/community_guidelines.html.erb b/app/views/static/community_guidelines.html.erb new file mode 100644 index 0000000..df39de1 --- /dev/null +++ b/app/views/static/community_guidelines.html.erb @@ -0,0 +1,51 @@ +
    +
    +

    Community Guidelines

    + +

    + EchoRemix is both a place to share and a place to listen. + By participating, you will: +

    +
      +
    • Keep an open mind
    • +
    • Give others a chance to explain themselves fully
    • +
    • Share evidence that supports your points of view (especially when asked)
    • +
    • Be prepared to confront uncomfortable and taboo differences
    • +
    • Engage with others who disagree with you on fundamental issues
    • +
    • Articulate your opinions fully and without restraint
    • +
    • Strive for better mutual understanding
    • +
    + +

    + When asking for clarification about a point that feels offensive to you, + ask open-ended questions. + For example, when discussing abortion, + if someone makes a comment about their definition of human + life that you disagree with, ask why they think that, + instead of telling them that they're wrong. +

    + +

    + It never hurts to start your statements with "For me...". + Start by talking about your opinions and your background, because, after all, + that's what you know best. +

    + +

    + The goal is not necessarily to convince others to change their mind. + The goal is for others to have a better understanding of how you have come to + a different point of view. For example, a religious person should not + strive to convince an atheist that God exists. + Rather, at the end of the conversation, both parties should have a better + understanding of why it could be reasonable for someone else to hold an opposing view. +

    + +

    + Thank you for engaging in this experiment. Hopefully we will all grow to have + greater empathy for one another and have the courage to seek out those who + disagree with us even on the most fundamental issues. + It seems foolish for us to get locked into an echo chamber. + Hopefully, this is one of many ways for us to keep the door open. +

    +
    +
    diff --git a/app/views/static/faq.html.erb b/app/views/static/faq.html.erb new file mode 100644 index 0000000..edf86c8 --- /dev/null +++ b/app/views/static/faq.html.erb @@ -0,0 +1,40 @@ +
    +
    +

    Frequently Asked Questions

    + +

    Can I save my conversations?

    +

    + No. EchoRemix does not store any of the messages sent by users. + Conversations are destroyed as soon as either user clicks Next Conversation. +

    + +

    What if someone takes a screenshot?

    +

    + If you're concerned that what you've said could be embarrassing if it were traced back to you, + then be sure to use a generic nickname like John Doe and refrain from sharing + any personally identifiable information. +

    + +

    What if I want to continue my conversation?

    +

    + Feel free to exchange email addresses or Twitter handles so you can get + in touch in the future. +

    + +

    Is it ok to play devil's advocate?

    +

    + Absolutely. Just remember to stay civil and to keep the tone constructive. +

    + +

    What do I do if someone is attacking me?

    +

    + If you ever feel uncomfortable during a conversation, remember that you're in control. + Don't hesitate to push Next Conversation. You won't be matched with + the same person again during the same session. Because every user is + anonymous, beware that as soon as you close your browser, you'll be treated + as a brand new user again. + As a result, there's no way for the system to police bad user behavior + or to know who you might be matched with in the future. +

    +
    +
    diff --git a/app/views/static/welcome.html.erb b/app/views/static/welcome.html.erb new file mode 100644 index 0000000..5cfd738 --- /dev/null +++ b/app/views/static/welcome.html.erb @@ -0,0 +1,20 @@ +
    +
    + +

    + Anonymous one-on-one conversations about topics that matter. + <%= link_to "Learn more", action: "about" %> about what to expect. +

    + +
    + + <%= form_tag chat_path, method: :post do %> + <%= text_field_tag(:nickname, "", placeholder: "Choose a nickname") %> +

    + By clicking accept, you agree to abide by our + <%= link_to "community guidelines", action: "community_guidelines" %>. +

    + <%= submit_tag "Accept & Get Started", class: "button" %> + <% end %> +
    +
    \ No newline at end of file diff --git a/app/views/topics/_form.html.erb b/app/views/topics/_form.html.erb new file mode 100644 index 0000000..c94fc12 --- /dev/null +++ b/app/views/topics/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_for(topic) do |f| %> + <%= render "shared/error_messages", object: f.object %> + +
    + <%= f.label :text %> + <%= f.text_field :text %> +
    + +
    + <%= f.label :weight %> + <%= f.number_field :weight %> +
    + +
    + <%= f.submit class: "button" %> +
    +<% end %> diff --git a/app/views/topics/_topic.json.jbuilder b/app/views/topics/_topic.json.jbuilder new file mode 100644 index 0000000..6912baa --- /dev/null +++ b/app/views/topics/_topic.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! topic, :id, :text, :weight, :created_at, :updated_at +json.url topic_url(topic, format: :json) \ No newline at end of file diff --git a/app/views/topics/edit.html.erb b/app/views/topics/edit.html.erb new file mode 100644 index 0000000..4146f18 --- /dev/null +++ b/app/views/topics/edit.html.erb @@ -0,0 +1,11 @@ +

    Editing Topic

    + +
    +
    + <%= render 'form', topic: @topic %> + + <%= link_to 'Show', @topic %> | + <%= link_to 'Back', topics_path %> + +
    +
    diff --git a/app/views/topics/index.html.erb b/app/views/topics/index.html.erb new file mode 100644 index 0000000..1eb638c --- /dev/null +++ b/app/views/topics/index.html.erb @@ -0,0 +1,33 @@ +

    Topics

    + + + + + + + + + + + + <% @topics.each do |topic| %> + + + + + + <% end %> + +
    TextWeight
    <%= topic.text %><%= topic.weight %> +
    + <%= link_to 'Show', topic, class: "button secondary" %> + <%= link_to 'Edit', edit_topic_path(topic), class: "button secondary" %> + <%= link_to 'Destroy', topic, method: :delete, data: { confirm: 'Are you sure?' }, class: "button alert" %> +
    +
    + +<%= will_paginate @topics, renderer: FoundationPagination::Rails %> + +
    + +<%= render "form", topic: @topic %> diff --git a/app/views/topics/index.json.jbuilder b/app/views/topics/index.json.jbuilder new file mode 100644 index 0000000..62da17b --- /dev/null +++ b/app/views/topics/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @topics, partial: 'topics/topic', as: :topic \ No newline at end of file diff --git a/app/views/topics/new.html.erb b/app/views/topics/new.html.erb new file mode 100644 index 0000000..f5bb870 --- /dev/null +++ b/app/views/topics/new.html.erb @@ -0,0 +1,9 @@ +

    New Topic

    + +
    +
    + <%= render 'form', topic: @topic %> + + <%= link_to 'Back', topics_path %> +
    +
    diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb new file mode 100644 index 0000000..114904e --- /dev/null +++ b/app/views/topics/show.html.erb @@ -0,0 +1,12 @@ +

    + Text: + <%= @topic.text %> +

    + +

    + Weight: + <%= @topic.weight %> +

    + +<%= link_to 'Edit', edit_topic_path(@topic) %> | +<%= link_to 'Back', topics_path %> diff --git a/app/views/topics/show.json.jbuilder b/app/views/topics/show.json.jbuilder new file mode 100644 index 0000000..c526a89 --- /dev/null +++ b/app/views/topics/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "topics/topic", topic: @topic \ No newline at end of file diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000..66e9889 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000..5badb2f --- /dev/null +++ b/bin/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..d87d5f5 --- /dev/null +++ b/bin/rake @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..e620b4d --- /dev/null +++ b/bin/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/spring b/bin/spring new file mode 100755 index 0000000..9bc076b --- /dev/null +++ b/bin/spring @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby + +# This file loads spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. + +unless defined?(Spring) + require 'rubygems' + require 'bundler' + + lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) + if spring = lockfile.specs.detect { |spec| spec.name == "spring" } + Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path + gem 'spring', spring.version + require 'spring/binstub' + end +end diff --git a/bin/update b/bin/update new file mode 100755 index 0000000..a8e4462 --- /dev/null +++ b/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..f7ba0b5 --- /dev/null +++ b/config.ru @@ -0,0 +1,5 @@ +# This file is used by Rack-based servers to start the application. + +require_relative 'config/environment' + +run Rails.application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000..b87c711 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,17 @@ +require_relative 'boot' + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +Dotenv::Railtie.load + +module EchoRemix + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000..30f5120 --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,3 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 0000000..0a0d73e --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,14 @@ +default: &default + adapter: redis + url: redis://localhost:6379/1 + +development: + <<: *default + +test: + <<: *default + url: redis://localhost:6379/2 + +production: + adapter: redis + url: redis://localhost:6379/1 diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..e4df54e --- /dev/null +++ b/config/database.yml @@ -0,0 +1,85 @@ +# PostgreSQL. Versions 9.1 and up are supported. +# +# Install the pg driver: +# gem install pg +# On OS X with Homebrew: +# gem install pg -- --with-pg-config=/usr/local/bin/pg_config +# On OS X with MacPorts: +# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config +# On Windows: +# gem install pg +# Choose the win32 build. +# Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem 'pg' +# +default: &default + adapter: postgresql + encoding: unicode + # For details on connection pooling, see rails configuration guide + # http://guides.rubyonrails.org/configuring.html#database-pooling + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + +development: + <<: *default + database: EchoRemix_development + + # The specified database role being used to connect to postgres. + # To create additional roles in postgres see `$ createuser --help`. + # When left blank, postgres will use the default role. This is + # the same name as the operating system user that initialized the database. + #username: EchoRemix + + # The password associated with the postgres role (username). + #password: + + # Connect on a TCP socket. Omitted by default since the client uses a + # domain socket that doesn't need configuration. Windows does not have + # domain sockets, so uncomment these lines. + #host: localhost + + # The TCP port the server listens on. Defaults to 5432. + # If your server runs on a different port number, change accordingly. + #port: 5432 + + # Schema search path. The server defaults to $user,public + #schema_search_path: myapp,sharedapp,public + + # Minimum log levels, in increasing order: + # debug5, debug4, debug3, debug2, debug1, + # log, notice, warning, error, fatal, and panic + # Defaults to warning. + #min_messages: notice + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: EchoRemix_test + +# As with config/secrets.yml, you never want to store sensitive information, +# like your database password, in your source code. If your source code is +# ever seen by anyone, they now have access to your database. +# +# Instead, provide the password as a unix environment variable when you boot +# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full rundown on how to provide these environment variables in a +# production deployment. +# +# On Heroku and other platform providers, you may have a full connection URL +# available as an environment variable. For example: +# +# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" +# +# You can use this database configuration with: +# +# production: +# url: <%= ENV['DATABASE_URL'] %> +# +production: + <<: *default + database: EchoRemix_production + username: <%= ENV['ECHOREMIX_DATABASE_USER'] %> + password: <%= ENV['ECHOREMIX_DATABASE_PASSWORD'] %> diff --git a/config/deploy.rb b/config/deploy.rb new file mode 100644 index 0000000..651739e --- /dev/null +++ b/config/deploy.rb @@ -0,0 +1,42 @@ +# config valid only for current version of Capistrano +lock "3.7.1" + +set :application, "echoremix" +set :repo_url, "git@github.com:cyrusstoller/EchoRemix.git" + +# Default branch is :master +# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp +set :branch, proc { ENV["REVISION"] || ENV["BRANCH_NAME"] || "master" } + +# Default deploy_to directory is /var/www/my_app_name +# set :deploy_to, "/var/www/my_app_name" + +# Default value for :format is :airbrussh. +# set :format, :airbrussh + +# You can configure the Airbrussh format using :format_options. +# These are the defaults. +# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto + +# Default value for :pty is false +set :pty, true + +# Default value for :linked_files is [] +append :linked_files, ".env", "config/puma.rb" + +# Default value for linked_dirs is [] +append :linked_dirs, *%w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/assets public/system} + +# Default value for default_env is {} +# set :default_env, { path: "/opt/ruby/bin:$PATH" } + +# Default value for keep_releases is 5 +# set :keep_releases, 5 + +set :rbenv_type, :system +set :rbenv_ruby, "2.3.1" + +set :puma_init_active_record, true +set :puma_bind, -> { File.join("unix://#{shared_path}", 'tmp', 'sockets', "#{fetch(:application)}_puma.sock") } +set :puma_workers, 2 +set :puma_conf, -> { "#{shared_path}/config/puma.rb" } diff --git a/config/deploy/production.rb b/config/deploy/production.rb new file mode 100644 index 0000000..9c5567f --- /dev/null +++ b/config/deploy/production.rb @@ -0,0 +1,65 @@ +# server-based syntax +# ====================== +# Defines a single server with a list of roles and multiple properties. +# You can define all roles on a single server, or split them: + +# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value +# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value +# server "db.example.com", user: "deploy", roles: %w{db} + +server "chat.echoremix.com", user: "deployer", roles: %w{app db web} + +set :rails_env, :production + +# role-based syntax +# ================== + +# Defines a role with one or multiple servers. The primary server in each +# group is considered to be the first unless any hosts have the primary +# property set. Specify the username and a domain or IP for the server. +# Don't use `:all`, it's a meta role. + +# role :app, %w{deploy@example.com}, my_property: :my_value +# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value +# role :db, %w{deploy@example.com} + + + +# Configuration +# ============= +# You can set any configuration variable like in config/deploy.rb +# These variables are then only loaded and set in this stage. +# For available Capistrano configuration variables see the documentation page. +# http://capistranorb.com/documentation/getting-started/configuration/ +# Feel free to add new variables to customise your setup. + +set :nginx_server_name, -> { "echoremix.com chat.echoremix.com" } +set :nginx_use_ssl, true +set :ssl_cert_domain, -> { "echoremix.com" } + +# Custom SSH Options +# ================== +# You may pass any option but keep in mind that net/ssh understands a +# limited set of options, consult the Net::SSH documentation. +# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start +# +# Global options +# -------------- +# set :ssh_options, { +# keys: %w(/home/rlisowski/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(password) +# } +# +# The server-based syntax can be used to override options: +# ------------------------------------ +# server "example.com", +# user: "user_name", +# roles: %w{web app}, +# ssh_options: { +# user: "user_name", # overrides user setting above +# keys: %w(/home/user_name/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(publickey password) +# # password: "please use keys" +# } diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb new file mode 100644 index 0000000..d4a9a13 --- /dev/null +++ b/config/deploy/staging.rb @@ -0,0 +1,63 @@ +# server-based syntax +# ====================== +# Defines a single server with a list of roles and multiple properties. +# You can define all roles on a single server, or split them: + +# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value +# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value +# server "db.example.com", user: "deploy", roles: %w{db} + +server "192.168.33.11", user: "deployer", roles: %w{app db web} + +set :rails_env, :production + +# role-based syntax +# ================== + +# Defines a role with one or multiple servers. The primary server in each +# group is considered to be the first unless any hosts have the primary +# property set. Specify the username and a domain or IP for the server. +# Don't use `:all`, it's a meta role. + +# role :app, %w{deploy@example.com}, my_property: :my_value +# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value +# role :db, %w{deploy@example.com} + + + +# Configuration +# ============= +# You can set any configuration variable like in config/deploy.rb +# These variables are then only loaded and set in this stage. +# For available Capistrano configuration variables see the documentation page. +# http://capistranorb.com/documentation/getting-started/configuration/ +# Feel free to add new variables to customise your setup. + + + +# Custom SSH Options +# ================== +# You may pass any option but keep in mind that net/ssh understands a +# limited set of options, consult the Net::SSH documentation. +# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start +# +# Global options +# -------------- +# set :ssh_options, { +# keys: %w(/home/rlisowski/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(password) +# } +# +# The server-based syntax can be used to override options: +# ------------------------------------ +# server "example.com", +# user: "user_name", +# roles: %w{web app}, +# ssh_options: { +# user: "user_name", # overrides user setting above +# keys: %w(/home/user_name/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(publickey password) +# # password: "please use keys" +# } diff --git a/config/deploy/templates/nginx_conf.erb b/config/deploy/templates/nginx_conf.erb new file mode 100644 index 0000000..ff9a590 --- /dev/null +++ b/config/deploy/templates/nginx_conf.erb @@ -0,0 +1,116 @@ +upstream puma_<%= fetch(:nginx_config_name) %> { <% + flags = 'fail_timeout=0' + @backends = [fetch(:puma_bind)].flatten.map do |m| + etype, address = /(tcp|unix|ssl):\/{1,2}(.+)/.match(m).captures + if etype =='unix' + "server #{etype}:#{address} #{fetch(:nginx_socket_flags)};" + else + "server #{address.gsub(/0\.0\.0\.0(.+)/, "127.0.0.1\\1")} #{fetch(:nginx_http_flags)};" + end +end +%><% @backends.each do |server| %> + <%= server %><% end %> +} +<% if fetch(:nginx_use_ssl) %> +server { + listen 80; + + server_name <%= fetch(:nginx_server_name) %>; + + location /.well-known { + root <%= fetch(:deploy_to) %>; + } + + location / { + rewrite ^(.*) https://$host$1 permanent; + } +} +<% end %> + + +server { +<% if fetch(:nginx_use_ssl) %> + listen 443; + ssl on; + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; + ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA; + ssl_session_cache shared:SSL:50m; + ssl_prefer_server_ciphers on; + + ssl_certificate /etc/letsencrypt/live/<%= fetch(:ssl_cert_domain) %>/fullchain.pem; + ssl_trusted_certificate /etc/letsencrypt/live/<%= fetch(:ssl_cert_domain) %>/chain.pem; + ssl_certificate_key /etc/letsencrypt/live/<%= fetch(:ssl_cert_domain) %>/privkey.pem; +<% else %> + listen 80; +<% end %> + + client_max_body_size 4G; + keepalive_timeout 10; + + error_page 500 502 504 /500.html; + error_page 503 @503; + + server_name <%= fetch(:nginx_server_name) %>; + root <%= current_path %>/public; + try_files $uri/index.html $uri @puma_<%= fetch(:nginx_config_name) %>; + + access_log /var/log/nginx/<%= fetch(:application) %>_access.log; + + location /.well-known { + root <%= fetch(:deploy_to) %>; + } + + location /cable { + proxy_pass http://puma_<%= fetch(:nginx_config_name) %>/cable; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_redirect off; + } + + location @puma_<%= fetch(:nginx_config_name) %> { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; +<% if fetch(:nginx_use_ssl) %> + proxy_set_header X-Forwarded-Proto https; +<% end %> + proxy_pass http://puma_<%= fetch(:nginx_config_name) %>; + # limit_req zone=one; + } + + location ^~ /assets/ { + gzip_static on; + expires max; + add_header Cache-Control public; + } + + location = /50x.html { + root html; + } + + location = /404.html { + root html; + } + + location @503 { + error_page 405 = /system/maintenance.html; + if (-f $document_root/system/maintenance.html) { + rewrite ^(.*)$ /system/maintenance.html break; + } + rewrite ^(.*)$ /503.html break; + } + + if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){ + return 405; + } + + if (-f $document_root/system/maintenance.html) { + return 503; + } + + location ~ \.(php|html)$ { + return 405; + } +} diff --git a/config/deploy/templates/puma.rb.erb b/config/deploy/templates/puma.rb.erb new file mode 100644 index 0000000..e5117be --- /dev/null +++ b/config/deploy/templates/puma.rb.erb @@ -0,0 +1,42 @@ +#!/usr/bin/env puma + +directory '<%= current_path %>' +rackup "<%=fetch(:puma_rackup)%>" +environment '<%= fetch(:puma_env) %>' +<% if fetch(:puma_tag) %> + tag '<%= fetch(:puma_tag)%>' +<% end %> +pidfile "<%=fetch(:puma_pid)%>" +state_path "<%=fetch(:puma_state)%>" +stdout_redirect '<%=fetch(:puma_access_log)%>', '<%=fetch(:puma_error_log)%>', true + + +threads <%=fetch(:puma_threads).join(',')%> + +<%= puma_bind %> +<% if fetch(:puma_control_app) %> +activate_control_app "<%= fetch(:puma_default_control_app) %>" +<% end %> +workers <%= puma_workers %> +<% if fetch(:puma_worker_timeout) %> +worker_timeout <%= fetch(:puma_worker_timeout).to_i %> +<% end %> + +<% if puma_preload_app? %> +preload_app! +<% else %> +prune_bundler +<% end %> + +on_restart do + puts 'Refreshing Gemfile' + ENV["BUNDLE_GEMFILE"] = "<%= fetch(:bundle_gemfile, "#{current_path}/Gemfile") %>" +end + +<% if puma_preload_app? and fetch(:puma_init_active_record) %> +on_worker_boot do + ActiveSupport.on_load(:active_record) do + ActiveRecord::Base.establish_connection + end +end +<% end %> diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..426333b --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000..64fb99a --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,57 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=172800' + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + # config.action_cable.allowed_request_origins = [ /https?:\/\/localhost:\d+/, /https?:\/\/vulcan.local:\d+/ ] + config.action_cable.disable_request_forgery_protection = true +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000..61b08cd --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,87 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Mount Action Cable outside main process or domain + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + config.action_cable.allowed_request_origins = [ /https?:\/\/.*echoremix.com/ ] + config.action_cable.disable_request_forgery_protection = ENV['ACTION_CABLE_ALL_DOMAINS'] ? true : false + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "EchoRemix_#{Rails.env}" + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000..30587ef --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,42 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=3600' + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000..51639b6 --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000..01ef3e6 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,11 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000..5a6a32d --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 0000000..dc18996 --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb new file mode 100644 index 0000000..0706caf --- /dev/null +++ b/config/initializers/new_framework_defaults.rb @@ -0,0 +1,24 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.0 upgrade. +# +# Read the Rails 5.0 release notes for more info on each option. + +# Enable per-form CSRF tokens. Previous versions had false. +Rails.application.config.action_controller.per_form_csrf_tokens = true + +# Enable origin-checking CSRF mitigation. Previous versions had false. +Rails.application.config.action_controller.forgery_protection_origin_check = true + +# Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. +# Previous versions had false. +ActiveSupport.to_time_preserves_timezone = true + +# Require `belongs_to` associations by default. Previous versions had false. +Rails.application.config.active_record.belongs_to_required_by_default = true + +# Do not halt callback chains when a callback returns false. Previous versions had true. +ActiveSupport.halt_callback_chains_on_return_false = false + +# Configure SSL options to enable HSTS with subdomains. Previous versions had false. +Rails.application.config.ssl_options = { hsts: { subdomains: true } } diff --git a/config/initializers/redis.rb b/config/initializers/redis.rb new file mode 100644 index 0000000..9f50e5b --- /dev/null +++ b/config/initializers/redis.rb @@ -0,0 +1,3 @@ +require "redis" + +REDIS = Redis.new(Rails.application.config_for("cable")) \ No newline at end of file diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb new file mode 100644 index 0000000..43cffa8 --- /dev/null +++ b/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.session_store :cookie_store, key: '_EchoRemix_session' diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..bbfc396 --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..0653957 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..9709e23 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,49 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum, this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. If you use this option +# you need to make sure to reconnect any threads in the `on_worker_boot` +# block. +# +# preload_app! + +# The code in the `on_worker_boot` will be called if you are using +# clustered mode by specifying a number of `workers`. After each worker +# process is booted this block will be run, if you are using `preload_app!` +# option you will want to use this block to reconnect to any threads +# or connections that may have been created at application boot, Ruby +# cannot share connections between processes. + +on_worker_boot do + ActiveRecord::Base.establish_connection if defined?(ActiveRecord) +end + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart + +pidfile 'tmp/puma.pid' diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..1bbdf2a --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,13 @@ +Rails.application.routes.draw do + root to: 'static#welcome' + get '/about', to: 'static#about', as: 'about' + get '/community-guidelines', to: 'static#community_guidelines', as: 'community_guidelines' + get '/faq', to: 'static#faq', as: 'faq' + get '/chat', to: 'chat#index', as: 'chat' + post '/chat', to: 'chat#create' + + resources :topics + + mount ActionCable.server, at: '/cable' + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html +end diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 0000000..4a1a495 --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rails secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: af95c117e9b06994c8f39c439405fdccd07a2622957a9c44c09504a31c08908b2f091c2f59566e944ef746ad05f335b24c3779e7b780ad2dd36c9af951ace54d + +test: + secret_key_base: cf331cbbe77ee4bc825f4479a6fd7a234ef4bbe36e783b40b74c9e9c2c736ac73c2d8886e2d44e4c9120f3d3a746d819deda1c61a844f02ec3925de43603c3dd + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 0000000..c9119b4 --- /dev/null +++ b/config/spring.rb @@ -0,0 +1,6 @@ +%w( + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +).each { |path| Spring.watch(path) } diff --git a/db/migrate/20161211085923_create_topics.rb b/db/migrate/20161211085923_create_topics.rb new file mode 100644 index 0000000..fb185af --- /dev/null +++ b/db/migrate/20161211085923_create_topics.rb @@ -0,0 +1,12 @@ +class CreateTopics < ActiveRecord::Migration[5.0] + def change + create_table :topics do |t| + t.string :text + t.integer :weight + + t.timestamps + end + + add_index :topics, :weight + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..e693fab --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,26 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20161211085923) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "topics", force: :cascade do |t| + t.string "text" + t.integer "weight" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["weight"], name: "index_topics_on_weight", using: :btree + end + +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000..1beea2a --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) +# Character.create(name: 'Luke', movie: movies.first) diff --git a/lib/assets/.keep b/lib/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/lib/capistrano/.gitkeep b/lib/capistrano/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/capistrano/tasks/.gitkeep b/lib/capistrano/tasks/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/capistrano/tasks/env.rake b/lib/capistrano/tasks/env.rake new file mode 100644 index 0000000..eee6d52 --- /dev/null +++ b/lib/capistrano/tasks/env.rake @@ -0,0 +1,29 @@ +require_relative "helper" + +namespace :env do + + desc "update environment variables and restart application" + task :update do + invoke "env:upload" + invoke "puma:phased-restart" + end + + desc "upload environment variables" + task :upload do + puts "Are you sure you want to overwrite your current environment variables (stage: #{fetch(:stage)})?" + puts "Varibles will be copied from lib/capistrano/templates/env.#{fetch(:stage)}" + puts "This cannot be undone. Enter 'yes' to confirm. Any other response will abort." + ask :confirm, "no" + on roles(:all) do |host| + if fetch(:confirm) =~ /\Ayes\z/i + info "uploading templates/env.#{fetch(:stage)} ==> #{shared_path}/.env" + env_config = template("env.#{fetch(:stage)}") + destination_path = Pathname.new("#{shared_path}/.env") + upload! StringIO.new(env_config), destination_path + else + info "aborting change of environment variables" + end + end + end + +end diff --git a/lib/capistrano/tasks/helper.rb b/lib/capistrano/tasks/helper.rb new file mode 100644 index 0000000..a0f66c0 --- /dev/null +++ b/lib/capistrano/tasks/helper.rb @@ -0,0 +1,3 @@ +def template(filename) + File.read(File.expand_path("../../templates/#{filename}", __FILE__)) +end \ No newline at end of file diff --git a/lib/capistrano/tasks/setup.rake b/lib/capistrano/tasks/setup.rake new file mode 100644 index 0000000..7059974 --- /dev/null +++ b/lib/capistrano/tasks/setup.rake @@ -0,0 +1,51 @@ +require_relative "helper" + +desc "Setup the server" +task :setup do + invoke "deploy:check:directories" + invoke "setup:shared_config" + invoke "env:upload" + invoke "puma:config" + invoke "setup:nginx" + invoke "setup:logrotation" + invoke "puma:monit:config" +end + +namespace :setup do + desc "Setup shared config file" + task :shared_config do + on roles(fetch(:puma_role, :app)) do |host| + execute :mkdir, "-p", "#{shared_path}/config" + execute :mkdir, "-p", "#{shared_path}/log" + end + end + + desc "Setup nginx" + task :nginx do + invoke "puma:nginx_config" + + on roles(fetch(:puma_nginx, :web)) do |role| + sudo :service, "nginx", "reload" + end + end + + desc "adding the logrotation config" + task :logrotation do + on roles(fetch(:puma_role, :app)) do |host| + info "copying the puma logrotate.d conf file" + logrotate_conf = ERB.new(template("puma_log_rotate.conf.erb")).result(binding) + + tmp_path = Pathname.new("#{shared_path}/config/puma_log_rotate.conf") + final_path = "/etc/logrotate.d/puma_#{fetch(:application)}" + + upload! StringIO.new(logrotate_conf), tmp_path + execute :chmod, 644, tmp_path + execute :sudo, :mv, tmp_path, final_path + execute :sudo, :chown, "root.root", final_path + + # set permissions + log_path = Pathname.new("#{shared_path}/log") + execute :chmod, 750, log_path + end + end +end diff --git a/lib/capistrano/tasks/uptime.rake b/lib/capistrano/tasks/uptime.rake new file mode 100644 index 0000000..8b9ec2c --- /dev/null +++ b/lib/capistrano/tasks/uptime.rake @@ -0,0 +1,6 @@ +desc "Report Uptimes" +task :uptime do + on roles(:all) do |host| + info "Host #{host} (roles: #{host.roles.map(&:to_s).join(", ")}):\t#{capture(:uptime)}" + end +end \ No newline at end of file diff --git a/lib/capistrano/templates/.gitkeep b/lib/capistrano/templates/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/lib/capistrano/templates/env.example b/lib/capistrano/templates/env.example new file mode 100644 index 0000000..4e3ee15 --- /dev/null +++ b/lib/capistrano/templates/env.example @@ -0,0 +1,6 @@ +ADMIN_USER=cyrus +ADMIN_PASSWORD=stoller +ECHOREMIX_DATABASE_USER=deployer +ECHOREMIX_DATABASE_PASSWORD=PASSWORD +SECRET_KEY_BASE=SECRET +GOOGLE_ANALYTICS_ID=UA-XXXXXX-Y diff --git a/lib/capistrano/templates/monit.conf.erb b/lib/capistrano/templates/monit.conf.erb new file mode 100644 index 0000000..a3ad4c9 --- /dev/null +++ b/lib/capistrano/templates/monit.conf.erb @@ -0,0 +1,7 @@ +# Monit configuration for Puma +# Service name: <%= puma_monit_service_name %> +# +check process <%= puma_monit_service_name %> + with pidfile "<%= fetch(:puma_pid) %>" + start program = "/usr/bin/sudo su - <%= puma_user(@role) %> /bin/bash -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:puma] %> -C <%= fetch(:puma_conf) %> --daemon'" + stop program = "/usr/bin/sudo su - <%= puma_user(@role) %> /bin/bash -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:pumactl] %> -S <%= fetch(:puma_state) %> stop'" diff --git a/lib/capistrano/templates/puma_log_rotate.conf.erb b/lib/capistrano/templates/puma_log_rotate.conf.erb new file mode 100644 index 0000000..4afcf8d --- /dev/null +++ b/lib/capistrano/templates/puma_log_rotate.conf.erb @@ -0,0 +1,31 @@ +# example logrotate config file, I usually keep this in +# /etc/logrotate.d/puma_app on my Debian systems +# +# See the logrotate(8) manpage for more information: +# http://linux.die.net/man/8/logrotate + +# Modify the following glob to match the logfiles your app writes to: +<%= shared_path %>/log/*.log { + # this first block is mostly just personal preference, though + # I wish logrotate offered an "hourly" option... + daily + missingok + rotate 180 + dateext + dateformat %Y%m%d%s + + # must use with delaycompress below + compress + + # this is important if using "compress" since we need to call + # the "lastaction" script below before compressing: + delaycompress + + # note the lack of the evil "copytruncate" option in this + # config. Puma supports the USR1 signal and we send it + # as our "lastaction" action: + lastaction + pid=<%=fetch(:puma_pid)%> + test -s $pid && kill -USR1 "$(cat $pid)" + endscript +} diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 0000000..e69de29 diff --git a/log/.keep b/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..b612547 --- /dev/null +++ b/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
    +
    +

    The page you were looking for doesn't exist.

    +

    You may have mistyped the address or the page may have moved.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/public/422.html b/public/422.html new file mode 100644 index 0000000..a21f82b --- /dev/null +++ b/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
    +
    +

    The change you wanted was rejected.

    +

    Maybe you tried to change something you didn't have access to.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/public/500.html b/public/500.html new file mode 100644 index 0000000..061abc5 --- /dev/null +++ b/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
    +
    +

    We're sorry, but something went wrong.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/public/apple-touch-icon-precomposed.png b/public/apple-touch-icon-precomposed.png new file mode 100644 index 0000000..e69de29 diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png new file mode 100644 index 0000000..e69de29 diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..3c01af3b47f4b64fb45affe9f6e483cd7d88665a GIT binary patch literal 5430 zcmeI0e@K;A7{_1dBt$MIA#ss=yEWXsEw1Lw?lsq_ML5~oa3W&=jEJ#G4F4Dr;$#!% zL}ckDM5I4L#%2(#ZPH*g?2g1Ugm2F| z=bq>JKIb{-JkNQvtUT*EYx8D{zmWC8^Op6ZTA}6sdB#sO7NM&t8qTx-wX6e-yZ_SZ zbl%f|L_AUr!fszHf~kDaR1r+pBLnI?=b*C*M8N=k?Av}J#+=cN4!Yq7v=_k~Xare5(J2F! z==C8V$VO%Grw47N5&Ve<+#Jf)XClN^q^CnSxpt1{ zEgsp5^sSZ;|4HBB^@AbM4z_{E-b?bKYE>z@NBMp$@PS9>WA_^1$p=2*XWipS)uv%k z1B%@9oqf0pK_@sD4JN-pD!(2EVc>Jlb+@rCUd6i(w1G3=7Ff=?@kk1Pn(3En`~`1K44Gvp%U~_3vVM0=Smr)zQ-e-APhYFf&D`AxN2;c z-_cf`xdy0Q-%$#yB^*v zYv7e%i|oM!XppX1gOS)({W*mE75N)={WemZZhti1-4yPL4aV%ctTX0bH|wvV;Y30?NId3h#4#vXb-U+@0cY15~o|O;eDz6X0)C^pwfPMa$55~iHKCg-Q@qX6*^!l)zH-_M@;mnjGmD5w;IPK!ctr;%8*AH@6 zTadb2muQWPQ_jXCCAZZ(+S(Ik*g`k&1=R zLX>&=iYfMvfC=)Zlgn_rrRGe+ubS#P6WA>V{lM@!rM^#x;oT)}vzOS?8LtNY_%n-i zbGrMg>n*?&1MC*T@xF_Hf&K(gP7i=Ach(2)80)8g*l(6I$Xg&+Jmwg0*V#0>PKj-u zdA$+ZGB`$FQ~oXop1SSSRa@U+*yr9Qqr|12_KEBn4B9odnepuRsas!tc;tgG1I5F$ z-duX_F}UT64_pP*?WDeUANdY++t`RcoE<>1_}97RKfJmlp0mCYYkOwn$-h+{{}u3` GH2(zR4D96q literal 0 HcmV?d00001 diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..3c9c7c0 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/test/controllers/.keep b/test/controllers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/controllers/chat_controller_test.rb b/test/controllers/chat_controller_test.rb new file mode 100644 index 0000000..7d3a178 --- /dev/null +++ b/test/controllers/chat_controller_test.rb @@ -0,0 +1,31 @@ +require 'test_helper' + +class ChatControllerTest < ActionDispatch::IntegrationTest + test "should redirect to the root if there is no nickname" do + get chat_url + assert_redirected_to root_url + end + + def create_a_nickname(nickname) + post chat_url, params: { nickname: nickname } + end + + test "should create a chat signed cookie" do + nickname = "cyro" + create_a_nickname nickname + assert_redirected_to chat_url + assert_equal nickname, request.cookie_jar.signed['nickname'] + assert_not_nil request.cookie_jar.signed['uuid'] + end + + test "should stay on the chat page if there is a nickname" do + create_a_nickname "cyrus" + get chat_url + assert_response :success + end + + test "should redirect back to the root_url if they try to call themselves root" do + create_a_nickname "system" + assert_redirected_to root_url + end +end diff --git a/test/controllers/static_controller_test.rb b/test/controllers/static_controller_test.rb new file mode 100644 index 0000000..001f103 --- /dev/null +++ b/test/controllers/static_controller_test.rb @@ -0,0 +1,27 @@ +require 'test_helper' + +class StaticControllerTest < ActionDispatch::IntegrationTest + test "should get welcome" do + get root_url + assert_response :success + assert_select "title", /Welcome/ + end + + test "should get about" do + get about_url + assert_response :success + assert_select "title", /About/ + end + + test "should get community_guidelines" do + get community_guidelines_url + assert_response :success + assert_select "title", /Community Guidelines/ + end + + test "should get faq" do + get faq_url + assert_response :success + assert_select "title", /FAQ/ + end +end diff --git a/test/controllers/topics_controller_test.rb b/test/controllers/topics_controller_test.rb new file mode 100644 index 0000000..e2a874c --- /dev/null +++ b/test/controllers/topics_controller_test.rb @@ -0,0 +1,59 @@ +require 'test_helper' + +class TopicsControllerTest < ActionDispatch::IntegrationTest + setup do + @topic = topics(:one) + end + + def auth_headers + user = ENV["ADMIN_USER"] + pw = ENV["ADMIN_PASSWORD"] + { "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("#{user}:#{pw}")}" } + end + + test "should return 401 without headers" do + get topics_url + assert_equal 401, status + end + + test "should get index" do + get topics_url, headers: auth_headers + assert_response :success + end + + test "should get new" do + get new_topic_url, headers: auth_headers + assert_response :success + end + + test "should create topic" do + assert_difference('Topic.count') do + post topics_url, params: { topic: { text: @topic.text + "!", weight: @topic.weight } }, headers: auth_headers + end + + assert_redirected_to topics_url + end + + test "should show topic" do + get topic_url(@topic), headers: auth_headers + assert_response :success + end + + test "should get edit" do + get edit_topic_url(@topic), headers: auth_headers + assert_response :success + end + + test "should update topic" do + patch topic_url(@topic), params: { topic: { text: @topic.text, weight: @topic.weight } }, headers: auth_headers + assert_redirected_to topic_url(@topic) + end + + test "should destroy topic" do + assert_difference('Topic.count', -1) do + delete topic_url(@topic), headers: auth_headers + end + + assert_redirected_to topics_url + end +end diff --git a/test/fixtures/.keep b/test/fixtures/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/topics.yml b/test/fixtures/topics.yml new file mode 100644 index 0000000..e611a85 --- /dev/null +++ b/test/fixtures/topics.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + text: MyString1 + weight: 1 + +two: + text: MyString2 + weight: 2 diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb new file mode 100644 index 0000000..11677eb --- /dev/null +++ b/test/helpers/application_helper_test.rb @@ -0,0 +1,35 @@ +require 'test_helper' + +class ApplicationHelperTest < ActionView::TestCase + test "should return a title with no bar" do + assert_equal "EchoRemix", title + end + + test "should return a title with a bar" do + @title = "Hello" + assert_equal "EchoRemix | Hello", title + end + + # Logo class tests + + test "should only return the base css class" do + assert_equal "title-logo", logo_class + end + + test "should return two css classes for the logo" do + @logo_class = "small" + assert_equal "title-logo small", logo_class + end + + # Alert type + + test "should return 'alert' when given 'error'" do + assert_equal "alert", alert_type('error') + assert_equal "alert", alert_type(:error) + end + + test "should return 'success' when given 'success'" do + assert_equal "success", alert_type('success') + assert_equal "success", alert_type(:success) + end +end diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/mailers/.keep b/test/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/models/.keep b/test/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/models/topic_test.rb b/test/models/topic_test.rb new file mode 100644 index 0000000..ef34de0 --- /dev/null +++ b/test/models/topic_test.rb @@ -0,0 +1,31 @@ +require 'test_helper' + +class TopicTest < ActiveSupport::TestCase + test "should not be valid without text" do + topic = topics(:one) + topic.text = "" + assert_not topic.valid? + end + + test "should not be valid if the text is non-unique" do + topic = topics(:one).dup + assert_not topic.valid? + end + + test "should not be valid without weight" do + topic = topics(:one) + topic.weight = nil + assert_not topic.valid? + end + + # random text + + test "should provide random text when there are Topics" do + assert_includes %w(MyString1 MyString2), Topic.random + end + + test "should not throw an error when there are no Topics" do + Topic.destroy_all + assert_match /waiting/i, Topic.random + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..92e39b2 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,10 @@ +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + + # Add more helper methods to be used by all tests here... +end diff --git a/tmp/.keep b/tmp/.keep new file mode 100644 index 0000000..e69de29 diff --git a/vendor/assets/javascripts/.keep b/vendor/assets/javascripts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/vendor/assets/stylesheets/.keep b/vendor/assets/stylesheets/.keep new file mode 100644 index 0000000..e69de29