Skip to content
This repository was archived by the owner on Jun 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo_token: h8IdAFE23MRKAgB2oEt2236iNhoFE8aAw
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.rbenv-gemsets

Gemfile.lock

# Ignore bundler config.
/.bundle
/vendor/bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
/config/database.yml

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
/coverage

.rspec
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format nested
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: ruby
rvm:
- 2.0.0
before_script:
- cp config/database.yml.example config/database.yml
script:
- RAILS_ENV=test bundle exec rake db:migrate --trace
- bundle exec rake db:test:prepare
- bundle exec rake
65 changes: 65 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
source 'https://rubygems.org'

gem 'rails', '4.0.0'
gem 'sqlite3', group: [:development, :test]
gem 'mysql2', group: [:production]
gem 'haml-rails'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'therubyracer', platforms: :ruby
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
gem 'websocket-rails'
gem 'kaminari'

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'erb2haml'

gem 'guard-bundler'
gem 'guard-migrate'
gem 'guard-livereload'
gem 'guard-pow' if /darwin/ =~ RUBY_PLATFORM
gem 'guard-spring'
gem 'growl'
end

group :development, :test do
gem 'debugger'
gem 'pry-rails'
gem 'pry-remote'
gem 'pry-doc'
gem 'pry-coolline'
gem 'pry-stack_explorer'
gem 'hirb'
gem 'hirb-unicode'
gem 'awesome_print'

gem 'rspec-rails'
gem 'factory_girl_rails'
end

group :test do
gem 'shoulda-matchers'
gem 'database_rewinder'
gem 'forgery'
gem 'capybara'

gem 'coveralls', require: false
end

group :doc do
gem 'sdoc', require: false
end
46 changes: 46 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# vim: ft=ruby

notification :growl

guard 'bundler' do
watch('Gemfile')
end

guard 'spring', :rspec_cli => '--color' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^spec/spec_helper\.rb$}) { |m| 'spec' }
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m|
%W(spec/routing/#{m[1]}_routing_spec.rb spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb spec/requests/#{m[1]}_spec.rb)
end
end

guard 'migrate' do
watch(%r{^db/migrate/(\d+).+\.rb})
watch('db/seeds.rb')
end

guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html))).*}) { |m| "/assets/#{m[3]}" }
end

if /darwin/ =~ RUBY_PLATFORM
guard 'pow' do
watch('.powrc')
watch('.powenv')
watch('.rvmrc')
watch('Gemfile')
watch('Gemfile.lock')
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.*\.rb$})
watch(%r{^config/initializers/.*\.rb$})
end
end

30 changes: 30 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
== README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...


Please feel free to use a different markup language if you do not plan to run
<tt>rake doc:app</tt>.

{<img src="https://coveralls.io/repos/raduwen/peca_uploader/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/raduwen/peca_uploader]
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

PecaUploader::Application.load_tasks
Empty file added app/assets/images/.keep
Empty file.
17 changes: 17 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
//= require websocket_rails/main
3 changes: 3 additions & 0 deletions app/assets/javascripts/upload.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/welcome.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
13 changes: 13 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require_tree .
*/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/upload.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the upload controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/welcome.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the welcome controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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

end
Empty file added app/controllers/concerns/.keep
Empty file.
34 changes: 34 additions & 0 deletions app/controllers/uploads_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class UploadsController < ApplicationController
before_action :set_upload, only: [:destroy]

def new
@upload = Upload.new
end

def create
@upload = Upload.new(upload_params)

if @upload.save
redirect_to root_url, notice: 'Upload was successfully created.'
else
render 'new'
end
end

# DELETE /uploads/1
# DELETE /uploads/1.json
def destroy
@upload.destroy
redirect_to root_url
end

private

def set_upload
@upload = Upload.find(params[:id])
end

def upload_params
params.require(:upload).permit(:file).merge(ip: request.remote_ip)
end
end
4 changes: 4 additions & 0 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class WelcomeController < ApplicationController
# def index
# end
end
5 changes: 5 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module ApplicationHelper
def title(subtitle=nil)
"PecaUploader" << (subtitle.nil? ? "" : "- #{subtitle}")
end
end
Empty file added app/mailers/.keep
Empty file.
Empty file added app/models/.keep
Empty file.
Empty file added app/models/concerns/.keep
Empty file.
29 changes: 29 additions & 0 deletions app/models/upload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Upload < ActiveRecord::Base
attr_accessor :file

before_validation :set_attributes_from_file, :if => Proc.new { |instance| instance.new_record? }

validates :filename, presence: true, format: { with: /\.[A-Za-z]+\Z/ }
validates :ext, presence: true
validates :ip, presence: true

private

def set_attributes_from_file
set_filename
set_ext
set_data
end

def set_data
self.data = @file.read
end

def set_filename
self.filename = @file.original_filename
end

def set_ext
self.ext = File.extname(@file.original_filename)
end
end
9 changes: 9 additions & 0 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!!!
%html
%head
%title= title ? title : "PecaUploader"
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= javascript_include_tag "application", "data-turbolinks-track" => true
= csrf_meta_tags
%body
= yield
14 changes: 14 additions & 0 deletions app/views/uploads/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
= form_for upload do |f|
- if upload.errors.any?
#error_explanation
%h2= "#{pluralize(upload.errors.count, "error")} prohibited this upload from being saved:"
%ul
- upload.errors.full_messages.each do |msg|
%li= msg

.actions
= f.label :file
= f.file_field :file
= f.label :comment
= f.text_field :comment
= f.submit 'Upload'
2 changes: 2 additions & 0 deletions app/views/uploads/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ファイルのアップロード
= render 'form', upload: @upload
3 changes: 3 additions & 0 deletions app/views/welcome/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%ul
%li Top Rate
%li Today
3 changes: 3 additions & 0 deletions bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
4 changes: 4 additions & 0 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
4 changes: 4 additions & 0 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run
2 changes: 2 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
exec $(dirname $0)/spring rspec "$@"
18 changes: 18 additions & 0 deletions bin/spring
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby

# This is a special way of invoking the spring gem in order to
# work around the performance issue discussed in
# https://github.com/rubygems/rubygems/pull/435

glob = "{#{Gem::Specification.dirs.join(",")}}/spring-*.gemspec"
candidates = Dir[glob].to_a.sort

spec = Gem::Specification.load(candidates.last)

if spec
spec.activate
load spec.bin_file("spring")
else
$stderr.puts "Could not find spring gem in #{Gem::Specification.dirs.join(", ")}."
exit 1
end
4 changes: 4 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
Loading