code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# 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 |
class ActiveRecord::Base
@@white_list_sanitizer = HTML::WhiteListSanitizer.new
class << self
attr_accessor :formatted_attributes
end
cattr_reader :white_list_sanitizer
def self.formats_attributes(*attributes)
(self.formatted_attributes ||= []).push *attributes
before_save :format_attri... | 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 er... | 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.
conf... | 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 be... | 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... | 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
... | Ruby |
ActionController::Routing::Routes.draw do |map|
map.resources :sites, :moderatorships
map.resources :forums, :has_many => :posts do |forum|
forum.resources :topics do |topic|
topic.resources :posts
topic.resource :monitorship
end
forum.resources :posts
end
map.resources :p... | Ruby |
xml.instruct! :xml, :version => "1.0"
xml.feed(:xmlns => "http://www.w3.org/2005/Atom") do |feed|
feed.title "Posts for #{[@forum, @topic].compact * ' > '}"
feed.link :href => request.url
feed.updated @posts.first.created_at.to_s(:rfc3339)
feed.id request.url
for post in @posts do
feed.entry do |e... | Ruby |
require 'md5'
module ApplicationHelper
def feed_icon_tag(title, url)
(@feed_icons ||= []) << { :url => url, :title => title }
link_to image_tag('feed-icon.png', :size => '14x14', :alt => "Subscribe to #{title}"), url
end
def pagination(collection)
if collection.page_count > 1
"<p class... | Ruby |
module TopicsHelper
end
| Ruby |
module ModeratorshipsHelper
end
| Ruby |
module UsersHelper
def user_count
pluralize current_site.users.size, 'user'[:user]
end
def active_user_count
pluralize current_site.users.count('users.posts_count > 0'), 'active user'[:active_user]
end
def lurking_user_count
pluralize current_site.users.count('users.posts_count =... | Ruby |
module ForumsHelper
# used to know if a topic has changed since we read it last
def recent_topic_activity(topic)
return false unless logged_in?
return topic.last_updated_at > ((session[:topics] ||= {})[topic.id] || last_active)
end
# used to know if a forum has changed since we read it last
... | Ruby |
module SessionsHelper
end | Ruby |
module PostsHelper
end
| Ruby |
module SitesHelper
end
| Ruby |
class UserMailer < ActionMailer::Base
def signup_notification(user)
setup_email(user)
@subject += 'Please activate your new account'
@body[:url] = activate_url(user.activation_code, :host => user.site.host)
end
def activation(user)
setup_email(user)
@subject += 'Your account... | Ruby |
class Topic < ActiveRecord::Base
include User::Editable
before_validation_on_create :set_default_attributes
after_create :create_initial_post
before_update :check_for_moved_forum
after_update :set_post_forum_id
before_destroy :count_user_posts_for_counter_cache
after_destroy :update_cached_... | Ruby |
class User
acts_as_state_machine :initial => :pending
state :passive
state :pending, :enter => :do_activation
state :active, :enter => :do_activate
state :suspended
state :deleted, :enter => :do_delete
event :register do
transitions :from => :passive, :to => :pending, :guard => Proc.new {... | Ruby |
require 'digest/sha1'
class User
# Virtual attribute for the unencrypted password
attr_accessor :password
validates_presence_of :login, :email
validates_presence_of :password, :if => :password_required?
validates_presence_of :password_confirmation, :if => :password_r... | Ruby |
module User::Editable
def editable_by?(user)
user && (user.id == user_id || user.moderator_of?(forum))
end
end | Ruby |
class User
# Creates new topic and post.
# Only..
# - sets sticky/locked bits if you're a moderator or admin
# - changes forum_id if you're an admin
#
def post(forum, attributes)
attributes.symbolize_keys!
Topic.new(attributes) do |topic|
topic.forum = forum
topic.user = se... | Ruby |
class User
after_create :set_first_user_as_activated
def set_first_user_as_activated
activate! if site.nil? or site.users.size <= 1
end
def remember_token?
active? && remember_token_expires_at && Time.now.utc < remember_token_expires_at
end
# These create and unset the fields required... | Ruby |
class Moderatorship < ActiveRecord::Base
belongs_to :user
belongs_to :forum
validates_presence_of :user_id, :forum_id
validate :uniqueness_of_relationship
validate :user_and_forum_in_same_site
protected
def uniqueness_of_relationship
if self.class.exists?(:user_id => user_id, :forum_id => fo... | Ruby |
class User < ActiveRecord::Base
concerned_with :validation, :states, :activation, :posting
formats_attributes :bio
belongs_to :site, :counter_cache => true
validates_presence_of :site_id
has_many :posts, :order => "#{Post.table_name}.created_at desc"
has_many :topics, :order => "#{Topic.table_na... | Ruby |
class Site < ActiveRecord::Base
class UndefinedError < StandardError; end
has_many :users, :conditions => {:state => 'active'}
has_many :all_users, :class_name => 'User'
has_many :forums
has_many :topics, :through => :forums
has_many :posts, :through => :forums
validates_presence_of :n... | Ruby |
class Monitorship < ActiveRecord::Base
belongs_to :user
belongs_to :topic
validates_presence_of :user_id, :topic_id
validate :uniqueness_of_relationship
before_create :check_for_inactive
attr_accessible :user_id, :topic_id
protected
def uniqueness_of_relationship
if self.class.exist... | Ruby |
class Forum < ActiveRecord::Base
formats_attributes :description
acts_as_list
validates_presence_of :name
belongs_to :site
attr_readonly :posts_count, :topics_count
has_many :topics, :order => "#{Topic.table_name}.sticky desc, #{Topic.table_name}.last_updated_at desc", :dependent => :d... | Ruby |
class Post < ActiveRecord::Base
include User::Editable
formats_attributes :body
# author of post
belongs_to :user, :counter_cache => true
belongs_to :topic, :counter_cache => true
# topic's forum (set by callback)
belongs_to :forum, :counter_cache => true
# topic's site (set by... | Ruby |
class ForumsController < ApplicationController
before_filter :admin_required, :except => [:index, :show]
# GET /forums
# GET /forums.xml
def index
# reset the page of each forum we have visited when we go back to index
session[:forums_page] = nil
@forums = current_site.ordered_forums
... | Ruby |
class TopicsController < ApplicationController
before_filter :find_forum
before_filter :find_topic, :only => [:show, :edit, :update, :destroy]
def index
respond_to do |format|
format.html { redirect_to forum_path(@forum) }
format.xml do
@topics = find_forum.topics.paginate(:page ... | Ruby |
class PostsController < ApplicationController
before_filter :find_parents
before_filter :find_post, :only => [:edit, :update, :destroy]
# /posts
# /users/1/posts
# /forums/1/posts
# /forums/1/topics/1/posts
def index
@posts = (@parent ? @parent.posts : Post).search(params[:q], :page => curre... | Ruby |
class SitesController < ApplicationController
before_filter :admin_required, :only => [ :destroy, :update, :edit ]
def index
@sites = Site.paginate(:all, :page => current_page, :order => 'host ASC')
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @sites... | Ruby |
# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController
# render new.rhtml
def new
end
def create
reset_session
self.current_user = current_site.users.authenticate(params[:login], params[:password])
if logged_in?
if params[... | 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
include AuthenticatedSystem
helper :all
helper_method :current_page
before_filter :configure_chars... | Ruby |
class ModeratorshipsController < ApplicationController
def create
@moderatorship = Moderatorship.new(params[:moderatorship])
respond_to do |format|
if @moderatorship.save
flash[:notice] = 'Moderatorship was successfully created.'
format.html { redirect_to(@moderatorship.user) }
... | Ruby |
class UsersController < ApplicationController
before_filter :admin_required, :only => [:suspend, :unsuspend, :destroy, :purge, :edit]
before_filter :find_user, :only => [:update, :show, :edit, :suspend, :unsuspend, :destroy, :purge]
before_filter :login_required, :only => [:settings, :update]
def index
... | 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/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'
require 'commands/about'
| Ruby |
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib"))
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__) + '/../../rspec/lib' # For svn
$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 F... | 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
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../rspec/lib' # For svn
$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 F... | 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
require File.dirname(__FILE__) + '/../config/boot'
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 'spec'
exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))
| Ruby |
class CreatePermalinks < ActiveRecord::Migration
def self.up
transaction do
User.paginated_each do |user|
User.update_all ['permalink = ?', PermalinkFu.escape(user.login)], ['id = ?', user.id]
end
Forum.paginated_each do |forum|
Forum.update_all ['permalink = ?', Permalink... | 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'
require 'rspec_on_rails_on_crack'
require 'model_stubbing'
requir... | Ruby |
ModelStubbing.define_models do
time 2007, 6, 15
model Site do
stub :name => 'default', :host => ''
end
model User do
stub :login => 'normal-user', :email => 'normal-user@example.com', :state => 'active',
:salt => '7e3041ebc2fc05a40c60028e2c4901a81035d3cd', :crypted_password => '00742970... | Ruby |
module HtmlFormatting
protected
def format_attributes
self.class.formatted_attributes.each do |attr|
raw = read_attribute attr
linked = auto_link(raw) { |text| truncate(text, 50) }
textilized = RedCloth.new(linked, [:hard_breaks])
textilized.hard_breaks = true if textilized... | Ruby |
module AuthenticatedSystem
protected
def current_site
@current_site ||= Site.find_by_host(request.host) or raise Site::UndefinedError
end
# 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?
cu... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', ... | 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 |
# Be sure to restart your server when you modify this file.
# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attac... | Ruby |
VestalVersions.configure do |config|
# Place any global options here. For example, in order to specify your own version model to use
# throughout the application, simply specify:
#
# config.class_name = "MyCustomVersion"
#
# Any options passed to the "versioned" method in the model itself will override this... | Ruby |
# Be sure to restart your server when you modify this file.
Marketplace::Application.config.session_store :cookie_store, :key => '_Marketplace_session'
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table wi... | Ruby |
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a probl... | Ruby |
Marketplace::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turne... | Ruby |
Marketplace::Application.configure do
# Settings specified here will take precedence over those in config/application.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 w... | Ruby |
Marketplace::Application.configure do
# Settings specified here will take precedence over those in config/application.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 t... | Ruby |
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Marketplace::Application.initialize!
| Ruby |
require 'rubygems'
# Set up gems listed in the Gemfile.
gemfile = File.expand_path('../../Gemfile', __FILE__)
begin
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'
Bundler.setup
rescue Bundler::GemNotFound => e
STDERR.puts e.message
STDERR.puts "Try running `bundle install`."
exit!
end if File.exist?(gem... | Ruby |
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
module Marketplace
class Application < Rails::Application
... | Ruby |
Marketplace::Application.routes.draw do
root :to => "apps#index"
resources :apps do
collection do
post 'exists', 'ids'
end
resources :visuals do
collection do
post 'exists'
end
end
end
resources :app_targets do
collection do
post 'exists'
end
end
... | Ruby |
module ApplicationHelper
end
| Ruby |
module PermissionsHelper
end
| Ruby |
module VisualsHelper
end
| Ruby |
module AppTargetHelper
end
| Ruby |
module AppPermissionHelper
end
| Ruby |
module CommentsHelper
end
| Ruby |
module AppsHelper
end
| Ruby |
class AppTarget < ActiveRecord::Base
belongs_to :app
belongs_to :target
end
| Ruby |
class App < ActiveRecord::Base
validates_uniqueness_of :packageName
has_one :rating, :dependent => :destroy
has_many :visuals, :dependent => :destroy
has_many :comments, :dependent => :destroy
has_many :app_targets
has_many :targets, :through => :app_targets
has_many :app_permissions
has_many :... | Ruby |
class Permission < ActiveRecord::Base
validates_uniqueness_of :name
validates_presence_of :name
has_many :app_permissions
has_many :apps, :through => :app_permissions
end
| Ruby |
class Target < ActiveRecord::Base
has_many :app_targets
has_many :apps, :through => :app_targets
end
| Ruby |
class Comment < ActiveRecord::Base
belongs_to :app
end
| Ruby |
class Rating < ActiveRecord::Base
versioned
belongs_to :app
end
| Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.