code
stringlengths
0
56.1M
repo_name
stringclasses
515 values
path
stringlengths
2
147
language
stringclasses
447 values
license
stringclasses
7 values
size
int64
0
56.8M
source 'https://rubygems.org' source 'https://rails-assets.org' gem 'rails', '4.2.1' gem 'rails-i18n' gem 'i18n-js' gem 'pg', group: :postgres gem 'mysql2', group: :mysql gem 'sass-rails', '~> 4.0.3' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.1.0' gem 'jquery-rails' gem 'turbolinks' gem 'jquery-turbolinks' gem 'jbuilder', '~> 2.2.4' gem 'sdoc', '~> 0.4.1', group: :doc gem 'bcrypt', '~> 3.1.7' gem 'haml' gem 'bootstrap-sass', '~> 3.2.0.1' gem 'bootswatch-rails' gem 'sweetalert-rails' gem 'will_paginate' gem 'will_paginate-bootstrap' gem 'devise' gem 'devise-i18n' gem 'devise-async' gem 'bootstrap_form' gem 'font-kit-rails' gem 'nprogress-rails' gem 'font-awesome-rails', '~> 4.3.0.0' gem 'rails-assets-growl' gem "paperclip", "~> 4.2" gem 'delayed_paperclip' gem 'fog' gem 'fog-aws' gem 'momentjs-rails', '>= 2.9.0' gem 'bootstrap3-datetimepicker-rails', '~> 4.7.14' gem 'twemoji-rails' gem 'ruby-progressbar' gem 'rails_admin' gem 'sidekiq' gem 'sinatra', require: false gem 'questiongenerator', git: 'https://github.com/retrospring/questiongenerator.git' gem 'sanitize' gem 'redcarpet' # OmniAuth and providers gem 'omniauth' gem 'omniauth-twitter' gem 'omniauth-tumblr' # OAuth clients gem 'twitter' gem 'tumblr_client' gem 'foreman' gem 'redis' group :development do # require spring 1.3.5 since shit's on fire on my local instance with 1.3.4 (Gem::LoadError) gem 'spring', '~> 1.3.5' # ten thousand raises no more! gem 'byebug' gem 'web-console' end group :production do gem 'unicorn', group: :production end group :development, :test do gem 'rake' gem 'thin' gem 'rspec-rails', '~> 3.0.0' gem 'factory_girl_rails', require: false gem 'faker' gem 'capybara' gem 'poltergeist' gem 'simplecov', require: false gem 'simplecov-json', require: false gem 'simplecov-rcov', require: false gem 'database_cleaner' gem 'better_errors' end
Sapphire/spring.moe
Gemfile
Ruby
mit
1,904
GIT remote: https://github.com/retrospring/questiongenerator.git revision: 902de3d7f930a4f67bbbbc414cc3556cc7114839 specs: questiongenerator (0.1.0) GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ specs: CFPropertyList (2.3.1) actionmailer (4.2.1) actionpack (= 4.2.1) actionview (= 4.2.1) activejob (= 4.2.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.5) actionpack (4.2.1) actionview (= 4.2.1) activesupport (= 4.2.1) rack (~> 1.6) rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.1) actionview (4.2.1) activesupport (= 4.2.1) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.1) activejob (4.2.1) activesupport (= 4.2.1) globalid (>= 0.3.0) activemodel (4.2.1) activesupport (= 4.2.1) builder (~> 3.1) activerecord (4.2.1) activemodel (= 4.2.1) activesupport (= 4.2.1) arel (~> 6.0) activesupport (4.2.1) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) addressable (2.3.8) arel (6.0.0) bcrypt (3.1.10) better_errors (2.1.1) coderay (>= 1.0.0) erubis (>= 2.6.6) rack (>= 0.9.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) bootstrap-sass (3.2.0.2) sass (~> 3.2) bootstrap3-datetimepicker-rails (4.7.14) momentjs-rails (>= 2.8.1) bootstrap_form (2.3.0) bootswatch-rails (3.2.4) railties (>= 3.1) buftok (0.2.0) builder (3.2.2) byebug (4.0.5) columnize (= 0.9.0) capybara (2.4.4) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) celluloid (0.16.0) timers (~> 4.0.0) climate_control (0.0.3) activesupport (>= 3.0) cliver (0.3.2) cocaine (0.5.7) climate_control (>= 0.0.3, < 1.0) coderay (1.1.0) coffee-rails (4.1.0) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) coffee-script (2.4.1) coffee-script-source execjs coffee-script-source (1.9.1.1) columnize (0.9.0) connection_pool (2.2.0) crass (1.0.2) daemons (1.2.2) database_cleaner (1.4.1) debug_inspector (0.0.2) delayed_paperclip (2.9.1) paperclip (>= 3.3) devise (3.4.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 3.2.6, < 5) responders thread_safe (~> 0.1) warden (~> 1.2.3) devise-async (0.9.0) devise (~> 3.2) devise-i18n (0.12.0) diff-lcs (1.2.5) docile (1.1.5) equalizer (0.0.11) erubis (2.7.0) eventmachine (1.0.7) excon (0.45.1) execjs (2.5.2) factory_girl (4.5.0) activesupport (>= 3.0.0) factory_girl_rails (4.5.0) factory_girl (~> 4.5.0) railties (>= 3.0.0) faker (1.4.3) i18n (~> 0.5) faraday (0.9.1) multipart-post (>= 1.2, < 3) faraday_middleware (0.9.1) faraday (>= 0.7.4, < 0.10) fission (0.5.0) CFPropertyList (~> 2.2) fog (1.28.0) fog-atmos fog-aws (~> 0.0) fog-brightbox (~> 0.4) fog-core (~> 1.27, >= 1.27.3) fog-ecloud fog-json fog-profitbricks fog-radosgw (>= 0.0.2) fog-riakcs fog-sakuracloud (>= 0.0.4) fog-serverlove fog-softlayer fog-storm_on_demand fog-terremark fog-vmfusion fog-voxel fog-xml (~> 0.1.1) ipaddress (~> 0.5) nokogiri (~> 1.5, >= 1.5.11) fog-atmos (0.1.0) fog-core fog-xml fog-aws (0.1.1) fog-core (~> 1.27) fog-json (~> 1.0) fog-xml (~> 0.1) ipaddress (~> 0.8) fog-brightbox (0.7.1) fog-core (~> 1.22) fog-json inflecto (~> 0.0.2) fog-core (1.29.0) builder excon (~> 0.38) formatador (~> 0.2) mime-types net-scp (~> 1.1) net-ssh (>= 2.1.3) fog-ecloud (0.0.2) fog-core fog-xml fog-json (1.0.0) multi_json (~> 1.0) fog-profitbricks (0.0.2) fog-core fog-xml nokogiri fog-radosgw (0.0.3) fog-core (>= 1.21.0) fog-json fog-xml (>= 0.0.1) fog-riakcs (0.1.0) fog-core fog-json fog-xml fog-sakuracloud (1.0.0) fog-core fog-json fog-serverlove (0.1.1) fog-core fog-json fog-softlayer (0.4.1) fog-core fog-json fog-storm_on_demand (0.1.0) fog-core fog-json fog-terremark (0.0.4) fog-core fog-xml fog-vmfusion (0.0.1) fission fog-core fog-voxel (0.0.2) fog-core fog-xml fog-xml (0.1.1) fog-core nokogiri (~> 1.5, >= 1.5.11) font-awesome-rails (4.3.0.0) railties (>= 3.2, < 5.0) font-kit-rails (1.1.0) rails foreman (0.78.0) thor (~> 0.19.1) formatador (0.2.5) globalid (0.3.5) activesupport (>= 4.1.0) haml (4.0.6) tilt hashie (3.4.1) hike (1.2.3) hitimes (1.2.2) http (0.6.4) http_parser.rb (~> 0.6.0) http_parser.rb (0.6.0) i18n (0.7.0) i18n-js (3.0.0.rc10) i18n (~> 0.6) inflecto (0.0.2) ipaddress (0.8.0) jbuilder (2.2.13) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) jquery-rails (4.0.3) rails-dom-testing (~> 1.0) railties (>= 4.2.0) thor (>= 0.14, < 2.0) jquery-turbolinks (2.1.0) railties (>= 3.1.0) turbolinks jquery-ui-rails (5.0.3) railties (>= 3.2.16) json (1.8.2) kaminari (0.16.3) actionpack (>= 3.0.0) activesupport (>= 3.0.0) kgio (2.9.3) loofah (2.0.1) nokogiri (>= 1.5.9) mail (2.6.3) mime-types (>= 1.16, < 3) memoizable (0.4.2) thread_safe (~> 0.3, >= 0.3.1) mime-types (2.4.3) mini_portile (0.6.2) minitest (5.6.0) momentjs-rails (2.9.0) railties (>= 3.1) multi_json (1.11.0) multipart-post (2.0.0) mysql2 (0.3.18) naught (1.0.0) nested_form (0.3.2) net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (2.9.2) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) nokogumbo (1.2.0) nokogiri nprogress-rails (0.1.6.6) oauth (0.4.7) omniauth (1.2.2) hashie (>= 1.2, < 4) rack (~> 1.0) omniauth-oauth (1.0.1) oauth omniauth (~> 1.0) omniauth-tumblr (1.1) omniauth-oauth (~> 1.0) omniauth-twitter (1.1.0) multi_json (~> 1.3) omniauth-oauth (~> 1.0) orm_adapter (0.5.0) paperclip (4.2.1) activemodel (>= 3.0.0) activesupport (>= 3.0.0) cocaine (~> 0.5.3) mime-types pg (0.18.1) poltergeist (1.6.0) capybara (~> 2.1) cliver (~> 0.3.1) multi_json (~> 1.0) websocket-driver (>= 0.2.0) rack (1.6.0) rack-pjax (0.8.0) nokogiri (~> 1.5) rack (~> 1.1) rack-protection (1.5.3) rack rack-test (0.6.3) rack (>= 1.0) rails (4.2.1) actionmailer (= 4.2.1) actionpack (= 4.2.1) actionview (= 4.2.1) activejob (= 4.2.1) activemodel (= 4.2.1) activerecord (= 4.2.1) activesupport (= 4.2.1) bundler (>= 1.3.0, < 2.0) railties (= 4.2.1) sprockets-rails rails-assets-growl (1.2.5) rails-assets-jquery rails-assets-jquery (2.1.3) rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) rails-dom-testing (1.0.6) activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) rails-html-sanitizer (1.0.2) loofah (~> 2.0) rails-i18n (4.0.4) i18n (~> 0.6) railties (~> 4.0) rails_admin (0.6.7) builder (~> 3.1) coffee-rails (~> 4.0) font-awesome-rails (>= 3.0, < 5) haml (~> 4.0) jquery-rails (>= 3.0, < 5) jquery-ui-rails (~> 5.0) kaminari (~> 0.14) nested_form (~> 0.3) rack-pjax (~> 0.7) rails (~> 4.0) remotipart (~> 1.0) safe_yaml (~> 1.0) sass-rails (>= 4.0, < 6) railties (4.2.1) actionpack (= 4.2.1) activesupport (= 4.2.1) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) raindrops (0.13.0) rake (10.4.2) rdoc (4.2.0) json (~> 1.4) redcarpet (3.2.3) redis (3.2.1) redis-namespace (1.5.2) redis (~> 3.0, >= 3.0.4) remotipart (1.2.1) responders (2.1.0) railties (>= 4.2.0, < 5) rspec-core (3.0.4) rspec-support (~> 3.0.0) rspec-expectations (3.0.4) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.0.0) rspec-mocks (3.0.4) rspec-support (~> 3.0.0) rspec-rails (3.0.2) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) rspec-core (~> 3.0.0) rspec-expectations (~> 3.0.0) rspec-mocks (~> 3.0.0) rspec-support (~> 3.0.0) rspec-support (3.0.4) ruby-progressbar (1.7.5) safe_yaml (1.0.4) sanitize (3.1.2) crass (~> 1.0.1) nokogiri (>= 1.4.4) nokogumbo (= 1.2.0) sass (3.2.19) sass-rails (4.0.5) railties (>= 4.0.0, < 5.0) sass (~> 3.2.2) sprockets (~> 2.8, < 3.0) sprockets-rails (~> 2.0) sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) sidekiq (3.3.3) celluloid (>= 0.16.0) connection_pool (>= 2.1.1) json redis (>= 3.0.6) redis-namespace (>= 1.3.1) simple_oauth (0.3.1) simplecov (0.10.0) docile (~> 1.1.0) json (~> 1.8) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) simplecov-json (0.2) json simplecov simplecov-rcov (0.2.3) simplecov (>= 0.4.1) sinatra (1.4.6) rack (~> 1.4) rack-protection (~> 1.4) tilt (>= 1.3, < 3) spring (1.3.5) sprockets (2.12.3) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sprockets-rails (2.2.4) actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) sweetalert-rails (0.5.0) railties (>= 3.1.0) thin (1.6.3) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0) rack (~> 1.0) thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) timers (4.0.1) hitimes tumblr_client (0.8.5) faraday (~> 0.9.0) faraday_middleware (~> 0.9.0) json mime-types oauth simple_oauth turbolinks (2.5.3) coffee-rails twemoji-rails (1.2.1.3) railties (>= 3.0.0) twitter (5.14.0) addressable (~> 2.3) buftok (~> 0.2.0) equalizer (~> 0.0.9) faraday (~> 0.9.0) http (~> 0.6.0) http_parser.rb (~> 0.6.0) json (~> 1.8) memoizable (~> 0.4.0) naught (~> 1.0) simple_oauth (~> 0.3.0) tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (2.7.1) execjs (>= 0.3.0) json (>= 1.8.0) unicorn (4.8.3) kgio (~> 2.6) rack raindrops (~> 0.7) warden (1.2.3) rack (>= 1.0) web-console (2.1.2) activemodel (>= 4.0) binding_of_caller (>= 0.7.2) railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) websocket-driver (0.5.4) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) will_paginate (3.0.7) will_paginate-bootstrap (1.0.1) will_paginate (>= 3.0.3) xpath (2.0.0) nokogiri (~> 1.3) PLATFORMS ruby DEPENDENCIES bcrypt (~> 3.1.7) better_errors bootstrap-sass (~> 3.2.0.1) bootstrap3-datetimepicker-rails (~> 4.7.14) bootstrap_form bootswatch-rails byebug capybara coffee-rails (~> 4.1.0) database_cleaner delayed_paperclip devise devise-async devise-i18n factory_girl_rails faker fog fog-aws font-awesome-rails (~> 4.3.0.0) font-kit-rails foreman haml i18n-js jbuilder (~> 2.2.4) jquery-rails jquery-turbolinks momentjs-rails (>= 2.9.0) mysql2 nprogress-rails omniauth omniauth-tumblr omniauth-twitter paperclip (~> 4.2) pg poltergeist questiongenerator! rails (= 4.2.1) rails-assets-growl rails-i18n rails_admin rake redcarpet redis rspec-rails (~> 3.0.0) ruby-progressbar sanitize sass-rails (~> 4.0.3) sdoc (~> 0.4.1) sidekiq simplecov simplecov-json simplecov-rcov sinatra spring (~> 1.3.5) sweetalert-rails thin tumblr_client turbolinks twemoji-rails twitter uglifier (>= 1.3.0) unicorn web-console will_paginate will_paginate-bootstrap
Sapphire/spring.moe
Gemfile.lock
lock
mit
12,702
web: bundle exec unicorn -E production -l unix:./tmp/sockets/justask.sock workers: bundle exec sidekiq -e production -C './config/sidekiq.yml'
Sapphire/spring.moe
Procfile
none
mit
142
# Retrospring [![Build Status](https://travis-ci.org/Retrospring/retrospring.svg)](https://travis-ci.org/Retrospring/retrospring) [![Bugs](https://badge.waffle.io/retrospring/bugs.svg?label=in+progress&title=In+Progress)](http://waffle.io/retrospring/bugs) This is the source code that powers Retrospring. Yep, all of it. Including all the branches where we left off. <!-- Except for the memes that happened 4 hours before the shutdown. I've edited it right on the server, without a special branch or something. If you want to, I can make a branch with all the modifications we made. --> ## Requirements - UNIX-like system (Linux, FreeBSD, ...) - Ruby 2.0.0+ - Bundler - PostgreSQL - Redis (for Sidekiq) - ImageMagick (for image processing) ## Installation (production) We've installed justask on FreeBSD 10 using rvm. What we also did was creating a new, seperate user just for justask to run in. On FreeBSD, this is done with: # pw user add justask ### Database At Retrospring, we were using PostgreSQL as the database backend. The software might work on MySQL too, but that was not tested. Installation from Ports (using `portmaster`): # portmaster databases/postgresql93-server #### PostgreSQL $ sudo -u postgres psql -d template1 template1=# CREATE USER justask CREATEDB; template1=# CREATE DATABASE justask_production OWNER justask; template1=# \q Try connecting to the database: $ psql -U justask -d justask_production ### nginx See [docs/nginx.conf](https://github.com/Retrospring/retrospring/blob/master/docs/nginx.conf) for the configuration we use on Retrospring. ### justask #### Clone the Source $ git clone --recursive https://github.com/Retrospring/retrospring.git retrospring #### Configure It # Change into the project directory $ cd retrospring # Copy the example config $ cp config/justask.yml.example config/justask.yml # Edit the configuration file $ vi config/justask.yml #### Database Configuration $ cp config/database.yml.postgres config/database.yml $ vi config/database.yml # Make database.yml readable only for you chmod o-rwx config/database.yml #### Install Gems # Deployment: $ bundle install --deployment --without development test mysql # Development: $ bundle install --without production mysql #### Initialize Database $ bundle exec rake db:migrate RAILS_ENV=production #### Compile Assets $ bundle exec rake assets:precompile RAILS_ENV=production #### Run the server # Production mode: $ foreman start # Development mode: $ bundle exec rails server Now, create an account on your justask installation. To make yourself an admin, just execute: $ bundle exec rake 'justask:admin[your_username]' RAILS_ENV=production If you want to remove admin status from a certain user, you can do this: $ bundle exec rake 'justask:deadmin[get_rekt]' RAILS_ENV=production Add/remove moderators (this can also be done via the web interface by visiting an user as an admin): $ bundle exec rake 'justask:mod[someone_else]' RAILS_ENV=production $ bundle exec rake 'justask:demod[someone_else]' RAILS_ENV=production Add/remove supporters (this can also be done via the web interface by visiting an user as an admin/mod): $ bundle exec rake 'justask:sup[someone_else]' RAILS_ENV=production $ bundle exec rake 'justask:desup[someone_else]' RAILS_ENV=production Export user data: $ bundle exec rake 'justask:export[jdoe@example.tld]' RAILS_ENV=production Find the user(s) with the most self-asked anonymous questions: $ bundle exec rake justask:loners #### Updating Submodules If you already have an existing copy of justask, you can initialize and update the submodules with; $ git submodule init $ git submodule update ## The Official Retrospring Closedown Soundtrack™ (now redundant) * [Scooter - Can't Stop The Hardcore](https://www.youtube.com/watch?v=nJ3bet-Y79w) * [Darude - Sandstorm](https://www.youtube.com/watch?v=y6120QOlsfU) * [Max Raabe - Oops I Did It Again](https://www.youtube.com/watch?v=qYr9kIyambE) ## License AGPLv3.
Sapphire/spring.moe
README.md
Markdown
mit
4,170
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) Rails.application.load_tasks namespace :justask do desc "Upload to AWS" task paperclaws: :environment do if APP_CONFIG["fog"]["credentials"].nil? or APP_CONFIG["fog"]["credentials"]["provider"] != "AWS" throw "Needs fog (AWS) to be defined in justask.yml" end format = '%t (%c/%C) [%b>%i] %e' root = "#{Rails.root}/public/system" files = Dir["#{root}/**/*.*"] progress = ProgressBar.create title: 'Processing files', format: format, starting_at: 0, total: files.length # weird voodoo, something is causing just using "APP_CONFIG["fog"]["credentials"]" as Fog::Storage.new to cause an exception # TODO: Programmatically copy? credentials = { provider: "AWS", aws_access_key_id: APP_CONFIG["fog"]["credentials"]["aws_access_key_id"], aws_secret_access_key: APP_CONFIG["fog"]["credentials"]["aws_secret_access_key"], region: APP_CONFIG["fog"]["credentials"]["region"] } fog = Fog::Storage.new credentials bucket = fog.directories.get APP_CONFIG["fog"]["directory"] files.each do |file| bucket.files.create key: file[root.length + 1 ... file.length], body: File.open(file), public: true progress.increment end puts "hopefully uploaded #{files.length} files" end desc "Recount everything!" task recount: :environment do format = '%t (%c/%C) [%b>%i] %e' total = User.count progress = ProgressBar.create title: 'Processing users', format: format, starting_at: 0, total: total User.all.each do |user| begin answered = Answer.where(user: user).count asked = Question.where(user: user).where(author_is_anonymous: false).count commented = Comment.where(user: user).count smiled = Smile.where(user: user).count user.friend_count = user.friends.count user.follower_count = user.followers.count user.answered_count = answered user.asked_count = asked user.commented_count = commented user.smiled_count = smiled user.save! end progress.increment end total = Question.count progress = ProgressBar.create title: 'Processing questions', format: format, starting_at: 0, total: total Question.all.each do |question| begin answers = Answer.where(question: question).count question.answer_count = answers question.save! end progress.increment end total = Answer.count progress = ProgressBar.create title: 'Processing answers', format: format, starting_at: 0, total: total Answer.all.each do |answer| begin smiles = Smile.where(answer: answer).count comments = Comment.where(answer: answer).count answer.comment_count = comments answer.smile_count = smiles answer.save! end progress.increment end end desc "Gives admin status to an user." task :admin, [:screen_name] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) fail "user #{args[:screen_name]} not found" if user.nil? user.admin = true user.save! puts "#{user.screen_name} is now an admin." end desc "Removes admin status from an user." task :deadmin, [:screen_name] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) fail "user #{args[:screen_name]} not found" if user.nil? user.admin = false user.save! puts "#{user.screen_name} is no longer an admin." end desc "Gives moderator status to an user." task :mod, [:screen_name] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) fail "user #{args[:screen_name]} not found" if user.nil? user.moderator = true user.save! puts "#{user.screen_name} is now an moderator." end desc "Removes moderator status from an user." task :demod, [:screen_name] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) fail "user #{args[:screen_name]} not found" if user.nil? user.moderator = false user.save! puts "#{user.screen_name} is no longer an moderator." end desc "Hits an user with the banhammer." task :permanently_ban, [:screen_name, :reason] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) fail "user #{args[:screen_name]} not found" if user.nil? user.permanently_banned = true user.ban_reason = args[:reason] user.save! puts "#{user.screen_name} got hit by\033[5m YE OLDE BANHAMMER\033[0m!!1!" end desc "Hits an user with the banhammer for one day." task :ban, [:screen_name, :reason] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) user.permanently_banned = false user.banned_until = DateTime.current + 1 user.ban_reason = args[:reason] user.save! puts "#{user.screen_name} got hit by\033[5m YE OLDE BANHAMMER\033[0m!!1!" end desc "Hits an user with the banhammer for one week." task :week_ban, [:screen_name, :reason] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) user.permanently_banned = false user.banned_until = DateTime.current + 7 user.ban_reason = args[:reason] user.save! puts "#{user.screen_name} got hit by\033[5m YE OLDE BANHAMMER\033[0m!!1!" end desc "Hits an user with the banhammer for one month." task :month_ban, [:screen_name, :reason] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) user.permanently_banned = false user.banned_until = DateTime.current + 30 user.ban_reason = args[:reason] user.save! puts "#{user.screen_name} got hit by\033[5m YE OLDE BANHAMMER\033[0m!!1!" end desc "Hits an user with the banhammer for one year." task :year_ban, [:screen_name, :reason] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) user.permanently_banned = false user.banned_until = DateTime.current + 365 user.ban_reason = args[:reason] user.save! puts "#{user.screen_name} got hit by\033[5m YE OLDE BANHAMMER\033[0m!!1!" end desc "Hits an user with the banhammer for one aeon." task :aeon_ban, [:screen_name, :reason] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) user.permanently_banned = false user.banned_until = DateTime.current + 365_000_000_000 user.ban_reason = args[:reason] user.save! puts "#{user.screen_name} got hit by\033[5m YE OLDE BANHAMMER\033[0m!!1!" end desc "Removes banned status from an user." task :unban, [:screen_name] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) fail "user #{args[:screen_name]} not found" if user.nil? user.permanently_banned = false user.banned_until = nil user.ban_reason = nil user.save! puts "#{user.screen_name} is no longer banned." end desc "Gives blogger status to an user." task :blog, [:screen_name] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) fail "user #{args[:screen_name]} not found" if user.nil? user.blogger = true user.save! puts "#{user.screen_name} is now a blogger." end desc "Removes blogger status from an user." task :unblog, [:screen_name] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) fail "user #{args[:screen_name]} not found" if user.nil? user.blogger = false user.save! puts "#{user.screen_name} is no longer a blogger." end desc "Gives supporter status to an user." task :sup, [:screen_name] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) fail "user #{args[:screen_name]} not found" if user.nil? user.supporter = true user.save! puts "#{user.screen_name} is now an supporter." end desc "Removes supporter status from an user." task :desup, [:screen_name] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) fail "user #{args[:screen_name]} not found" if user.nil? user.supporter = false user.save! puts "#{user.screen_name} is no longer an supporter." end desc "Gives contributor status to an user." task :contrib, [:screen_name] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) fail "user #{args[:screen_name]} not found" if user.nil? user.contributor = true user.save! puts "#{user.screen_name} is now a contributor." end desc "Removes contributor status from an user." task :decontrib, [:screen_name] => :environment do |t, args| fail "screen name required" if args[:screen_name].nil? user = User.find_by_screen_name(args[:screen_name]) fail "user #{args[:screen_name]} not found" if user.nil? user.contributor = false user.save! puts "#{user.screen_name} is no longer a contributor." end desc "Lists all users." task lusers: :environment do User.all.each do |u| puts "#{sprintf "%3d", u.id}. #{u.screen_name}" end end desc "Fixes the notifications" task fix_notifications: :environment do format = '%t (%c/%C) [%b>%i] %e' total = Notification.count progress = ProgressBar.create title: 'Processing notifications', format: format, starting_at: 0, total: total destroyed_count = 0 Notification.all.each do |n| if n.target.nil? n.destroy destroyed_count += 1 end progress.increment end puts "Purged #{destroyed_count} dead notifications." end desc "Subscribes everyone to their answers" task fix_submarines: :environment do format = '%t (%c/%C) [%b>%i] %e' total = Answer.count progress = ProgressBar.create title: 'Processing answers', format: format, starting_at: 0, total: total subscribed = 0 Answer.all.each do |a| if not a.user.nil? Subscription.subscribe a.user, a subscribed += 1 end progress.increment end puts "Subscribed to #{subscribed} posts." end desc "Destroy lost subscriptions" task fix_torpedoes: :environment do format = '%t (%c/%C) [%b>%i] %e' total = Subscription.count progress = ProgressBar.create title: 'Processing subscriptions', format: format, starting_at: 0, total: total destroyed = 0 Subscription.all.each do |s| if s.user.nil? or s.answer.nil? s.destroy destroyed += 1 end progress.increment end puts "Put #{destroyed} subscriptions up for adoption." end desc "Fixes reports" task fix_reports: :environment do format = '%t (%c/%C) [%b>%i] %e' total = Report.count progress = ProgressBar.create title: 'Processing reports', format: format, starting_at: 0, total: total destroyed = 0 Report.all.each do |r| if r.target.nil? and not r.deleted? r.deleted = true r.save destroyed += 1 elsif r.user.nil? r.destroy destroyed += 1 end progress.increment end puts "Marked #{destroyed} reports as deleted." end desc "Fixes everything else" task fix_db: :environment do format = '%t (%c/%C) [%b>%i] %e' destroyed_count = { inbox: 0, question: 0, answer: 0, smile: 0, comment: 0, subscription: 0, report: 0 } total = Inbox.count progress = ProgressBar.create title: 'Processing inboxes', format: format, starting_at: 0, total: total Inbox.all.each do |n| if n.question.nil? n.destroy destroyed_count[:inbox] += 1 end progress.increment end total = Question.count progress = ProgressBar.create title: 'Processing questions', format: format, starting_at: 0, total: total Question.all.each do |q| if q.user.nil? q.user_id = nil q.author_is_anonymous = true destroyed_count[:question] += 1 end progress.increment end total = Answer.count progress = ProgressBar.create title: 'Processing answers', format: format, starting_at: 0, total: total Answer.all.each do |a| if a.user.nil? or a.question.nil? a.destroy destroyed_count[:answer] += 1 end progress.increment end total = Comment.count progress = ProgressBar.create title: 'Processing comments', format: format, starting_at: 0, total: total Comment.all.each do |c| if c.user.nil? or c.answer.nil? c.destroy destroyed_count[:comment] += 1 end progress.increment end total = Subscription.count progress = ProgressBar.create title: 'Processing subscriptions', format: format, starting_at: 0, total: total Subscription.all.each do |s| if s.user.nil? or s.answer.nil? s.destroy destroyed_count[:subscription] += 1 end progress.increment end total = Report.count progress = ProgressBar.create title: 'Processing reports', format: format, starting_at: 0, total: total Report.all.each do |r| if r.target.nil? and not r.deleted? r.deleted = true r.save destroyed_count[:report] += 1 elsif r.user.nil? r.destroy destroyed_count[:report] += 1 end progress.increment end puts "Put #{destroyed_count[:subscription]} subscriptions up for adoption." puts "Purged #{destroyed_count[:inbox]} dead inbox entries." puts "Marked #{destroyed_count[:question]} questions as anonymous." puts "Purged #{destroyed_count[:answer]} dead answers." puts "Purged #{destroyed_count[:comment]} dead comments." puts "Purged #{destroyed_count[:subscription]} dead subscriptions." puts "Marked #{destroyed_count[:report]} reports as deleted." end desc "Prints lonely people." task loners: :environment do people = {} Question.all.each do |q| if q.author_is_anonymous and q.author_name != 'justask' q.answers.each do |a| if q.user == a.user people[q.user.screen_name] ||= 0 people[q.user.screen_name] += 1 puts "#{q.user.screen_name} -- answer id #{a.id}" end end end end max = 0 res = [] people.each { |k, v| max = v if v > max } people.each { |k, v| res << k if v == max } if res.length == 0 puts "No one? I hope you're just on the development session." else puts res.length == 1 ? "And the winner is..." : "And the winners are..." print "\033[5;31m" res.each { |name| puts " - #{name}" } print "\033[0m" end end desc "Export data for an user" task :export, [:email] => :environment do |t, args| require 'json' require 'yaml' return if args[:email].nil? obj = {} format = '%t (%c/%C) [%b>%i] %e' u = User.where("LOWER(email) = ?", args[:email].downcase).first! export_dirname = "export_#{u.screen_name}_#{Time.now.to_i}" export_filename = u.screen_name %i(id screen_name display_name created_at sign_in_count last_sign_in_at friend_count follower_count asked_count answered_count commented_count smiled_count motivation_header bio website location moderator admin supporter banned blogger).each do |f| obj[f] = u.send f end total = u.questions.count progress = ProgressBar.create title: 'Processing questions', format: format, starting_at: 0, total: total obj[:questions] = [] u.questions.each do |q| qobj = {} %i(id content author_is_anonymous created_at answer_count).each do |f| qobj[f] = q.send f end obj[:questions] << qobj progress.increment end total = u.answers.count progress = ProgressBar.create title: 'Processing answers', format: format, starting_at: 0, total: total obj[:answers] = [] u.answers.each do |a| aobj = {} %i(id content comment_count smile_count created_at).each do |f| aobj[f] = a.send f end aobj[:question] = {} %i(id content author_is_anonymous created_at answer_count).each do |f| aobj[:question][f] = a.question.send f end aobj[:question][:user] = a.question.user.screen_name unless a.question.author_is_anonymous aobj[:comments] = [] a.comments.each do |c| cobj = {} %i(id content created_at).each do |f| cobj[f] = c.send f end cobj[:user] = c.user.screen_name aobj[:comments] << cobj end obj[:answers] << aobj progress.increment end total = u.comments.count progress = ProgressBar.create title: 'Processing comments', format: format, starting_at: 0, total: total obj[:comments] = [] u.comments.each do |c| cobj = {} %i(id content created_at).each do |f| cobj[f] = c.send f end cobj[:answer] = {} %i(id content comment_count smile_count created_at).each do |f| cobj[:answer][f] = c.answer.send f end cobj[:answer][:question] = {} %i(id content author_is_anonymous created_at answer_count).each do |f| cobj[:answer][:question][f] = c.answer.question.send f end cobj[:answer][:question][:user] = c.answer.question.user.screen_name unless c.answer.question.author_is_anonymous obj[:comments] << cobj progress.increment end total = u.smiles.count progress = ProgressBar.create title: 'Processing smiles', format: format, starting_at: 0, total: total obj[:smiles] = [] u.smiles.each do |s| sobj = {} %i(id created_at).each do |f| sobj[f] = s.send f end sobj[:answer] = {} %i(id content comment_count smile_count created_at).each do |f| sobj[:answer][f] = s.answer.send f end sobj[:answer][:question] = {} %i(id content author_is_anonymous created_at answer_count).each do |f| sobj[:answer][:question][f] = s.answer.question.send f end sobj[:answer][:question][:user] = s.answer.question.user.screen_name unless s.answer.question.author_is_anonymous obj[:smiles] << sobj progress.increment end `mkdir -p /usr/home/justask/justask/public/export` `mkdir -p /tmp/rs_export/#{export_dirname}/picture` if u.profile_picture %i(large medium small original).each do |s| x = u.profile_picture.path(s).gsub('"', '\\"') `cp "#{x}" "/tmp/rs_export/#{export_dirname}/picture/#{s}_#{File.basename x}"` end end File.open "/tmp/rs_export/#{export_dirname}/#{export_filename}.json", 'w' do |f| f.puts obj.to_json end File.open "/tmp/rs_export/#{export_dirname}/#{export_filename}.yml", 'w' do |f| f.puts obj.to_yaml end `tar czvf public/export/#{export_dirname}.tar.gz -C /tmp/rs_export #{export_dirname}` puts "\033[1mhttps://retrospring.net/export/#{export_dirname}.tar.gz\033[0m" end end
Sapphire/spring.moe
Rakefile
Ruby
mit
20,095
Not done: [001| 0%] user blocking (prohibits blocked user from asking question to that person and seeing their answers) [007| 20%] (?) keyboard shortcuts |----- Open "Ask your followers" with Ctrl/Meta+M [010| 0%] locales (these can wait for now) |----- (somewhat) working in justask/feature-semantic [015| 0%] make a public accessible API (maybe even as an oauth provider?) [016| 5%] WRYYYYte more specs [020| 0%] helper function for profile headings to resize on certain string length [022| 0%] recommended follows [023| 0%] disabling group-questions [024| 0%] disabling questions from certain users [025| 0%] answering options (sharing/nsfw/private) in inbox panels [026| 0%] profile headers [027| 66%] moderation |----- moderator user group √ |----- moderation panel √ |----- ability to report questions × In Progress: [003| 50%] file uploads (for now only avatars, file uploads for embedding images in questions MAYBE LATER) [011| 75%] auto-posting to other services (twatter, fakelook) Finished: [002|100%] asking modal (ask all followers/one person a question with a modal you can open over the navbar) [004|100%] admin status page (like the one from justask2 in Python) [005|100%] make the hamburger menu button glow or something if there are new questions in the inbox [006|100%] privacy options (e.g. profile visible for members only, disable anonymous questions, opt-out from public timeline) [008|100%] make email work! [009|100%] a notification view or something [013|100%] restructure questions (has_many :answers) for less redundancy in the DB when implementing #002 [014|100%] generate questions if there are none in the inbox (probably make it as a gem) [018|100%] that annoying "we use cookies" thing every website in the EU must? add [019|100%] omniAuth (twatter, fakelook, goggles plus) for social networking elitists [021|100%] deleting comments |----- restructure comment design [012|100%] (?) open source the entire thing – in late 2015 or 2016 maybe, after we got bought by fakelook. [017|100%] write "terms of service" and a privacy policy.
Sapphire/spring.moe
TODO
none
mit
2,109
Sapphire/spring.moe
app/assets/images/.keep
none
mit
0
# Toggle button $(document).on "click", "button[name=ab-comments]", -> btn = $(this) aid = btn[0].dataset.aId state = btn[0].dataset.state commentBox = $("#ab-comments-section-#{aid}") switch state when 'hidden' commentBox.slideDown() btn[0].dataset.state = 'shown' when 'shown' commentBox.slideUp() btn[0].dataset.state = 'hidden' $(document).on "keyup", "input[name=ab-comment-new]", (evt) -> input = $(this) aid = input[0].dataset.aId ctr = $("span#ab-comment-charcount-#{aid}") cbox = $("div[name=ab-comment-new-group][data-a-id=#{aid}]") if evt.which == 13 # return key evt.preventDefault() return cbox.addClass "has-error" if input.val().length > 160 || input.val().trim().length == 0 input.attr 'disabled', 'disabled' $.ajax url: '/ajax/create_comment' type: 'POST' data: answer: aid comment: input.val() dataType: 'json' # jQuery can't guess the datatype correctly here... success: (data, status, jqxhr) -> console.log data if data.success $("#ab-comments-#{aid}").html data.render input.val '' ctr.html 160 $("span#ab-comment-count-#{aid}").html data.count subs = $("a[data-action=ab-submarine][data-a-id=#{aid}]")[0] subs.dataset.torpedo = "no" subs.children[0].nextSibling.textContent = translate('views.actions.unsubscribe') showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> input.removeAttr 'disabled' # character count $(document).on "input", "input[name=ab-comment-new]", (evt) -> input = $(this) aid = input[0].dataset.aId ctr = $("span#ab-comment-charcount-#{aid}") cbox = $("div[name=ab-comment-new-group][data-a-id=#{aid}]") cbox.removeClass "has-error" if cbox.hasClass "has-error" ctr.html 160 - input.val().length if Number(ctr.html()) < 0 ctr.removeClass 'text-muted' ctr.addClass 'text-danger' else ctr.removeClass 'text-danger' ctr.addClass 'text-muted'
Sapphire/spring.moe
app/assets/javascripts/answerbox/comment.coffee
CoffeeScript
mit
2,214
$(document).on "click", "a[data-action=ab-comment-destroy]", (ev) -> ev.preventDefault() btn = $(this) cid = btn[0].dataset.cId swal title: translate('frontend.destroy_comment.confirm.title') text: translate('frontend.destroy_comment.confirm.text') type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: translate('views.actions.delete') cancelButtonText: translate('views.actions.cancel') closeOnConfirm: true , -> $.ajax url: '/ajax/destroy_comment' type: 'POST' data: comment: cid success: (data, status, jqxhr) -> if data.success $("li[data-comment-id=#{cid}]").slideUp() showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) ->
Sapphire/spring.moe
app/assets/javascripts/answerbox/comment/destroy.coffee
CoffeeScript
mit
940
$(document).on "click", "a[data-action=ab-comment-report]", (ev) -> ev.preventDefault() btn = $(this) cid = btn[0].dataset.cId reportDialog "comment", cid, -> btn.button "reset"
Sapphire/spring.moe
app/assets/javascripts/answerbox/comment/report.coffee
CoffeeScript
mit
186
$(document).on "click", "button[name=ab-smile-comment]", -> btn = $(this) cid = btn[0].dataset.cId action = btn[0].dataset.action count = Number $("span#ab-comment-smile-count-#{cid}").html() btn[0].dataset.loadingText = "<i class=\"fa fa-meh-o fa-spin\"></i> <span id=\"ab-smile-count-#{cid}\">#{count}</span>" btn.button "loading" target_url = switch action when 'smile' count++ '/ajax/create_comment_smile' when 'unsmile' count-- '/ajax/destroy_comment_smile' success = false $.ajax url: target_url type: 'POST' data: id: cid success: (data, status, jqxhr) -> success = data.success if success $("span#ab-comment-smile-count-#{cid}").html(count) showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> btn.button "reset" if success switch action when 'smile' btn[0].dataset.action = 'unsmile' btn.html "<i class=\"fa fa-frown-o\"></i> <span id=\"ab-comment-smile-count-#{cid}\">#{count}</span>" when 'unsmile' btn[0].dataset.action = 'smile' btn.html "<i class=\"fa fa-smile-o\"></i> <span id=\"ab-comment-smile-count-#{cid}\">#{count}</span>"
Sapphire/spring.moe
app/assets/javascripts/answerbox/comment/smile.coffee
CoffeeScript
mit
1,399
$(document).on "click", "a[data-action=ab-destroy]", (ev) -> ev.preventDefault() btn = $(this) aid = btn[0].dataset.aId swal title: translate('frontend.destroy_question.confirm.title') text: translate('frontend.destroy_question.confirm.text') type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: translate('views.actions.y') cancelButtonText: translate('views.actions.n') closeOnConfirm: true , -> $.ajax url: '/ajax/destroy_answer' # TODO: find a way to use rake routes instead of hardcoding them here type: 'POST' data: answer: aid success: (data, status, jqxhr) -> if data.success $("div.answerbox[data-id=#{aid}]").slideUp() showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) ->
Sapphire/spring.moe
app/assets/javascripts/answerbox/destroy.coffee
CoffeeScript
mit
995
$(document).on "click", "a[data-action=ab-report]", (ev) -> ev.preventDefault() btn = $(this) aid = btn[0].dataset.aId reportDialog "answer", aid, -> btn.button "reset"
Sapphire/spring.moe
app/assets/javascripts/answerbox/report.coffee
CoffeeScript
mit
177
$(document).on "click", "button[name=ab-smile]", -> btn = $(this) aid = btn[0].dataset.aId action = btn[0].dataset.action count = Number $("span#ab-smile-count-#{aid}").html() btn[0].dataset.loadingText = "<i class=\"fa fa-meh-o fa-spin\"></i> <span id=\"ab-smile-count-#{aid}\">#{count}</span>" btn.button "loading" target_url = switch action when 'smile' count++ '/ajax/create_smile' when 'unsmile' count-- '/ajax/destroy_smile' success = false $.ajax url: target_url type: 'POST' data: id: aid success: (data, status, jqxhr) -> success = data.success if success $("span#ab-smile-count-#{aid}").html(count) showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> btn.button "reset" if success switch action when 'smile' btn[0].dataset.action = 'unsmile' btn.html "<i class=\"fa fa-frown-o\"></i> <span id=\"ab-smile-count-#{aid}\">#{count}</span>" when 'unsmile' btn[0].dataset.action = 'smile' btn.html "<i class=\"fa fa-smile-o\"></i> <span id=\"ab-smile-count-#{aid}\">#{count}</span>"
Sapphire/spring.moe
app/assets/javascripts/answerbox/smile.coffee
CoffeeScript
mit
1,343
# the laziest coding known to man # TODO: so lazy, I don't know how to localize it properly $(document).on "click", "a[data-action=ab-submarine]", (ev) -> ev.preventDefault() btn = $(this) aid = btn[0].dataset.aId torpedo = 0 if btn[0].dataset.torpedo == "yes" torpedo = 1 endpoint = "subscribe" if torpedo == 0 endpoint = "un" + endpoint $.ajax url: '/ajax/' + endpoint # TODO: find a way to use rake routes instead of hardcoding them here type: 'POST' data: answer: aid success: (data, status, jqxhr) -> if data.success btn[0].dataset.torpedo = ["yes", "no"][torpedo] btn[0].children[0].nextSibling.textContent = if torpedo then translate("views.actions.unsubscribe") else translate("views.actions.subscribe") showNotification translate("frontend.subscription.#{endpoint}"), true else showNotification translate("frontend.subscription.fail.#{endpoint}"), false error: showNotificationXHRError complete: (jqxhr, status) ->
Sapphire/spring.moe
app/assets/javascripts/answerbox/subscribe.coffee
CoffeeScript
mit
1,024
#= require jquery #= require jquery_ujs #= require jquery.turbolinks #= require turbolinks #= require bootstrap #= require twemoji #= require nprogress #= require nprogress-turbolinks #= require growl #= require cheet #= require jquery.guillotine #= require jquery.particleground #= require sweet-alert #= require js.cookie #= require i18n #= require i18n/translations # local requires to be seen by everyone: #= require_tree ./answerbox #= require_tree ./questionbox #= require groups #= require inbox #= require memes #= require notifications #= require pagination #= require piwik #= require question #= require settings #= require user #= require report # not required: # _tree ./moderation NProgress.configure showSpinner: false window.translate = (scope, options) -> # for some reason I18n errors when calling it by assign proxy, so we got to wrap it I18n.translate(scope, options) window.showNotification = (text, success=true) -> args = title: translate((if success then 'frontend.success.title' else 'frontend.error.title')) message: text if success $.growl.notice args else $.growl.error args I18n.defaultLocale = 'en'; I18n.locale = Cookies.get('hl') || 'en'; window.showNotificationXHRError = (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false $(document).on "click", "button#create-account", -> Turbolinks.visit "/sign_up" _ready = -> if typeof sweetAlertInitialize != "undefined" sweetAlertInitialize() if document.getElementById('particles')? particleground document.getElementById('particles'), dotColor: '#5e35b1' lineColor: '#5e35b1' if twemoji? twemoji.parse document.body, size: 16 callback: (icon, options) -> switch icon # copyright, registered, trademark when 'a9' or 'ae' or '2122' false else ''.concat(options.base, options.size, '/', icon, options.ext) $(document).ready _ready $(document).on 'page:load', _ready
Sapphire/spring.moe
app/assets/javascripts/application.js.erb.coffee
CoffeeScript
mit
2,056
($ document).on "click", "input[type=checkbox][name=gm-group-check]", -> box = $(this) box.attr 'disabled', 'disabled' groupName = box[0].dataset.group count = Number ($ "span##{groupName}-members").html() boxChecked = box[0].checked count += if boxChecked then 1 else -1 $.ajax url: '/ajax/group_membership' type: 'POST' data: user: box[0].dataset.user group: groupName add: boxChecked success: (data, status, jqxhr) -> if data.success box[0].checked = if data.checked? then data.checked else !boxChecked ($ "span##{groupName}-members").html(count) showNotification data.message, data.success error: (jqxhr, status, error) -> box[0].checked = false console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> box.removeAttr "disabled" $(document).on "keyup", "input#new-group-name", (evt) -> if evt.which == 13 # return key evt.preventDefault() $("button#create-group").trigger 'click' ($ document).on "click", "button#create-group", -> btn = $(this) btn.button "loading" input = ($ "input#new-group-name") $.ajax url: '/ajax/create_group' type: 'POST' data: name: input.val() user: btn[0].dataset.user dataType: 'json' success: (data, status, jqxhr) -> if data.success ($ "ul.list-group.groups--list").append(data.render) input.val '' showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> btn.button "reset" ($ document).on "click", "a#delete-group", (ev) -> ev.preventDefault() btn = $(this) group = btn[0].dataset.group swal title: translate('frontend.group.title') text: translate('frontend.group.text') type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: translate('views.actions.delete') cancelButtonText: translate('views.actions.cancel') closeOnConfirm: true , -> $.ajax url: '/ajax/destroy_group' type: 'POST' data: group: group dataType: 'json' success: (data, status, jqxhr) -> if data.success ($ "li.list-group-item#group-#{group}").slideUp() showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) ->
Sapphire/spring.moe
app/assets/javascripts/groups.coffee
CoffeeScript
mit
2,661
($ document).on "click", "button#ib-generate-question", -> btn = ($ this) btn.button "loading" $.ajax url: '/ajax/generate_question' type: 'POST' dataType: 'json' success: (data, status, jqxhr) -> if data.success ($ "div#entries").prepend(data.render) # TODO: slideDown or something # GitHub issue #26: del_all_btn = ($ "button#ib-delete-all") del_all_btn.removeAttr 'disabled' del_all_btn[0].dataset.ibCount = (Number del_all_btn[0].dataset.ibCount) + 1 error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> btn.button "reset" ($ document).on "click", "button#ib-delete-all", -> btn = ($ this) count = btn[0].dataset.ibCount swal title: translate('frontend.inbox.confirm_all.title', {count: count}) text: translate('frontend.inbox.confirm_all.text') type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: translate('views.actions.delete') cancelButtonText: translate('views.actions.cancel') closeOnConfirm: true , -> btn.button "loading" succ = no $.ajax url: '/ajax/delete_all_inbox' type: 'POST' dataType: 'json' success: (data, status, jqxhr) -> if data.success succ = yes ($ "div#pagination, button#load-more-btn").slideUp() entries = ($ "div#entries") entries.slideUp 400, -> entries.html("Nothing to see here.") entries.fadeIn() error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> if succ # and now: a (broken?) re-implementation of Bootstrap's button.js btn.html btn.data('resetText') btn.removeClass 'disabled' btn[0].dataset.ibCount = 0 $(document).on "keydown", "textarea[name=ib-answer]", (evt) -> iid = $(this)[0].dataset.id if evt.keyCode == 13 and (evt.ctrlKey or evt.metaKey) # trigger warning: $("button[name=ib-answer][data-ib-id=#{iid}]").trigger 'click' $(document).on "click", "button[name=ib-answer]", -> btn = $(this) btn.button "loading" iid = btn[0].dataset.ibId $("textarea[name=ib-answer][data-id=#{iid}]").attr "readonly", "readonly" shareTo = [] ($ "input[type=checkbox][name=ib-share][data-ib-id=#{iid}]:checked").each (i, share) -> shareTo.push share.dataset.service $.ajax url: '/ajax/answer' type: 'POST' data: id: iid answer: $("textarea[name=ib-answer][data-id=#{iid}]").val() share: JSON.stringify shareTo inbox: true success: (data, status, jqxhr) -> if data.success $("div.inbox-box[data-id=#{iid}]").slideUp() showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> btn.button "reset" $("textarea[name=ib-answer][data-id=#{iid}]").removeAttr "readonly" $(document).on "click", "button[name=ib-destroy]", -> btn = $(this) swal title: translate('frontend.inbox.confirm.title') text: translate('frontend.inbox.confirm.text') type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: translate('views.actions.delete') cancelButtonText: translate('views.actions.cancel') closeOnConfirm: true , -> btn.button "loading" iid = btn[0].dataset.ibId $("textarea[name=ib-answer][data-id=#{iid}]").attr "readonly", "readonly" $.ajax url: '/ajax/delete_inbox' type: 'POST' data: id: iid success: (data, status, jqxhr) -> if data.success $("div.inbox-box[data-id=#{iid}]").slideUp() showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> btn.button "reset" $("textarea[name=ib-answer][data-id=#{iid}]").removeAttr "readonly" # Toggle button $(document).on "click", "button[name=ib-options]", -> btn = $(this) ibid = btn[0].dataset.ibId state = btn[0].dataset.state optionBox = $("#ib-options-#{ibid}") switch state when 'hidden' optionBox.slideDown() btn[0].dataset.state = 'shown' when 'shown' optionBox.slideUp() btn[0].dataset.state = 'hidden'
Sapphire/spring.moe
app/assets/javascripts/inbox.coffee
CoffeeScript
mit
4,676
cheet 'up up down down left right left right b a', -> ($ "body").addClass 'fa-spin' ($ "p.answerbox--question-text").each (i) -> ($ this).html ":^)"
Sapphire/spring.moe
app/assets/javascripts/memes.coffee
CoffeeScript
mit
152
#= require moment #= require bootstrap-datetimepicker #= require_tree ./moderation
Sapphire/spring.moe
app/assets/javascripts/moderation.js.erb.coffee
CoffeeScript
mit
83
load = -> parent = $ "#ban-control-super" return unless parent.length > 0 parent.find('#_ban').on "change", (event) -> $t = $ this if $t.is(":checked") $("#ban-controls").show() else $("#ban-controls").hide() parent.find('#_permaban').on "change", (event) -> $t = $ this if $t.is(":checked") $("#ban-controls-time").hide() else $("#ban-controls-time").show() parent.find("#until").datetimepicker defaultDate: parent.find("#until").val() sideBySide: true icons: time: "fa fa-clock-o" date: "fa fa-calendar" up: "fa fa-chevron-up" down: "fa fa-chevron-down" previous: "fa fa-chevron-left" next: "fa fa-chevron-right" today: "fa fa-home" clear: "fa fa-trash-o" close: "fa fa-times" parent.parent()[0].addEventListener "submit", (event) -> event.preventDefault(); $("#modal-ban").modal "hide" checktostr = (selector) -> if $(selector)[0].checked "1" else "0" data = { ban: checktostr "#_ban" permaban: checktostr "#_permaban" until: $("#until")[0].value.trim() reason: $("#reason")[0].value.trim() user: $("#_user")[0].value } $.ajax url: '/ajax/mod/ban' type: 'POST' data: data success: (data, status, jqxhr) -> showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> $(document).on "DOMContentLoaded", -> load() $(document).on "page:load", -> load()
Sapphire/spring.moe
app/assets/javascripts/moderation/ban.coffee
CoffeeScript
mit
1,672
# Toggle button $(document).on "click", "button[name=mod-comments]", -> btn = $(this) id = btn[0].dataset.id state = btn[0].dataset.state commentBox = $("#mod-comments-section-#{id}") switch state when 'hidden' commentBox.slideDown() btn[0].dataset.state = 'shown' when 'shown' commentBox.slideUp() btn[0].dataset.state = 'hidden' $(document).on "keyup", "input[name=mod-comment-new]", (evt) -> input = $(this) id = input[0].dataset.id ctr = $("span#mod-comment-charcount-#{id}") cbox = $("div[name=mod-comment-new-group][data-id=#{id}]") if evt.which == 13 # return key evt.preventDefault() return cbox.addClass "has-error" if input.val().length > 160 || input.val().trim().length == 0 input.attr 'disabled', 'disabled' $.ajax url: '/ajax/mod/create_comment' type: 'POST' data: id: id comment: input.val() dataType: 'json' # jQuery can't guess the datatype correctly here... success: (data, status, jqxhr) -> console.log data if data.success $("#mod-comments-#{id}").html data.render input.val '' ctr.html 160 $("span#mod-comment-count-#{id}").html data.count showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> input.removeAttr 'disabled' # character count $(document).on "input", "input[name=mod-comment-new]", (evt) -> input = $(this) id = input[0].dataset.id ctr = $("span#mod-comment-charcount-#{id}") cbox = $("div[name=mod-comment-new-group][data-id=#{id}]") cbox.removeClass "has-error" if cbox.hasClass "has-error" ctr.html 160 - input.val().length if Number(ctr.html()) < 0 ctr.removeClass 'text-muted' ctr.addClass 'text-danger' else ctr.removeClass 'text-danger' ctr.addClass 'text-muted' # destroy $(document).on "click", "a[data-action=mod-comment-destroy]", (ev) -> ev.preventDefault() btn = $(this) cid = btn[0].dataset.id swal title: translate('frontend.destroy_comment.confirm.title') text: translate('frontend.destroy_comment.confirm.text') type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: translate('views.actions.delete') cancelButtonText: translate('views.actions.cancel') closeOnConfirm: true , -> $.ajax url: '/ajax/mod/destroy_comment' type: 'POST' data: comment: cid success: (data, status, jqxhr) -> if data.success $("li[data-comment-id=#{cid}]").slideUp() showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) ->
Sapphire/spring.moe
app/assets/javascripts/moderation/comment.coffee
CoffeeScript
mit
2,961
$(document).on "click", "button[name=mod-delete-report]", -> btn = $(this) id = btn[0].dataset.id swal title: translate('frontend.destroy_report.confirm.title') text: translate('frontend.destroy_report.confirm.text') type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: translate('views.actions.delete') cancelButtonText: translate('views.actions.cancel') closeOnConfirm: true , -> $.ajax url: '/ajax/mod/destroy_report' type: 'POST' data: id: id success: (data, status, jqxhr) -> if data.success $("div.moderationbox[data-id=#{id}]").slideUp() showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) ->
Sapphire/spring.moe
app/assets/javascripts/moderation/destroy.coffee
CoffeeScript
mit
909
($ document).on "click", "input[type=checkbox][name=check-your-privileges]", -> box = $(this) box.attr 'disabled', 'disabled' privType = box[0].dataset.type boxChecked = box[0].checked $.ajax url: '/ajax/mod/privilege' type: 'POST' data: user: box[0].dataset.user type: privType status: boxChecked success: (data, status, jqxhr) -> if data.success box[0].checked = if data.checked? then data.checked else !boxChecked showNotification data.message, data.success error: (jqxhr, status, error) -> box[0].checked = false console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> box.removeAttr "disabled"
Sapphire/spring.moe
app/assets/javascripts/moderation/privileges.coffee
CoffeeScript
mit
763
($ document).on "click", "button[name=mod-vote]", -> btn = $(this) id = btn[0].dataset.id action = btn[0].dataset.action upvote = btn[0].dataset.voteType == 'upvote' btn.attr 'disabled', 'disabled' target_url = switch action when 'vote' '/ajax/mod/create_vote' when 'unvote' '/ajax/mod/destroy_vote' success = false $.ajax url: target_url type: 'POST' data: id: id upvote: upvote success: (data, status, jqxhr) -> success = data.success if success ($ "span#mod-count-#{id}").html(data.count) showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> if success switch action when 'vote' btn.attr 'disabled', 'disabled' btn[0].dataset.action = 'unvote' console.log("vote for #{upvote ? 'downvote' : 'upvote'}") other_btn = $ "button[name=mod-vote][data-id=#{id}][data-vote-type=#{if upvote then 'downvote' else 'upvote'}]" other_btn.removeAttr 'disabled' other_btn[0].dataset.action = 'unvote' when 'unvote' btn.removeAttr 'disabled' btn[0].dataset.action = 'vote' console.log("vote for #{upvote ? 'downvote' : 'upvote'}") other_btn = $ "button[name=mod-vote][data-id=#{id}][data-vote-type=#{if upvote then 'downvote' else 'upvote'}]" other_btn.removeAttr 'disabled', 'disabled' other_btn[0].dataset.action = 'vote'
Sapphire/spring.moe
app/assets/javascripts/moderation/vote.coffee
CoffeeScript
mit
1,647
($ document).ready -> ($ '[data-toggle="tooltip"]').tooltip()
Sapphire/spring.moe
app/assets/javascripts/notifications.coffee
CoffeeScript
mit
62
jQuery -> if $('#pagination').size() > 0 $('#pagination').hide() loading_posts = false $('#load-more-btn').show().click -> unless loading_posts loading_posts = true more_posts_url = $('#pagination .pagination .next a').attr('href') $this = $(this) $this.html('<i class="fa fa-spinner fa-spin"></i>').addClass('disabled') $.getScript more_posts_url, -> $this.text('Load more').removeClass('disabled') if $this loading_posts = false $('[data-toggle="tooltip"]').tooltip() return
Sapphire/spring.moe
app/assets/javascripts/pagination.coffee
CoffeeScript
mit
574
// -*- C++ -*- <% if Rails.env.production? %> var _paq = _paq || []; _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); _paq.push(['setCustomUrl', document.location]); _paq.push(['setDocumentTitle', document.title]); (function() { var u="//stat.rrerr.net/"; _paq.push(['setTrackerUrl', u+'piwik.php']); _paq.push(['setSiteId', 9]); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); })(); <% elsif !Rails.env.test? %> console.log("i track'd ur bich"); <% end %>
Sapphire/spring.moe
app/assets/javascripts/piwik.js.erb
erb
mit
635
$(document).on "keydown", "textarea#q-answer", (evt) -> qid = $(this)[0].dataset.id if evt.keyCode == 13 and evt.ctrlKey # trigger warning: $("button#q-answer").trigger 'click' $(document).on "click", "button#q-answer", -> btn = $(this) btn.button "loading" qid = btn[0].dataset.qId $("textarea#q-answer").attr "readonly", "readonly" shareTo = [] ($ "input[type=checkbox][name=share][data-q-id=#{qid}]:checked").each (i, share) -> shareTo.push share.dataset.service $.ajax url: '/ajax/answer' type: 'POST' dataType: 'json' data: id: qid answer: $("textarea#q-answer[data-id=#{qid}]").val() share: JSON.stringify shareTo inbox: false success: (data, status, jqxhr) -> if data.success $("div#q-answer-box").slideUp() ($ "div#answers").prepend data.render showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> btn.button "reset" $("textarea#q-answer").removeAttr "readonly"
Sapphire/spring.moe
app/assets/javascripts/question.coffee
CoffeeScript
mit
1,154
$(document).on "click", "button[name=qb-all-ask]", -> btn = $(this) btn.button "loading" $("textarea[name=qb-all-question]").attr "readonly", "readonly" rcptSelect = ($ 'select[name=qb-all-rcpt]') rcpt = if rcptSelect.length > 0 rcptSelect.first().val() else 'followers' $.ajax url: '/ajax/ask' type: 'POST' data: rcpt: rcpt question: $("textarea[name=qb-all-question]").val() anonymousQuestion: false success: (data, status, jqxhr) -> if data.success $("textarea[name=qb-all-question]").val '' $('#modal-ask-followers').modal('hide') showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> btn.button "reset" $("textarea[name=qb-all-question]").removeAttr "readonly" # hotkey for accessing this quickly $(document).on "keydown", (evt) -> if evt.keyCode == 77 and (evt.ctrlKey or evt.metaKey) $('.btn[name=toggle-all-ask]').trigger 'click' # see GitHub issue #2 ($ document).on "keydown", "textarea[name=qb-all-question]", (evt) -> if evt.keyCode == 13 and (evt.ctrlKey or evt.metaKey) ($ "button[name=qb-all-ask]").trigger 'click'
Sapphire/spring.moe
app/assets/javascripts/questionbox/all.coffee
CoffeeScript
mit
1,329
$(document).on "click", "a[data-action=ab-question-destroy]", (ev) -> ev.preventDefault() btn = $(this) qid = btn[0].dataset.qId swal title: translate('frontend.destroy_own.confirm.title') text: translate('frontend.destroy_own.confirm.text') type: "warning" showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: translate('views.actions.y') cancelButtonText: translate('views.actions.n') closeOnConfirm: true , -> $.ajax url: '/ajax/destroy_question' # TODO: find a way to use rake routes instead of hardcoding them here type: 'POST' data: question: qid success: (data, status, jqxhr) -> if data.success if btn[0].dataset.redirect != undefined window.location.pathname = btn[0].dataset.redirect else $("div.answerbox[data-q-id=#{qid}], div.questionbox[data-id=#{qid}]").slideUp() showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) ->
Sapphire/spring.moe
app/assets/javascripts/questionbox/destroy.coffee
CoffeeScript
mit
1,163
$(document).on "click", "a[data-action=ab-question-report]", (ev) -> ev.preventDefault() btn = $(this) qId = btn[0].dataset.qId reportDialog "question", qId, -> btn.button "reset"
Sapphire/spring.moe
app/assets/javascripts/questionbox/report.coffee
CoffeeScript
mit
188
$(document).on "click", "button[name=qb-ask]", -> btn = $(this) btn.button "loading" promote = btn[0].dataset.promote == "true" $("textarea[name=qb-question]").attr "readonly", "readonly" anonymousQuestion = if $("input[name=qb-anonymous]")[0] != undefined $("input[name=qb-anonymous]")[0].checked else true $.ajax url: '/ajax/ask' # TODO: find a way to use rake routes instead of hardcoding them here type: 'POST' data: rcpt: $("input[name=qb-to]").val() question: $("textarea[name=qb-question]").val() anonymousQuestion: anonymousQuestion success: (data, status, jqxhr) -> if data.success $("textarea[name=qb-question]").val '' if promote $("div#question-box").hide() $("div#question-box-promote").show() showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> btn.button "reset" $("textarea[name=qb-question]").removeAttr "readonly" # for that promotional thing $(document).on "click", "button#new-question", -> $("div#question-box").show() $("div#question-box-promote").hide() # see GitHub issue #2 ($ document).on "keydown", "textarea[name=qb-question]", (evt) -> if evt.keyCode == 13 and evt.ctrlKey ($ "button[name=qb-ask]").trigger 'click'
Sapphire/spring.moe
app/assets/javascripts/questionbox/user.coffee
CoffeeScript
mit
1,441
window.reportDialog = (type, target, callback) -> swal title: translate('frontend.report.confirm.title', {type: type}) text: translate('frontend.report.confirm.text') type: "input" showCancelButton: true confirmButtonColor: "#DD6B55" confirmButtonText: translate('views.actions.report') cancelButtonText: translate('views.actions.cancel') closeOnConfirm: true inputPlaceholder: translate('frontend.report.confirm.input') , (value) -> if typeof value == "boolean" && value == false return false $.ajax url: '/ajax/report' type: 'POST' data: id: target type: type reason: value success: (data, status, jqxhr) -> showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> callback type, target, jqxhr, status
Sapphire/spring.moe
app/assets/javascripts/report.coffee
CoffeeScript
mit
993
# see GitHub issue #11 ($ document).on "submit", "form#edit_user", (evt) -> if ($ "input#user_current_password").val().length == 0 evt.preventDefault() $("button[data-target=#modal-passwd]").trigger 'click' readImage = (file, callback) -> fr = new FileReader() fr.addEventListener "load", (e) -> callback e.target.result fr.readAsBinaryString file freeURL = () -> if window.URL? or window.webkitURL? readImage = (file, callback) -> callback (window.URL || window.webkitURL).createObjectURL file freeURL = (url) -> URL.revokeObjectURL url # Profile pic ($ document).on 'change', 'input#user_profile_picture[type=file]', -> input = this ($ '#profile-picture-crop-controls').slideUp 400, -> if input.files and input.files[0] readImage input.files[0], (src) -> cropper = ($ '#profile-picture-cropper') preview = ($ '#profile-picture-preview') updateVars = (data, action) -> ($ '#crop_x').val Math.floor(data.x / data.scale) ($ '#crop_y').val Math.floor(data.y / data.scale) ($ '#crop_w').val Math.floor(data.w / data.scale) ($ '#crop_h').val Math.floor(data.h / data.scale) # rx = 100 / data.w # ry = 100 / data.h # ($ '#profile-picture-preview').css # width: Math.round(rx * preview[0].naturalWidth) + 'px' # height: Math.round(ry * preview[0].naturalHeight) + 'px' # marginLeft: '-' + Math.round(rx * data.x) + 'px' # marginTop: '-' + Math.round(ry * data.y) + 'px' cropper.on 'load', -> if ({}.toString).call(src) == "[object URL]" freeURL src side = if cropper[0].naturalWidth > cropper[0].naturalHeight cropper[0].naturalHeight else cropper[0].naturalWidth cropper.guillotine width: side height: side onChange: updateVars updateVars cropper.guillotine('getData'), 'drag' # just because unless ($ '#profile-picture-crop-controls')[0].dataset.bound? ($ '#cropper-zoom-out').click -> cropper.guillotine 'zoomOut' ($ '#cropper-zoom-in').click -> cropper.guillotine 'zoomIn' ($ '#profile-picture-crop-controls')[0].dataset.bound = true ($ '#profile-picture-crop-controls').slideDown() cropper.attr 'src', src ($ document).on 'change', 'input#user_profile_header[type=file]', -> input = this ($ '#profile-header-crop-controls').slideUp 400, -> if input.files and input.files[0] readImage input.files[0], (src) -> cropper = ($ '#profile-header-cropper') preview = ($ '#profile-header-preview') updateVars = (data, action) -> ($ '#crop_h_x').val Math.floor(data.x / data.scale) ($ '#crop_h_y').val Math.floor(data.y / data.scale) ($ '#crop_h_w').val Math.floor(data.w / data.scale) ($ '#crop_h_h').val Math.floor(data.h / data.scale) cropper.on 'load', -> if ({}.toString).call(src) == "[object URL]" freeURL src cropper.guillotine width: 1500 height: 350 onChange: updateVars updateVars cropper.guillotine('getData'), 'drag' unless ($ '#profile-header-crop-controls')[0].dataset.bound? ($ '#cropper-header-zoom-out').click -> cropper.guillotine 'zoomOut' ($ '#cropper-header-zoom-in').click -> cropper.guillotine 'zoomIn' ($ '#profile-header-crop-controls')[0].dataset.bound = true ($ '#profile-header-crop-controls').slideDown() cropper.attr 'src', src
Sapphire/spring.moe
app/assets/javascripts/settings.coffee
CoffeeScript
mit
3,672
$(document).on "click", "button[name=user-action]", -> btn = $(this) btn.button "loading" type = btn[0].dataset.type target = btn[0].dataset.target action = btn[0].dataset.action if type in ['follower', 'friend'] count = Number $("h4.entry-text##{type}-count").html() target_url = switch action when 'follow' count++ '/ajax/create_friend' when 'unfollow' count-- '/ajax/destroy_friend' success = false $.ajax url: target_url type: 'POST' data: screen_name: target success: (data, status, jqxhr) -> success = data.success if data.success if type in ['follower', 'friend'] $("h4.entry-text##{type}-count").html(count) showNotification data.message, data.success error: (jqxhr, status, error) -> console.log jqxhr, status, error showNotification translate('frontend.error.message'), false complete: (jqxhr, status) -> btn.button "reset" if success switch action when 'follow' btn[0].dataset.action = 'unfollow' btn.attr 'class', 'btn btn-default btn-block profile--follow-btn' btn.html translate('views.actions.unfollow') when 'unfollow' btn[0].dataset.action = 'follow' btn.attr 'class', 'btn btn-primary btn-block profile--follow-btn' btn.html translate('views.actions.follow') # report user $(document).on "click", "a[data-action=report-user]", (ev) -> ev.preventDefault() btn = $(this) target = btn[0].dataset.target reportDialog "user", target, -> btn.button "reset" # parallax PARALLAX_PREFIX = null if typeof document.documentElement.style.webkitTransform == "string" PARALLAX_PREFIX = "webkit" if typeof document.documentElement.style.mozTransform == "string" PARALLAX_PREFIX = "moz" if typeof document.documentElement.style.oTransform == "string" PARALLAX_PREFIX = "o" if typeof document.documentElement.style.msTransform == "string" PARALLAX_PREFIX = "ms" if typeof document.documentElement.style.khtmlTransform == "string" PARALLAX_PREFIX = "khtml" if typeof document.documentElement.style.transform == "string" PARALLAX_PREFIX = "" HEADER_PARALLAX = null if PARALLAX_PREFIX? PARALLAX_CSS = "transform" if PARALLAX_PREFIX.length PARALLAX_CSS = PARALLAX_PREFIX + PARALLAX_CSS.charAt(0).toUpperCase() + PARALLAX_CSS.slice(1) window.HEADER_PARALLAX_INERTIA = 0.4; HEADER_PARALLAX = -> header = $("#profile--header:not(.profile--no-header) img")[0] if header? headerOffset = Math.max(window.pageYOffset, window.scrollY, document.documentElement.scrollTop) * HEADER_PARALLAX_INERTIA header.style[PARALLAX_CSS] = "translate3d(0px, #{headerOffset}px, 0px)"; return # coffee doesn't have !-> to prevent returning like LiveScript has, god I miss livescript ;-; # also no := to set global variables :-( # or var-iables = varIables :-(( # or fun! = fun() :-((( $(window).on "scroll", (event) -> HEADER_PARALLAX() return $(document).ready -> HEADER_PARALLAX() if HEADER_PARALLAX? return
Sapphire/spring.moe
app/assets/javascripts/user.coffee
CoffeeScript
mit
3,121
/* *= require rails_bootstrap_forms *= require growl *= require jquery.guillotine *= require sweet-alert *= require_self */ @import url(https://fonts.googleapis.com/css?family=Lato:400,700); $font-family-sans-serif: "Lato","Open Sans", "Helvetica Neue", Helvetica, "DejaVu Sans", Arial, sans-serif; $font-family-serif: Georgia, "DejaVu Serif", "Times New Roman", Times, serif; //** Default monospace fonts for `<code>`, `<kbd>`, and `<pre>`. $font-family-monospace: "PragmataPro", Monaco, "Ubuntu Mono", Menlo, "DejaVu Sans Mono", monospace; $font-family-base: $font-family-sans-serif; $font-size-base: 14px; $font-size-large: ceil(($font-size-base * 1.25)); // ~18px $font-size-small: ceil(($font-size-base * 0.85)); // ~12px $font-size-h1: floor(($font-size-base * 2.6)); // ~36px $font-size-h2: floor(($font-size-base * 2.15)); // ~30px $font-size-h3: ceil(($font-size-base * 1.7)); // ~24px $font-size-h4: ceil(($font-size-base * 1.25)); // ~18px $font-size-h5: $font-size-base; $font-size-h6: ceil(($font-size-base * 0.85)); // ~12px $brand-primary: #5e35b1; $navbar-inverse-bg: #5e35b1; $navbar-inverse-link-color: #ffffff; $navbar-inverse-link-hover-color: #ffffff; $navbar-inverse-link-hover-bg: transparent; $navbar-inverse-link-active-color: #ffffff; $navbar-inverse-link-active-bg: transparent; $navbar-inverse-link-active-bg-mobile: darken(#5e35b1, 7%); $navbar-inverse-link-disabled-color: darken(#fff, 12.5%); $navbar-inverse-link-disabled-bg: transparent; $navbar-inverse-brand-color: $navbar-inverse-link-color; $navbar-inverse-brand-hover-color: darken($navbar-inverse-link-color, 10%); $navbar-inverse-brand-hover-bg: transparent; $navbar-inverse-toggle-hover-bg: #512da8; $navbar-inverse-toggle-icon-bar-bg: #7e57c2; $navbar-inverse-toggle-border-color: #512da8; @import "bootswatch/cosmo/variables"; @import "bootstrap"; body { padding-top: $navbar-height; } @import 'bootstrap-datetimepicker'; .remove-native-picker::-webkit-calendar-picker-indicator{ display: none } @import "bootswatch/cosmo/bootswatch"; @import "base"; @import "font-awesome"; $nprogress-color: lighten($navbar-inverse-bg, 25%); @import 'nprogress'; @import 'nprogress-bootstrap';
Sapphire/spring.moe
app/assets/stylesheets/application.css.scss
CSS
mit
2,300
/* all custom SCSS should go into here */ body { overflow-y: scroll; word-wrap: break-word; background-color: #fafafa; } @import "scss/variable"; @import "scss/generic"; @import "scss/answerbox"; @import "scss/comments"; @import "scss/entry"; @import "scss/navbar"; @import "scss/panel"; @import "scss/user"; @import "scss/notifications"; @import "scss/groups"; @import "scss/mobile"; .j2-page { padding-top: 30px; } .centre { text-align: center; } .ios-web-app { padding-top: 1em; } #load-more-btn { margin-bottom: 1.5em; } .j2-jumbo { background-color: darken($navbar-inverse-bg, 10%); color: #fff; } .j2-jumbo h1, .j2-jumbo h2, .j2-jumbo h3, .j2-jumbo h4, .j2-jumbo h5, .j2-jumbo h6 { color: #fff; } .j2-jumbo a, .j2-jumbo a:hover { color: #fff; opacity: 0.6; } .j2-jumbo a:hover { opacity: 1; } .j2-jumbo a .btn { opacity: 1; } .smiles { margin-bottom: 7px; } .j2-lh { color: $main-color; } .about--moderator { padding-left: 0px; } .about--moderator li { list-style: none; } .about--moderator a { text-decoration: none; } .about--moderator a:hover { text-decoration: none; } .j2-up { text-transform: uppercase; } .j2-label { display: inline-block; } .j2-table { display: table; } .input--center { display: table-cell; vertical-align: middle; } .sweet-overlay { z-index: 1031; } #create-group { margin-top: 5px; } .j2-delete { color: $brand-danger; text-decoration: none; } .j2-navbar { margin-bottom: 0px; } @media (max-width: $screen-xs-max) { .j2-col-reset { padding-left: 0px; padding-right: 0px; } } #growls.default{ top:64px; right:10px } .links { padding-bottom: 10px; } .panel { box-shadow: 0px 0px 20px rgba(0,0,0,0.1); } .panel-default > .panel-heading { box-shadow: inset 0 -10px 10px -10px rgba(0,0,0,0.1); } .panel-default > .panel-footer { box-shadow: inset 0 10px 10px -10px rgba(0,0,0,0.1); } #profile { border-color: transparent; border-width: 0px; } .panel { border-radius: 2px; } .panel > .panel-heading { border-top-left-radius: 2px; border-top-right-radius: 2px; } .panel > .panel-footer { border-bottom-left-radius: 2px; border-bottom-right-radius: 2px; } .particle-jumbotron { padding: 0px; overflow: hidden; position: relative; width: 100%; } .particle-content { position: relative; top: 0; padding-top: 48px; padding-bottom: 48px; padding-left: 30px; padding-right: 30px; } #particles { position: absolute; width: 100%; height: 100%; } .icon-showcase { font-size: 78px; text-align: center; display: block; } .heading-showcase { margin-top: 5px; } .heading-about { margin-top: 0px; } .discover { padding-top: 20px; }
Sapphire/spring.moe
app/assets/stylesheets/base.css.scss
CSS
mit
2,721
// Place all the styles related to the inbox controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/
Sapphire/spring.moe
app/assets/stylesheets/inbox.css.scss
CSS
mit
176
.answerbox .text-muted a, .answerbox .text-muted a:hover { color: $gray; text-decoration: none; } .answerbox--img { min-height: 32px; min-width: 32px; height: 32px; width: 32px; } .answerbox--img-small { min-height: 20px; min-width: 20px; height: 20px; width: 20px; } .answerbox--question-text, .answerbox--question-user, .answerbox--answer-user, .answerbox--answer-date { margin-bottom: 0px; overflow: hidden; } .answerbox--question-text { color: $gray; } .answerbox--answer-text { font-size: 16px; color: #000; line-height: 1.3em; } .answerbox--question-text { line-height: 1.3em; overflow: hidden; } .answerbox--answer-date { font-size: 12px; line-height: 1.3em; } .answerbox [name="ab-smile"], .answerbox [name="ab-smile-comment"] { padding: 6px 11px; padding-left: 21px; position: relative; overflow: hidden; border: none; i.fa.fa-smile-o, i.fa.fa-frown-o, i.fa.fa-meh-o { position: absolute; font-size: 3em; left: -13px; top: -10px; display: block; } }
Sapphire/spring.moe
app/assets/stylesheets/scss/answerbox.scss
CSS
mit
1,042
.comments { padding-left: 0; } .comments li { list-style-type: none; } .comments .pull-right { margin-top: -13px; } .comments--box { z-index: 99; } .comments--count { z-index: 0; margin-top: -2em; } .comments--body { overflow: visible !important; } .comments--content { overflow: hidden; word-break: normal; } .comments--content p { margin-bottom: 0px; } .comments--media { overflow: visible !important; }
Sapphire/spring.moe
app/assets/stylesheets/scss/comments.scss
CSS
mit
435
.entry-subtext { color: $navbar-inverse-bg; margin-top: 0px; text-transform: uppercase; font-weight: bold; font-size: 80%; } .entry-text { margin-bottom: 0px; } .entry-about { margin-top: 0px; } .statistics { .entry-text { display: block; text-align: center; margin-top: 5px; } .entry-subtext { text-align: center; display: block; margin-bottom: 5px; } } .users { .entry-text { display: block; text-align: center; margin-top: 7px; font-size: 78px; line-height: 1; } .entry-subtext { text-align: center; display: block; margin-bottom: 5px; } }
Sapphire/spring.moe
app/assets/stylesheets/scss/entry.scss
CSS
mit
634
.user-list { margin: 0; padding: 0; } .user-list-entry-smiles { * { display: inline-block; vertical-align: middle; } img { height: 64px } span { margin-left: 5px; } a:hover { text-decoration: none; span { text-decoration: underline; } } }
Sapphire/spring.moe
app/assets/stylesheets/scss/generic.scss
CSS
mit
297
.groups--list .list-group-item-heading { margin-top: 0px; margin-bottom: 0px; line-height: 1.3; } .groups--list .list-group-item { padding: 5px 7px; } a[role="tab"] { outline: 0px none; border: none !important; }
Sapphire/spring.moe
app/assets/stylesheets/scss/groups.scss
CSS
mit
226
@media (max-width: 768px) { @import "mobile/settings"; @import "mobile/profile"; }
Sapphire/spring.moe
app/assets/stylesheets/scss/mobile.scss
CSS
mit
87
.container.headerable:not(.profile--no-header) { margin-top: 0; padding-top: 0; } #profile--header:not(.profile--no-header) { min-width: 0px; * { min-width: 0px; } } .container.headerable { #profile-info { box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.1); margin-bottom: 15px; #profile.panel, #profile-stats.panel { box-shadow: none; margin-bottom: 0; } #profile.panel { font-size: 0; .profile--avatar { width: 64px; position: relative; top: -15px; left: 5px; display: inline; } .profile--panel-badge { display: inline-block; padding: 0 5px; vertical-align: top; width: auto; margin-top: -15px; &:nth-child(2) { margin-left: 5px; } .fa { font-size: 15px; } } .panel-body { font-size: 15px; .profile--panel-name { margin-top: -75px; margin-left: 60px } } } #profile-stats { border: none; .panel-heading { display: none; } .panel-body { font-size: 0px; padding: 0; .row { width: 50%; display: inline-block; font-size: 12px; margin: 0; } } } } }
Sapphire/spring.moe
app/assets/stylesheets/scss/mobile/profile.scss
CSS
mit
1,342
#profile-header-media { clear: both; display: block; .pull-left { float: none !important; clear: both; img { width: 100% } } }
Sapphire/spring.moe
app/assets/stylesheets/scss/mobile/settings.scss
CSS
mit
157
.navbar .nav .badge { padding: 3px 6px 3px; background-color: $navbar-inverse-link-active-bg; color: #fff; } .navbar .nav .active .badge, li.dropdown.open a.dropdown-toggle span.badge { padding: 3px 6px 3px; background-color: $navbar-inverse-bg; color: #fff; } .navbar--inbox-animation { animation: animationFrames ease-in-out 1.5s; animation-iteration-count: infinite; -webkit-animation: animationFrames ease-in-out 1.5s; -webkit-animation-iteration-count: infinite; -moz-animation: animationFrames ease-in-out 1.5s; -moz-animation-iteration-count: infinite; -o-animation: animationFrames ease-in-out 1.5s; -o-animation-iteration-count: infinite; -ms-animation: animationFrames ease-in-out 1.5s; -ms-animation-iteration-count: infinite; } @keyframes animationFrames{ 0% { background-color: #fff; } 100% { background-color: $navbar-inverse-toggle-border-color; } } @-moz-keyframes animationFrames{ 0% { background-color: #fff; } 100% { background-color: $navbar-inverse-toggle-border-color; } } @-webkit-keyframes animationFrames { 0% { background-color: #fff; } 100% { background-color: $navbar-inverse-toggle-border-color; } } @-o-keyframes animationFrames { 0% { background-color: #fff; } 100% { background-color: $navbar-inverse-toggle-border-color; } } @-ms-keyframes animationFrames { 0% { background-color: #fff; } 100% { background-color: $navbar-inverse-toggle-border-color; } } .btn-fab { border-radius: 100%; box-shadow: 0px 1px 6px rgba(0, 0, 0, 0.12), 0px 1px 6px rgba(0, 0, 0, 0.12); margin: 0px; padding: 3px 5px 4px 8px; font-size: 26px; width: 56px; height: 56px; transition: box-shadow 0.28s cubic-bezier(0.4, 0, 0.2, 1) 0s; outline: medium none !important; text-transform: uppercase; text-decoration: none; position: fixed; bottom: 0px; right: 0px; margin-right: 7px; margin-bottom: 7px; z-index: 99; } .profile--dropdown { min-width: 220px; margin-top: 0px !important; } .profile--dropdown-media { padding: 3px 15px; } .profile--dropdown-img { min-height: 45px; min-width: 45px; height: 45px; width: 45px; } .profile--dropdown-username { font-weight: 700; font-size: 1.2em; line-height: 1.33em; margin-top: 10px; } .profile--dropdown-displayname { font-weight: 700; font-size: 1.2em; line-height: 1.33em; margin-top: 2px; } .profile--image-dropdown > a { padding: 0px !important; } .profile--image-avatar { min-height: 50px; min-width: 50px; height: 50px; width: 50px; } .navbar-inverse { border: none; } @media (min-width: 769px) { nav.navbar .nav > li:not(.profile--image-dropdown) { -moz-osx-font-smoothing: grayscale; position: relative; &:before { content: ""; position: absolute; left: 0; right: 0; bottom: 0; background: $navbar-inverse-link-color; height: 0px; -webkit-transition-property: height; transition-property: height; -webkit-transition-duration: 0.3s; transition-duration: 0.3s; -webkit-transition-timing-function: ease-out; transition-timing-function: ease-out; } &:hover, &:focus, &:active { &:before { height: 4px } } &.active:before { height: 4px; } } } @media (max-width: 768px) { nav.navbar .nav { margin-bottom: 0; margin-top: 0; & > li { &.active a { background-color: $navbar-inverse-link-active-bg-mobile !important; } &.dropdown.profile--image-dropdown a .visible-xs { padding-left: 15px; line-height: 40px; margin: 0; } } } }
Sapphire/spring.moe
app/assets/stylesheets/scss/navbar.scss
CSS
mit
3,729
.notification--img { min-height: 32px; min-width: 32px; height: 32px; width: 32px; } .notification--user, .notification--text { z-index: 99; margin-bottom: 0px; } .notification--icon { position: absolute; right: 0px; bottom: 0px; padding: 5px; font-size: 36px; color: $gray; opacity: 0.4; z-index: 0; } .notification--dropdown { min-width: 370px; margin-top: 0px !important; } .notification--dropdown-media { padding: 3px 5px; } .notification--dropdown-user, .notification--dropdown-text { margin-bottom: 0px; overflow: hidden; line-height: 1.3em; } .notification--dropdown-user { margin-top: 0px; } .notification--dropdown-img { min-height: 32px; min-width: 32px; height: 32px; width: 32px; }
Sapphire/spring.moe
app/assets/stylesheets/scss/notifications.scss
CSS
mit
750
.panel-primary .text-muted a, .panel-primary .text-muted a:hover { color: #fff; text-decoration: none; opacity: 1; } .panel-primary .text-muted { color: #fff; opacity: 0.7; } .panel-primary .answerbox--question-text { color: #fff; } #questions .panel-body .media { &, .media-body { overflow: visible; } } .panel-question { position: fixed; border-top: 1px solid #fff; width: 100%; z-index: 999; border-color: #fff; } .panel-question.question-hidden { visibility: hidden; position: relative; box-shadow: none; z-index: -1; } .answerbox--question-media, .question-media, .question-body { overflow: visible !important; }
Sapphire/spring.moe
app/assets/stylesheets/scss/panel.scss
CSS
mit
664
.profile--img { min-height: 80px; min-width: 80px; height: 80px; width: 8px; } .profile--displayname { font-weight: 700; font-size: 1.2em; margin-top: -0.165em; line-height: 1.33em; } .profile--username { font-size: 0.9em; color: rgba(0, 0, 0, 0.4); line-height: 1.33; } .profile--followtag { margin: 0px 0px 0.2em; } .profile--text { margin-bottom: 2px; line-height: 1.5em; margin-top: 0.65em; } #profile--header { position: relative; z-index: -1; width: 100%; overflow: hidden; background-color: darken($navbar-inverse-bg, 10%); } #profile--header.profile--no-header { position: absolute; } .profile--panel .panel-heading { color: $brand-primary; border-bottom: 2px solid $brand-primary; background-color: #fff; text-transform: uppercase; } .profile--panel .panel-body { padding-top: 0px; } .inbox--panel .panel-heading { color: $brand-info; border-bottom: 2px solid $brand-info; background-color: #fff; text-transform: uppercase; } .warning--panel .panel-heading { color: $brand-danger; border-bottom: 2px solid $brand-danger; background-color: #fff; text-transform: uppercase; } .profile--follow-btn { margin-top: 5px; } .profile--avatar { width: 100%; height: auto; border: medium none; } .profile--panel-badge { width: 100%; text-align: center; padding-top: 0.15em; padding-bottom: 0.15em; text-transform: uppercase; font-weight: bold; margin: 0; color: #fff; } $colours: danger $brand-danger, default #BBB, success $brand-success, warning $brand-warning, primary $brand-primary, info #2980b9; @each $colour in $colours { .panel-badge-#{nth($colour, 1)} { background-color: nth($colour, 2); } } .user--banned { text-decoration: line-through !important; } .profile--panel-push-inner:not(.profile--no-header) { display: block; height: 60px; } .profile--header-img { display: block; min-width: 900px; width: 100%; } @media(min-width: 767px) { .container.headerable:not(.profile--no-header) { padding-top: 0; margin-top: -30px; } }
Sapphire/spring.moe
app/assets/stylesheets/scss/user.scss
CSS
mit
2,127
$main-color: #5e35b1; $black: #000;
Sapphire/spring.moe
app/assets/stylesheets/scss/variable.scss
CSS
mit
36
// Place all the styles related to the user controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/
Sapphire/spring.moe
app/assets/stylesheets/user.css.scss
CSS
mit
175
class Ajax::AnswerController < ApplicationController rescue_from(ActionController::ParameterMissing) do |titanic_param| @status = :parameter_error @message = I18n.t('messages.parameter_error', parameter: titanic_param.param.capitalize) @success = false render partial: "ajax/shared/status" end def create params.require :id params.require :answer params.require :share params.require :inbox inbox = (params[:inbox] == 'true') if inbox inbox_entry = Inbox.find(params[:id]) unless current_user == inbox_entry.user @status = :fail @message = I18n.t('messages.answer.create.fail') @success = false return end else question = Question.find(params[:id]) unless question.user.privacy_allow_stranger_answers @status = :privacy_stronk @message = I18n.t('messages.answer.create.privacy_stronk') @success = false return end end # this should never trigger because empty params throw ParameterMissing unless params[:answer].length > 0 @status = :peter_dinklage @message = I18n.t('messages.answer.create.peter_dinklage') @success = false return end answer = nil begin answer = if inbox inbox_entry.answer params[:answer], current_user else current_user.answer question, params[:answer] end rescue @status = :err @message = I18n.t('messages.error') @success = false return end services = JSON.parse params[:share] ShareWorker.perform_async(current_user.id, answer.id, services) @status = :okay @message = I18n.t('messages.answer.create.okay') @success = true unless inbox @question = 1 @render = render_to_string(partial: 'shared/answerbox', locals: { a: answer, show_question: false }) end end def destroy params.require :answer answer = Answer.find(params[:answer]) unless (current_user == answer.user) or (privileged? answer.user) @status = :nopriv @message = I18n.t('messages.answer.destroy.nopriv') @success = false return end if answer.user == current_user Inbox.create!(user: answer.user, question: answer.question, new: true) end # TODO: decide what happens with the question answer.destroy @status = :okay @message = I18n.t('messages.answer.destroy.okay') @success = true end end
Sapphire/spring.moe
app/controllers/ajax/answer_controller.rb
Ruby
mit
2,508
class Ajax::CommentController < ApplicationController rescue_from(ActionController::ParameterMissing) do |param_miss_ex| @status = :parameter_error @message = I18n.t('messages.parameter_error', parameter: param_miss_ex.param.capitalize) @success = false render partial: "ajax/shared/status" end def create params.require :answer params.require :comment answer = Answer.find(params[:answer]) begin current_user.comment(answer, params[:comment]) rescue ActiveRecord::RecordInvalid @status = :rec_inv @message = I18n.t('messages.comment.create.rec_inv') @success = false return end @status = :okay @message = I18n.t('messages.comment.create.okay') @success = true @render = render_to_string(partial: 'shared/comments', locals: { a: answer }) @count = answer.comment_count end def destroy params.require :comment @status = :err @success = false comment = Comment.find(params[:comment]) unless (current_user == comment.user) or (current_user == comment.answer.user) or (privileged? comment.user) @status = :nopriv @message = I18n.t('messages.comment.destroy.nopriv') @success = false return end @count = comment.answer.comment_count - 1 comment.destroy @status = :okay @message = I18n.t('messages.comment.destroy.okay') @success = true end end
Sapphire/spring.moe
app/controllers/ajax/comment_controller.rb
Ruby
mit
1,418
class Ajax::FriendController < ApplicationController rescue_from(ActionController::ParameterMissing) do |param_miss_ex| @status = :parameter_error @message = I18n.t('messages.parameter_error', parameter: param_miss_ex.param.capitalize) @success = false render partial: "ajax/shared/status" end def create params.require :screen_name target_user = User.find_by_screen_name(params[:screen_name]) begin current_user.follow target_user rescue @status = :fail @message = I18n.t('messages.friend.create.fail') @success = false return end @status = :okay @message = I18n.t('messages.friend.create.okay') @success = true end def destroy params.require :screen_name target_user = User.find_by_screen_name(params[:screen_name]) begin current_user.unfollow target_user rescue @status = :fail @message = I18n.t('messages.friend.destroy.fail') @success = false return end @status = :okay @message = I18n.t('messages.friend.destroy.okay') @success = true end end
Sapphire/spring.moe
app/controllers/ajax/friend_controller.rb
Ruby
mit
1,111
class Ajax::GroupController < ApplicationController rescue_from(ActionController::ParameterMissing) do |param_miss_ex| @status = :parameter_error @message = I18n.t('messages.parameter_error', parameter: param_miss_ex.param.capitalize) @success = false render partial: "ajax/shared/status" end def create @status = :err @success = false unless user_signed_in? @status = :noauth @message = I18n.t('messages.noauth') return end begin params.require :name rescue ActionController::ParameterMissing @status = :toolong @message = I18n.t('messages.group.create.noname') return end params.require :user begin target_user = User.find_by_screen_name(params[:user]) group = Group.create! user: current_user, display_name: params[:name] rescue ActiveRecord::RecordInvalid @status = :toolong @message = I18n.t('messages.group.create.toolong') return rescue ActiveRecord::RecordNotFound @status = :notfound @message = I18n.t('messages.group.create.notfound') return rescue ActiveRecord::RecordNotUnique @status = :exists @message = I18n.t('messages.group.create.exists') return end @status = :okay @success = true @message = I18n.t('messages.group.create.okay') @render = render_to_string(partial: 'user/modal_group_item', locals: { group: group, user: target_user }) end def destroy @status = :err @success = false unless user_signed_in? @status = :noauth @message = I18n.t('messages.noauth') return end params.require :group begin Group.where(user: current_user, name: params[:group]).first.destroy! rescue ActiveRecord::RecordNotFound @status = :notfound @message = I18n.t('messages.group.destroy.notfound') return end @status = :okay @success = true @message = I18n.t('messages.group.destroy.okay') end def membership @status = :err @success = false unless user_signed_in? @status = :noauth @message = I18n.t('messages.noauth') return end params.require :user params.require :group params.require :add add = params[:add] == 'true' begin group = current_user.groups.find_by_name(params[:group]) rescue ActiveRecord::RecordNotFound @status = :notfound @message = I18n.t('messages.group.membership.notfound') return end target_user = User.find_by_screen_name(params[:user]) if add group.add_member target_user if group.members.find_by_user_id(target_user.id).nil? @checked = true @message = I18n.t('messages.group.membership.add') else group.remove_member target_user unless group.members.find_by_user_id(target_user.id).nil? @checked = false @message = I18n.t('messages.group.membership.remove') end @status = :okay @success = true end end
Sapphire/spring.moe
app/controllers/ajax/group_controller.rb
Ruby
mit
2,988
class Ajax::InboxController < ApplicationController rescue_from(ActionController::ParameterMissing) do |param_miss_ex| @status = :parameter_error @message = I18n.t('messages.parameter_error', parameter: param_miss_ex.param.capitalize) @success = false render partial: "ajax/shared/status" end def create unless user_signed_in? @status = :noauth @message = I18n.t('messages.noauth') @success = false return end question = Question.create!(content: QuestionGenerator.generate, author_is_anonymous: true, author_name: 'justask', user: current_user) inbox = Inbox.create!(user: current_user, question_id: question.id, new: true) @status = :okay @message = I18n.t('messages.inbox.create.okay') @success = true @render = render_to_string(partial: 'inbox/entry', locals: { i: inbox }) inbox.update(new: false) end def remove params.require :id inbox = Inbox.find(params[:id]) unless current_user == inbox.user @status = :fail @message = I18n.t('messages.inbox.remove.fail') @success = false return end begin inbox.remove rescue @status = :err @message = I18n.t('messages.error') @success = false return end @status = :okay @message = I18n.t('messages.inbox.remove.okay') @success = true end def remove_all begin Inbox.where(user: current_user).each { |i| i.remove } rescue @status = :err @message = I18n.t('messages.error') @success = false return end @status = :okay @message = I18n.t('messages.inbox.remove_all.okay') @success = true render 'ajax/inbox/remove' end end
Sapphire/spring.moe
app/controllers/ajax/inbox_controller.rb
Ruby
mit
1,817
class Ajax::ModerationController < ApplicationController rescue_from(ActionController::ParameterMissing) do |param_miss_ex| @status = :parameter_error @message = I18n.t('messages.parameter_error', parameter: param_miss_ex.param.capitalize) @success = false render partial: "ajax/shared/status" end def vote params.require :id params.require :upvote report = Report.find(params[:id]) begin current_user.report_vote(report, params[:upvote]) rescue @status = :fail @message = I18n.t('messages.moderation.vote.fail') @success = false return end @count = report.votes @status = :okay @message = I18n.t('messages.moderation.vote.okay') @success = true end def destroy_vote params.require :id report = Report.find(params[:id]) begin current_user.report_unvote report rescue @status = :fail @message = I18n.t('messages.moderation.destroy_vote.fail') @success = false return end @count = report.votes @status = :okay @message = I18n.t('messages.moderation.destroy_vote.okay') @success = true end def destroy_report params.require :id report = Report.find(params[:id]) begin report.deleted = true report.save rescue @status = :fail @message = I18n.t('messages.moderation.destroy_report.fail') @success = false return end @status = :okay @message = I18n.t('messages.moderation.destroy_report.okay') @success = true end def create_comment params.require :id params.require :comment report = Report.find(params[:id]) @success = false begin current_user.report_comment(report, params[:comment]) rescue ActiveRecord::RecordInvalid @status = :rec_inv @message = I18n.t('messages.moderation.create_comment.rec_inv') return end @status = :okay @message = I18n.t('messages.moderation.create_comment.okay') @success = true @render = render_to_string(partial: 'moderation/discussion', locals: { report: report }) @count = report.moderation_comments.all.count end def destroy_comment params.require :comment @status = :err @success = false comment = ModerationComment.find(params[:comment]) unless current_user == comment.user @status = :nopriv @message = I18n.t('messages.moderation.destroy_comment.nopriv') @success = false return end comment.destroy @status = :okay @message = I18n.t('messages.moderation.destroy_comment.okay') @success = true end def ban @status = :err @message = I18n.t('messages.moderation.ban.error') @success = false params.require :user params.require :ban params.require :permaban reason = params[:reason] target = User.find_by_screen_name(params[:user]) unban = params[:ban] == "0" perma = params[:permaban] == "1" buntil = DateTime.strptime params[:until], "%m/%d/%Y %I:%M %p" unless unban or perma if not unban and target.admin? @status = :nopriv @message = I18n.t('messages.moderation.ban.nopriv') @success = false return end if unban target.unban @message = I18n.t('messages.moderation.ban.unban') @success = true elsif perma target.ban nil, reason @message = I18n.t('messages.moderation.ban.perma') else target.ban buntil, reason @message = I18n.t('messages.moderation.ban.temp', date: buntil.to_s) end target.save! @status = :okay @success = target.banned? == !unban end def privilege @status = :err @success = false params.require :user params.require :type params.require :status status = params[:status] == 'true' target_user = User.find_by_screen_name(params[:user]) @message = I18n.t('messages.moderation.privilege.nope') return unless %w(blogger supporter moderator admin contributor translator).include? params[:type].downcase if %w(supporter moderator admin).include?(params[:type].downcase) and !current_user.admin? @status = :nopriv @message = I18n.t('messages.moderation.privilege.nopriv') @success = false return end @checked = status target_user.send("#{params[:type]}=", status) target_user.save! @message = I18n.t('messages.moderation.privilege.checked', privilege: params[:type]) @status = :okay @success = true end end
Sapphire/spring.moe
app/controllers/ajax/moderation_controller.rb
Ruby
mit
4,516
class Ajax::QuestionController < ApplicationController include MarkdownHelper rescue_from(ActionController::ParameterMissing) do |param_miss_ex| @status = :parameter_error @message = I18n.t('messages.parameter_error', parameter: param_miss_ex.param.capitalize) @success = false render partial: "ajax/shared/status" end def destroy params.require :question question = Question.find params[:question] if question.nil? @status = :not_found @message = I18n.t('messages.question.destroy.not_found') @success = false return end if not (current_user.mod? or question.user == current_user) @status = :not_authorized @message = I18n.t('messages.question.destroy.not_authorized') @success = false return end question.destroy! @status = :okay @message = I18n.t('messages.question.destroy.okay') @success = true end def create params.require :question params.require :anonymousQuestion params.require :rcpt begin question = Question.create!(content: params[:question], author_is_anonymous: params[:anonymousQuestion], user: current_user) rescue ActiveRecord::RecordInvalid @status = :rec_inv @message = I18n.t('messages.question.create.rec_inv') @success = false return end unless current_user.nil? current_user.increment! :asked_count unless params[:anonymousQuestion] == 'true' end if params[:rcpt] == 'followers' unless current_user.nil? current_user.followers.each do |f| Inbox.create!(user_id: f.id, question_id: question.id, new: true) end end elsif params[:rcpt].start_with? 'grp:' unless current_user.nil? begin current_user.groups.find_by_name!(params[:rcpt].sub 'grp:', '').members.each do |m| Inbox.create!(user_id: m.user.id, question_id: question.id, new: true) end rescue ActiveRecord::RecordNotFound @status = :not_found @message = I18n.t('messages.question.create.not_found') @success = false return end end else Inbox.create!(user_id: params[:rcpt], question_id: question.id, new: true) end @status = :okay @message = I18n.t('messages.question.create.okay') @success = true end def preview params.require :md @message = I18n.t('messages.question.preview.fail') begin @markdown = markdown params[:md] @message = I18n.t('messages.question.preview.okay') rescue @status = :fail @success = false return end @status = :okay @success = true end end
Sapphire/spring.moe
app/controllers/ajax/question_controller.rb
Ruby
mit
2,757
class Ajax::ReportController < ApplicationController rescue_from(ActionController::ParameterMissing) do |param_miss_ex| @status = :parameter_error @message = I18n.t('messages.parameter_error', parameter: param_miss_ex.param.capitalize) @success = false render partial: "ajax/shared/status" end def create params.require :id params.require :type @status = :err @success = false if current_user.nil? @message = I18n.t('messages.report.create.login') return end unless %w(answer comment question user).include? params[:type] @message = I18n.t('messages.report.create.unknown') return end object = if params[:type] == 'user' User.find_by_screen_name params[:id] else params[:type].strip.capitalize.constantize.find params[:id] end if object.nil? @message = I18n.t('messages.report.create.not_found', parameter: params[:type]) return end current_user.report object, params[:reason] @status = :okay @message = I18n.t('messages.report.create.okay', parameter: params[:type]) @success = true end end
Sapphire/spring.moe
app/controllers/ajax/report_controller.rb
Ruby
mit
1,178
class Ajax::SmileController < ApplicationController rescue_from(ActionController::ParameterMissing) do |param_miss_ex| @status = :parameter_error @message = I18n.t('messages.parameter_error', parameter: param_miss_ex.param.capitalize) @success = false render partial: "ajax/shared/status" end def create params.require :id answer = Answer.find(params[:id]) begin current_user.smile answer rescue @status = :fail @message = I18n.t('messages.smile.create.fail') @success = false return end @status = :okay @message = I18n.t('messages.smile.create.okay') @success = true end def destroy params.require :id answer = Answer.find(params[:id]) begin current_user.unsmile answer rescue @status = :fail @message = I18n.t('messages.smile.destroy.fail') @success = false return end @status = :okay @message = I18n.t('messages.smile.destroy.okay') @success = true end def create_comment params.require :id comment = Comment.find(params[:id]) begin current_user.smile_comment comment rescue @status = :fail @message = I18n.t('messages.smile.create_comment.fail') @success = false return end @status = :okay @message = I18n.t('messages.smile.create_comment.okay') @success = true end def destroy_comment params.require :id comment = Comment.find(params[:id]) begin current_user.unsmile_comment comment rescue @status = :fail @message = I18n.t('messages.smile.destroy_comment.fail') @success = false return end @status = :okay @message = I18n.t('messages.smile.destroy_comment.okay') @success = true end end
Sapphire/spring.moe
app/controllers/ajax/smile_controller.rb
Ruby
mit
1,795
class Ajax::SubscriptionController < ApplicationController before_filter :authenticate_user! rescue_from(ActionController::ParameterMissing) do |param_miss_ex| @status = :parameter_error @message = I18n.t('messages.parameter_error', parameter: param_miss_ex.param.capitalize) @success = false render partial: "ajax/shared/status" end def subscribe params.require :answer @status = 418 @message = I18n.t('messages.subscription.torpedo') state = Subscription.subscribe(current_user, Answer.find(params[:answer])).nil? @success = state == false end def unsubscribe params.require :answer @status = 418 @message = I18n.t('messages.subscription.torpedo') state = Subscription.unsubscribe(current_user, Answer.find(params[:answer])).nil? @success = state == false end end
Sapphire/spring.moe
app/controllers/ajax/subscription_controller.rb
Ruby
mit
838
class AnswerController < ApplicationController def show @answer = Answer.find(params[:id]) @display_all = true if user_signed_in? notif = Notification.where(target_type: "Answer", target_id: @answer.id, recipient_id: current_user.id, new: true).first unless notif.nil? notif.new = false notif.save end notif = Notification.where(target_type: "Comment", target_id: @answer.comments.pluck(:id), recipient_id: current_user.id, new: true) notif.update_all(new: false) unless notif.empty? notif = Notification.where(target_type: "Smile", target_id: @answer.smiles.pluck(:id), recipient_id: current_user.id, new: true) notif.update_all(new: false) unless notif.empty? # @answer.comments.smiles throws notif = Notification.where(target_type: "CommentSmile", target_id: @answer.comment_smiles.pluck(:id), recipient_id: current_user.id, new: true) notif.update_all(new: false) unless notif.empty? end end end
Sapphire/spring.moe
app/controllers/answer_controller.rb
Ruby
mit
997
class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception before_filter :configure_permitted_parameters, if: :devise_controller? before_filter :check_locale before_filter :banned? # check if user wants to read def check_locale return I18n.locale = 'en' if Rails.env.test? if params[:hl].nil? if current_user.present? I18n.locale = current_user.locale elsif not cookies[:lang].nil? I18n.locale = cookies[:lang] else I18n.locale = 'en' end else I18n.locale = params[:hl] if current_user.present? current_user.locale = I18n.locale current_user.save! end end cookies[:lang] = I18n.locale #unless cookies[:allow_cookies].nil? # some EU cookie bullsh- end # check if user got hit by the banhammer of doom def banned? if current_user.present? && current_user.banned? name = current_user.screen_name # obligatory '2001: A Space Odyssey' reference flash[:notice] = t('flash.ban.error', name: name) unless current_user.ban_reason.nil? flash[:notice] += "\n#{t('flash.ban.reason', reason: current_user.ban_reason)}" end if not current_user.permanently_banned? # TODO format banned_until flash[:notice] += "\n#{t('flash.ban.until', time: current_user.banned_until)}" end sign_out current_user redirect_to new_user_session_path end end include ApplicationHelper protected def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:screen_name, :email, :password, :password_confirmation, :remember_me) } devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :screen_name, :email, :password, :remember_me) } devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:screen_name, :email, :password, :password_confirmation, :current_password) } end end
Sapphire/spring.moe
app/controllers/application_controller.rb
Ruby
mit
2,061
Sapphire/spring.moe
app/controllers/concerns/.keep
none
mit
0
class DiscoverController < ApplicationController before_filter :authenticate_user! def index top_x = 10 # only display the top X items @popular_answers = Answer.where("created_at > ?", Time.now.ago(1.week)).order(:smile_count).reverse_order.limit(top_x) @most_discussed = Answer.where("created_at > ?", Time.now.ago(1.week)).order(:comment_count).reverse_order.limit(top_x) @popular_questions = Question.where("created_at > ?", Time.now.ago(1.week)).order(:answer_count).reverse_order.limit(top_x) @new_users = User.where("asked_count > 0").order(:id).reverse_order.limit(top_x) # .user = the user # .question_count = how many questions did the user ask @users_with_most_questions = Question.select('user_id, COUNT(*) AS question_count'). where("created_at > ?", Time.now.ago(1.week)). where(author_is_anonymous: false). group(:user_id). order('question_count'). reverse_order.limit(top_x) # .user = the user # .answer_count = how many questions did the user answer @users_with_most_answers = Answer.select('user_id, COUNT(*) AS answer_count'). where("created_at > ?", Time.now.ago(1.week)). group(:user_id). order('answer_count'). reverse_order.limit(top_x) end end
Sapphire/spring.moe
app/controllers/discover_controller.rb
Ruby
mit
1,294
class GroupController < ApplicationController before_filter :authenticate_user! def index @group = current_user.groups.find_by_name!(params[:group_name]) @timeline = @group.timeline.paginate(page: params[:page]) end end
Sapphire/spring.moe
app/controllers/group_controller.rb
Ruby
mit
235
class InboxController < ApplicationController before_filter :authenticate_user! def show @inbox = Inbox.where(user: current_user).order(:created_at).reverse_order.paginate(page: params[:page]) respond_to do |format| format.html format.js end end end
Sapphire/spring.moe
app/controllers/inbox_controller.rb
Ruby
mit
281
class ModerationController < ApplicationController before_filter :authenticate_user! def index @type = params[:type] @reports = if @type == 'all' Report.where(deleted: false).reverse_order else Report.where(deleted: false).where('LOWER(type) = ?', "reports::#{@type}").reverse_order end end end
Sapphire/spring.moe
app/controllers/moderation_controller.rb
Ruby
mit
374
class NotificationsController < ApplicationController before_filter :authenticate_user! def index @type = params[:type] @notifications = if @type == 'all' Notification.for(current_user) else Notification.for(current_user).where('LOWER(target_type) = ?', @type) end.paginate(page: params[:page]) respond_to do |format| format.html format.js end end end
Sapphire/spring.moe
app/controllers/notifications_controller.rb
Ruby
mit
475
class PublicController < ApplicationController before_filter :authenticate_user! def index @timeline = Answer.joins(:user).where(users: { privacy_allow_public_timeline: true }).all.reverse_order.paginate(page: params[:page]) respond_to do |format| format.html format.js end end end
Sapphire/spring.moe
app/controllers/public_controller.rb
Ruby
mit
313
class QuestionController < ApplicationController def show @question = Question.find(params[:id]) @answers = @question.answers.reverse_order.paginate(page: params[:page]) respond_to do |format| format.html format.js end end end
Sapphire/spring.moe
app/controllers/question_controller.rb
Ruby
mit
259
class ServicesController < ApplicationController skip_before_action :verify_authenticity_token, :only => :create before_action :authenticate_user! def index @services = current_user.services end def create service = Service.initialize_from_omniauth( omniauth_hash ) if current_user.services << service flash[:success] = t('flash.service.create.success') else flash[:error] = t('flash.service.create.error') end if origin redirect_to origin else redirect_to services_path end end def failure Rails.logger.info "oauth error: #{params.inspect}" flash[:error] = t('flash.service.failure') redirect_to services_path end def destroy @service = current_user.services.find(params[:id]) @service.destroy flash[:success] = t('flash.service.destroy') redirect_to services_path end private def origin request.env['omniauth.origin'] end def omniauth_hash request.env['omniauth.auth'] end end
Sapphire/spring.moe
app/controllers/services_controller.rb
Ruby
mit
1,023
class StaticController < ApplicationController def index if user_signed_in? @timeline = current_user.timeline.paginate(page: params[:page]) respond_to do |format| format.html format.js end end end def about @admins = User.where(admin: true).order(:id) end def faq end def privacy_policy end def terms end end
Sapphire/spring.moe
app/controllers/static_controller.rb
Ruby
mit
382
class UserController < ApplicationController before_filter :authenticate_user!, only: %w(edit update edit_privacy update_privacy) def show @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! @answers = @user.answers.reverse_order.paginate(page: params[:page]) if user_signed_in? notif = Notification.where(target_type: "Relationship", target_id: @user.active_relationships.where(target_id: current_user.id).pluck(:id), recipient_id: current_user.id, new: true).first unless notif.nil? notif.new = false notif.save end end respond_to do |format| format.html format.js end end # region Account settings def edit end def update user_attributes = params.require(:user).permit(:display_name, :profile_picture, :profile_header, :motivation_header, :website, :location, :bio, :crop_x, :crop_y, :crop_w, :crop_h, :crop_h_x, :crop_h_y, :crop_h_w, :crop_h_h) if current_user.update_attributes(user_attributes) text = t('flash.user.update.text') text += t('flash.user.update.avatar') if user_attributes[:profile_picture] text += t('flash.user.update.header') if user_attributes[:profile_header] flash[:success] = text else flash[:error] = t('flash.user.update.error') end redirect_to edit_user_profile_path end # endregion # region Privacy settings def edit_privacy end def update_privacy user_attributes = params.require(:user).permit(:privacy_allow_anonymous_questions, :privacy_allow_public_timeline, :privacy_allow_stranger_answers, :privacy_show_in_search) if current_user.update_attributes(user_attributes) flash[:success] = t('flash.user.update_privacy.success') else flash[:error] = t('flash.user.update_privacy.error') end redirect_to edit_user_privacy_path end # endregion # region Groups def groups @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! @groups = if current_user == @user @user.groups else @user.groups.where(private: false) end.all end # endregion def followers @title = 'Followers' @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! @users = @user.followers.reverse_order.paginate(page: params[:page]) @type = :friend render 'show_follow' end def friends @title = 'Following' @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! @users = @user.friends.reverse_order.paginate(page: params[:page]) @type = :friend render 'show_follow' end def questions @title = 'Questions' @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! @questions = @user.questions.where(author_is_anonymous: false).reverse_order.paginate(page: params[:page]) end end
Sapphire/spring.moe
app/controllers/user_controller.rb
Ruby
mit
3,132
module AjaxHelper end
Sapphire/spring.moe
app/helpers/ajax_helper.rb
Ruby
mit
22
module AnswerHelper end
Sapphire/spring.moe
app/helpers/answer_helper.rb
Ruby
mit
24
module ApplicationHelper def nav_entry(body, path, options = {}) options = { badge: nil, badge_color: nil, icon: nil, class: '' }.merge(options) unless options[:icon].nil? body = "#{content_tag(:i, '', class: "mdi-#{options[:icon]}")} #{body}" end unless options[:badge].nil? # TODO: make this prettier? body << " #{ content_tag(:span, options[:badge], class: ("badge#{ " badge-#{options[:badge_color]}" unless options[:badge_color].nil? }"))}" end content_tag(:li, link_to(body.html_safe, path), class: ("#{'active ' if current_page? path}#{options[:class]}")) end def list_group_item(body, path, options = {}) options = { badge: nil, badge_color: nil, class: '' }.merge(options) unless options[:badge].nil? or options[:badge] == 0 # TODO: make this prettier? body << " #{ content_tag(:span, options[:badge], class: ("badge#{ " badge-#{options[:badge_color]}" unless options[:badge_color].nil? }"))}" end content_tag(:a, body.html_safe, href: path, class: ("list-group-item #{'active ' if current_page? path}#{options[:class]}")) end def tooltip(body, tooltip_content, placement = "bottom") content_tag(:span, body, {title: tooltip_content, "data-toggle" => "tooltip", "data-placement" => placement} ) end def time_tooltip(subject, placement = "bottom") tooltip time_ago_in_words(subject.created_at), localize(subject.created_at), placement end def hidespan(body, hide) content_tag(:span, body, class: "hidden-#{hide}") end ## # def bootstrap_color c case c when "error", "alert" "danger" when "notice" "info" else c end end def inbox_count return 0 unless user_signed_in? count = Inbox.select("COUNT(id) AS count") .where(new: true) .where(user_id: current_user.id) .group(:user_id) .order(:count) .first return nil if count.nil? return nil unless count.count > 0 count.count end def notification_count return 0 unless user_signed_in? count = Notification.for(current_user).where(new: true) return nil if count.nil? return nil unless count.count > 0 count.count end def privileged?(user) ((!current_user.nil?) && ((current_user == user) || current_user.mod?)) ? true : false end # @deprecated Use {User#profile_picture.url} instead. def gravatar_url(user) return user.profile_picture.url :medium # return '/cage.png' #return '//www.gravatar.com/avatar' if user.nil? #return "//www.gravatar.com/avatar/#{Digest::MD5.hexdigest(user)}" if user.is_a? String #"//www.gravatar.com/avatar/#{Digest::MD5.hexdigest(user.email)}" end def ios_web_app? user_agent = request.env['HTTP_USER_AGENT'] || 'Mozilla/5.0' # normal MobileSafari.app UA: Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B435 Safari/600.1.4 # webapp UA: Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B435 return true if user_agent.match /^Mozilla\/\d+\.\d+ \(i(?:Phone|Pad|Pod); CPU(?:.*) like Mac OS X\)(?:.*) Mobile(?:\S*)$/ false end def generate_title(name, junction = nil, content = nil, s = false) if s if name[-1].downcase != "s" name = name + "'s" else name = name + "'" end end list = [name] list.push junction unless junction.nil? unless content.nil? content = strip_markdown(content) if content.length > 45 content = content[0..42] + "..." end list.push content end list.push "|", APP_CONFIG['site_name'] list.join " " end def question_title(question) name = user_screen_name question.user, question.author_is_anonymous, false generate_title name, "asked", question.content end def answer_title(answer) name = user_screen_name answer.user, false, false generate_title name, "answered", answer.question.content end def user_title(user, junction = nil) name = user_screen_name user, false, false generate_title name, junction, nil, !junction.nil? end def questions_title(user) user_title user, "questions" end def answers_title(user) user_title user, "answers" end def smiles_title(user) user_title user, "smiles" end def comments_title(user) user_title user, "comments" end def group_title(group) generate_title group.name end # NOTE: when adding new flags, add data here def get_flag_info { # "permanently_banned" => { # key: "banned", # overriding, would be "permanently_banned" # icon: "fa-ban", # no icon if not defined # class: "panel-badge-default" # badge class, defaults to panel-badge-default # }, # commented because we use more than just the flag. "admin" => { icon: "fa-flask", class: "panel-badge-danger" }, "moderator" => { icon: "fa-users", class: "panel-badge-success" }, "supporter" => { icon: "fa-star", class: "panel-badge-warning" }, "contributor" => { icon: "fa-github", class: "panel-badge-primary" }, "blogger" => { icon: "fa-pencil", class: "panel-badge-info" }, "translator" => { icon: "fa-globe", class: "panel-badge-info" } } end end
Sapphire/spring.moe
app/helpers/application_helper.rb
Ruby
mit
5,653
module DiscoverHelper end
Sapphire/spring.moe
app/helpers/discover_helper.rb
Ruby
mit
26
module InboxHelper end
Sapphire/spring.moe
app/helpers/inbox_helper.rb
Ruby
mit
23
module MarkdownHelper def markdown(content) md = Redcarpet::Markdown.new(FlavoredMarkdown, MARKDOWN_OPTS) Sanitize.fragment(md.render(content), EVIL_TAGS).html_safe end def strip_markdown(content) md = Redcarpet::Markdown.new(Redcarpet::Render::StripDown, MARKDOWN_OPTS) CGI.unescape_html(Sanitize.fragment(md.render(content), EVIL_TAGS)).strip end def twitter_markdown(content) md = Redcarpet::Markdown.new(TwitteredMarkdown, MARKDOWN_OPTS) CGI.unescape_html(Sanitize.fragment(md.render(content), EVIL_TAGS)).strip end def raw_markdown(content) md = Redcarpet::Markdown.new(Redcarpet::Render::HTML, RAW_MARKDOWN_OPTS) raw md.render content end def get_markdown(path, relative_to = Rails.root) begin File.read relative_to.join(path) rescue Errno::ENOENT "# Error reading #{relative_to.join(path)}" end end def markdown_io(path, relative_to = Rails.root) markdown get_markdown path, relative_to end def strip_markdown_io(path, relative_to = Rails.root) strip_markdown get_markdown path, relative_to end def twitter_markdown_io(path, relative_to = Rails.root) twitter_markdown get_markdown path, relative_to end def raw_markdown_io(path, relative_to = Rails.root) raw_markdown get_markdown path, relative_to end end
Sapphire/spring.moe
app/helpers/markdown_helper.rb
Ruby
mit
1,331
module ModerationHelper # @param report [Report] def content_url(report) target = report.target case report.type when 'Reports::Answer' show_user_answer_path target.user.screen_name, target.id when 'Reports::Comment' show_user_answer_path target.answer.user.screen_name, target.answer.id when 'Reports::Question' show_user_question_path 'user', target.id when 'Reports::User' show_user_profile_path target.screen_name else '#' end end end
Sapphire/spring.moe
app/helpers/moderation_helper.rb
Ruby
mit
527
module NotificationsHelper end
Sapphire/spring.moe
app/helpers/notifications_helper.rb
Ruby
mit
31
module PublicHelper end
Sapphire/spring.moe
app/helpers/public_helper.rb
Ruby
mit
24
module ServicesHelper end
Sapphire/spring.moe
app/helpers/services_helper.rb
Ruby
mit
26
module StaticHelper end
Sapphire/spring.moe
app/helpers/static_helper.rb
Ruby
mit
24
module SubscribeHelper end
Sapphire/spring.moe
app/helpers/subscribe_helper.rb
Ruby
mit
27
module UserHelper # Decides what user name to show. # @return [String] The user name def user_screen_name(user, anonymous=false, url=true) return APP_CONFIG['anonymous_name'] if user.nil? || anonymous name = user.display_name.blank? ? user.screen_name : user.display_name return link_to(name, show_user_profile_path(user.screen_name), class: "#{"user--banned" if user.banned?}") if url name.strip end end
Sapphire/spring.moe
app/helpers/user_helper.rb
Ruby
mit
429
Sapphire/spring.moe
app/mailers/.keep
none
mit
0
Sapphire/spring.moe
app/models/.keep
none
mit
0
class Answer < ActiveRecord::Base belongs_to :user belongs_to :question has_many :comments, dependent: :destroy has_many :smiles, dependent: :destroy has_many :subscriptions, dependent: :destroy has_many :comment_smiles, through: :comments, source: :smiles after_create do Inbox.where(user: self.user, question: self.question).destroy_all Notification.notify self.question.user, self unless self.question.user == self.user or self.question.user.nil? Subscription.subscribe self.user, self Subscription.subscribe self.question.user, self unless self.question.author_is_anonymous self.user.increment! :answered_count self.question.increment! :answer_count end before_destroy do # mark a report as deleted if it exists rep = Report.where(target_id: self.id, type: 'Reports::Answer') rep.each do |r| unless r.nil? r.deleted = true r.save end end self.user.decrement! :answered_count self.question.decrement! :answer_count self.smiles.each do |smile| Notification.denotify self.user, smile end self.comments.each do |comment| comment.user.decrement! :commented_count Subscription.denotify comment, self end Notification.denotify self.question.user, self Subscription.destruct self end def notification_type(*_args) Notifications::QuestionAnswered end end
Sapphire/spring.moe
app/models/answer.rb
Ruby
mit
1,401
class Comment < ActiveRecord::Base belongs_to :user belongs_to :answer validates :user_id, presence: true validates :answer_id, presence: true has_many :smiles, class_name: "CommentSmile", foreign_key: :comment_id, dependent: :destroy validates :content, length: { maximum: 160 } after_create do Subscription.subscribe self.user, answer, false Subscription.notify self, answer user.increment! :commented_count answer.increment! :comment_count end before_destroy do rep = Report.where(target_id: self.id, type: 'Reports::Comment') rep.each do |r| unless r.nil? r.deleted = true r.save end end Subscription.denotify self, answer user.decrement! :commented_count answer.decrement! :comment_count end def notification_type(*_args) Notifications::Commented end end
Sapphire/spring.moe
app/models/comment.rb
Ruby
mit
862
class CommentSmile < ActiveRecord::Base belongs_to :user belongs_to :comment validates :user_id, presence: true, uniqueness: { scope: :comment_id, message: "already smiled comment" } validates :comment_id, presence: true after_create do Notification.notify comment.user, self unless comment.user == user user.increment! :comment_smiled_count comment.increment! :smile_count end before_destroy do Notification.denotify comment.user, self unless comment.user == user user.decrement! :comment_smiled_count comment.decrement! :smile_count end def notification_type(*_args) Notifications::CommentSmiled end end
Sapphire/spring.moe
app/models/comment_smile.rb
Ruby
mit
657
Sapphire/spring.moe
app/models/concerns/.keep
none
mit
0
class Group < ActiveRecord::Base belongs_to :user has_many :group_members, dependent: :destroy validates :display_name, length: { maximum: 30 } before_validation do self.display_name.strip! self.name = self.display_name.parameterize self.name = '-followers-' if self.name == 'followers' end alias members group_members def add_member(user) GroupMember.create! group: self, user: user end def remove_member(user) GroupMember.where(group: self, user: user).first!.destroy end # @return [Array] the groups' timeline def timeline Answer.where("user_id in (?)", members.pluck(:user_id)).order(:created_at).reverse_order end end
Sapphire/spring.moe
app/models/group.rb
Ruby
mit
679
class GroupMember < ActiveRecord::Base belongs_to :user belongs_to :group end
Sapphire/spring.moe
app/models/group_member.rb
Ruby
mit
82
class Inbox < ActiveRecord::Base belongs_to :user belongs_to :question before_create do raise "User does not want to receive anonymous questions" if self.question.author_is_anonymous and self.question.author_name != 'justask' and !self.user.privacy_allow_anonymous_questions? end def answer(answer_content, user) answer = user.answer(self.question, answer_content) self.destroy answer end def remove self.question.destroy if self.question.can_be_removed? self.destroy end end
Sapphire/spring.moe
app/models/inbox.rb
Ruby
mit
519
class ModerationComment < ActiveRecord::Base belongs_to :user belongs_to :report validates :user_id, presence: true validates :report_id, presence: true validates :content, length: { maximum: 160 } end
Sapphire/spring.moe
app/models/moderation_comment.rb
Ruby
mit
213
class ModerationVote < ActiveRecord::Base belongs_to :user belongs_to :report validates :user_id, presence: true validates :report_id, presence: true end
Sapphire/spring.moe
app/models/moderation_vote.rb
Ruby
mit
162