diff --git a/.components b/.components new file mode 100644 index 0000000..fed7ac3 --- /dev/null +++ b/.components @@ -0,0 +1,9 @@ +--- +:orm: activerecord +:test: none +:mock: none +:script: none +:renderer: none +:stylesheet: none +:namespace: Embadge +:migration_format: number diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0c7972 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +log/**/* +tmp/**/* +vendor/gems/* +!vendor/gems/cache/ +.sass-cache/* +db/*.db +.*.sw* diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..af6cfd8 --- /dev/null +++ b/Gemfile @@ -0,0 +1,34 @@ +source 'https://rubygems.org' + +# Padrino supports Ruby version 1.9 and later +# ruby '2.1.0' + +# Distribute your app as a gem +# gemspec + +# Server requirements +# gem 'thin' # or mongrel +# gem 'trinidad', :platform => 'jruby' + +# Optional JSON codec (faster performance) +# gem 'oj' + +# Project requirements +gem 'rake' + +# Component requirements +gem 'activerecord', '>= 3.1', :require => 'active_record' +gem 'sqlite3' + +# Test requirements + +# Padrino Stable Gem +gem 'padrino', '0.13.1' + +# Or Padrino Edge +# gem 'padrino', :github => 'padrino/padrino-framework' + +# Or Individual Gems +# %w(core support gen helpers cache mailer admin).each do |g| +# gem 'padrino-' + g, '0.13.1' +# end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..455c003 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,85 @@ +GEM + remote: https://rubygems.org/ + specs: + 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) + arel (6.0.3) + builder (3.2.2) + enumerable-lazy (0.0.1) + i18n (0.7.0) + json (1.8.3) + mail (2.6.4.rc2) + mime-types (>= 1.16, < 4) + mime-types (2.4.3) + minitest (5.7.0) + moneta (0.7.20) + mustermann19 (0.4.0) + enumerable-lazy + padrino (0.13.1) + padrino-admin (= 0.13.1) + padrino-cache (= 0.13.1) + padrino-core (= 0.13.1) + padrino-gen (= 0.13.1) + padrino-helpers (= 0.13.1) + padrino-mailer (= 0.13.1) + padrino-support (= 0.13.1) + padrino-admin (0.13.1) + padrino-core (= 0.13.1) + padrino-helpers (= 0.13.1) + padrino-cache (0.13.1) + moneta (~> 0.7.0) + padrino-core (= 0.13.1) + padrino-helpers (= 0.13.1) + padrino-core (0.13.1) + activesupport (>= 3.1) + mustermann19 + padrino-support (= 0.13.1) + rack-protection (>= 1.5.0) + sinatra (~> 1.4.6) + thor (~> 0.18) + padrino-gen (0.13.1) + bundler (~> 1.0) + padrino-core (= 0.13.1) + padrino-helpers (0.13.1) + i18n (~> 0.6, >= 0.6.7) + padrino-support (= 0.13.1) + tilt (~> 1.4.1) + padrino-mailer (0.13.1) + mail (~> 2.5) + padrino-core (= 0.13.1) + padrino-support (0.13.1) + activesupport (>= 3.1) + rack (1.6.0) + rack-protection (1.5.3) + rack + rake (10.4.2) + sinatra (1.4.6) + rack (~> 1.4) + rack-protection (~> 1.4) + tilt (>= 1.3, < 3) + sqlite3 (1.3.11) + thor (0.18.1) + thread_safe (0.3.5) + tilt (1.4.1) + tzinfo (1.2.2) + thread_safe (~> 0.1) + +PLATFORMS + ruby + +DEPENDENCIES + activerecord (>= 3.1) + padrino (= 0.13.1) + rake + sqlite3 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..743ec99 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +require 'bundler/setup' +require 'padrino-core/cli/rake' + +PadrinoTasks.use(:database) +PadrinoTasks.use(:activerecord) +PadrinoTasks.init diff --git a/app/app.rb b/app/app.rb new file mode 100644 index 0000000..ad874ab --- /dev/null +++ b/app/app.rb @@ -0,0 +1,66 @@ +module Embadge + class App < Padrino::Application + use ConnectionPoolManagement + register Padrino::Mailer + register Padrino::Helpers + + enable :sessions + + ## + # Caching support. + # + # register Padrino::Cache + # enable :caching + # + # You can customize caching store engines: + # + # set :cache, Padrino::Cache.new(:LRUHash) # Keeps cached values in memory + # set :cache, Padrino::Cache.new(:Memcached) # Uses default server at localhost + # set :cache, Padrino::Cache.new(:Memcached, :server => '127.0.0.1:11211', :exception_retry_limit => 1) + # set :cache, Padrino::Cache.new(:Memcached, :backend => memcached_or_dalli_instance) + # set :cache, Padrino::Cache.new(:Redis) # Uses default server at localhost + # set :cache, Padrino::Cache.new(:Redis, :host => '127.0.0.1', :port => 6379, :db => 0) + # set :cache, Padrino::Cache.new(:Redis, :backend => redis_instance) + # set :cache, Padrino::Cache.new(:Mongo) # Uses default server at localhost + # set :cache, Padrino::Cache.new(:Mongo, :backend => mongo_client_instance) + # set :cache, Padrino::Cache.new(:File, :dir => Padrino.root('tmp', app_name.to_s, 'cache')) # default choice + # + + ## + # Application configuration options. + # + # set :raise_errors, true # Raise exceptions (will stop application) (default for test) + # set :dump_errors, true # Exception backtraces are written to STDERR (default for production/development) + # set :show_exceptions, true # Shows a stack trace in browser (default for development) + # set :logging, true # Logging in STDOUT for development and file for production (default only for development) + # set :public_folder, 'foo/bar' # Location for static assets (default root/public) + # set :reload, false # Reload application files (default in development) + # set :default_builder, 'foo' # Set a custom form builder (default 'StandardFormBuilder') + # set :locale_path, 'bar' # Set path for I18n translations (default your_apps_root_path/locale) + # disable :sessions # Disabled sessions by default (enable if needed) + # disable :flash # Disables sinatra-flash (enabled by default if Sinatra::Flash is defined) + # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application) + # + + ## + # You can configure for a specified environment like: + # + # configure :development do + # set :foo, :bar + # disable :asset_stamp # no asset timestamping for dev + # end + # + + ## + # You can manage errors like: + # + # error 404 do + # render 'errors/404' + # end + # + # error 500 do + # render 'errors/500' + # end + # + end +end diff --git a/bin/embadge b/bin/embadge new file mode 100755 index 0000000..ca28252 --- /dev/null +++ b/bin/embadge @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)+'/..') + +# Start the app with Padrino::Server +require 'bundler/setup' +require 'padrino-core/cli/launcher' + +ARGV.unshift('start') if ARGV.first.nil? || ARGV.first.start_with?('-') +Padrino::Cli::Launcher.start ARGV + +# Start the app with Rack::Server +#require "rack" +#Rack::Server.start diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..63045a0 --- /dev/null +++ b/config.ru @@ -0,0 +1,9 @@ +#!/usr/bin/env rackup +# encoding: utf-8 + +# This file can be used to start Padrino, +# just execute it from the command line. + +require File.expand_path("../config/boot.rb", __FILE__) + +run Padrino.application diff --git a/config/apps.rb b/config/apps.rb new file mode 100644 index 0000000..0cb6822 --- /dev/null +++ b/config/apps.rb @@ -0,0 +1,36 @@ +## +# This file mounts each app in the Padrino project to a specified sub-uri. +# You can mount additional applications using any of these commands below: +# +# Padrino.mount('blog').to('/blog') +# Padrino.mount('blog', :app_class => 'BlogApp').to('/blog') +# Padrino.mount('blog', :app_file => 'path/to/blog/app.rb').to('/blog') +# +# You can also map apps to a specified host: +# +# Padrino.mount('Admin').host('admin.example.org') +# Padrino.mount('WebSite').host(/.*\.?example.org/) +# Padrino.mount('Foo').to('/foo').host('bar.example.org') +# +# Note 1: Mounted apps (by default) should be placed into the project root at '/app_name'. +# Note 2: If you use the host matching remember to respect the order of the rules. +# +# By default, this file mounts the primary app which was generated with this project. +# However, the mounted app can be modified as needed: +# +# Padrino.mount('AppName', :app_file => 'path/to/file', :app_class => 'BlogApp').to('/') +# + +## +# Setup global project settings for your apps. These settings are inherited by every subapp. You can +# override these settings in the subapps as needed. +# +Padrino.configure_apps do + # enable :sessions + set :session_secret, 'ac2bf22d4285cabbdb6146b0a5cd2eae3452fde141a23b0cfa59d1eaa53477b3' + set :protection, :except => :path_traversal + set :protect_from_csrf, true +end + +# Mounts the core application for this project +Padrino.mount('Embadge::App', :app_file => Padrino.root('app/app.rb')).to('/') diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000..2f44f1a --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,49 @@ +# Defines our constants +RACK_ENV = ENV['RACK_ENV'] ||= 'development' unless defined?(RACK_ENV) +PADRINO_ROOT = File.expand_path('../..', __FILE__) unless defined?(PADRINO_ROOT) + +# Load our dependencies +require 'bundler/setup' +Bundler.require(:default, RACK_ENV) + +## +# ## Enable devel logging +# +# Padrino::Logger::Config[:development][:log_level] = :devel +# Padrino::Logger::Config[:development][:log_static] = true +# +# ## Enable logging of source location +# +# Padrino::Logger::Config[:development][:source_location] = true +# +# ## Configure your I18n +# +# I18n.default_locale = :en +# I18n.enforce_available_locales = false +# +# ## Configure your HTML5 data helpers +# +# Padrino::Helpers::TagHelpers::DATA_ATTRIBUTES.push(:dialog) +# text_field :foo, :dialog => true +# Generates: +# +# ## Add helpers to mailer +# +# Mail::Message.class_eval do +# include Padrino::Helpers::NumberHelpers +# include Padrino::Helpers::TranslationHelpers +# end + +## +# Add your before (RE)load hooks here +# +Padrino.before_load do +end + +## +# Add your after (RE)load hooks here +# +Padrino.after_load do +end + +Padrino.load! diff --git a/config/database.rb b/config/database.rb new file mode 100644 index 0000000..366ae17 --- /dev/null +++ b/config/database.rb @@ -0,0 +1,63 @@ +## +# You can use other adapters like: +# +# ActiveRecord::Base.configurations[:development] = { +# :adapter => 'mysql2', +# :encoding => 'utf8', +# :reconnect => true, +# :database => 'your_database', +# :pool => 5, +# :username => 'root', +# :password => '', +# :host => 'localhost', +# :socket => '/tmp/mysql.sock' +# } +# +ActiveRecord::Base.configurations[:development] = { + :adapter => 'sqlite3', + :database => Padrino.root('db', 'embadge_development.db') + +} + +ActiveRecord::Base.configurations[:production] = { + :adapter => 'sqlite3', + :database => Padrino.root('db', 'embadge_production.db') + +} + +ActiveRecord::Base.configurations[:test] = { + :adapter => 'sqlite3', + :database => Padrino.root('db', 'embadge_test.db') + +} + +# Setup our logger +ActiveRecord::Base.logger = logger + +if ActiveRecord::VERSION::MAJOR.to_i < 4 + # Raise exception on mass assignment protection for Active Record models. + ActiveRecord::Base.mass_assignment_sanitizer = :strict + + # Log the query plan for queries taking more than this (works + # with SQLite, MySQL, and PostgreSQL). + ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5 +end + +# Doesn't include Active Record class name as root for JSON serialized output. +ActiveRecord::Base.include_root_in_json = false + +# Store the full class name (including module namespace) in STI type column. +ActiveRecord::Base.store_full_sti_class = true + +# Use ISO 8601 format for JSON serialized times and dates. +ActiveSupport.use_standard_json_time_format = true + +# Don't escape HTML entities in JSON, leave that for the #json_escape helper +# if you're including raw JSON in an HTML page. +ActiveSupport.escape_html_entities_in_json = false + +# Now we can establish connection with our db. +ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env]) + +# Timestamps are in the utc by default. +ActiveRecord::Base.default_timezone = :utc diff --git a/db/migrate/001_create_users.rb b/db/migrate/001_create_users.rb new file mode 100644 index 0000000..41b38b3 --- /dev/null +++ b/db/migrate/001_create_users.rb @@ -0,0 +1,15 @@ +class CreateUsers < ActiveRecord::Migration + def self.up + create_table :users do |t| + t.string :name + t.integer :github_id + t.integer :github_handle + t.string :email + t.timestamps + end + end + + def self.down + drop_table :users + end +end diff --git a/db/migrate/002_create_badges.rb b/db/migrate/002_create_badges.rb new file mode 100644 index 0000000..3ddb288 --- /dev/null +++ b/db/migrate/002_create_badges.rb @@ -0,0 +1,17 @@ +class CreateBadges < ActiveRecord::Migration + def self.up + create_table :badges do |t| + t.references :user_id + t.string :uuid + t.string :label + t.string :title + t.string :url + t.boolean :is_public + t.timestamps + end + end + + def self.down + drop_table :badges + end +end diff --git a/db/migrate/003_create_badge_infos.rb b/db/migrate/003_create_badge_infos.rb new file mode 100644 index 0000000..89c4b08 --- /dev/null +++ b/db/migrate/003_create_badge_infos.rb @@ -0,0 +1,17 @@ +class CreateBadgeInfos < ActiveRecord::Migration + def self.up + create_table :badge_infos do |t| + t.references :badge_id + t.boolean :is_active + t.integer :created_by + t.string :version_start + t.string :version_end + t.string :version_range + t.timestamps + end + end + + def self.down + drop_table :badge_infos + end +end diff --git a/db/migrate/004_create_votes.rb b/db/migrate/004_create_votes.rb new file mode 100644 index 0000000..60acd78 --- /dev/null +++ b/db/migrate/004_create_votes.rb @@ -0,0 +1,14 @@ +class CreateVotes < ActiveRecord::Migration + def self.up + create_table :votes do |t| + t.references :user + t.references :badge_info + t.text :comment + t.timestamps + end + end + + def self.down + drop_table :votes + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..53c1d0a --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,50 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 4) do + + create_table "badge_infos", force: :cascade do |t| + t.integer "badge_id_id" + t.boolean "is_active" + t.integer "created_by" + t.string "version_start" + t.string "version_end" + t.string "version_range" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "badges", force: :cascade do |t| + t.integer "user_id_id" + t.string "uuid" + t.string "label" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "users", force: :cascade do |t| + t.string "name" + t.string "email" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "votes", force: :cascade do |t| + t.integer "user_id" + t.integer "badge_info_id" + t.text "comment" + t.datetime "created_at" + t.datetime "updated_at" + end + +end diff --git a/lib/connection_pool_management_middleware.rb b/lib/connection_pool_management_middleware.rb new file mode 100644 index 0000000..94aa2d3 --- /dev/null +++ b/lib/connection_pool_management_middleware.rb @@ -0,0 +1,9 @@ +class ConnectionPoolManagement + def initialize(app) + @app = app + end + + def call(env) + ActiveRecord::Base.connection_pool.with_connection { @app.call(env) } + end +end diff --git a/models/badge.rb b/models/badge.rb new file mode 100644 index 0000000..102efc9 --- /dev/null +++ b/models/badge.rb @@ -0,0 +1,5 @@ +class Badge < ActiveRecord::Base + + belongs_to :user + has_many :badge_infos +end diff --git a/models/badge_info.rb b/models/badge_info.rb new file mode 100644 index 0000000..351f758 --- /dev/null +++ b/models/badge_info.rb @@ -0,0 +1,5 @@ +class BadgeInfo < ActiveRecord::Base + + has_many :votes + belongs_to :badge +end diff --git a/models/user.rb b/models/user.rb new file mode 100644 index 0000000..a66032d --- /dev/null +++ b/models/user.rb @@ -0,0 +1,5 @@ +class User < ActiveRecord::Base + + has_many :badges + has_many :votes +end diff --git a/models/vote.rb b/models/vote.rb new file mode 100644 index 0000000..4f1dede --- /dev/null +++ b/models/vote.rb @@ -0,0 +1,3 @@ +class Vote < ActiveRecord::Base + +end diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..4e26b19 Binary files /dev/null and b/public/favicon.ico differ