├── .env.sample ├── .gitignore ├── .ruby-version ├── .travis.yml ├── Dockerfile ├── Gemfile ├── Gemfile.lock ├── LICENSE.txt ├── README.md ├── Rakefile ├── app ├── assets │ ├── config │ │ └── manifest.js │ ├── fonts │ │ ├── inkle-Baskerville.woff │ │ ├── inkle-Baskerville.woff2 │ │ ├── writer-Baskerville.woff │ │ └── writer-Baskerville.woff2 │ ├── images │ │ └── .keep │ ├── javascripts │ │ ├── admin │ │ │ └── adminpages │ │ │ │ └── index.js │ │ ├── application.js │ │ ├── channels │ │ │ └── .keep │ │ ├── inklewriter-read.js │ │ ├── inklewriter-write.js │ │ ├── pages │ │ │ └── index.js │ │ └── stories │ │ │ └── show.js │ └── stylesheets │ │ ├── admin │ │ ├── adminpages.scss │ │ └── authorizer.scss │ │ ├── application.css │ │ ├── devise.css.scss │ │ ├── emails.css.scss │ │ ├── errors.css.scss │ │ ├── inking.css.scss │ │ ├── inklewriter.css.scss │ │ ├── pages.css.scss │ │ ├── stories.css.scss │ │ └── users │ │ ├── confirmations.css.scss │ │ ├── passwords.css.scss │ │ ├── registrations.css.scss │ │ ├── sessions.css.scss │ │ └── unlocks.css.scss ├── channels │ └── application_cable │ │ ├── channel.rb │ │ └── connection.rb ├── controllers │ ├── admin │ │ ├── adminpages_controller.rb │ │ └── authorizer_controller.rb │ ├── application_controller.rb │ ├── concerns │ │ └── .keep │ ├── errors_controller.rb │ ├── pages_controller.rb │ ├── stories_controller.rb │ └── users │ │ ├── confirmations_controller.rb │ │ ├── omniauth_callbacks_controller.rb │ │ ├── passwords_controller.rb │ │ ├── registrations_controller.rb │ │ ├── sessions_controller.rb │ │ └── unlocks_controller.rb ├── helpers │ ├── admin │ │ ├── adminpages_helper.rb │ │ └── authorizer_helper.rb │ ├── application_helper.rb │ ├── errors_helper.rb │ ├── pages_helper.rb │ └── stories_helper.rb ├── jobs │ └── application_job.rb ├── mailers │ ├── application_mailer.rb │ ├── custom_devise_mailer.rb │ └── user_mailer.rb ├── models │ ├── admin.rb │ ├── application_record.rb │ ├── concerns │ │ └── .keep │ ├── story.rb │ ├── story_stat.rb │ └── user.rb ├── services │ ├── rating.rb │ ├── rating_unused.rb │ └── stats.rb └── views │ ├── admin │ └── adminpages │ │ └── index.html.erb │ ├── errors │ ├── internal_server_error.html.erb │ └── not_found.html.erb │ ├── layouts │ ├── application.html.erb │ ├── devise_mailer.html.erb │ ├── mailer.html.erb │ └── mailer.text.erb │ ├── pages │ ├── health.html.erb │ ├── index.html.erb │ └── privacy.html.erb │ ├── stories │ ├── cannot_display_stories.html.erb │ ├── inking.html.erb │ ├── not_found.html.erb │ ├── not_story_owner.html.erb │ ├── show.html.erb │ └── show.json.erb │ ├── user_mailer │ ├── test.html.erb │ └── test.text.erb │ └── users │ ├── confirmations │ └── new.html.erb │ ├── mailer │ ├── confirmation_instructions.html.erb │ ├── email_changed.html.erb │ ├── password_change.html.erb │ ├── reset_password_instructions.html.erb │ └── unlock_instructions.html.erb │ ├── passwords │ ├── edit.html.erb │ └── new.html.erb │ ├── registrations │ ├── edit.html.erb │ └── new.html.erb │ ├── sessions │ └── new.html.erb │ ├── shared │ ├── _error_messages.html.erb │ └── _links.html.erb │ └── unlocks │ └── new.html.erb ├── bin ├── bundle ├── rails ├── rake ├── setup ├── spring ├── update └── yarn ├── config.ru ├── config ├── application.rb ├── boot.rb ├── cable.yml ├── credentials.yml.enc ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── application_controller_renderer.rb │ ├── assets.rb │ ├── backtrace_silencers.rb │ ├── content_security_policy.rb │ ├── cookies_serializer.rb │ ├── devise.rb │ ├── filter_parameter_logging.rb │ ├── health_check.rb │ ├── inflections.rb │ ├── mime_types.rb │ ├── session_store.rb │ └── wrap_parameters.rb ├── locales │ ├── devise.en.yml │ └── en.yml ├── puma.rb ├── routes.rb ├── spring.rb └── storage.yml ├── db ├── migrate │ ├── 20190219150520_devise_create_users.rb │ ├── 20190219160258_add_authentication_token_to_users.rb │ ├── 20190618142849_create_stories.rb │ ├── 20190618215055_add_title_to_stories.rb │ ├── 20190827143319_add_url_key_to_stories.rb │ ├── 20201122095701_create_admins.rb │ ├── 20201208163624_create_story_stats.rb │ ├── 20201208164040_add_foreign_key_to_story_stats.rb │ ├── 20201209165106_add_to_story_stat.rb │ └── 20201209182413_add_score.rb ├── schema.rb ├── seeds.rb └── seeds │ ├── development.rb │ ├── production.rb │ └── test.rb ├── docker-compose.yml ├── entrypoint.sh ├── lib ├── assets │ └── .keep ├── mailer_previews │ └── custom_devise_mailer_preview.rb └── tasks │ ├── .keep │ ├── scoring.rake │ └── verify_sanitizing.rake ├── log └── .keep ├── package.json ├── public ├── 404.html ├── 422.html ├── 500.html ├── apple-touch-icon-precomposed.png ├── apple-touch-icon.png ├── favicon.ico ├── img │ ├── 80-days-shelf-icon.png │ ├── arrow-linked.png │ ├── arrow-unlinked.png │ ├── back-arrow.png │ ├── bookmark-cross.png │ ├── bookmark-end.png │ ├── bookmark-left.png │ ├── bookmark-plus.png │ ├── close.png │ ├── conditional-disclosure-closed.png │ ├── conditional-disclosure-open.png │ ├── disclose-close.png │ ├── disclose-open.png │ ├── divider-line.png │ ├── forwardwind.png │ ├── inkle-email-logo.png │ ├── inklewriter_logo-beta.png │ ├── inklewriter_logo-free.png │ ├── lined-paper-bottom.png │ ├── lined-paper-mid.png │ ├── lined-paper-top-cut.png │ ├── lined-paper-top.png │ ├── linen.jpg │ ├── link.png │ ├── magnifying_glass_icon.png │ ├── menubar_bg.png │ ├── menubar_divider.png │ ├── minus.png │ ├── overboard-shelf-icon.png │ ├── pendragon-shelf-icon.png │ ├── point-right-arrow.png │ ├── popupArrow.png │ ├── popupArrow_right.png │ ├── red.png │ ├── rewind.png │ ├── shelf_small.jpg │ ├── small-black-cross.png │ ├── small-plus-black.png │ ├── sorcery-shelf-icon.png │ ├── splash-logo-beta.png │ ├── splash-logo-free.png │ ├── splash-splats.png │ ├── unlink.png │ ├── widgets │ │ ├── bold-enabled.png │ │ ├── bold.png │ │ ├── conditional.png │ │ ├── elipsis.png │ │ ├── insert-image-enabled.png │ │ ├── insert-image.png │ │ ├── italic-enabled.png │ │ ├── italic.png │ │ └── new_section.png │ └── wood.jpg └── robots.txt ├── storage └── .keep ├── system ├── dev_run.sh └── install.sh ├── test ├── application_system_test_case.rb ├── controllers │ ├── .keep │ ├── admin │ │ ├── adminpages_controller_test.rb │ │ └── authorizer_controller_test.rb │ ├── errors_controller_test.rb │ ├── pages_controller_test.rb │ └── stories_controller_test.rb ├── fixtures │ ├── .keep │ ├── admins.yml │ ├── files │ │ └── .keep │ ├── stories.yml │ ├── story_stats.yml │ └── users.yml ├── helpers │ └── .keep ├── integration │ └── .keep ├── mailers │ ├── .keep │ ├── previews │ │ └── user_mailer_preview.rb │ └── user_mailer_test.rb ├── models │ ├── .keep │ ├── admin_test.rb │ ├── story_stat_test.rb │ ├── story_test.rb │ └── user_test.rb ├── system │ └── .keep └── test_helper.rb ├── vendor ├── .keep └── assets │ └── javascript │ ├── ifwriter-main.js │ ├── inklewriter-convert.js │ └── inlewriter-convert.js.map └── yarn.lock /.env.sample: -------------------------------------------------------------------------------- 1 | PGDATA=/var/lib/postgresql/data/pgdata 2 | POSTGRES_HOST=db 3 | POSTGRES_USER=web 4 | POSTGRES_PASSWORD=super_secure 5 | PGPASSWORD=super_secure 6 | SECRET_KEY_BASE=development_secret 7 | RAILS_ENV=production 8 | # Mailer configuration 9 | MAILING_ADDRESS=127.0.0.1 10 | MAILING_PORT=25 11 | MAILING_USER=test 12 | MAILING_PASSWORD=user_smtp_password 13 | MAILING_DOMAIN=inklewriter.com 14 | ACTION_MAILER_HOST=www.inklewriter.com -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-journal 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/* 16 | /tmp/* 17 | !/log/.keep 18 | !/tmp/.keep 19 | 20 | # Ignore uploaded files in development 21 | /storage/* 22 | !/storage/.keep 23 | 24 | /node_modules 25 | /yarn-error.log 26 | 27 | /public/assets 28 | .byebug_history 29 | 30 | # Ignore master key for decrypting credentials and more. 31 | /config/master.key 32 | /config/secrets.yml 33 | 34 | # Netbeans 35 | /nbproject 36 | 37 | # Docker 38 | .env 39 | 40 | # Vim 41 | .*swp 42 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-2.5.0 -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.6 4 | services: 5 | - postgresql 6 | env: 7 | global: 8 | 9 | # for postgresql 10 | - PGHOST=localhost 11 | - PGPORT=5432 12 | - PGUSER=postgres 13 | - PGPASSWORD=anything 14 | 15 | # for application 16 | - POSTGRES_DB=travis_ci 17 | - POSTGRES_HOST=localhost 18 | - POSTGRES_PORT=5433 19 | - POSTGRES_USER=postgres 20 | - POSTGRES_PASSWORD=anything 21 | - SECRET_KEY_BASE=development_secret 22 | 23 | # for docker 24 | - COMMIT=${TRAVIS_COMMIT::8} 25 | 26 | before_install: 27 | # make sure postgres is initialised 28 | - sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf 29 | - sudo service postgresql restart 30 | - sleep 1 31 | - psql -c 'create database inklewriter_test' -U postgres 32 | # install curl for webhooks 33 | - sudo apt-get -y install 34 | 35 | script: 36 | - RAILS_ENV=test bundle exec rake --trace db:migrate 37 | - bundle exec rake db:test:prepare 38 | # build and test docker image: 39 | - cp .env.sample .env 40 | - docker volume create --name=inkledb 41 | - docker-compose up -d || travis_terminate 1 42 | - docker-compose stop 43 | - > 44 | if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then 45 | echo "$DOCKER_PASS" | docker login -u=albancrommer --password-stdin; 46 | case "$TRAVIS_BRANCH" in 47 | "master") 48 | TAG="latest" 49 | ;; 50 | "dev") 51 | TAG="dev" 52 | CD="stageme.inklewriter.com" 53 | ;; 54 | esac 55 | if [[ -n "$TAG" ]]; then 56 | docker tag albancrommer/inklewriter albancrommer/inklewriter:$COMMIT; 57 | docker push albancrommer/inklewriter:$COMMIT; 58 | docker tag albancrommer/inklewriter albancrommer/inklewriter:$TAG; 59 | docker push albancrommer/inklewriter:$TAG; 60 | fi 61 | if [[ -n "$CD" ]]; then 62 | URL="https://$CD/webhooks" 63 | echo "Requesting deployment for branch '$TRAVIS_BRANCH' on '$URL'" 64 | curl -X POST -H "Content-Length: 0" -H "Token: $CD_TOKEN" "$URL" 65 | fi 66 | fi 67 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:2.6.7-alpine 2 | 3 | WORKDIR /usr/src/app 4 | COPY Gemfile* /usr/src/app/ 5 | RUN apk add --update \ 6 | build-base \ 7 | nodejs \ 8 | postgresql-client \ 9 | postgresql-dev \ 10 | shared-mime-info \ 11 | sqlite-dev \ 12 | tzdata \ 13 | yarn \ 14 | && rm -rf /var/cache/apk/* \ 15 | && cd /usr/src/app \ 16 | && bundle install 17 | COPY . . 18 | 19 | COPY entrypoint.sh /usr/bin/ 20 | RUN chmod +x /usr/bin/entrypoint.sh 21 | 22 | ENTRYPOINT ["entrypoint.sh"] 23 | EXPOSE 3000 24 | 25 | # Start the main process. 26 | CMD ["rails", "server", "-b", "0.0.0.0"] 27 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | ruby '> 2.6.0' 5 | 6 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 7 | gem 'rails', '5.2.4.6' 8 | gem 'sprockets', '3.7.2' 9 | # Use sqlite3 as the database for Active Record 10 | # gem 'sqlite3', "~> 1.3.6" 11 | # Use Puma as the app server 12 | gem 'puma', '>= 3.12' 13 | # Use SCSS for stylesheets 14 | gem 'sass-rails', '>= 5.0' 15 | # Use Uglifier as compressor for JavaScript assets 16 | gem 'uglifier', '>= 1.3.0' 17 | # See https://github.com/rails/execjs#readme for more supported runtimes 18 | # gem 'mini_racer', platforms: :ruby 19 | 20 | gem 'pg' 21 | # Use CoffeeScript for .coffee assets and views 22 | # gem 'coffee-rails', '~> 4.2' 23 | # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 24 | # gem 'turbolinks', '~> 5' 25 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 26 | # gem 'jbuilder', '~> 2.5' 27 | # Use Redis adapter to run Action Cable in production 28 | # gem 'redis', '~> 4.0' 29 | # Use ActiveModel has_secure_password 30 | gem 'bcrypt', '~> 3.1.7' 31 | 32 | # Use ActiveStorage variant 33 | # gem 'mini_magick', '~> 4.8' 34 | 35 | # Use Capistrano for deployment 36 | # gem 'capistrano-rails', group: :development 37 | 38 | # Reduces boot times through caching; required in config/boot.rb 39 | gem 'bootsnap', '>= 1.1.0', require: false 40 | 41 | gem 'devise' 42 | # gem 'devise-jwt' 43 | 44 | 45 | # premailer allows to define email styling in a CSS file and automatically inlines it when email is sent 46 | gem 'premailer-rails' 47 | 48 | gem "health_check" 49 | 50 | 51 | group :development, :test do 52 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console 53 | gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 54 | end 55 | 56 | group :development do 57 | # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 58 | gem 'web-console', '>= 3.3.0' 59 | gem 'listen', '>= 3.0.5', '< 3.2' 60 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 61 | gem 'spring' 62 | gem 'spring-watcher-listen', '~> 2.0.0' 63 | end 64 | 65 | group :test do 66 | # Adds support for Capybara system testing and selenium driver 67 | gem 'capybara', '>= 2.15' 68 | gem 'selenium-webdriver' 69 | # Easy installation and use of chromedriver to run system tests with Chrome 70 | gem 'chromedriver-helper' 71 | end 72 | 73 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 74 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 75 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actioncable (5.2.4.6) 5 | actionpack (= 5.2.4.6) 6 | nio4r (~> 2.0) 7 | websocket-driver (>= 0.6.1) 8 | actionmailer (5.2.4.6) 9 | actionpack (= 5.2.4.6) 10 | actionview (= 5.2.4.6) 11 | activejob (= 5.2.4.6) 12 | mail (~> 2.5, >= 2.5.4) 13 | rails-dom-testing (~> 2.0) 14 | actionpack (5.2.4.6) 15 | actionview (= 5.2.4.6) 16 | activesupport (= 5.2.4.6) 17 | rack (~> 2.0, >= 2.0.8) 18 | rack-test (>= 0.6.3) 19 | rails-dom-testing (~> 2.0) 20 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 21 | actionview (5.2.4.6) 22 | activesupport (= 5.2.4.6) 23 | builder (~> 3.1) 24 | erubi (~> 1.4) 25 | rails-dom-testing (~> 2.0) 26 | rails-html-sanitizer (~> 1.0, >= 1.0.3) 27 | activejob (5.2.4.6) 28 | activesupport (= 5.2.4.6) 29 | globalid (>= 0.3.6) 30 | activemodel (5.2.4.6) 31 | activesupport (= 5.2.4.6) 32 | activerecord (5.2.4.6) 33 | activemodel (= 5.2.4.6) 34 | activesupport (= 5.2.4.6) 35 | arel (>= 9.0) 36 | activestorage (5.2.4.6) 37 | actionpack (= 5.2.4.6) 38 | activerecord (= 5.2.4.6) 39 | marcel (~> 0.3.1) 40 | activesupport (5.2.4.6) 41 | concurrent-ruby (~> 1.0, >= 1.0.2) 42 | i18n (>= 0.7, < 2) 43 | minitest (~> 5.1) 44 | tzinfo (~> 1.1) 45 | addressable (2.8.0) 46 | public_suffix (>= 2.0.2, < 5.0) 47 | archive-zip (0.12.0) 48 | io-like (~> 0.3.0) 49 | arel (9.0.0) 50 | bcrypt (3.1.16) 51 | bindex (0.8.1) 52 | bootsnap (1.4.9) 53 | msgpack (~> 1.0) 54 | builder (3.2.4) 55 | byebug (11.1.3) 56 | capybara (3.33.0) 57 | addressable 58 | mini_mime (>= 0.1.3) 59 | nokogiri (~> 1.8) 60 | rack (>= 1.6.0) 61 | rack-test (>= 0.6.3) 62 | regexp_parser (~> 1.5) 63 | xpath (~> 3.2) 64 | childprocess (3.0.0) 65 | chromedriver-helper (2.1.1) 66 | archive-zip (~> 0.10) 67 | nokogiri (~> 1.8) 68 | concurrent-ruby (1.1.9) 69 | crass (1.0.6) 70 | css_parser (1.7.1) 71 | addressable 72 | devise (4.7.3) 73 | bcrypt (~> 3.0) 74 | orm_adapter (~> 0.1) 75 | railties (>= 4.1.0) 76 | responders 77 | warden (~> 1.2.3) 78 | erubi (1.10.0) 79 | execjs (2.7.0) 80 | ffi (1.13.1) 81 | globalid (0.4.2) 82 | activesupport (>= 4.2.0) 83 | health_check (3.0.0) 84 | railties (>= 5.0) 85 | htmlentities (4.3.4) 86 | i18n (1.8.10) 87 | concurrent-ruby (~> 1.0) 88 | io-like (0.3.1) 89 | listen (3.1.5) 90 | rb-fsevent (~> 0.9, >= 0.9.4) 91 | rb-inotify (~> 0.9, >= 0.9.7) 92 | ruby_dep (~> 1.2) 93 | loofah (2.19.1) 94 | crass (~> 1.0.2) 95 | nokogiri (>= 1.5.9) 96 | mail (2.7.1) 97 | mini_mime (>= 0.1.1) 98 | marcel (0.3.3) 99 | mimemagic (~> 0.3.2) 100 | method_source (1.0.0) 101 | mimemagic (0.3.10) 102 | nokogiri (~> 1) 103 | rake 104 | mini_mime (1.1.0) 105 | mini_portile2 (2.8.0) 106 | minitest (5.14.4) 107 | msgpack (1.3.3) 108 | nio4r (2.5.8) 109 | nokogiri (1.13.10) 110 | mini_portile2 (~> 2.8.0) 111 | racc (~> 1.4) 112 | orm_adapter (0.5.0) 113 | pg (1.2.3) 114 | premailer (1.14.2) 115 | addressable 116 | css_parser (>= 1.6.0) 117 | htmlentities (>= 4.0.0) 118 | premailer-rails (1.11.1) 119 | actionmailer (>= 3) 120 | premailer (~> 1.7, >= 1.7.9) 121 | public_suffix (4.0.6) 122 | puma (5.6.4) 123 | nio4r (~> 2.0) 124 | racc (1.6.1) 125 | rack (2.2.3.1) 126 | rack-test (1.1.0) 127 | rack (>= 1.0, < 3) 128 | rails (5.2.4.6) 129 | actioncable (= 5.2.4.6) 130 | actionmailer (= 5.2.4.6) 131 | actionpack (= 5.2.4.6) 132 | actionview (= 5.2.4.6) 133 | activejob (= 5.2.4.6) 134 | activemodel (= 5.2.4.6) 135 | activerecord (= 5.2.4.6) 136 | activestorage (= 5.2.4.6) 137 | activesupport (= 5.2.4.6) 138 | bundler (>= 1.3.0) 139 | railties (= 5.2.4.6) 140 | sprockets-rails (>= 2.0.0) 141 | rails-dom-testing (2.0.3) 142 | activesupport (>= 4.2.0) 143 | nokogiri (>= 1.6) 144 | rails-html-sanitizer (1.4.3) 145 | loofah (~> 2.3) 146 | railties (5.2.4.6) 147 | actionpack (= 5.2.4.6) 148 | activesupport (= 5.2.4.6) 149 | method_source 150 | rake (>= 0.8.7) 151 | thor (>= 0.19.0, < 2.0) 152 | rake (13.0.6) 153 | rb-fsevent (0.10.4) 154 | rb-inotify (0.10.1) 155 | ffi (~> 1.0) 156 | regexp_parser (1.8.2) 157 | responders (3.0.1) 158 | actionpack (>= 5.0) 159 | railties (>= 5.0) 160 | ruby_dep (1.5.0) 161 | rubyzip (2.3.0) 162 | sass-rails (6.0.0) 163 | sassc-rails (~> 2.1, >= 2.1.1) 164 | sassc (2.4.0) 165 | ffi (~> 1.9) 166 | sassc-rails (2.1.2) 167 | railties (>= 4.0.0) 168 | sassc (>= 2.0) 169 | sprockets (> 3.0) 170 | sprockets-rails 171 | tilt 172 | selenium-webdriver (3.142.7) 173 | childprocess (>= 0.5, < 4.0) 174 | rubyzip (>= 1.2.2) 175 | spring (2.1.1) 176 | spring-watcher-listen (2.0.1) 177 | listen (>= 2.7, < 4.0) 178 | spring (>= 1.2, < 3.0) 179 | sprockets (3.7.2) 180 | concurrent-ruby (~> 1.0) 181 | rack (> 1, < 3) 182 | sprockets-rails (3.2.2) 183 | actionpack (>= 4.0) 184 | activesupport (>= 4.0) 185 | sprockets (>= 3.0.0) 186 | thor (1.1.0) 187 | thread_safe (0.3.6) 188 | tilt (2.0.10) 189 | tzinfo (1.2.10) 190 | thread_safe (~> 0.1) 191 | uglifier (4.2.0) 192 | execjs (>= 0.3.0, < 3) 193 | warden (1.2.9) 194 | rack (>= 2.0.9) 195 | web-console (3.7.0) 196 | actionview (>= 5.0) 197 | activemodel (>= 5.0) 198 | bindex (>= 0.4.0) 199 | railties (>= 5.0) 200 | websocket-driver (0.7.5) 201 | websocket-extensions (>= 0.1.0) 202 | websocket-extensions (0.1.5) 203 | xpath (3.2.0) 204 | nokogiri (~> 1.8) 205 | 206 | PLATFORMS 207 | ruby 208 | 209 | DEPENDENCIES 210 | bcrypt (~> 3.1.7) 211 | bootsnap (>= 1.1.0) 212 | byebug 213 | capybara (>= 2.15) 214 | chromedriver-helper 215 | devise 216 | health_check 217 | listen (>= 3.0.5, < 3.2) 218 | pg 219 | premailer-rails 220 | puma (>= 3.12) 221 | rails (= 5.2.4.6) 222 | sass-rails (>= 5.0) 223 | selenium-webdriver 224 | spring 225 | spring-watcher-listen (~> 2.0.0) 226 | sprockets (= 3.7.2) 227 | tzinfo-data 228 | uglifier (>= 1.3.0) 229 | web-console (>= 3.3.0) 230 | 231 | RUBY VERSION 232 | ruby 2.6.5p114 233 | 234 | BUNDLED WITH 235 | 1.17.3 236 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Status 2 | [![Build Status](https://travis-ci.com/inklewriter/freeinklewriter.svg?branch=master)](https://travis-ci.com/inklewriter/freeinklewriter) 3 | 4 | # Inklewriter / Freeinklewriter 5 | 6 | This project is a free reverse-engineered version of the [inklewriter server](https://writer.inklestudios.com). 7 | 8 | We would like to thank Inkle Studio for letting us open their great software! 9 | 10 | ## Test 11 | 12 | You can test it on https://www.inklewriter.com 13 | 14 | ## Run your own 15 | 16 | We strongly advise you to check the [dedicated repository](https://github.com/inklewriter/freeinklewriter-system) for running this application on a system in a "production-ready" approach. 17 | 18 | It runs on x86 and arm, using docker-compose or as a system service. 19 | 20 | 21 | ## Development Crash course 22 | 23 | ### docker-compose 24 | 25 | ``` 26 | git clone https://github.com/inklewriter/freeinklewriter 27 | cd freeinklewriter 28 | cp .env.template .env 29 | docker-compose run 30 | ``` 31 | Open your browser on http://localhost:3000 32 | 33 | ## Support 34 | 35 | Please open tickets in this issue tracker. 36 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative 'config/application' 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /app/assets/config/manifest.js: -------------------------------------------------------------------------------- 1 | //= link_tree ../images 2 | //= link_directory ../javascripts .js 3 | //= link_directory ../stylesheets .css 4 | -------------------------------------------------------------------------------- /app/assets/fonts/inkle-Baskerville.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/fonts/inkle-Baskerville.woff -------------------------------------------------------------------------------- /app/assets/fonts/inkle-Baskerville.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/fonts/inkle-Baskerville.woff2 -------------------------------------------------------------------------------- /app/assets/fonts/writer-Baskerville.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/fonts/writer-Baskerville.woff -------------------------------------------------------------------------------- /app/assets/fonts/writer-Baskerville.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/fonts/writer-Baskerville.woff2 -------------------------------------------------------------------------------- /app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/images/.keep -------------------------------------------------------------------------------- /app/assets/javascripts/admin/adminpages/index.js: -------------------------------------------------------------------------------- 1 | var months = {"1":"January", "2":"February", "3":"March", "4":"April", "5":"May", "6":"June", "7":"July", "8":"August", "9":"September", "10":"October", "11":"November", "12":"December"}; 2 | var days = {"1":"31", "2":"28", "3":"31", "4":"30", "5":"31", "6":"30", "7":"31", "8":"31", "9":"30", "10":"31", "11":"30", "12":"31"} 3 | 4 | document.addEventListener('DOMContentLoaded', function() { 5 | 6 | document.querySelector('#minmonth').addEventListener('input', function(){ 7 | // need handle bissextile years 8 | document.querySelector('#minday').max = days[this.value]; 9 | }); 10 | 11 | document.querySelectorAll('.search-elem').forEach( function(element) { 12 | element.addEventListener("change", function(){ 13 | setTimeout(doSearch,400); 14 | }) 15 | }); 16 | 17 | document.querySelectorAll('.search-elem-text').forEach( function(element) { 18 | element.addEventListener("keyup", function(){ 19 | setTimeout(doSearch,400); 20 | }) 21 | }); 22 | 23 | function doSearch(){ 24 | fetch('/admin/score_search', { 25 | method: "POST", 26 | credentials: 'include', 27 | headers: { 28 | 'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content, 29 | 'Content-Type': 'application/json' 30 | }, 31 | body: JSON.stringify({ 32 | rating_search: { 33 | minday: document.querySelector("#minday").value, 34 | minmonth: document.querySelector("#minmonth").value, 35 | minyear: document.querySelector("#minyear").value, 36 | maxday: document.querySelector("#maxday").value, 37 | maxmonth: document.querySelector("#maxmonth").value, 38 | maxyear: document.querySelector("#maxyear").value, 39 | minwords: document.querySelector("#minwords").value, 40 | maxwords: document.querySelector("#maxwords").value 41 | } 42 | }) 43 | 44 | }).then(r => r.json()) 45 | .then(r => { 46 | console.log(r.message); 47 | if(r["story_selection"]){ 48 | document.querySelector('#search-results').innerHTML = ""; 49 | r.story_selection.forEach( function(s) { 50 | document.querySelector('#search-results').innerHTML += 51 | `

