Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
macbury committed Aug 6, 2010
1 parent bcf7c17 commit 086d0cf
Show file tree
Hide file tree
Showing 901 changed files with 50,120 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Gemfile
@@ -0,0 +1,32 @@
source 'http://rubygems.org'

gem 'rails', '3.0.0.beta3'

# Bundle edge Rails instead:
#gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'pg'
gem 'color-tools'
gem 'youtube-g'
gem 'less'
gem 'paperclip', :git => 'git://github.com/JasonKing/paperclip.git', :branch => 'rails3'
gem 'libxml-ruby', :require => false
gem 'nokogiri', :require => false
gem "will_paginate", :git => "http://github.com/mislav/will_paginate.git", :branch => "rails3"
# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri', '1.4.1'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for certain environments:
# gem 'rspec', :group => :test
# group :test do
# gem 'webrat'
# end
674 changes: 674 additions & 0 deletions README

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Rakefile
@@ -0,0 +1,10 @@
# 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__)

require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

Rails::Application.load_tasks
73 changes: 73 additions & 0 deletions app/controllers/animes_controller.rb
@@ -0,0 +1,73 @@
class AnimesController < ApplicationController

before_filter :authenticate, :only => [:merge, :invalid, :destroy]
before_filter :prepare_query, :only => [:index, :latest]

def latest
@animes = @query.latest.paginate :per_page => 15, :page => params[:page]
render(:index)
end

def index
@animes = @query.paginate :per_page => 15, :page => params[:page]
end

def invalid
@animes = Anime.where("anidb_id IS NULL").order("created_at DESC").all

end

def show
@anime = Anime.find_by_permalink!(params[:id])
@episodes = @anime.episodes.order('number DESC').all(:include => :links)
@titles = @anime.titles.order('main DESC, name ASC').all
end

def merge
@anime = Anime.find_by_permalink!(params[:id])
if params[:anidb_id]
Title.find_by_anidb_id!(params[:anidb_id])

@destination_anime = Anime.find_or_initialize_by_anidb_id(params[:anidb_id])

if @destination_anime.new_record?
@destination_anime.proposeName
@destination_anime.save
end
else
@destination_anime = Anime.find_by_permalink!(params[:anime_id])
end

@destination_anime = @anime.merge_with_anime(@destination_anime)

if @destination_anime
@anime.destroy
redirect_to @destination_anime
else
logger.debug @destination_anime.errors.full_messages.join(", ")
redirect_to invalid_animes_path
end

end

def destroy
@anime = Anime.find_by_permalink!(params[:id])
@anime.destroy

redirect_to invalid_animes_path
end

protected

def prepare_query
@query = Anime.visible
if params[:letter]
if params[:letter] == "0"
@query = @query.where("name !~* '^[a-z]'") # thank god for postgresql regexp
else
@query = @query.where("name ILIKE ?", "#{params[:letter]}%")
end
end
@query = @query.order("name ASC")
end
end
22 changes: 22 additions & 0 deletions app/controllers/application_controller.rb
@@ -0,0 +1,22 @@
class ApplicationController < ActionController::Base
protect_from_forgery
layout 'application'

before_filter :set_locale

def set_locale
I18n.locale = params[:locale] || :en
end

def default_url_options(options={})
{:locale => I18n.locale.to_s}
end

USER_NAME, PASSWORD = "macbury", "password"

def authenticate
authenticate_or_request_with_http_basic do |user_name, password|
user_name == USER_NAME && password == PASSWORD
end
end
end
15 changes: 15 additions & 0 deletions app/controllers/links_controller.rb
@@ -0,0 +1,15 @@
class LinksController < ApplicationController
layout false
before_filter :load_anime

def show
@link = Link.find(params[:id])
end

protected

def load_anime
@anime = Anime.find_by_permalink!(params[:anime_id])
end

end
15 changes: 15 additions & 0 deletions app/controllers/search_controller.rb
@@ -0,0 +1,15 @@
class SearchController < ApplicationController

def show
@title = Title.find_by_title(params[:query]).anidb_id rescue 0
@animes = Anime.visible.where("animes.anidb_id = ? OR animes.name ILIKE ? OR titles.name ILIKE ?", @title, "%#{params[:query]}%", "%#{params[:query]}%").order("updated_at DESC").paginate(
:joins => [:titles],
:per_page => 15,
:page => params[:page],
:select => "DISTINCT (animes.*)")


