code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
if defined?(ActiveRecord)
# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
# Store the full clas... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
| Ruby |
# A Site key gives additional protection against a dictionary attack if your
# DB is ever compromised. With no site key, we store
# DB_password = hash(user_password, DB_user_salt)
# If your database were to be compromised you'd be vulnerable to a dictionary
# attack on all your stupid users' passwords. With a site... | Ruby |
# replace with the name of your application
set :application, "Write-A-Story"
# replace with the HTTP (NOT HTTPS) read-only URL of your Google Code SVN
set :repository, "http://write-a-story.googlecode.com/svn/trunk/"
# directory for deployment on remote machine
set :deploy_to, "/mnt/app"
# If you aren't using Subve... | Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Full error repor... | Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.ca... | Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between... | Ruby |
# Be sure to restart your server when you modify this file
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
# ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
#RAILS_GEM_VERSION = '2.... | Ruby |
# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
module Rails
class << self
def boot!
unless booted?
preinitialize
pick_boot.run
end
end
def booted?
... | Ruby |
ActionController::Routing::Routes.draw do |map|
map.resources :tags
map.connect '/users/:id/make_mod', :controller => 'users', :action => 'make_moderator'
map.connect '/users/:id/remove_mod', :controller => 'users', :action => 'remove_moderator'
map.logout '/logout', :controller => 'sessions', :action => 'd... | Ruby |
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
Dir['lib/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy'
| Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def generate_random_story
stories = Story.find(:all)
stories[rand(stories.length)]
end
def snippet(summary)
wordcount = 30
summary.split[0..(wordcount-1)].join(" ") + (summary... | Ruby |
module LinesHelper
end
| Ruby |
module UsersHelper
#
# Use this to wrap view elements that the user can't access.
# !! Note: this is an *interface*, not *security* feature !!
# You need to do all access control at the controller level.
#
# Example:
# <%= if_authorized?(:index, User) do link_to('List all users', users_path) end %> ... | Ruby |
module StoriesHelper
def find_contributors(story)
users = {}
story.lines.each do |line|
users[line.user.id] = nil
end
users.each_key do |user_id|
user_id
end
end
def get_user(user_id)
User.find(user_id)
end
end
| Ruby |
module TagsHelper
def tag_font_size(id)
@max_size = tag_max_size
@tag_size = tag_story_length(id)
Integer(Float(@tag_size) / Float(@max_size) * 8)
end
def make_name(name, id)
name + " (" + tag_story_length(id).to_s + ")"
end
def tag_story_length(id)
@tag = Tag.find(id)
@tag.stor... | Ruby |
module SessionsHelper
end | Ruby |
module RatingHelper
end
| Ruby |
module CommentsHelper
end
| Ruby |
class Line < ActiveRecord::Base
belongs_to :story
belongs_to :user
validates_presence_of :line
# validates_length_of :line, :maximum => 500, :allow_blank => true
validates_presence_of :story
validates_associated :story
validates_presence_of :user
validates_associated :user
end
| Ruby |
class Story < ActiveRecord::Base
require File.dirname(__FILE__) + '/../../lib/lingua/en/readability'
acts_as_rateable
has_many :lines
has_and_belongs_to_many :tags
has_many :comments
belongs_to :user
validates_presence_of :title
validates_length_of :title, :maximum => 100, :allow_blan... | Ruby |
require 'digest/sha1'
class User < ActiveRecord::Base
include Authentication
include Authentication::ByPassword
include Authentication::ByCookieToken
has_many :stories
has_many :lines
validates_presence_of :login
validates_length_of :login, :within => 3..40
validates_uniqueness_of :l... | Ruby |
class Tag < ActiveRecord::Base
has_and_belongs_to_many :stories
end
| Ruby |
class Comment < ActiveRecord::Base
end
| Ruby |
class Rating < ActiveRecord::Base
end | Ruby |
class StoriesController < ApplicationController
before_filter :login_required, :except => [:index, :show, :report, :flag_line, :remove_flag, :fetch_earlier]
before_filter :check_user, :only => [:edit, :update, :destroy]
after_filter :store_location, :only => [:index, :new, :show, :edit]
@@lines_f... | Ruby |
class RatingController < ApplicationController
def rate
if logged_in?
@story = Story.find(params[:id])
Rating.delete_all(["rateable_type = 'Story' AND rateable_id = ? AND user_id = ?",
@story.id, current_user.id])
@story.add_rating Rating.new(:rating => params[:rating],
... | Ruby |
class LinesController < ApplicationController
before_filter :login_required
before_filter :get_story
before_filter :check_user, :except => [:create, :new]
before_filter :check_same_user, :only => [:create]
before_filter :check_last_line, :except => [:create, :new]
before_filter :check_restrictions, :on... | Ruby |
class CommentsController < ApplicationController
# GET /comments
# GET /comments.xml
def index
@comments = Comment.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @comments }
end
end
# GET /comments/1
# GET /comments/1.xml
def show
... | Ruby |
# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController
# render new.rhtml
def new
end
def create
logout_keeping_session!
user = User.authenticate(params[:login], params[:password])
if user
# Protects against session fixation attack... | Ruby |
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
include AuthenticatedSystem
# See ActionController::Reques... | Ruby |
class TagsController < ApplicationController
# GET /tags
# GET /tags.xml
def index
@tags = Tag.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @tags }
end
end
# GET /tags/1
# GET /tags/1.xml
def show
@tag = Tag.find(params[:id])
... | Ruby |
class UsersController < ApplicationController
before_filter :check_root, :only => [:make_moderator, :remove_moderator]
after_filter :store_location, :only => [:show]
# render new.rhtml
def new
@user = User.new
end
def index
@users = User.find(:all)
end
def make_moderator
@... | Ruby |
# 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.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/dbconsole'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/console'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/runner'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/request'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/profiler'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/profiler'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/request'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/plugin'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/destroy'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
require 'commands/about' | Ruby |
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib"))
require 'rubygems'
require 'spec'
exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))
| Ruby |
#!/usr/bin/env ruby
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin
require 'rubygems'
require 'drb/drb'
require 'rbconfig'
require 'spec'
require 'optparse'
# This is based on Florian Weber's TDDMate
module Spec
module Runner
class RailsSpecServer
... | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/dbconsole'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/runner'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/generate'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/console'
| Ruby |
#!/usr/bin/env ruby
ENV['RSPEC'] = 'true' # allows autotest to discover rspec
ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
$stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH")
| Ruby |
#!/usr/bin/env ruby
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin
require 'rubygems'
require 'drb/drb'
require 'rbconfig'
require 'spec'
require 'optparse'
# This is based on Florian Weber's TDDMate
module Spec
module Runner
class RailsSpecServer
... | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/reaper'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/inspector'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/inspector'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/spawner'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/reaper'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/spawner'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/destroy'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/generate'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'
| Ruby |
#!/usr/bin/env ruby
ENV['RSPEC'] = 'true' # allows autotest to discover rspec
ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
$stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH")
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
require 'commands/about' | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/plugin'
| Ruby |
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib"))
require 'rubygems'
require 'spec'
exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))
| Ruby |
class RenameRatingsInStories < ActiveRecord::Migration
def self.up
rename_column :stories, :rating, :story_rating
add_column :stories, :rating, :integer
end
def self.down
rename_column :stories, :story_rating, :rating
remove_column :stories, :rating, :integer
end
end
| Ruby |
class CreateRatings < ActiveRecord::Migration
def self.up
create_table :ratings, :force => true do |t|
t.column :rating, :integer, :default => 0
t.column :created_at, :datetime, :null => false
t.column :rateable_type, :string, :limit => 15,
:default => "", :null => false
t.col... | Ruby |
class CreateUsers < ActiveRecord::Migration
def self.up
create_table "users", :force => true do |t|
t.column :login, :string, :limit => 40
t.column :name, :string, :limit => 100, :default => '', :null => true
t.column :email, :string, ... | Ruby |
class CreateStories < ActiveRecord::Migration
def self.up
create_table :stories do |t|
t.string :title
t.string :rating
t.text :summary
t.references :user
t.string :type
t.timestamps
end
end
def self.down
drop_table :stories
end
end
| Ruby |
class StoriesTagsMapping < ActiveRecord::Migration
def self.up
create_table :stories_tags, :id=>false do |t|
t.column :story_id, :integer
t.column :tag_id, :integer
end
end
def self.down
drop_table :stories_tags
end
end
| Ruby |
class AddModeratorFieldToUser < ActiveRecord::Migration
def self.up
add_column :users, :moderator, :boolean
end
def self.down
remove_column :users, :moderator
end
end
| Ruby |
class CreateTags < ActiveRecord::Migration
def self.up
create_table :tags do |t|
t.string :name
t.timestamps
end
end
def self.down
drop_table :tags
end
end
| Ruby |
class AddLineCountToStory < ActiveRecord::Migration
def self.up
add_column :stories, :max_line_length, :integer, :default=>500
end
def self.down
drop_column :stories, :max_line_length
end
end
| Ruby |
class CreateLines < ActiveRecord::Migration
def self.up
create_table :lines do |t|
t.text :line
t.boolean :inappropriate, :default => false
t.references :user
t.references :story
t.timestamps
end
end
def self.down
drop_table :lines
end
end
| Ruby |
class AddReportingUsertoLine < ActiveRecord::Migration
def self.up
add_column :lines, :reporting_user, :string
end
def self.down
drop_column :lines, :reporting_user
end
end
| Ruby |
class FixIdiocy < ActiveRecord::Migration
def self.up
rename_column :stories, :type, :typ
end
def self.down
rename_column :stories, :typ, :type
end
end
| Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'spec/rails/story_adapter' | Ruby |
dir = File.dirname(__FILE__)
Dir[File.expand_path("#{dir}/**/*.rb")].uniq.each do |file|
require file
end | Ruby |
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'spec'
require 'spec/rails'
Spec::Runner.configure do |config|
# If you're not using ActiveRecord ... | Ruby |
module AuthenticatedSystem
protected
# Returns true or false if the user is logged in.
# Preloads @current_user with the user model if they're logged in.
def logged_in?
!!current_user
end
# Accesses the current user from the session.
# Future calls avoid the database because nil is not ... | Ruby |
raise "To avoid rake task loading problems: run 'rake clobber' in vendor/plugins/rspec" if File.directory?(File.join(File.dirname(__FILE__), *%w[.. .. vendor plugins rspec pkg]))
raise "To avoid rake task loading problems: run 'rake clobber' in vendor/plugins/rspec-rails" if File.directory?(File.join(File.dirname(__FIL... | Ruby |
module AuthenticatedTestHelper
# Sets the current user in the session from the user fixtures.
def login_as(user)
@request.session[:user_id] = user ? users(user).id : nil
end
def authorize_as(user)
@request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials... | Ruby |
namespace :deploy do
namespace :mongrel do
set :mongrel_clean, false
set :mongrel_rails, 'mongrel_rails'
set :mongrel_conf, nil
def set_mongrel_conf
set :mongrel_conf, "/etc/mongrel.yml" unless mongrel_conf
end
desc "Setup mongrel cluster configuration"
task :configure, :ro... | Ruby |
module Lingua
module EN
# The module Lingua::EN::Sentence takes English text, and attempts to split it
# up into sentences, respecting abbreviations.
module Sentence
EOS = "\001" # temporary end of sentence marker
Titles = [ 'jr', 'mr', 'mrs', 'ms', 'dr', 'prof', 'sr', 'sen', 'rep',
'rev', 'gov', ... | Ruby |
module Lingua
module EN
# The class Lingua::EN::Readability takes English text and analyses formal
# characteristic
class Readability
require 'lingua/en/syllable'
require 'lingua/en/sentence'
attr_reader :text, :paragraphs, :sentences, :words, :frequencies
# The constructor accepts the text to be a... | Ruby |
module Lingua
module EN
# The module Lingua::EN::Syllable contains a single class method, +syllable+,
# which will use the most accurate technique available to determine the number
# syllables in a string containing a word passed to it.
# The exact definition of the function depends on the availability of the
# Carnegi... | Ruby |
module Lingua
module EN
module Syllable
# Uses english word patterns to guess the number of syllables. A single module
# method is made available, +syllables+, which, when passed an english word,
# will return the number of syllables it estimates are in the word.
# English orthography (the representation of spo... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispat... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispat... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
#
# You may specify the path to the FastCGI crash log (a log of unhandled
# exceptions which forced the FastCGI instance to exit, great for debugging)
# and the number of requests to process before running garbage collection.
#
# By default, the Fast... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispat... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispat... | Ruby |
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
#
# You may specify the path to the FastCGI crash log (a log of unhandled
# exceptions which forced the FastCGI instance to exit, great for debugging)
# and the number of requests to process before running garbage collection.
#
# By default, the Fast... | Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
class Test::Unit::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
# in a transaction that's rolled back on completion. This ensures that the
# test datab... | Ruby |
#
# << Haru Free PDF Library 2.0.2 >> -- line_demo.rb
#
# http://libharu.org/
#
# Copyright (c) 1999-2006 Takeshi Kanno
#
# Permission to use, copy, modify, distribute and sell this software
# and its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear... | Ruby |
#
# << Haru Free PDF Library 2.0.6 >> -- ext_gstate_demo.rb
#
# http://libharu.org/
#
# Copyright (c) 1999-2006 Takeshi Kanno
#
# Permission to use, copy, modify, distribute and sell this software
# and its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice ... | Ruby |
#
# << Haru Free PDF Library 2.0.0 >> -- text_demo2.rb
#
# Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
#
# Permission to use, copy, modify, distribute and sell this software
# and its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.