52 | ${s[0]} 53 | ${s[1]} 54 | ${s[2]} 55 | ${s[3]} 56 | ${s[4]} 57 |

58 | ` 59 | }); 60 | }; 61 | }); 62 | 63 | }; 64 | 65 | }, false); -------------------------------------------------------------------------------- /app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's 5 | // vendor/assets/javascripts directory can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. JavaScript code in this file should be added after the last require_* statement. 9 | // 10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require rails-ujs 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/assets/javascripts/channels/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/javascripts/channels/.keep -------------------------------------------------------------------------------- /app/assets/javascripts/pages/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/javascripts/pages/index.js -------------------------------------------------------------------------------- /app/assets/javascripts/stories/show.js: -------------------------------------------------------------------------------- 1 | // Advertisement handling 2 | document.addEventListener('DOMContentLoaded', function() { 3 | 4 | const AdvertItems = document.querySelectorAll("#sidebar-ads > div"); 5 | 6 | AdvertItems.forEach(function(element){ 7 | 8 | if(window.localStorage.getItem(element.dataset.adname) == "closed"){ 9 | element.style.visibility = "hidden"; 10 | }; 11 | 12 | element.querySelector(".ad-close").addEventListener('click', function(){ 13 | element.style.visibility = "hidden"; 14 | window.localStorage.setItem(element.dataset.adname, 'closed'); 15 | }) 16 | }); 17 | 18 | }, false); -------------------------------------------------------------------------------- /app/assets/stylesheets/admin/adminpages.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the pages controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | 5 | html,body { 6 | margin: 0; 7 | padding: 0; 8 | border: 0; 9 | outline: 0; 10 | font-size: 100%; 11 | vertical-align: baseline; 12 | background: transparent; 13 | position: relative 14 | } 15 | html { 16 | 17 | } 18 | body { 19 | line-height: 1; 20 | 21 | } 22 | 23 | #index { 24 | 25 | padding: 10px; 26 | 27 | h1 {} 28 | h2 { 29 | margin: 0; 30 | font-size: 1.2em; 31 | } 32 | table#stats { 33 | th { 34 | padding: 10px; 35 | text-align: center; 36 | } 37 | td { 38 | text-align: center; 39 | } 40 | } 41 | 42 | table#search { 43 | td:nth-child(1) { 44 | padding: 10px; 45 | width: 80px; 46 | text-align: center; 47 | } 48 | td:nth-child(2) { 49 | width: 200px; 50 | } 51 | input { 52 | width: 120px; 53 | align: left; 54 | } 55 | output { 56 | width: 200px; 57 | } 58 | 59 | 60 | } 61 | 62 | #search-results { 63 | span { 64 | display: inline-block; 65 | overflow: hidden 66 | } 67 | .id { 68 | width: 40px; 69 | color: blue; 70 | font-weight: bold; 71 | } 72 | .title { 73 | width: 180px; 74 | font-weight: bold; 75 | } 76 | .author { 77 | width: 140px; 78 | } 79 | .email { 80 | width: 220px; 81 | } 82 | .score { 83 | width: 220px; 84 | color: #c39; 85 | font-weight: bold; 86 | } 87 | 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/assets/stylesheets/admin/authorizer.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the admin/authorizer controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: https://sass-lang.com/ 4 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's 6 | * vendor/assets/stylesheets directory can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 10 | * files in this directory. Styles in this file should be added after the last require_* statement. 11 | * It is generally better to create a new file per style scope. 12 | * 13 | *= require_self 14 | */ 15 | -------------------------------------------------------------------------------- /app/assets/stylesheets/devise.css.scss: -------------------------------------------------------------------------------- 1 | .edit-password{ 2 | #player_container #read_area h1{ 3 | padding-top:20px; 4 | 5 | } 6 | #player_container .chunk { 7 | padding: 50px; 8 | } 9 | .field { 10 | padding: 0 0 20px 0; 11 | } 12 | 13 | form { 14 | padding: 0 0 30px 0; 15 | } 16 | 17 | h3{ 18 | font-weight: bold; 19 | } 20 | } -------------------------------------------------------------------------------- /app/assets/stylesheets/emails.css.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/stylesheets/emails.css.scss -------------------------------------------------------------------------------- /app/assets/stylesheets/errors.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the errors controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | 5 | .error-404 .error-500 { 6 | #player_container #read_area h1{ 7 | padding-top:20px; 8 | } 9 | #player_container .chunk { 10 | padding: 50px; 11 | } 12 | p,ul,li,a, h3{ 13 | font-size: 16pt; 14 | text-align: left; 15 | margin-top: 20px; 16 | line-height: 1.4em; 17 | } 18 | li{ 19 | list-style-type: decimal; 20 | margin-left: 20px; 21 | } 22 | h3{ 23 | font-weight: bold; 24 | } 25 | } -------------------------------------------------------------------------------- /app/assets/stylesheets/inking.css.scss: -------------------------------------------------------------------------------- 1 | html { 2 | height: 100%; 3 | width: 100%; 4 | background-color: white !important; 5 | } 6 | 7 | body { 8 | background-color: white; 9 | overflow: auto; 10 | height: 100%; 11 | } 12 | 13 | #inking { 14 | 15 | // width: auto; 16 | margin: 0 auto; 17 | padding: 20px 5px 10px 5px; 18 | max-width: 1000px; 19 | width: 100%; 20 | 21 | h1 { 22 | text-align: left; 23 | font-size: 24px; 24 | margin: 5px 0 10px 0; 25 | } 26 | 27 | textarea { 28 | // display: block; 29 | 30 | max-width: 978px; 31 | border-radius: 5px; 32 | width: 90%; 33 | padding: 10px; 34 | 35 | } 36 | 37 | .input_option { 38 | padding: 10px 0 10px 0; 39 | } 40 | 41 | .inline { 42 | display: inline-block; 43 | } 44 | 45 | .converted_ink { 46 | margin: 20px 0; 47 | 48 | #download_button { 49 | max-width: 90%; 50 | } 51 | 52 | #result_ink{ 53 | margin: 20px 0 0 0; 54 | padding: 20px 5px; 55 | border-radius: 5px; 56 | box-shadow: 0px 5px 20px 0 rgba(0,0,0,0.13); 57 | overflow: auto; 58 | width: 90%; 59 | height: 200px; 60 | white-space: pre-wrap; 61 | display: inline-block; 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /app/assets/stylesheets/pages.css.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/stylesheets/pages.css.scss -------------------------------------------------------------------------------- /app/assets/stylesheets/stories.css.scss: -------------------------------------------------------------------------------- 1 | // Place all the styles related to the stories controller here. 2 | // They will automatically be included in application.css. 3 | // You can use Sass (SCSS) here: http://sass-lang.com/ 4 | 5 | 6 | .story-not-found{ 7 | #player_container #read_area h1{ 8 | padding-top:20px; 9 | 10 | } 11 | #player_container .chunk { 12 | padding: 50px; 13 | } 14 | p,ul,li,a, h3{ 15 | font-size: 16pt; 16 | text-align: left; 17 | margin-top: 20px; 18 | line-height: 1.4em; 19 | } 20 | li{ 21 | list-style-type: decimal; 22 | margin-left: 20px; 23 | } 24 | h3{ 25 | font-weight: bold; 26 | } 27 | } 28 | 29 | 30 | 31 | .cannot-display-story{ 32 | #player_container #read_area h1{ 33 | padding-top:20px; 34 | } 35 | #player_container .chunk { 36 | padding: 50px; 37 | } 38 | p,ul,li,a, h3{ 39 | font-size: 16pt; 40 | text-align: left; 41 | margin-top: 20px; 42 | line-height: 1.4em; 43 | } 44 | li{ 45 | list-style-type: decimal; 46 | margin-left: 20px; 47 | } 48 | h3{ 49 | font-weight: bold; 50 | margin-bottom: 40px; 51 | } 52 | } 53 | 54 | 55 | 56 | 57 | .not-story-owner{ 58 | #player_container #read_area h1{ 59 | padding-top:20px; 60 | } 61 | #player_container .chunk { 62 | padding: 50px; 63 | } 64 | p,ul,li,a, h3{ 65 | font-size: 16pt; 66 | text-align: left; 67 | margin-top: 20px; 68 | line-height: 1.4em; 69 | } 70 | li{ 71 | list-style-type: decimal; 72 | margin-left: 20px; 73 | } 74 | h3{ 75 | font-weight: bold; 76 | margin-bottom: 40px; 77 | } 78 | } 79 | 80 | 81 | -------------------------------------------------------------------------------- /app/assets/stylesheets/users/confirmations.css.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/stylesheets/users/confirmations.css.scss -------------------------------------------------------------------------------- /app/assets/stylesheets/users/passwords.css.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/stylesheets/users/passwords.css.scss -------------------------------------------------------------------------------- /app/assets/stylesheets/users/registrations.css.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/stylesheets/users/registrations.css.scss -------------------------------------------------------------------------------- /app/assets/stylesheets/users/sessions.css.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/stylesheets/users/sessions.css.scss -------------------------------------------------------------------------------- /app/assets/stylesheets/users/unlocks.css.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/assets/stylesheets/users/unlocks.css.scss -------------------------------------------------------------------------------- /app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/controllers/admin/adminpages_controller.rb: -------------------------------------------------------------------------------- 1 | class Admin::AdminpagesController < Admin::AuthorizerController 2 | 3 | # Be careful to make every admin controller a child of Admin::AuthorizerController 4 | # as this is where the Admins authorization happen 5 | 6 | # in order to make a preexisting user an admin 7 | # open Rails console and type "Admin.create(user_id: XXX)" with the user id 8 | # and voila 9 | 10 | # Here lies the adhoc admin pages. 11 | # specific logic is handled by specific Admin namespaced controllers in controllers/admin folder 12 | 13 | def index 14 | 15 | @current_year = Time.now.year.to_i 16 | @last_three_years = {@current_year.to_s => stories_created_monthly_in(@current_year), (@current_year-1).to_s => stories_created_monthly_in(@current_year-1), (@current_year-2).to_s => stories_created_monthly_in(@current_year-2) } 17 | 18 | @first_story = Story.first 19 | @last_story = Story.last 20 | 21 | end 22 | 23 | def score_search 24 | # https://stackoverflow.com/questions/42686139/strong-parameters-permit-an-array-of-symbols 25 | if %i( minwords maxwords minday maxday minmonth maxmonth minyear maxyear).all? { |key| params[:rating_search][key].present? } 26 | 27 | subselection = Story.joins(:story_stat).where(created_at: Date.civil(params[:rating_search][:minyear].to_i, params[:rating_search][:minmonth].to_i, params[:rating_search][:minday].to_i)..Date.civil(params[:rating_search][:maxyear].to_i, params[:rating_search][:maxmonth].to_i, params[:rating_search][:maxday].to_i), story_stats: {total_words: params[:rating_search][:minwords].to_i..params[:rating_search][:maxwords].to_i}).order(score: :desc).first(10) 28 | subselection_ids = subselection.map {|e| [e.id, e.title, e.data["editorData"]["authorName"], e.user.email, e.story_stat.score]} 29 | if subselection_ids.present? 30 | message = "Search successful. Hourray some results have been found" 31 | else 32 | message = "Search successful. Yet it returned no record." 33 | end 34 | render json: {message: message, story_selection: subselection_ids}, status: 200 35 | else 36 | render json: {message: "search failed. No sufficient params"}, status: 400 37 | end 38 | end 39 | 40 | private 41 | 42 | def stories_created_monthly_in(year) 43 | monthly_stories = {} 44 | if year.to_i.in?(2000..2050) 45 | 12.times do |m| 46 | monthly_stories[(m+1).to_s] = Story.where(created_at: Date.civil(year, m+1, 1)..Date.civil(year, m+1, -1)).count 47 | end 48 | end 49 | return monthly_stories 50 | end 51 | 52 | 53 | end 54 | -------------------------------------------------------------------------------- /app/controllers/admin/authorizer_controller.rb: -------------------------------------------------------------------------------- 1 | class Admin::AuthorizerController < ApplicationController 2 | 3 | before_action :authorize_admin 4 | 5 | 6 | private 7 | 8 | def authorize_admin 9 | unless current_user.present? and current_user.admin.present? 10 | redirect_to root_path 11 | end 12 | end 13 | 14 | end 15 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | end 11 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/controllers/errors_controller.rb: -------------------------------------------------------------------------------- 1 | class ErrorsController < ApplicationController 2 | 3 | def not_found 4 | render(:status => 404) 5 | end 6 | 7 | def internal_server_error 8 | render(:status => 500) 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /app/controllers/pages_controller.rb: -------------------------------------------------------------------------------- 1 | class PagesController < ApplicationController 2 | 3 | def index 4 | end 5 | 6 | def privacy 7 | respond_to do |format| 8 | format.html 9 | end 10 | end 11 | def health 12 | @status = {} 13 | @status[:database_connected] = ::ActiveRecord::Base.connection_pool.with_connection(&:active?) rescue false 14 | 15 | respond_to do |format| 16 | format.html 17 | format.json {render json: @status} 18 | end 19 | 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /app/controllers/stories_controller.rb: -------------------------------------------------------------------------------- 1 | class StoriesController < ApplicationController 2 | 3 | # before_action :authenticate_user!, only: [:create, :update, :destroy] 4 | before_action :user_logged_in, only: [:create, :update, :destroy] 5 | before_action :check_story_owner, only: [:update, :destroy] 6 | 7 | def show 8 | if Story.exists?(params[:id]) 9 | @story = Story.find(params[:id]) 10 | @data = {title: @story.title, data: @story.data, url_key: @story.id}.to_json 11 | @author = @story.data["editorData"]["authorName"] 12 | @title = @story.title 13 | 14 | 15 | respond_to do |format| 16 | format.html { 17 | # building preview here 18 | @first_stitches_content = [] 19 | @first_options_content = [] 20 | finding_option(@story.data["stitches"][@story.data["initial"]], @first_stitches_content, @first_options_content) 21 | } 22 | format.json 23 | format.ink { render "inking.html" } 24 | end 25 | 26 | else 27 | # below id is created to pass to the failing view the id of what might be an oldinklewriter story 28 | @id = params[:id] 29 | 30 | respond_to do |format| 31 | format.html { render "stories/not_found.html.erb" } 32 | format.json { render json: { message: "Oops like you searched for a non existing story. You may head to legacy app and check this address http://oldinklewriter.inklestudios.com/stories/#{@id}.json to retrieve your story. You can then import it into the new app"}, status: 404 } 33 | format.ink { render "stories/not_found.html.erb" } 34 | end 35 | end 36 | end 37 | 38 | 39 | def index 40 | if current_user.present? 41 | @stories = set_user.stories 42 | render json: @stories.to_a , :status => 200 43 | else 44 | render "stories/cannot_display_stories" 45 | end 46 | end 47 | 48 | def update 49 | @story = Story.find(params[:id]) 50 | 51 | if params[:data].present? and params[:title].present? 52 | @story.data = params[:data] 53 | @story.title = params[:title] 54 | @story.save 55 | 56 | render json: { message: "ok" }, :status => 201 57 | else 58 | render json: {}, :status => 400 59 | end 60 | 61 | end 62 | 63 | 64 | def create 65 | @story = set_user.stories.new(data: params[:data], title: params[:title]) 66 | if @story.save 67 | render json: { title: @story.title, data: @story.data, url_key: @story.url_key }, :status => 201 68 | else 69 | render json: {}, :status => 400 70 | end 71 | end 72 | 73 | def destroy 74 | @story = Story.find(params[:id]) 75 | if @story.destroy 76 | render json: { message: "ok" }, :status => 201 77 | else 78 | render json: {}, :status => 400 79 | end 80 | end 81 | 82 | private 83 | 84 | # The 4 methods below help to recursively build the story preview in show action 85 | 86 | def find_chain(current_stitch, story_diverts) 87 | current_stitch["content"].each do |elem| 88 | if elem.is_a?String 89 | story_diverts << elem 90 | end 91 | end 92 | end 93 | 94 | def find_next_stitch(current_stitch) 95 | found = false 96 | 97 | current_stitch["content"].each do |elem| 98 | if elem.is_a?Hash 99 | if elem.has_key?("divert") 100 | found = @story.data["stitches"][elem["divert"]] 101 | end 102 | end 103 | end 104 | return found 105 | end 106 | 107 | def is_an_option(current_stitch, story_options) 108 | found = false 109 | answer = [] 110 | current_stitch["content"].each do |elem| 111 | if elem.is_a?Hash 112 | if elem.has_key?("option") 113 | story_options << elem["option"] 114 | found = true 115 | end 116 | end 117 | end 118 | end 119 | 120 | 121 | def finding_option(current_stitch, story_diverts, story_options) 122 | find_chain(current_stitch, story_diverts) 123 | is_an_option(current_stitch, story_options) 124 | 125 | if find_next_stitch(current_stitch) 126 | finding_option(find_next_stitch(current_stitch), story_diverts, story_options) 127 | end 128 | 129 | end 130 | 131 | 132 | 133 | def user_logged_in 134 | unless current_user.present? 135 | redirect_to root_path 136 | end 137 | end 138 | 139 | def set_user 140 | return current_user 141 | end 142 | 143 | def check_story_owner 144 | unless set_user.id == Story.find(params[:id]).user.id 145 | redirect_to "stories/not_story_owner" 146 | end 147 | end 148 | 149 | def story_params 150 | params.require(:story).permit(:data, :title) 151 | end 152 | 153 | 154 | 155 | end 156 | -------------------------------------------------------------------------------- /app/controllers/users/confirmations_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Users::ConfirmationsController < Devise::ConfirmationsController 4 | # GET /resource/confirmation/new 5 | # def new 6 | # super 7 | # end 8 | 9 | # POST /resource/confirmation 10 | # def create 11 | # super 12 | # end 13 | 14 | # GET /resource/confirmation?confirmation_token=abcdef 15 | # def show 16 | # super 17 | # end 18 | 19 | # protected 20 | 21 | # The path used after resending confirmation instructions. 22 | # def after_resending_confirmation_instructions_path_for(resource_name) 23 | # super(resource_name) 24 | # end 25 | 26 | # The path used after confirmation. 27 | # def after_confirmation_path_for(resource_name, resource) 28 | # super(resource_name, resource) 29 | # end 30 | end 31 | -------------------------------------------------------------------------------- /app/controllers/users/omniauth_callbacks_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController 4 | # You should configure your model like this: 5 | # devise :omniauthable, omniauth_providers: [:twitter] 6 | 7 | # You should also create an action method in this controller like this: 8 | # def twitter 9 | # end 10 | 11 | # More info at: 12 | # https://github.com/plataformatec/devise#omniauth 13 | 14 | # GET|POST /resource/auth/twitter 15 | # def passthru 16 | # super 17 | # end 18 | 19 | # GET|POST /users/auth/twitter/callback 20 | # def failure 21 | # super 22 | # end 23 | 24 | # protected 25 | 26 | # The path used when OmniAuth fails 27 | # def after_omniauth_failure_path_for(scope) 28 | # super(scope) 29 | # end 30 | end 31 | -------------------------------------------------------------------------------- /app/controllers/users/passwords_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Users::PasswordsController < Devise::PasswordsController 4 | 5 | 6 | 7 | # GET /resource/password/new 8 | # def new 9 | # super 10 | # end 11 | 12 | # POST /resource/password 13 | def create 14 | self.resource = resource_class.send_reset_password_instructions(resource_params) 15 | yield resource if block_given? 16 | 17 | if successfully_sent?(resource) 18 | render json: { message: "Success, an email has been sent over to you" }, status: 200 19 | else 20 | render json: { errors: "Invalid or not found email address." }, status: 200 21 | end 22 | 23 | end 24 | 25 | # GET /resource/password/edit?reset_password_token=abcdef 26 | # def edit 27 | # super 28 | # end 29 | 30 | # PUT /resource/password 31 | # def update 32 | # super 33 | # end 34 | 35 | # protected 36 | 37 | # def after_resetting_password_path_for(resource) 38 | # super(resource) 39 | # end 40 | 41 | # The path used after sending reset password instructions 42 | # def after_sending_reset_password_instructions_path_for(resource_name) 43 | # super(resource_name) 44 | # end 45 | end 46 | -------------------------------------------------------------------------------- /app/controllers/users/registrations_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Users::RegistrationsController < Devise::RegistrationsController 4 | # before_action :configure_sign_up_params, only: [:create] 5 | # before_action :configure_account_update_params, only: [:update] 6 | clear_respond_to 7 | respond_to :json 8 | # GET /resource/sign_up 9 | # def new 10 | # super 11 | # end 12 | 13 | # POST /resource 14 | # def create 15 | # super 16 | # # user = User.new(params[:user]) 17 | # # if user.save 18 | # # render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201 19 | # # return 20 | # # else 21 | # # warden.custom_failure! 22 | # # render :json=> user.errors, :status=>422 23 | # # end 24 | 25 | # end 26 | 27 | # GET /resource/edit 28 | # def edit 29 | # super 30 | 31 | # end 32 | 33 | # PUT /resource 34 | # def update 35 | # super 36 | 37 | # end 38 | 39 | # DELETE /resource 40 | # def destroy 41 | # super 42 | 43 | # end 44 | 45 | # GET /resource/cancel 46 | # Forces the session data which is usually expired after sign 47 | # in to be expired now. This is useful if the user wants to 48 | # cancel oauth signing in/up in the middle of the process, 49 | # removing all OAuth session data. 50 | # def cancel 51 | # super 52 | 53 | # end 54 | 55 | # protected 56 | 57 | # If you have extra params to permit, append them to the sanitizer. 58 | # def configure_sign_up_params 59 | # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) 60 | # end 61 | 62 | # If you have extra params to permit, append them to the sanitizer. 63 | # def configure_account_update_params 64 | # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) 65 | # end 66 | 67 | # The path used after sign up. 68 | # def after_sign_up_path_for(resource) 69 | # super(resource) 70 | # end 71 | 72 | # The path used after sign up for inactive accounts. 73 | # def after_inactive_sign_up_path_for(resource) 74 | # super(resource) 75 | # end 76 | end 77 | -------------------------------------------------------------------------------- /app/controllers/users/sessions_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Users::SessionsController < Devise::SessionsController 4 | # before_action :configure_sign_in_params, only: [:create] 5 | 6 | clear_respond_to 7 | respond_to :json 8 | 9 | # GET /resource/sign_in 10 | # def new 11 | # super 12 | # end 13 | 14 | # POST /resource/sign_in 15 | # def create 16 | # super 17 | # end 18 | 19 | # DELETE /resource/sign_out 20 | # def destroy 21 | # super 22 | # end 23 | 24 | # protected 25 | 26 | # If you have extra params to permit, append them to the sanitizer. 27 | # def configure_sign_in_params 28 | # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute]) 29 | # end 30 | end 31 | -------------------------------------------------------------------------------- /app/controllers/users/unlocks_controller.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class Users::UnlocksController < Devise::UnlocksController 4 | # GET /resource/unlock/new 5 | # def new 6 | # super 7 | # end 8 | 9 | # POST /resource/unlock 10 | # def create 11 | # super 12 | # end 13 | 14 | # GET /resource/unlock?unlock_token=abcdef 15 | # def show 16 | # super 17 | # end 18 | 19 | # protected 20 | 21 | # The path used after sending unlock password instructions 22 | # def after_sending_unlock_instructions_path_for(resource) 23 | # super(resource) 24 | # end 25 | 26 | # The path used after unlocking the resource 27 | # def after_unlock_path_for(resource) 28 | # super(resource) 29 | # end 30 | end 31 | -------------------------------------------------------------------------------- /app/helpers/admin/adminpages_helper.rb: -------------------------------------------------------------------------------- 1 | module Admin::AdminpagesHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/admin/authorizer_helper.rb: -------------------------------------------------------------------------------- 1 | module Admin::AuthorizerHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/errors_helper.rb: -------------------------------------------------------------------------------- 1 | module ErrorsHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/pages_helper.rb: -------------------------------------------------------------------------------- 1 | module PagesHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/helpers/stories_helper.rb: -------------------------------------------------------------------------------- 1 | module StoriesHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | end 3 | -------------------------------------------------------------------------------- /app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: 'do-not-reply@inklewriter.com' 3 | layout 'mailer' 4 | end 5 | -------------------------------------------------------------------------------- /app/mailers/custom_devise_mailer.rb: -------------------------------------------------------------------------------- 1 | class CustomDeviseMailer < Devise::Mailer 2 | 3 | include Devise::Controllers::UrlHelpers 4 | end -------------------------------------------------------------------------------- /app/mailers/user_mailer.rb: -------------------------------------------------------------------------------- 1 | class UserMailer < ApplicationMailer 2 | 3 | def test(id) 4 | @user = User.find_by(email: id) 5 | # testing if USER email field is a real email address. Regexp taken here http://emailregex.com/ 6 | # then email is sent 7 | if @user.email.match /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i 8 | mail(to: @user.email, subject: "email de test") 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /app/models/admin.rb: -------------------------------------------------------------------------------- 1 | class Admin < ApplicationRecord 2 | belongs_to :user 3 | end 4 | -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/models/story.rb: -------------------------------------------------------------------------------- 1 | class Story < ApplicationRecord 2 | 3 | after_create :assign_url_key 4 | after_save :process_stats, if: :data_is_present 5 | after_save :process_rating, if: :data_is_present 6 | 7 | before_save :sanitize_title 8 | before_save :sanitize_author 9 | # before_save :sanitize_stitches 10 | 11 | belongs_to :user 12 | has_one :story_stat, dependent: :destroy 13 | 14 | validates :data, presence: true 15 | 16 | 17 | def sanitize_s 18 | 19 | if self.data.present? 20 | nh = {} 21 | olds = self.data 22 | 23 | olds.each do |k1,v1| 24 | if k1 == "stitches" 25 | nh[k1] = {} 26 | 27 | v1.each do |k2,v2| 28 | nh[k1][k2] = {} 29 | 30 | v2.each do |k3,v3| 31 | 32 | if k3 == "content" 33 | cont = [] 34 | v3.each do |elem| 35 | if elem.is_a?String 36 | st = ActionController::Base.helpers.sanitize(elem) 37 | cont << st 38 | elsif elem.is_a?Hash 39 | sh = {} 40 | elem.each do |k4,v4| 41 | if k4 == "option" 42 | sh[k4] = ActionController::Base.helpers.sanitize(v4) 43 | else 44 | sh[k4] = v4 45 | end 46 | end 47 | cont << sh 48 | else 49 | cont << elem 50 | end 51 | end 52 | nh[k1][k2][k3] = cont 53 | else 54 | nh[k1][k2][k3] = v3 55 | end 56 | 57 | end 58 | 59 | end 60 | else 61 | nh[k1] = v1 62 | end 63 | end 64 | return nh 65 | else 66 | return {} 67 | end 68 | 69 | end 70 | 71 | 72 | private 73 | 74 | def assign_url_key 75 | self.url_key = self.id 76 | self.save 77 | end 78 | 79 | def data_is_present 80 | self.data.present? 81 | end 82 | 83 | def process_stats 84 | unless self.story_stat.present? 85 | self.build_story_stat 86 | end 87 | 88 | stat_results = Stats::Story.new(self).stats 89 | 90 | stat_results.each do |k,v| 91 | self.story_stat[k]=v 92 | end 93 | 94 | self.story_stat.save 95 | 96 | end 97 | 98 | def process_rating 99 | 100 | if self.story_stat.present? 101 | ratings = Rating::S_m_l_rating.new(self).calc 102 | ratings.each do |k,v| 103 | self.story_stat[k]=v 104 | end 105 | self.story_stat.save 106 | end 107 | 108 | end 109 | 110 | def sanitize_title 111 | if self.title.present? 112 | self.title = ActionController::Base.helpers.sanitize(self.title) 113 | end 114 | end 115 | 116 | def sanitize_author 117 | if self.data["editorData"]["authorName"].present? 118 | self.data["editorData"]["authorName"] = ActionController::Base.helpers.sanitize(self.data["editorData"]["authorName"]) 119 | end 120 | end 121 | 122 | def sanitize_stitches 123 | 124 | if self.data.present? 125 | nh = {} 126 | olds = self.data 127 | 128 | olds.each do |k1,v1| 129 | if k1 == "stitches" 130 | nh[k1] = {} 131 | 132 | v1.each do |k2,v2| 133 | nh[k1][k2] = {} 134 | 135 | v2.each do |k3,v3| 136 | 137 | if k3 == "content" 138 | cont = [] 139 | v3.each do |elem| 140 | if elem.is_a?String 141 | st = ActionController::Base.helpers.sanitize(elem) 142 | cont << st 143 | elsif elem.is_a?Hash 144 | sh = {} 145 | elem.each do |k4,v4| 146 | if k4 == "option" 147 | sh[k4] = ActionController::Base.helpers.sanitize(v4) 148 | else 149 | sh[k4] = v4 150 | end 151 | end 152 | cont << sh 153 | else 154 | cont << elem 155 | end 156 | end 157 | nh[k1][k2][k3] = cont 158 | else 159 | nh[k1][k2][k3] = v3 160 | end 161 | 162 | end 163 | 164 | end 165 | else 166 | nh[k1] = v1 167 | end 168 | end 169 | self.data = nh 170 | end 171 | 172 | end 173 | 174 | end 175 | -------------------------------------------------------------------------------- /app/models/story_stat.rb: -------------------------------------------------------------------------------- 1 | class StoryStat < ApplicationRecord 2 | belongs_to :story, optional: true 3 | end 4 | -------------------------------------------------------------------------------- /app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ApplicationRecord 2 | # Include default devise modules. Others available are: 3 | # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 4 | #:recoverable, :rememberable, :validatable 5 | devise :database_authenticatable, :registerable, :rememberable, :recoverable 6 | 7 | has_many :stories, dependent: :destroy 8 | has_one :admin, dependent: :destroy 9 | 10 | 11 | validates :email, presence: true 12 | validates :email, format: { with: /\A\S+@.+\.\S+\z/ } 13 | 14 | end 15 | -------------------------------------------------------------------------------- /app/services/rating.rb: -------------------------------------------------------------------------------- 1 | module Rating 2 | 3 | class S_m_l_rating 4 | def initialize(story) 5 | # recovering story data by any identifier 6 | if story.class.name == "Story" 7 | @s = story.story_stat 8 | elsif story.class.name == "Integer" 9 | if Story.exists?(id: story) 10 | @s = Story.find(story).story_stat 11 | end 12 | elsif story.class.name == "String" 13 | if Story.exists?(id: story.to_i) 14 | @s = Story.find(story.to_i).story_stat 15 | end 16 | elsif story.class.name == "Hash" 17 | @s = story.story_stat 18 | else 19 | @s = 'unprocessable' 20 | end 21 | 22 | @pi_square = 2.5066282746310005024157652848110452530069867406099 23 | 24 | end 25 | 26 | 27 | 28 | def get_pdf(x, mean, variance) 29 | Math.exp( -0.5 * ( ( (x-mean) / variance ) **2 ) ) / ( @pi_square * variance ) 30 | end 31 | 32 | def prob( x,m,s) 33 | p1 = ( x - m)**2; 34 | p2 = 2 * s**2; 35 | return Math.exp(-( p1/p2 )) 36 | #puts "p1:#{p1} p2:#{p2} p3:#{p3}" 37 | end 38 | 39 | def calc 40 | # Calculate indice: stitches / words 41 | if @s.total_words == 0 42 | angle = 0 43 | indice_angle = 0 44 | else 45 | angle = Math.atan(20 * Float(@s.stitches) / @s.total_words) 46 | indice_angle = get_pdf( angle, 0.7853981634, 0.3926990817) # pi/4, pi/8 47 | end 48 | 49 | # Calculate indice: branching quality 50 | if @s.stitches == 0 51 | indice_branching = 0 52 | else 53 | indice_branching = Float( 2*@s.with_choice + @s.with_end + @s.with_divert - 2*@s.with_fake_choice - 2*@s.with_end ) / @s.stitches 54 | end 55 | 56 | # Calculate indice; size 57 | indice_size = 1/(1+Math.exp( Float(-@s.stitches)/25)) 58 | 59 | # Calculate indice: syntax quality 60 | indice_syntax = 1 / (@s.with_flag > 0 ? 1 : 1.5)/ ( @s.advanced_syntax > 0 ? 1 : 1.5) / (@s.with_condition > 0 ? 1 : 1.5) 61 | 62 | # Calculate global score 63 | score = Float(indice_angle * indice_branching * indice_size * indice_syntax) 64 | 65 | # Calculate short / medium / long score 66 | # 0 -> 10K 67 | # short_score = prob( @s.total_words, 2000, 800 ) * score 68 | 69 | # 10K -> 30 K 70 | # medium_score = prob( @s.total_words, 20000, 8000 ) * score 71 | 72 | # 30K -> 250k 73 | # long_score = prob( @s.total_words, 200000, 80000 ) * score 74 | 75 | # return { score_short: prob( @s.total_words, 2000, 800 ) * score, score_medium: prob( @s.total_words, 20000, 8000 ) * score, score_long: prob( @s.total_words, 200000, 80000 ) * score} 76 | 77 | return {score: score} 78 | end 79 | 80 | end 81 | 82 | # angle = atan( y / x) 83 | # size indice = gauss( angle, pi/4, pi/4) 84 | # quality indice = ( choice + divert - end - fake ) / stitches 85 | end -------------------------------------------------------------------------------- /app/services/rating_unused.rb: -------------------------------------------------------------------------------- 1 | module RatingUnused 2 | 3 | 4 | class Interest 5 | def initialize(target, loss_of_interest_further_from = 0.10, speed_of_disinterest = 2) 6 | # target value is the desired value for the criteria studied: number of words in story etc .. 7 | @t = target 8 | # speed_of_disinterest is includeed between 1 and 3. 3 showing a faster disinterest 9 | if speed_of_disinterest < 1 10 | @s = 1 11 | elsif speed_of_disinterest > 2 12 | @s = 2 13 | else 14 | @s = speed_of_disinterest.to_i 15 | end 16 | # loss_of_interest_further_from is the pourcentage of the target value from which rating decrease faster 17 | @d = loss_of_interest_further_from.to_f 18 | end 19 | 20 | def calc(value, best_mark = 10) 21 | rating = best_mark.to_i 22 | safe_range = @t * @d 23 | target_miss = (@t - value).abs 24 | if target_miss < safe_range 25 | rating = rating - (rating * (target_miss / safe_range) / @t) 26 | else 27 | further_from_limit = target_miss - safe_range 28 | prerating = rating * (1-@d) 29 | rating = prerating - (further_from_limit / safe_range)**(1+0.3*@s) 30 | return rating < 0 ? 0 : rating 31 | end 32 | end 33 | end 34 | 35 | # usage 36 | # Interest.new(2000, 0.1, 1).calc(xxx, 10) 37 | 38 | class Gauss 39 | def initialize(avg, std) 40 | @mean = avg.to_f 41 | @standard_deviation = std.to_f 42 | @variance = std.to_f**2 43 | end 44 | 45 | def density(value) 46 | return 0 if @standard_deviation <= 0 47 | 48 | up_right = (value - @mean)**2.0 49 | down_right = 2.0 * @variance 50 | right = Math.exp(-(up_right/down_right)) 51 | left_down = Math.sqrt(2.0 * Math::PI * @variance) 52 | left_up = 1.0 53 | 54 | (left_up/(left_down) * right) 55 | end 56 | 57 | def cumulative(value) 58 | (1/2.0) * (1.0 + Math.erf((value - @mean)/(@standard_deviation * Math.sqrt(2.0)))) 59 | end 60 | 61 | end 62 | 63 | # inspired from estebanz01/ruby-statistics 64 | # Under Mit License !! 65 | # licenses may mismatch 66 | 67 | # usage 68 | # Gauss.new(2000, 500).cumulative(2550) 69 | # Gauss.new(2000, 500).density(2550) 70 | end -------------------------------------------------------------------------------- /app/services/stats.rb: -------------------------------------------------------------------------------- 1 | module Stats 2 | # The 4 methods below help to recursively build the story preview in show action 3 | class Story 4 | 5 | def initialize(story) 6 | 7 | # recovering story data by any identifier 8 | if story.class.name == "Story" 9 | @story = story.data 10 | elsif story.class.name == "Integer" 11 | if Story.exists?(id: story) 12 | @story = Story.find(story).data 13 | end 14 | elsif story.class.name == "String" 15 | if Story.exists?(id: story.to_i) 16 | @story = Story.find(story.to_i).data 17 | end 18 | elsif story.class.name == "Hash" 19 | @story = story 20 | else 21 | @story = 'unprocessable' 22 | end 23 | 24 | @stitches = 0 25 | @words = [] 26 | @stitchesWithImage = 0 27 | @stitchesWithChoices = 0 28 | @stitchesWithFakeChoices = 0 29 | @stitchesWithCondition = 0 30 | @averageContentSize = 0 31 | @stitchesWithDiverts = 0 32 | @advancedSyntax = 0 33 | @stitchesWithEnd = 0 34 | @totalContentSize = 0 35 | @stitchesWithFlag = 0 36 | # @useCondition = false 37 | # @useFlag = false 38 | end 39 | 40 | 41 | def stats 42 | unless @story == 'unprocessable' 43 | @story["stitches"].each do |stitchkey, stitchval| 44 | @stitches += 1 45 | choices = 0 46 | has_condition = false 47 | has_flag = false 48 | has_divert = false 49 | has_choice = false 50 | 51 | 52 | stitchval["content"].each do |arrayval| 53 | if arrayval.is_a?String 54 | @words << arrayval.split(" ").count 55 | if hasAdvancedSyntax(arrayval) 56 | @advancedSyntax = 1 57 | end 58 | else 59 | if arrayval.is_a?Hash 60 | if arrayval.has_key?("image") 61 | @stitchesWithImage += 1 62 | elsif arrayval.has_key?("divert") 63 | @stitchesWithDiverts += 1 64 | has_divert = true 65 | elsif arrayval.has_key?("flagName") 66 | has_flag = true 67 | elsif arrayval.has_key?("option") 68 | choices +=1 69 | has_choice = true 70 | elsif arrayval.has_key?("ifCondition") || arrayval.has_key?("NotIfCondition") || arrayval.has_key?("ifConditions") || arrayval.has_key?("NotIfConditions") 71 | has_condition = true 72 | end 73 | end 74 | end 75 | end 76 | 77 | if has_condition == true 78 | @stitchesWithCondition += 1 79 | end 80 | 81 | if has_flag == true 82 | @stitchesWithFlag += 1 83 | end 84 | 85 | if choices > 1 86 | @stitchesWithChoices += 1 87 | elsif choices == 1 88 | @stitchesWithFakeChoices +=1 89 | end 90 | 91 | unless has_divert == true or has_choice == true 92 | @stitchesWithEnd += 1 93 | end 94 | 95 | end 96 | 97 | 98 | if @words.length != 0 99 | @averageContentSize = @words.inject(0, :+) / @stitches; 100 | @totalContentSize = @words.inject(0, :+) 101 | else 102 | @averageContentSize = 0 103 | @totalContentSize = 0 104 | end 105 | 106 | return {stitches: @stitches, total_words: @totalContentSize, with_choice: @stitchesWithChoices, with_condition: @stitchesWithCondition, avg_words: @averageContentSize, with_flag: @stitchesWithFlag, advanced_syntax: @advancedSyntax, with_end: @stitchesWithEnd, with_image: @stitchesWithImage, with_divert: @stitchesWithDiverts, with_fake_choice: @stitchesWithFakeChoices } 107 | 108 | end 109 | end 110 | 111 | 112 | def hasAdvancedSyntax(value) 113 | if value.match(/\{[^:]*:.*\}/) 114 | return true 115 | elsif value.match(/\[[^:]*:.*\]/) 116 | return true 117 | end 118 | return false 119 | end 120 | 121 | 122 | end 123 | 124 | end -------------------------------------------------------------------------------- /app/views/admin/adminpages/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Hello <%= current_user.email %>

4 |

You are an admin

5 | 6 |
7 |

Recent stats

8 | 9 |

New stories for the last 3 years

10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | <% @last_three_years.count.times do |y| %> 29 | <% year = @current_year-y %> 30 | 31 | 32 | 33 | <% 12.times do |m| %> 34 | 35 | <% end %> 36 | 37 | 38 | <% end %> 39 |
JanFebMarAprMayJunJulAugSepOctNovDec
<%= year %><%= @last_three_years[year.to_s][(m+1).to_s] %>
40 |
41 | 42 | 97 | 98 |
-------------------------------------------------------------------------------- /app/views/errors/internal_server_error.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 | 6 |
7 | 8 | 9 |
10 |
11 | 12 | 13 |
14 | 15 |

Oops! This is an internal server error

16 |

You may try go back to root page

17 | 18 |
19 |
20 |
21 | 22 | 23 |
-------------------------------------------------------------------------------- /app/views/errors/not_found.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 | 6 |
7 | 8 | 9 |
10 |
11 | 12 | 13 |
14 | 15 |

Oops! Page cannot be found

16 |

You may try go back to root page

17 | 18 |
19 |
20 |
21 | 22 | 23 |
-------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | <%= content_for?(:title) ? yield(:title) : "inklewriter" %> 14 | 15 | <%= csrf_meta_tags %> 16 | <%= csp_meta_tag %> 17 | 18 | <%# below stylesheet has been removed from global scope %> 19 | <%# stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 20 | 21 | <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> 22 | <%= yield(:headcss) %> 23 | <%= stylesheet_link_tag "#{params[:controller]}", media: 'all' %> 24 | 25 | 26 | <%= if File.exist?("app/assets/javascripts/#{params[:controller]}/#{params[:action]}.js") 27 | then javascript_include_tag "#{params[:controller]}/#{params[:action]}" 28 | end %> 29 | 30 | <%# adding inklewriter story reader to the controller stories and action show %> 31 | <% if params[:controller] == "stories" and params[:action] == "show" %> 32 | <%= javascript_include_tag 'inklewriter-read' %> 33 | <% end %> 34 | 35 | <%# adding inklewriter story writer to the root of site %> 36 | <% if params[:controller] == "pages" and params[:action] == "index" %> 37 | <%= javascript_include_tag 'inklewriter-write' %> 38 | <% end %> 39 | 40 | <%# adding inle CSS to stories and pages#index %> 41 | <% if params[:controller] == "stories" or (params[:controller] == "pages" and params[:action] == "index") %> 42 | <%= stylesheet_link_tag 'inklewriter' %> 43 | <% end %> 44 | 45 | 56 | 57 | 58 | 59 | 60 | <%= yield %> 61 | 62 | 63 | -------------------------------------------------------------------------------- /app/views/layouts/devise_mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <%= stylesheet_link_tag 'emails.css' %> 6 | 7 | 8 | 9 | <%= yield %> 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | <%= stylesheet_link_tag 'emails.css' %> 9 | 10 | 11 | 12 | <%= yield %> 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /app/views/pages/health.html.erb: -------------------------------------------------------------------------------- 1 | database is connected = <%= @status[:database_connected] %> -------------------------------------------------------------------------------- /app/views/pages/index.html.erb: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 | 5 |
6 | 7 | 8 |
9 | Source Code 10 | Privacy Policy 11 | 12 |
13 | 14 | 15 | 16 |
17 |
18 | 19 |
20 | 21 | 22 | 23 | 71 | 72 |
73 |
74 | 75 |
76 |
77 | 78 |
79 |
80 | 81 |
82 | 83 | -------------------------------------------------------------------------------- /app/views/pages/privacy.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 | 6 |
7 |
8 | 9 |

Privacy Policy

10 |

This Privacy Policy applies to Inklewriter Free or www.inklewriter.com (hereinafter, "us", "we", or "www.inklewriter.com").

11 |

Your privacy is essential

12 |

We collect as little information as possible as a general policy.

13 |

We use no tracker or any other tool to identify, profile, or target visitors.

14 |

We display no paid ads.

15 |

We don't distribute, sell, or trade any personal data to anyone.

16 |

Collected informations

17 | 22 |
23 |
24 | 25 | 26 | 56 | -------------------------------------------------------------------------------- /app/views/stories/cannot_display_stories.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 | 6 |
7 | 8 | 9 |
10 |
11 | 12 | 13 |
14 | 15 |

Oops! Looks like you are not connected to your account.

16 |

This route is only available to connected users to return their stories as JSON.

17 | 18 | 19 |
20 |
21 |
22 | 23 | 24 |
25 | -------------------------------------------------------------------------------- /app/views/stories/inking.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |

inklewriter JSON to ink converter

6 | 7 |

This converter takes the data from an inklewriter story, and converts it to an ink file.

8 | 9 | 10 |
11 | 12 | 13 |
14 | 15 | 16 | 17 |
18 | 19 | 20 |
21 | 22 | 27 | 28 | 29 | 30 |
31 | 32 | 33 | 34 | <%= javascript_include_tag 'inklewriter-convert.js' %> 35 | 36 | 37 | 146 | 147 | 148 | <% content_for :headcss do %> 149 | <%= stylesheet_link_tag "inking.css" %> 150 | <% end %> 151 | -------------------------------------------------------------------------------- /app/views/stories/not_found.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 | 6 |
7 | 8 | 9 |
10 |
11 | 12 | 13 |
14 | 15 |

Oops! Looks like you searched for a non-existing story.

16 |

You might have followed a link to a story stored on the legacy version of Inklewriter.

17 |

If so there is a solution to your problem!

18 | 19 |

Old stories can be imported out of the old database and into the new one, but the process should be fast and easy. You can start importing now:

20 | 21 |
    22 |
  1. Head to the legacy version of inklewriter to grab your the story 23 | data in JSON format (if it exists, of course).
  2. 24 | 25 | 26 |
  3. Open in another tab this version of inklewriter at inklewriter.com.
  4. 27 |
  5. You'll need to first register a new account on the new version to import your story
  6. 28 |
  7. Once logged in, click on the import link.
  8. 29 |
  9. Copy the JSON data from your story, and paste it into the text area of the import box, and click Import.
  10. 30 |
  11. Next click on the "open" link: your story should be here, ready to open.
  12. 31 |
32 | 33 |
34 |
35 |
36 | 37 | 38 |
39 | -------------------------------------------------------------------------------- /app/views/stories/not_story_owner.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 | 6 |
7 | 8 | 9 |
10 |
11 | 12 | 13 |
14 | 15 |

Oops! Looks like you don't own this story.

16 |

You cannot alter other people stories.

17 | 18 | 19 |
20 |
21 |
22 | 23 | 24 |
-------------------------------------------------------------------------------- /app/views/stories/show.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 |
6 | 7 |
8 | 9 | 10 |
11 | 12 |
13 | 14 | 15 | 16 |
17 |
18 | 19 |
20 | 21 | 22 | 41 | 42 | 74 | 75 |
76 | 77 |
78 | 79 | 80 | 81 | 82 |
83 | 84 |

<%= @title %>

85 |

<%= @author %>

86 | 87 | <% if @first_stitches_content.present? %> 88 |
89 |
90 | <%= @first_stitches_content.first %> 91 |
92 | 93 | <% @first_stitches_content = @first_stitches_content.drop(1) %> 94 | 95 | <% if @first_stitches_content.present? %> 96 | <% @first_stitches_content.each do |value| %> 97 |
98 | <%= value %> 99 |
100 | <% end %> 101 | <% end %> 102 |
103 | <% end %> 104 | 105 | 106 | <% if @first_options_content.present? %> 107 |
108 | <% @first_options_content.each do |value| %> 109 |
<%= value %>
110 | <% end %> 111 |
112 | <% end %> 113 | 114 |
115 | 116 | 121 | 122 |
123 |
124 | 125 | 126 | 127 |
128 | 129 | 130 | <% content_for :title do %><%= "#{@title} by #{@author}" %><% end %> 131 | -------------------------------------------------------------------------------- /app/views/stories/show.json.erb: -------------------------------------------------------------------------------- 1 | <%= raw(@data) %> -------------------------------------------------------------------------------- /app/views/user_mailer/test.html.erb: -------------------------------------------------------------------------------- 1 | Ceci est un email de test -------------------------------------------------------------------------------- /app/views/user_mailer/test.text.erb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/app/views/user_mailer/test.text.erb -------------------------------------------------------------------------------- /app/views/users/confirmations/new.html.erb: -------------------------------------------------------------------------------- 1 |

Resend confirmation instructions

2 | 3 | <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> 4 | <%= render "devise/shared/error_messages", resource: resource %> 5 | 6 |
7 | <%= f.label :email %>
8 | <%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> 9 |
10 | 11 |
12 | <%= f.submit "Resend confirmation instructions" %> 13 |
14 | <% end %> 15 | 16 | <%= render "users/shared/links" %> 17 | -------------------------------------------------------------------------------- /app/views/users/mailer/confirmation_instructions.html.erb: -------------------------------------------------------------------------------- 1 |
2 | inklewriter 3 |
4 | 5 |

Welcome <%= @email %>!

6 | 7 |

You can confirm your account email through the link below:

8 | 9 |

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

10 | -------------------------------------------------------------------------------- /app/views/users/mailer/email_changed.html.erb: -------------------------------------------------------------------------------- 1 |
2 | inklewriter 3 |
4 | 5 |

Hello <%= @email %>!

6 | 7 | <% if @resource.try(:unconfirmed_email?) %> 8 |

We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.

9 | <% else %> 10 |

We're contacting you to notify you that your email has been changed to <%= @resource.email %>.

11 | <% end %> 12 | -------------------------------------------------------------------------------- /app/views/users/mailer/password_change.html.erb: -------------------------------------------------------------------------------- 1 |
2 | inklewriter 3 |
4 | 5 |

Hello <%= @resource.email %>!

6 | 7 |

We're contacting you to notify you that your password has been changed.

8 | -------------------------------------------------------------------------------- /app/views/users/mailer/reset_password_instructions.html.erb: -------------------------------------------------------------------------------- 1 |
2 | inklewriter 3 |
4 | 5 |

Hello <%= @resource.email %>!

6 | 7 |

Someone has requested a link to change your password. You can do this through the link below.

8 | 9 |

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

10 | 11 |

If you didn't request this, please ignore this email.

12 |

Your password won't change until you access the link above and create a new one.

13 | -------------------------------------------------------------------------------- /app/views/users/mailer/unlock_instructions.html.erb: -------------------------------------------------------------------------------- 1 |
2 | inklewriter 3 |
4 | 5 |

Hello <%= @resource.email %>!

6 | 7 |

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

8 | 9 |

Click the link below to unlock your account:

10 | 11 |

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

12 | -------------------------------------------------------------------------------- /app/views/users/passwords/edit.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 | 6 |
7 | 8 | 9 |
10 |
11 | 12 | 13 |
14 | 15 |

Change your password

16 | 17 | <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> 18 | <%= render "devise/shared/error_messages", resource: resource %> 19 | <%= f.hidden_field :reset_password_token %> 20 | 21 |
22 | <%= f.label :password, "New password" %>
23 | <% if @minimum_password_length %> 24 | (<%= @minimum_password_length %> characters minimum)
25 | <% end %> 26 | <%= f.password_field :password, autofocus: true, autocomplete: "new-password" %> 27 |
28 | 29 |
30 | <%= f.label :password_confirmation, "Confirm new password" %>
31 | <%= f.password_field :password_confirmation, autocomplete: "new-password" %> 32 |
33 | 34 | 35 |
36 | <%= f.submit "Change my password" %> 37 |
38 | <% end %> 39 |
40 | 41 | 42 |
43 |
44 | 45 | 46 |
47 | 48 | <% content_for :headcss do %> 49 | <%= stylesheet_link_tag "inklewriter" %> 50 | <% end %> -------------------------------------------------------------------------------- /app/views/users/passwords/new.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 | 6 |
7 | 8 | 9 |
10 |
11 | 12 | 13 |
14 | 15 |

Forgot your password?

16 | 17 | <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> 18 | <%= render "devise/shared/error_messages", resource: resource %> 19 | 20 |
21 | <%= f.label :email %>
22 | <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 23 |
24 | 25 |
26 | <%= f.submit "Send me reset password instructions" %> 27 |
28 | <% end %> 29 | 30 | 31 |
32 |
33 |
34 | 35 | 36 |
37 | 38 | <% content_for :headcss do %> 39 | <%= stylesheet_link_tag "inklewriter" %> 40 | <% end %> -------------------------------------------------------------------------------- /app/views/users/registrations/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Edit <%= resource_name.to_s.humanize %>

2 | 3 | <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> 4 | <%= render "devise/shared/error_messages", resource: resource %> 5 | 6 |
7 | <%= f.label :email %>
8 | <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 9 |
10 | 11 | <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> 12 |
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
13 | <% end %> 14 | 15 |
16 | <%= f.label :password %> (leave blank if you don't want to change it)
17 | <%= f.password_field :password, autocomplete: "new-password" %> 18 | <% if @minimum_password_length %> 19 |
20 | <%= @minimum_password_length %> characters minimum 21 | <% end %> 22 |
23 | 24 |
25 | <%= f.label :password_confirmation %>
26 | <%= f.password_field :password_confirmation, autocomplete: "new-password" %> 27 |
28 | 29 |
30 | <%= f.label :current_password %> (we need your current password to confirm your changes)
31 | <%= f.password_field :current_password, autocomplete: "current-password" %> 32 |
33 | 34 |
35 | <%= f.submit "Update" %> 36 |
37 | <% end %> 38 | 39 |

Cancel my account

40 | 41 |

Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

42 | 43 | <%= link_to "Back", :back %> 44 | -------------------------------------------------------------------------------- /app/views/users/registrations/new.html.erb: -------------------------------------------------------------------------------- 1 |

Sign up

2 | 3 | <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> 4 | <%= render "devise/shared/error_messages", resource: resource %> 5 | 6 |
7 | <%= f.label :email %>
8 | <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 9 |
10 | 11 |
12 | <%= f.label :password %> 13 | <% if @minimum_password_length %> 14 | (<%= @minimum_password_length %> characters minimum) 15 | <% end %>
16 | <%= f.password_field :password, autocomplete: "new-password" %> 17 |
18 | 19 |
20 | <%= f.label :password_confirmation %>
21 | <%= f.password_field :password_confirmation, autocomplete: "new-password" %> 22 |
23 | 24 |
25 | <%= f.submit "Sign up" %> 26 |
27 | <% end %> 28 | 29 | <%= render "users/shared/links" %> 30 | -------------------------------------------------------------------------------- /app/views/users/sessions/new.html.erb: -------------------------------------------------------------------------------- 1 |

Log in

2 | 3 | <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> 4 |
5 | <%= f.label :email %>
6 | <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 7 |
8 | 9 |
10 | <%= f.label :password %>
11 | <%= f.password_field :password, autocomplete: "current-password" %> 12 |
13 | 14 | <% if devise_mapping.rememberable? %> 15 |
16 | <%= f.check_box :remember_me %> 17 | <%= f.label :remember_me %> 18 |
19 | <% end %> 20 | 21 |
22 | <%= f.submit "Log in" %> 23 |
24 | <% end %> 25 | 26 | <%= render "users/shared/links" %> 27 | -------------------------------------------------------------------------------- /app/views/users/shared/_error_messages.html.erb: -------------------------------------------------------------------------------- 1 | <% if resource.errors.any? %> 2 |
3 |

4 | <%= I18n.t("errors.messages.not_saved", 5 | count: resource.errors.count, 6 | resource: resource.class.model_name.human.downcase) 7 | %> 8 |

9 | 14 |
15 | <% end %> 16 | -------------------------------------------------------------------------------- /app/views/users/shared/_links.html.erb: -------------------------------------------------------------------------------- 1 | <%- if controller_name != 'sessions' %> 2 | <%= link_to "Log in", new_session_path(resource_name) %>
3 | <% end %> 4 | 5 | <%- if devise_mapping.registerable? && controller_name != 'registrations' %> 6 | <%= link_to "Sign up", new_registration_path(resource_name) %>
7 | <% end %> 8 | 9 | <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> 10 | <%= link_to "Forgot your password?", new_password_path(resource_name) %>
11 | <% end %> 12 | 13 | <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> 14 | <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
15 | <% end %> 16 | 17 | <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> 18 | <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
19 | <% end %> 20 | 21 | <%- if devise_mapping.omniauthable? %> 22 | <%- resource_class.omniauth_providers.each do |provider| %> 23 | <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %>
24 | <% end %> 25 | <% end %> 26 | -------------------------------------------------------------------------------- /app/views/users/unlocks/new.html.erb: -------------------------------------------------------------------------------- 1 |

Resend unlock instructions

2 | 3 | <%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> 4 | <%= render "devise/shared/error_messages", resource: resource %> 5 | 6 |
7 | <%= f.label :email %>
8 | <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 9 |
10 | 11 |
12 | <%= f.submit "Resend unlock instructions" %> 13 |
14 | <% end %> 15 | 16 | <%= render "users/shared/links" %> 17 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../config/application', __dir__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'fileutils' 3 | include FileUtils 4 | 5 | # path to your application root. 6 | APP_ROOT = File.expand_path('..', __dir__) 7 | 8 | def system!(*args) 9 | system(*args) || abort("\n== Command #{args} failed ==") 10 | end 11 | 12 | chdir APP_ROOT do 13 | # This script is a starting point to setup your application. 14 | # Add necessary setup steps to this file. 15 | 16 | puts '== Installing dependencies ==' 17 | system! 'gem install bundler --conservative' 18 | system('bundle check') || system!('bundle install') 19 | 20 | # Install JavaScript dependencies if using Yarn 21 | # system('bin/yarn') 22 | 23 | # puts "\n== Copying sample files ==" 24 | # unless File.exist?('config/database.yml') 25 | # cp 'config/database.yml.sample', 'config/database.yml' 26 | # end 27 | 28 | puts "\n== Preparing database ==" 29 | system! 'bin/rails db:setup' 30 | 31 | puts "\n== Removing old logs and tempfiles ==" 32 | system! 'bin/rails log:clear tmp:clear' 33 | 34 | puts "\n== Restarting application server ==" 35 | system! 'bin/rails restart' 36 | end 37 | -------------------------------------------------------------------------------- /bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This file loads spring without using Bundler, in order to be fast. 4 | # It gets overwritten when you run the `spring binstub` command. 5 | 6 | unless defined?(Spring) 7 | require 'rubygems' 8 | require 'bundler' 9 | 10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) 11 | spring = lockfile.specs.detect { |spec| spec.name == "spring" } 12 | if spring 13 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path 14 | gem 'spring', spring.version 15 | require 'spring/binstub' 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'fileutils' 3 | include FileUtils 4 | 5 | # path to your application root. 6 | APP_ROOT = File.expand_path('..', __dir__) 7 | 8 | def system!(*args) 9 | system(*args) || abort("\n== Command #{args} failed ==") 10 | end 11 | 12 | chdir APP_ROOT do 13 | # This script is a way to update your development environment automatically. 14 | # Add necessary update steps to this file. 15 | 16 | puts '== Installing dependencies ==' 17 | system! 'gem install bundler --conservative' 18 | system('bundle check') || system!('bundle install') 19 | 20 | # Install JavaScript dependencies if using Yarn 21 | # system('bin/yarn') 22 | 23 | puts "\n== Updating database ==" 24 | system! 'bin/rails db:migrate' 25 | 26 | puts "\n== Removing old logs and tempfiles ==" 27 | system! 'bin/rails log:clear tmp:clear' 28 | 29 | puts "\n== Restarting application server ==" 30 | system! 'bin/rails restart' 31 | end 32 | -------------------------------------------------------------------------------- /bin/yarn: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_ROOT = File.expand_path('..', __dir__) 3 | Dir.chdir(APP_ROOT) do 4 | begin 5 | exec "yarnpkg", *ARGV 6 | rescue Errno::ENOENT 7 | $stderr.puts "Yarn executable was not detected in the system." 8 | $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" 9 | exit 1 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative 'config/environment' 4 | 5 | run Rails.application 6 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative 'boot' 2 | 3 | require 'rails/all' 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module Freeifwriter 10 | class Application < Rails::Application 11 | # Initialize configuration defaults for originally generated Rails version. 12 | config.load_defaults 5.2 13 | 14 | 15 | config.action_controller.default_protect_from_forgery = false 16 | 17 | # Allow custom 404 500 ... 18 | config.exceptions_app = self.routes 19 | 20 | # Settings in config/environments/* take precedence over those specified here. 21 | # Application configuration can go into files in config/initializers 22 | # -- all .rb files in that directory are automatically loaded after loading 23 | # the framework and any gems in your application. 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 2 | 3 | require 'bundler/setup' # Set up gems listed in the Gemfile. 4 | require 'bootsnap/setup' # Speed up boot time by caching expensive operations. 5 | -------------------------------------------------------------------------------- /config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: async 6 | 7 | production: 8 | adapter: redis 9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 10 | channel_prefix: freeifwriter_production 11 | -------------------------------------------------------------------------------- /config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | /k9WpH/qQtXxKdHNs8s5JjVuvUbx7Oo9hrm33KZG9vXUxs0bJtx57EPtbfm6bBr1R5r2GkuUDt5lzDOS5q1lh8E7ipwbsO/IURWwZ55batxxvLzIS1xBOmsJUNoWFYhwD5BZo01ogmMwVb18aZhgBc/V9JD5LTPFH5Fo9kR4zJDmNi3RvMhMlJVKAxVksfMFXxotTXn60fPzMUx8wO2zDVMeobphymfl31xpIqGYzCFbq8xQ9wAoz8oPyiJqIARPeJTzVq6JlWpHUinzOfMApmqWsZcO/aqoUVgzM2jzdMoRxAO88NLAgF6rpCw97wXvaP8jk0+msWvrgSjWS7Tkw70U556rnj14oKwKX0anSkAyBkRa/zJt/N3BJGOq9TzgCUPtmnF/OXzZRTlojQKt2+PkovmSoVVMuQsj--7nelkeVyPJGsKBYq--6PeU8tZgbVXOeOujdAcT4w== -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | default: &default 2 | adapter: postgresql 3 | encoding: unicode 4 | pool: 5 5 | 6 | development: 7 | <<: *default 8 | database: inklewriter_dev 9 | user: <%= ENV.has_key?('POSTGRES_USER') ? ENV['POSTGRES_USER'] : Rails.application.secrets.db_user %> 10 | password: <%= ENV.has_key?('POSTGRES_PASSWORD') ? ENV['POSTGRES_PASSWORD'] : Rails.application.secrets.db_password %> 11 | host: <%= ENV.has_key?('POSTGRES_HOST') ? ENV['POSTGRES_HOST'] : Rails.application.secrets.dh_host %> 12 | 13 | # Warning: The database defined as "test" will be erased and 14 | # re-generated from your development database when you run "rake". 15 | # Do not set this db to the same as development or production. 16 | test: 17 | <<: *default 18 | database: inklewriter_test 19 | username: <%= ENV["POSTGRES_USER"] %> 20 | password: <%= ENV["POSTGRES_PASSWORD"] %> 21 | host: <%= ENV["POSTGRES_HOST"] %> 22 | 23 | production: 24 | <<: *default 25 | database: inklewriter_prod 26 | username: <%= ENV["POSTGRES_USER"] %> 27 | password: <%= ENV["POSTGRES_PASSWORD"] %> 28 | host: <%= ENV["POSTGRES_HOST"] %> 29 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative 'application' 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | config.serve_static_assets = false 13 | 14 | # Show full error reports. 15 | config.consider_all_requests_local = true 16 | 17 | # Enable/disable caching. By default caching is disabled. 18 | # Run rails dev:cache to toggle caching. 19 | if Rails.root.join('tmp', 'caching-dev.txt').exist? 20 | config.action_controller.perform_caching = true 21 | 22 | config.cache_store = :memory_store 23 | config.public_file_server.headers = { 24 | 'Cache-Control' => "public, max-age=#{2.days.to_i}" 25 | } 26 | else 27 | config.action_controller.perform_caching = false 28 | 29 | config.cache_store = :null_store 30 | end 31 | 32 | # Store uploaded files on the local file system (see config/storage.yml for options) 33 | config.active_storage.service = :local 34 | 35 | # Don't care if the mailer can't send. 36 | # config.action_mailer.raise_delivery_errors = true 37 | 38 | config.action_mailer.perform_caching = false 39 | 40 | # Print deprecation notices to the Rails logger. 41 | config.active_support.deprecation = :log 42 | 43 | # Raise an error on page load if there are pending migrations. 44 | config.active_record.migration_error = :page_load 45 | 46 | # Highlight code that triggered database queries in logs. 47 | config.active_record.verbose_query_logs = true 48 | 49 | # Debug mode disables concatenation and preprocessing of assets. 50 | # This option may cause significant delays in view rendering with a large 51 | # number of complex assets. 52 | config.assets.debug = true 53 | 54 | # Suppress logger output for asset requests. 55 | config.assets.quiet = true 56 | 57 | # Raises error for missing translations 58 | # config.action_view.raise_on_missing_translations = true 59 | 60 | # Use an evented file watcher to asynchronously detect changes in source code, 61 | # routes, locales, etc. This feature depends on the listen gem. 62 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker 63 | 64 | config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews" 65 | 66 | config.action_mailer.delivery_method = :smtp 67 | config.action_mailer.raise_delivery_errors = true 68 | config.action_mailer.perform_deliveries = false 69 | config.action_mailer.default :charset => "utf-8" 70 | 71 | config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } 72 | 73 | config.action_mailer.smtp_settings = { 74 | address: Rails.application.secrets.mailing_address.present? ? Rails.application.secrets.mailing_address : ENV["MAILING_ADDRESS"], 75 | port: Rails.application.secrets.mailing_port.present? ? Rails.application.secrets.mailing_port : ENV["MAILING_PORT"], 76 | user_name: Rails.application.secrets.mailing_user.present? ? Rails.application.secrets.mailing_user : ENV["MAILING_USER"], #Your SMTP user 77 | password: Rails.application.secrets.mailing_password.present? ? Rails.application.secrets.mailing_password : ENV["MAILING_PASSWORD"], #Your SMTP password 78 | authentication: :login, 79 | enable_starttls_auto: true, 80 | ssl: true, 81 | domain: Rails.application.secrets.mailing_domain.present? ? Rails.application.secrets.mailing_domain : ENV["MAILING_DOMAIN"] 82 | } 83 | 84 | end 85 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both threaded web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 18 | # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 19 | # config.require_master_key = true 20 | 21 | # Disable serving static files from the `/public` folder by default since 22 | # Apache or NGINX already handles this. 23 | config.public_file_server.enabled = true 24 | 25 | # Compress JavaScripts and CSS. 26 | config.assets.js_compressor = Uglifier.new(harmony: true) 27 | config.assets.css_compressor = :sass 28 | 29 | # Do not fallback to assets pipeline if a precompiled asset is missed. 30 | config.assets.compile = true 31 | 32 | # caching policy for static assets 33 | config.public_file_server.headers = { 34 | 'Cache-Control' => 'public, max-age=15552000', 35 | 'Expires' => 1.year.from_now.to_formatted_s(:rfc822) 36 | } 37 | 38 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 39 | 40 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 41 | # config.action_controller.asset_host = 'http://assets.example.com' 42 | 43 | # Specifies the header that your server uses for sending files. 44 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 45 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 46 | 47 | # Store uploaded files on the local file system (see config/storage.yml for options) 48 | config.active_storage.service = :local 49 | 50 | # Mount Action Cable outside main process or domain 51 | # config.action_cable.mount_path = nil 52 | # config.action_cable.url = 'wss://example.com/cable' 53 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] 54 | 55 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 56 | # config.force_ssl = true 57 | 58 | # Use the lowest log level to ensure availability of diagnostic information 59 | # when problems arise. 60 | config.log_level = :debug 61 | 62 | # Prepend all log lines with the following tags. 63 | config.log_tags = [ :request_id ] 64 | 65 | # Use a different cache store in production. 66 | # config.cache_store = :mem_cache_store 67 | 68 | # Use a real queuing backend for Active Job (and separate queues per environment) 69 | # config.active_job.queue_adapter = :resque 70 | # config.active_job.queue_name_prefix = "freeifwriter_#{Rails.env}" 71 | 72 | config.action_mailer.perform_caching = false 73 | 74 | # Ignore bad email addresses and do not raise email delivery errors. 75 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 76 | # config.action_mailer.raise_delivery_errors = false 77 | 78 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 79 | # the I18n.default_locale when a translation cannot be found). 80 | config.i18n.fallbacks = true 81 | 82 | # Send deprecation notices to registered listeners. 83 | config.active_support.deprecation = :notify 84 | 85 | # Use default logging formatter so that PID and timestamp are not suppressed. 86 | config.log_formatter = ::Logger::Formatter.new 87 | 88 | # Use a different logger for distributed setups. 89 | # require 'syslog/logger' 90 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 91 | 92 | if ENV["RAILS_LOG_TO_STDOUT"].present? 93 | logger = ActiveSupport::Logger.new(STDOUT) 94 | logger.formatter = config.log_formatter 95 | config.logger = ActiveSupport::TaggedLogging.new(logger) 96 | end 97 | 98 | 99 | 100 | # Do not dump schema after migrations. 101 | config.active_record.dump_schema_after_migration = false 102 | 103 | config.action_mailer.delivery_method = :smtp 104 | config.action_mailer.raise_delivery_errors = true 105 | config.action_mailer.perform_deliveries = true 106 | config.action_mailer.default :charset => "utf-8" 107 | 108 | config.action_mailer.default_url_options = { host: ENV["ACTION_MAILER_HOST"], :protocol => 'https'} 109 | 110 | config.action_mailer.smtp_settings = { 111 | address: ENV["MAILING_ADDRESS"], 112 | port: ENV["MAILING_PORT"], 113 | user_name: ENV["MAILING_USER"], #Your SMTP user 114 | password: ENV["MAILING_PASSWORD"], #Your SMTP password 115 | authentication: :login, 116 | enable_starttls_auto: true, 117 | ssl: true, 118 | domain: ENV["MAILING_DOMAIN"] 119 | } 120 | 121 | end 122 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure public file server for tests with Cache-Control for performance. 16 | config.public_file_server.enabled = true 17 | config.public_file_server.headers = { 18 | 'Cache-Control' => "public, max-age=#{1.hour.to_i}" 19 | } 20 | 21 | # Show full error reports and disable caching. 22 | config.consider_all_requests_local = true 23 | config.action_controller.perform_caching = false 24 | 25 | # Raise exceptions instead of rendering exception templates. 26 | config.action_dispatch.show_exceptions = false 27 | 28 | # Disable request forgery protection in test environment. 29 | config.action_controller.allow_forgery_protection = false 30 | 31 | # Store uploaded files on the local file system in a temporary directory 32 | config.active_storage.service = :test 33 | 34 | config.action_mailer.perform_caching = false 35 | 36 | # Tell Action Mailer not to deliver emails to the real world. 37 | # The :test delivery method accumulates sent emails in the 38 | # ActionMailer::Base.deliveries array. 39 | config.action_mailer.delivery_method = :test 40 | 41 | # Print deprecation notices to the stderr. 42 | config.active_support.deprecation = :stderr 43 | 44 | # Raises error for missing translations 45 | # config.action_view.raise_on_missing_translations = true 46 | end 47 | -------------------------------------------------------------------------------- /config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ActiveSupport::Reloader.to_prepare do 4 | # ApplicationController.renderer.defaults.merge!( 5 | # http_host: 'example.org', 6 | # https: false 7 | # ) 8 | # end 9 | -------------------------------------------------------------------------------- /config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = '1.0' 5 | 6 | # Add additional assets to the asset load path. 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | # Add Yarn node_modules folder to the asset load path. 9 | Rails.application.config.assets.paths << Rails.root.join('node_modules') 10 | Rails.application.config.assets.paths << Rails.root.join('vendor', 'assets') 11 | 12 | Rails.application.config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.svg *.ttf *.webp *.woff *.woff2 *.eot) 13 | 14 | # Precompile additional assets. 15 | # application.js, application.css, and all non-JS/CSS in the app/assets 16 | # folder are already added. 17 | # Rails.application.config.assets.precompile += %w( admin.js admin.css ) 18 | Rails.application.config.assets.precompile += %w( ifwriter-main.js ) 19 | Rails.application.config.assets.precompile += %w( pages/index.js ) 20 | Rails.application.config.assets.precompile += %w( stories/show.js ) 21 | Rails.application.config.assets.precompile += %w( emails.css ) 22 | Rails.application.config.assets.precompile += %w( devise.css ) 23 | Rails.application.config.assets.precompile += %w( errors.css ) 24 | Rails.application.config.assets.precompile += %w( inklewriter-convert.js ) 25 | Rails.application.config.assets.precompile += %w( inking.css ) 26 | Rails.application.config.assets.precompile += %w( inklewriter-read.js ) 27 | Rails.application.config.assets.precompile += %w( inklewriter-write.js ) 28 | Rails.application.config.assets.precompile += %w( pages.css ) 29 | Rails.application.config.assets.precompile += %w( inking.css ) 30 | Rails.application.config.assets.precompile += %w( stories.css ) 31 | Rails.application.config.assets.precompile += %w( inklewriter.css ) 32 | Rails.application.config.assets.precompile += %w( admin/adminpages.css ) 33 | Rails.application.config.assets.precompile += %w( users/confirmations.css ) 34 | Rails.application.config.assets.precompile += %w( users/sessions.css ) 35 | Rails.application.config.assets.precompile += %w( users/registrations.css ) 36 | Rails.application.config.assets.precompile += %w( users/unlocks.css ) 37 | Rails.application.config.assets.precompile += %w( users/passwords.css ) 38 | Rails.application.config.assets.precompile += %w( admin/adminpages/index.js ) 39 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /config/initializers/content_security_policy.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Define an application-wide content security policy 4 | # For further information see the following documentation 5 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy 6 | 7 | # Rails.application.config.content_security_policy do |policy| 8 | # policy.default_src :self, :https 9 | # policy.font_src :self, :https, :data 10 | # policy.img_src :self, :https, :data 11 | # policy.object_src :none 12 | # policy.script_src :self, :https 13 | # policy.style_src :self, :https 14 | 15 | # # Specify URI for violation reports 16 | # # policy.report_uri "/csp-violation-report-endpoint" 17 | # end 18 | 19 | # If you are using UJS then enable automatic nonce generation 20 | # Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } 21 | 22 | # Report CSP violations to a specified URI 23 | # For further information see the following documentation: 24 | # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only 25 | # Rails.application.config.content_security_policy_report_only = true 26 | -------------------------------------------------------------------------------- /config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Specify a serializer for the signed and encrypted cookie jars. 4 | # Valid options are :json, :marshal, and :hybrid. 5 | Rails.application.config.action_dispatch.cookies_serializer = :json 6 | -------------------------------------------------------------------------------- /config/initializers/devise.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Use this hook to configure devise mailer, warden hooks and so forth. 4 | # Many of these configuration options can be set straight in your model. 5 | Devise.setup do |config| 6 | # The secret key used by Devise. Devise uses this key to generate 7 | # random tokens. Changing this key will render invalid all existing 8 | # confirmation, reset password and unlock tokens in the database. 9 | # Devise will use the `secret_key_base` as its `secret_key` 10 | # by default. You can change it below and use your own secret key. 11 | # config.secret_key = '3895c1ef7b59bc2d60d0dfd026a3098f1cfb20eb957903c069d82f4a7cccbd85851f7c26e4a22e80ebfcbe2910b29f90cb3a4c07a06c47b1edaea712a41b8a1d' 12 | 13 | # ==> Controller configuration 14 | # Configure the parent class to the devise controllers. 15 | # config.parent_controller = 'DeviseController' 16 | 17 | # ==> Mailer Configuration 18 | # Configure the e-mail address which will be shown in Devise::Mailer, 19 | # note that it will be overwritten if you use your own mailer class 20 | # with default "from" parameter. 21 | config.mailer_sender = 'do-not-reply@inklewriter.com' 22 | 23 | # Configure the class responsible to send e-mails. 24 | config.mailer = 'CustomDeviseMailer' 25 | 26 | # Configure the parent class responsible to send e-mails. 27 | config.parent_mailer = 'ActionMailer::Base' 28 | 29 | # ==> ORM configuration 30 | # Load and configure the ORM. Supports :active_record (default) and 31 | # :mongoid (bson_ext recommended) by default. Other ORMs may be 32 | # available as additional gems. 33 | require 'devise/orm/active_record' 34 | 35 | # ==> Configuration for any authentication mechanism 36 | # Configure which keys are used when authenticating a user. The default is 37 | # just :email. You can configure it to use [:username, :subdomain], so for 38 | # authenticating a user, both parameters are required. Remember that those 39 | # parameters are used only when authenticating and not when retrieving from 40 | # session. If you need permissions, you should implement that in a before filter. 41 | # You can also supply a hash where the value is a boolean determining whether 42 | # or not authentication should be aborted when the value is not present. 43 | # config.authentication_keys = [:email] 44 | 45 | # Configure parameters from the request object used for authentication. Each entry 46 | # given should be a request method and it will automatically be passed to the 47 | # find_for_authentication method and considered in your model lookup. For instance, 48 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. 49 | # The same considerations mentioned for authentication_keys also apply to request_keys. 50 | # config.request_keys = [] 51 | 52 | # Configure which authentication keys should be case-insensitive. 53 | # These keys will be downcased upon creating or modifying a user and when used 54 | # to authenticate or find a user. Default is :email. 55 | config.case_insensitive_keys = [:email] 56 | 57 | # Configure which authentication keys should have whitespace stripped. 58 | # These keys will have whitespace before and after removed upon creating or 59 | # modifying a user and when used to authenticate or find a user. Default is :email. 60 | config.strip_whitespace_keys = [:email] 61 | 62 | # Tell if authentication through request.params is enabled. True by default. 63 | # It can be set to an array that will enable params authentication only for the 64 | # given strategies, for example, `config.params_authenticatable = [:database]` will 65 | # enable it only for database (email + password) authentication. 66 | # config.params_authenticatable = true 67 | 68 | # Tell if authentication through HTTP Auth is enabled. False by default. 69 | # It can be set to an array that will enable http authentication only for the 70 | # given strategies, for example, `config.http_authenticatable = [:database]` will 71 | # enable it only for database authentication. The supported strategies are: 72 | # :database = Support basic authentication with authentication key + password 73 | # config.http_authenticatable = false 74 | 75 | # If 401 status code should be returned for AJAX requests. True by default. 76 | config.http_authenticatable_on_xhr = true 77 | 78 | # The realm used in Http Basic Authentication. 'Application' by default. 79 | # config.http_authentication_realm = 'Application' 80 | 81 | # It will change confirmation, password recovery and other workflows 82 | # to behave the same regardless if the e-mail provided was right or wrong. 83 | # Does not affect registerable. 84 | # config.paranoid = true 85 | 86 | # By default Devise will store the user in session. You can skip storage for 87 | # particular strategies by setting this option. 88 | # Notice that if you are skipping storage for all authentication paths, you 89 | # may want to disable generating routes to Devise's sessions controller by 90 | # passing skip: :sessions to `devise_for` in your config/routes.rb 91 | config.skip_session_storage = [:http_auth] 92 | 93 | # By default, Devise cleans up the CSRF token on authentication to 94 | # avoid CSRF token fixation attacks. This means that, when using AJAX 95 | # requests for sign in and sign up, you need to get a new CSRF token 96 | # from the server. You can disable this option at your own risk. 97 | # config.clean_up_csrf_token_on_authentication = false 98 | 99 | # When false, Devise will not attempt to reload routes on eager load. 100 | # This can reduce the time taken to boot the app but if your application 101 | # requires the Devise mappings to be loaded during boot time the application 102 | # won't boot properly. 103 | # config.reload_routes = true 104 | 105 | # ==> Configuration for :database_authenticatable 106 | # For bcrypt, this is the cost for hashing the password and defaults to 11. If 107 | # using other algorithms, it sets how many times you want the password to be hashed. 108 | # 109 | # Limiting the stretches to just one in testing will increase the performance of 110 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use 111 | # a value less than 10 in other environments. Note that, for bcrypt (the default 112 | # algorithm), the cost increases exponentially with the number of stretches (e.g. 113 | # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). 114 | config.stretches = Rails.env.test? ? 1 : 11 115 | 116 | # Set up a pepper to generate the hashed password. 117 | # config.pepper = '0e2e3a42f864180988088156313d0abda5c57007d3a4ccd3a598c4001db869a8d90d10d771e7e1fccf9405ba9c387bf5ce790da11148362a44987d68b8d25c1a' 118 | 119 | # Send a notification to the original email when the user's email is changed. 120 | # config.send_email_changed_notification = false 121 | 122 | # Send a notification email when the user's password is changed. 123 | # config.send_password_change_notification = false 124 | 125 | # ==> Configuration for :confirmable 126 | # A period that the user is allowed to access the website even without 127 | # confirming their account. For instance, if set to 2.days, the user will be 128 | # able to access the website for two days without confirming their account, 129 | # access will be blocked just in the third day. 130 | # You can also set it to nil, which will allow the user to access the website 131 | # without confirming their account. 132 | # Default is 0.days, meaning the user cannot access the website without 133 | # confirming their account. 134 | # config.allow_unconfirmed_access_for = 2.days 135 | 136 | # A period that the user is allowed to confirm their account before their 137 | # token becomes invalid. For example, if set to 3.days, the user can confirm 138 | # their account within 3 days after the mail was sent, but on the fourth day 139 | # their account can't be confirmed with the token any more. 140 | # Default is nil, meaning there is no restriction on how long a user can take 141 | # before confirming their account. 142 | # config.confirm_within = 3.days 143 | 144 | # If true, requires any email changes to be confirmed (exactly the same way as 145 | # initial account confirmation) to be applied. Requires additional unconfirmed_email 146 | # db field (see migrations). Until confirmed, new email is stored in 147 | # unconfirmed_email column, and copied to email column on successful confirmation. 148 | config.reconfirmable = true 149 | 150 | # Defines which key will be used when confirming an account 151 | # config.confirmation_keys = [:email] 152 | 153 | # ==> Configuration for :rememberable 154 | # The time the user will be remembered without asking for credentials again. 155 | config.remember_for = 2.weeks 156 | 157 | # Invalidates all the remember me tokens when the user signs out. 158 | config.expire_all_remember_me_on_sign_out = true 159 | 160 | # If true, extends the user's remember period when remembered via cookie. 161 | # config.extend_remember_period = false 162 | 163 | # Options to be passed to the created cookie. For instance, you can set 164 | # secure: true in order to force SSL only cookies. 165 | # config.rememberable_options = {} 166 | 167 | # ==> Configuration for :validatable 168 | # Range for password length. 169 | config.password_length = 6..128 170 | 171 | # Email regex used to validate email formats. It simply asserts that 172 | # one (and only one) @ exists in the given string. This is mainly 173 | # to give user feedback and not to assert the e-mail validity. 174 | config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ 175 | 176 | # ==> Configuration for :timeoutable 177 | # The time you want to timeout the user session without activity. After this 178 | # time the user will be asked for credentials again. Default is 30 minutes. 179 | # config.timeout_in = 30.minutes 180 | 181 | # ==> Configuration for :lockable 182 | # Defines which strategy will be used to lock an account. 183 | # :failed_attempts = Locks an account after a number of failed attempts to sign in. 184 | # :none = No lock strategy. You should handle locking by yourself. 185 | # config.lock_strategy = :failed_attempts 186 | 187 | # Defines which key will be used when locking and unlocking an account 188 | # config.unlock_keys = [:email] 189 | 190 | # Defines which strategy will be used to unlock an account. 191 | # :email = Sends an unlock link to the user email 192 | # :time = Re-enables login after a certain amount of time (see :unlock_in below) 193 | # :both = Enables both strategies 194 | # :none = No unlock strategy. You should handle unlocking by yourself. 195 | # config.unlock_strategy = :both 196 | 197 | # Number of authentication tries before locking an account if lock_strategy 198 | # is failed attempts. 199 | # config.maximum_attempts = 20 200 | 201 | # Time interval to unlock the account if :time is enabled as unlock_strategy. 202 | # config.unlock_in = 1.hour 203 | 204 | # Warn on the last attempt before the account is locked. 205 | # config.last_attempt_warning = true 206 | 207 | # ==> Configuration for :recoverable 208 | # 209 | # Defines which key will be used when recovering the password for an account 210 | # config.reset_password_keys = [:email] 211 | 212 | # Time interval you can reset your password with a reset password key. 213 | # Don't put a too small interval or your users won't have the time to 214 | # change their passwords. 215 | config.reset_password_within = 6.hours 216 | 217 | # When set to false, does not sign a user in automatically after their password is 218 | # reset. Defaults to true, so a user is signed in automatically after a reset. 219 | # config.sign_in_after_reset_password = true 220 | 221 | # ==> Configuration for :encryptable 222 | # Allow you to use another hashing or encryption algorithm besides bcrypt (default). 223 | # You can use :sha1, :sha512 or algorithms from others authentication tools as 224 | # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 225 | # for default behavior) and :restful_authentication_sha1 (then you should set 226 | # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). 227 | # 228 | # Require the `devise-encryptable` gem when using anything other than bcrypt 229 | # config.encryptor = :sha512 230 | 231 | # ==> Scopes configuration 232 | # Turn scoped views on. Before rendering "sessions/new", it will first check for 233 | # "users/sessions/new". It's turned off by default because it's slower if you 234 | # are using only default views. 235 | config.scoped_views = true 236 | 237 | # Configure the default scope given to Warden. By default it's the first 238 | # devise role declared in your routes (usually :user). 239 | # config.default_scope = :user 240 | 241 | # Set this configuration to false if you want /users/sign_out to sign out 242 | # only the current scope. By default, Devise signs out all scopes. 243 | # config.sign_out_all_scopes = true 244 | 245 | # ==> Navigation configuration 246 | # Lists the formats that should be treated as navigational. Formats like 247 | # :html, should redirect to the sign in page when the user does not have 248 | # access, but formats like :xml or :json, should return 401. 249 | # 250 | # If you have any extra navigational formats, like :iphone or :mobile, you 251 | # should add them to the navigational formats lists. 252 | # 253 | # The "*/*" below is required to match Internet Explorer requests. 254 | # config.navigational_formats = ['*/*', :html] 255 | 256 | # The default HTTP method used to sign out a resource. Default is :delete. 257 | config.sign_out_via = :delete 258 | 259 | # ==> OmniAuth 260 | # Add a new OmniAuth provider. Check the wiki for more information on setting 261 | # up on your models and hooks. 262 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' 263 | 264 | # ==> Warden configuration 265 | # If you want to use other strategies, that are not supported by Devise, or 266 | # change the failure app, you can configure them inside the config.warden block. 267 | # 268 | # config.warden do |manager| 269 | # manager.intercept_401 = false 270 | # manager.default_strategies(scope: :user).unshift :some_external_strategy 271 | # end 272 | 273 | # ==> Mountable engine configurations 274 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine 275 | # is mountable, there are some extra configurations to be taken into account. 276 | # The following options are available, assuming the engine is mounted as: 277 | # 278 | # mount MyEngine, at: '/my_engine' 279 | # 280 | # The router that invoked `devise_for`, in the example above, would be: 281 | # config.router_name = :my_engine 282 | # 283 | # When using OmniAuth, Devise cannot automatically set OmniAuth path, 284 | # so you need to do it manually. For the users scope, it would be: 285 | # config.omniauth_path_prefix = '/my_engine/users/auth' 286 | 287 | # ==> Turbolinks configuration 288 | # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly: 289 | # 290 | # ActiveSupport.on_load(:devise_failure_app) do 291 | # include Turbolinks::Controller 292 | # end 293 | 294 | # ==> Configuration for :registerable 295 | 296 | # When set to false, does not sign a user in automatically after their password is 297 | # changed. Defaults to true, so a user is signed in automatically after changing a password. 298 | # config.sign_in_after_change_password = true 299 | end 300 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /config/initializers/health_check.rb: -------------------------------------------------------------------------------- 1 | HealthCheck.setup do |config| 2 | 3 | # uri prefix (no leading slash) 4 | config.uri = 'health_check' 5 | 6 | # Text output upon success 7 | config.success = 'success' 8 | 9 | # Timeout in seconds used when checking smtp server 10 | config.smtp_timeout = 30.0 11 | 12 | # http status code used when plain text error message is output 13 | # Set to 200 if you want your want to distinguish between partial (text does not include success) and 14 | # total failure of rails application (http status of 500 etc) 15 | 16 | config.http_status_for_error_text = 500 17 | 18 | # http status code used when an error object is output (json or xml) 19 | # Set to 200 if you want your want to distinguish between partial (healthy property == false) and 20 | # total failure of rails application (http status of 500 etc) 21 | 22 | config.http_status_for_error_object = 500 23 | 24 | # bucket names to test connectivity - required only if s3 check used, access permissions can be mixed 25 | config.buckets = {'bucket_name' => [:R, :W, :D]} 26 | 27 | # You can customize which checks happen on a standard health check, eg to set an explicit list use: 28 | config.standard_checks = [ 'database', 'migrations', 'custom' ] 29 | 30 | # Or to exclude one check: 31 | config.standard_checks -= [ 'emailconf' ] 32 | 33 | # You can set what tests are run with the 'full' or 'all' parameter 34 | config.full_checks = ['database', 'migrations', 'custom', 'email', 'cache', 'redis', 'resque-redis', 'sidekiq-redis', 's3'] 35 | 36 | # Add one or more custom checks that return a blank string if ok, or an error message if there is an error 37 | config.add_custom_check do 38 | CustomHealthCheck.perform_check # any code that returns blank on success and non blank string upon failure 39 | end 40 | 41 | # Add another custom check with a name, so you can call just specific custom checks. This can also be run using 42 | # the standard 'custom' check. 43 | # You can define multiple tests under the same name - they will be run one after the other. 44 | config.add_custom_check('sometest') do 45 | CustomHealthCheck.perform_another_check # any code that returns blank on success and non blank string upon failure 46 | end 47 | 48 | # max-age of response in seconds 49 | # cache-control is public when max_age > 1 and basic_auth_username is not set 50 | # You can force private without authentication for longer max_age by 51 | # setting basic_auth_username but not basic_auth_password 52 | config.max_age = 1 53 | 54 | # Protect health endpoints with basic auth 55 | # These default to nil and the endpoint is not protected 56 | # config.basic_auth_username = 'my_username' 57 | # config.basic_auth_password = 'my_password' 58 | config.basic_auth_username = nil 59 | config.basic_auth_password = nil 60 | 61 | # Whitelist requesting IPs 62 | # Defaults to blank and allows any IP 63 | config.origin_ip_whitelist = %w(123.123.123.123) 64 | 65 | # http status code used when the ip is not allowed for the request 66 | config.http_status_for_ip_whitelist_error = 403 67 | 68 | # When redis url is non-standard 69 | config.redis_url = 'redis_url' 70 | 71 | # Disable the error message to prevent /health_check from leaking 72 | # sensitive information 73 | # config.include_error_in_response_body = false 74 | end -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | 18 | ActiveSupport::Inflector.inflections(:en) do |inflect| 19 | inflect.irregular 'story', 'stories' 20 | end -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | Mime::Type.register "text/html", :ink -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | Rails.application.config.session_store :cookie_store, key: '_inklewriter_session' -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /config/locales/devise.en.yml: -------------------------------------------------------------------------------- 1 | # Additional translations at https://github.com/plataformatec/devise/wiki/I18n 2 | 3 | en: 4 | devise: 5 | confirmations: 6 | confirmed: "Your email address has been successfully confirmed." 7 | send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." 8 | send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." 9 | failure: 10 | already_authenticated: "You are already signed in." 11 | inactive: "Your account is not activated yet." 12 | invalid: "Invalid %{authentication_keys} or password." 13 | locked: "Your account is locked." 14 | last_attempt: "You have one more attempt before your account is locked." 15 | not_found_in_database: "Invalid %{authentication_keys} or password." 16 | timeout: "Your session expired. Please sign in again to continue." 17 | unauthenticated: "You need to sign in or sign up before continuing." 18 | unconfirmed: "You have to confirm your email address before continuing." 19 | mailer: 20 | confirmation_instructions: 21 | subject: "Confirmation instructions" 22 | reset_password_instructions: 23 | subject: "Reset password instructions" 24 | unlock_instructions: 25 | subject: "Unlock instructions" 26 | email_changed: 27 | subject: "Email Changed" 28 | password_change: 29 | subject: "Password Changed" 30 | omniauth_callbacks: 31 | failure: "Could not authenticate you from %{kind} because \"%{reason}\"." 32 | success: "Successfully authenticated from %{kind} account." 33 | passwords: 34 | no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." 35 | send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." 36 | send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." 37 | updated: "Your password has been changed successfully. You are now signed in." 38 | updated_not_active: "Your password has been changed successfully." 39 | registrations: 40 | destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." 41 | signed_up: "Welcome! You have signed up successfully." 42 | signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." 43 | signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." 44 | signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." 45 | update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address." 46 | updated: "Your account has been updated successfully." 47 | updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again" 48 | sessions: 49 | signed_in: "Signed in successfully." 50 | signed_out: "Signed out successfully." 51 | already_signed_out: "Signed out successfully." 52 | unlocks: 53 | send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." 54 | send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." 55 | unlocked: "Your account has been unlocked successfully. Please sign in to continue." 56 | errors: 57 | messages: 58 | already_confirmed: "was already confirmed, please try signing in" 59 | confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" 60 | expired: "has expired, please request a new one" 61 | not_found: "not found" 62 | not_locked: "was not locked" 63 | not_saved: 64 | one: "1 error prohibited this %{resource} from being saved:" 65 | other: "%{count} errors prohibited this %{resource} from being saved:" 66 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # 'true': 'foo' 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at http://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers: a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum; this matches the default thread size of Active Record. 6 | # 7 | threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 8 | threads threads_count, threads_count 9 | 10 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 11 | # 12 | port ENV.fetch("PORT") { 3000 } 13 | 14 | # Specifies the `environment` that Puma will run in. 15 | # 16 | environment ENV.fetch("RAILS_ENV") { "development" } 17 | 18 | # Specifies the number of `workers` to boot in clustered mode. 19 | # Workers are forked webserver processes. If using threads and workers together 20 | # the concurrency of the application would be max `threads` * `workers`. 21 | # Workers do not work on JRuby or Windows (both of which do not support 22 | # processes). 23 | # 24 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 25 | 26 | # Use the `preload_app!` method when specifying a `workers` number. 27 | # This directive tells Puma to first boot the application and load code 28 | # before forking the application. This takes advantage of Copy On Write 29 | # process behavior so workers use less memory. 30 | # 31 | # preload_app! 32 | 33 | # Allow puma to be restarted by `rails restart` command. 34 | plugin :tmp_restart 35 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | devise_for :users, controllers: { sessions: "users/sessions", registrations: "users/registrations", passwords: "users/passwords"} 3 | # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 4 | root to: 'pages#index' 5 | 6 | 7 | 8 | resources :stories 9 | 10 | resources :users do 11 | resources :stories 12 | end 13 | 14 | namespace :admin do 15 | get '/', to: 'adminpages#index' 16 | post 'score_search', to: 'adminpages#score_search' 17 | end 18 | 19 | match "/404", :to => "errors#not_found", :via => :all 20 | match "/500", :to => "errors#internal_server_error", :via => :all 21 | get 'health', to: 'pages#health' 22 | get 'privacy', to: 'pages#privacy' 23 | 24 | end 25 | -------------------------------------------------------------------------------- /config/spring.rb: -------------------------------------------------------------------------------- 1 | %w[ 2 | .ruby-version 3 | .rbenv-vars 4 | tmp/restart.txt 5 | tmp/caching-dev.txt 6 | ].each { |path| Spring.watch(path) } 7 | -------------------------------------------------------------------------------- /config/storage.yml: -------------------------------------------------------------------------------- 1 | test: 2 | service: Disk 3 | root: <%= Rails.root.join("tmp/storage") %> 4 | 5 | local: 6 | service: Disk 7 | root: <%= Rails.root.join("storage") %> 8 | 9 | # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) 10 | # amazon: 11 | # service: S3 12 | # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> 13 | # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> 14 | # region: us-east-1 15 | # bucket: your_own_bucket 16 | 17 | # Remember not to checkin your GCS keyfile to a repository 18 | # google: 19 | # service: GCS 20 | # project: your_project 21 | # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> 22 | # bucket: your_own_bucket 23 | 24 | # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) 25 | # microsoft: 26 | # service: AzureStorage 27 | # storage_account_name: your_account_name 28 | # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> 29 | # container: your_container_name 30 | 31 | # mirror: 32 | # service: Mirror 33 | # primary: local 34 | # mirrors: [ amazon, google, microsoft ] 35 | -------------------------------------------------------------------------------- /db/migrate/20190219150520_devise_create_users.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | class DeviseCreateUsers < ActiveRecord::Migration[5.2] 4 | def change 5 | create_table :users do |t| 6 | ## Database authenticatable 7 | t.string :email, null: false, default: "" 8 | t.string :encrypted_password, null: false, default: "" 9 | 10 | ## Recoverable 11 | t.string :reset_password_token 12 | t.datetime :reset_password_sent_at 13 | 14 | ## Rememberable 15 | t.datetime :remember_created_at 16 | 17 | ## Trackable 18 | # t.integer :sign_in_count, default: 0, null: false 19 | # t.datetime :current_sign_in_at 20 | # t.datetime :last_sign_in_at 21 | # t.string :current_sign_in_ip 22 | # t.string :last_sign_in_ip 23 | 24 | ## Confirmable 25 | # t.string :confirmation_token 26 | # t.datetime :confirmed_at 27 | # t.datetime :confirmation_sent_at 28 | # t.string :unconfirmed_email # Only if using reconfirmable 29 | 30 | ## Lockable 31 | # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 32 | # t.string :unlock_token # Only if unlock strategy is :email or :both 33 | # t.datetime :locked_at 34 | 35 | 36 | t.timestamps null: false 37 | end 38 | 39 | add_index :users, :email, unique: true 40 | add_index :users, :reset_password_token, unique: true 41 | # add_index :users, :confirmation_token, unique: true 42 | # add_index :users, :unlock_token, unique: true 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /db/migrate/20190219160258_add_authentication_token_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddAuthenticationTokenToUsers < ActiveRecord::Migration[5.2] 2 | def change 3 | add_column :users, :authentication_token, :string 4 | add_index :users, :authentication_token 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/20190618142849_create_stories.rb: -------------------------------------------------------------------------------- 1 | class CreateStories < ActiveRecord::Migration[5.2] 2 | def change 3 | create_table :stories do |t| 4 | t.references :user, foreign_key: true 5 | t.json :data 6 | 7 | t.timestamps 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/migrate/20190618215055_add_title_to_stories.rb: -------------------------------------------------------------------------------- 1 | class AddTitleToStories < ActiveRecord::Migration[5.2] 2 | def change 3 | add_column :stories, :title, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20190827143319_add_url_key_to_stories.rb: -------------------------------------------------------------------------------- 1 | class AddUrlKeyToStories < ActiveRecord::Migration[5.2] 2 | def change 3 | add_column :stories, :url_key, :integer 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20201122095701_create_admins.rb: -------------------------------------------------------------------------------- 1 | class CreateAdmins < ActiveRecord::Migration[5.2] 2 | def change 3 | create_table :admins do |t| 4 | t.references :user, foreign_key: true 5 | 6 | t.timestamps 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20201208163624_create_story_stats.rb: -------------------------------------------------------------------------------- 1 | class CreateStoryStats < ActiveRecord::Migration[5.2] 2 | def change 3 | create_table :story_stats do |t| 4 | t.integer :stitches 5 | t.integer :with_choice 6 | t.integer :with_condition 7 | t.integer :with_flag 8 | t.float :avg_words 9 | t.integer :total_words 10 | t.integer :advanced_syntax 11 | t.float :score_short 12 | t.float :score_medium 13 | t.float :score_long 14 | 15 | t.timestamps 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /db/migrate/20201208164040_add_foreign_key_to_story_stats.rb: -------------------------------------------------------------------------------- 1 | class AddForeignKeyToStoryStats < ActiveRecord::Migration[5.2] 2 | def change 3 | add_reference :story_stats, :story, foreign_key: true 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20201209165106_add_to_story_stat.rb: -------------------------------------------------------------------------------- 1 | class AddToStoryStat < ActiveRecord::Migration[5.2] 2 | def change 3 | add_column :story_stats, :with_end, :integer 4 | add_column :story_stats, :with_image, :integer 5 | add_column :story_stats, :with_divert, :integer 6 | add_column :story_stats, :with_fake_choice, :integer 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /db/migrate/20201209182413_add_score.rb: -------------------------------------------------------------------------------- 1 | class AddScore < ActiveRecord::Migration[5.2] 2 | def change 3 | remove_column :story_stats, :score_short 4 | remove_column :story_stats, :score_medium 5 | remove_column :story_stats, :score_long 6 | add_column :story_stats, :score, :float 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # Note that this schema.rb definition is the authoritative source for your 6 | # database schema. If you need to create the application database on another 7 | # system, you should be using db:schema:load, not running all the migrations 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 2020_12_09_182413) do 14 | 15 | # These are extensions that must be enabled in order to support this database 16 | enable_extension "plpgsql" 17 | 18 | create_table "admins", force: :cascade do |t| 19 | t.bigint "user_id" 20 | t.datetime "created_at", null: false 21 | t.datetime "updated_at", null: false 22 | t.index ["user_id"], name: "index_admins_on_user_id" 23 | end 24 | 25 | create_table "stories", force: :cascade do |t| 26 | t.bigint "user_id" 27 | t.json "data" 28 | t.datetime "created_at", null: false 29 | t.datetime "updated_at", null: false 30 | t.string "title" 31 | t.integer "url_key" 32 | t.index ["user_id"], name: "index_stories_on_user_id" 33 | end 34 | 35 | create_table "story_stats", force: :cascade do |t| 36 | t.integer "stitches" 37 | t.integer "with_choice" 38 | t.integer "with_condition" 39 | t.integer "with_flag" 40 | t.float "avg_words" 41 | t.integer "total_words" 42 | t.integer "advanced_syntax" 43 | t.datetime "created_at", null: false 44 | t.datetime "updated_at", null: false 45 | t.bigint "story_id" 46 | t.integer "with_end" 47 | t.integer "with_image" 48 | t.integer "with_divert" 49 | t.integer "with_fake_choice" 50 | t.float "score" 51 | t.index ["story_id"], name: "index_story_stats_on_story_id" 52 | end 53 | 54 | create_table "users", force: :cascade do |t| 55 | t.string "email", default: "", null: false 56 | t.string "encrypted_password", default: "", null: false 57 | t.string "reset_password_token" 58 | t.datetime "reset_password_sent_at" 59 | t.datetime "remember_created_at" 60 | t.datetime "created_at", null: false 61 | t.datetime "updated_at", null: false 62 | t.string "authentication_token" 63 | t.index ["authentication_token"], name: "index_users_on_authentication_token" 64 | t.index ["email"], name: "index_users_on_email", unique: true 65 | t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true 66 | end 67 | 68 | add_foreign_key "admins", "users" 69 | add_foreign_key "stories", "users" 70 | add_foreign_key "story_stats", "stories" 71 | end 72 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) 7 | # Character.create(name: 'Luke', movie: movies.first) 8 | -------------------------------------------------------------------------------- /db/seeds/development.rb: -------------------------------------------------------------------------------- 1 | user=User.new( 2 | email: "john@the.ripper.com", 3 | password: "john@the.ripper.com" 4 | ) 5 | user.save! 6 | 7 | story = user.stories.new( 8 | data: '{"title":"Untitled Story","data":{"stitches":{"onceUponATime":{"content":["Once upon a time...",{"divert":"thereWasAGiantIn"},{"pageNum":1}]},"thereWasAGiantIn":{"content":["There was a giant in the woods."]}},"initial":"onceUponATime","optionMirroring":true,"allowCheckpoints":false,"editorData":{"playPoint":"thereWasAGiantIn","libraryVisible":false,"authorName":"Anonymous","textSize":0}}}', 9 | title: "My first story", 10 | url_key: 1 11 | ) 12 | story.save! -------------------------------------------------------------------------------- /db/seeds/production.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/db/seeds/production.rb -------------------------------------------------------------------------------- /db/seeds/test.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/db/seeds/test.rb -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | volumes: 4 | inkledb: 5 | 6 | networks: 7 | inklenet: 8 | 9 | services: 10 | 11 | db: 12 | networks: 13 | - inklenet 14 | env_file: .env 15 | image: postgres 16 | volumes: 17 | - inkledb:/var/lib/postgresql/data/pgdata 18 | 19 | app: 20 | networks: 21 | - inklenet 22 | env_file: .env 23 | build: . 24 | image: albancrommer/inklewriter:latest 25 | volumes: 26 | - .:/usr/src/app 27 | ports: 28 | - "3000:3000" 29 | depends_on: 30 | - db 31 | 32 | 33 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | # Remove a potentially pre-existing server.pid for Rails. 5 | rm -f /usr/src/app/tmp/pids/server.pid 6 | 7 | # Initialize / update DB 8 | rake db:create db:migrate 9 | 10 | # Then exec the container's main process (what's set as CMD in the Dockerfile). 11 | exec "$@" 12 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/lib/assets/.keep -------------------------------------------------------------------------------- /lib/mailer_previews/custom_devise_mailer_preview.rb: -------------------------------------------------------------------------------- 1 | class CustomDeviseMailerPreview < ActionMailer::Preview 2 | 3 | def password_change 4 | CustomDeviseMailer.password_change(User.all.sample, {}) 5 | end 6 | 7 | def reset_password_instructions 8 | CustomDeviseMailer.reset_password_instructions(User.all.sample, "faketoken") 9 | end 10 | end -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inklewriter/freeinklewriter/ed0a31b40d05d39f05b041188264abf29a902423/lib/tasks/.keep -------------------------------------------------------------------------------- /lib/tasks/scoring.rake: -------------------------------------------------------------------------------- 1 | desc "Forces a save on all stories to refresh stats and scores" 2 | task :score => :environment do 3 | Story.find_each do |s| 4 | s.save 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/tasks/verify_sanitizing.rake: -------------------------------------------------------------------------------- 1 | desc "Verify that sanitizing does not alter stories JSON" 2 | task :verify_sanitizing => :environment do 3 | mismatches = [] 4 | Story.find_each do |s| 5 | unless s.sanitize_s == s.data 6 | mismatches << s.id 7 | end 8 | end 9 | if mismatches.present? 10 | p "These stories show some mismatches" 11 | p mismatches 12 | p "Now let's check all our stories include string