redirect_to @animes.first if @animes.size == 1
end

end
85 changes: 85 additions & 0 deletions app/controllers/sources_controller.rb
@@ -0,0 +1,85 @@
class SourcesController < ApplicationController
before_filter :authenticate
# GET /sources
# GET /sources.xml
def index
@sources = Source.all

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @sources }
end
end

# GET /sources/1
# GET /sources/1.xml
def show
@source = Source.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @source }
end
end

# GET /sources/new
# GET /sources/new.xml
def new
@source = Source.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @source }
end
end

# GET /sources/1/edit
def edit
@source = Source.find(params[:id])
end

# POST /sources
# POST /sources.xml
def create
@source = Source.new(params[:source])

respond_to do |format|
if @source.save
format.html { redirect_to(@source, :notice => 'Source was successfully created.') }
format.xml { render :xml => @source, :status => :created, :location => @source }
else
format.html { render :action => "new" }
format.xml { render :xml => @source.errors, :status => :unprocessable_entity }
end
end
end

# PUT /sources/1
# PUT /sources/1.xml
def update
@source = Source.find(params[:id])

respond_to do |format|
if @source.update_attributes(params[:source])
format.html { redirect_to(@source, :notice => 'Source was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @source.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /sources/1
# DELETE /sources/1.xml
def destroy
@source = Source.find(params[:id])
@source.destroy

respond_to do |format|
format.html { redirect_to(sources_url) }
format.xml { head :ok }
end
end

end
19 changes: 19 additions & 0 deletions app/controllers/stylesheets_controller.rb
@@ -0,0 +1,19 @@
class StylesheetsController < ApplicationController
#caches_action :show, :for => 24.hours
respond_to :css

def show
@wallpaper = YAML.load_file(File.join([Rails.root, "config/wallpaper.yml"]))

stylesheet_filename = File.join([Rails.root, 'app', 'stylesheets', "#{params[:name]}.less"])

if File.exists?(stylesheet_filename)
stylesheet = render_to_string(stylesheet_filename, :layout => false)

render :text => Less.parse(stylesheet), :content_type => "text/css"
else
render :text => ".no_file {} ", :content_type => "text/css"
end
end

end
12 changes: 12 additions & 0 deletions app/controllers/tags_controller.rb
@@ -0,0 +1,12 @@
class TagsController < ApplicationController

def index
@tags = Tag.order('name ASC').all
end

def show
@tag = Tag.find_by_permalink!(params[:id])
@animes = @tag.animes.order("name ASC").paginate :per_page => 15, :page => params[:page]
end

end
18 changes: 18 additions & 0 deletions app/helpers/animes_helper.rb
@@ -0,0 +1,18 @@
module AnimesHelper

def description(text)
return if text.nil?
text.gsub!(/\A^\*.+$/i, '')
text.gsub!(/(http:\/\/anidb\.net\/[a-zA-Z0-9]+)\s\[([a-zA-Z0-9\s\/`\-"]+)\]/i, link_to('\2','\1', :target => "_blank"))
text.html_safe
end

def aired_ago(date)
if date.to_datetime >= 7.days.ago.at_beginning_of_day
content_tag :span, distance_of_time_in_words_to_now(date) + " " + t('datetime.distance_in_words.ago'), :title => l(date, :format => :long)
else
content_tag :span, l(date, :format => "%d %b %Y"), :title => distance_of_time_in_words_to_now(date) + " " + t('datetime.distance_in_words.ago')
end
end

end
5 changes: 5 additions & 0 deletions app/helpers/application_helper.rb
@@ -0,0 +1,5 @@
module ApplicationHelper
def rss_link(title, path)
tag :link, :type => 'application/rss+xml', :title => title, :href => path, :rel => "alternate"
end
end
18 changes: 18 additions & 0 deletions app/helpers/tags_helper.rb
@@ -0,0 +1,18 @@
module TagsHelper

def tag_cloud_for_tags(tags,classes=%w( tag1 tag2 tag3 tag4, tag5, tag6, tag7, tag8, tag9, tag10, tag11, tag12 ))
max, min = 0, 0

tags.each do |tag|
max = [tag.taggables_count, max].max
min = [tag.taggables_count, min].min
end

div = ((max - min) / classes.size) + 1

tags.each do |tag|
yield tag, classes[(tag.taggables_count - min) / div]
end
end

end

0 comments on commit 086d0cf

Please sign in to comment.