code
stringlengths
1
1.73M
language
stringclasses
1 value
class LanguageController < ApplicationController def set_lang @session['lang'] = params[:id] redirect_to last_request_uri end end
Ruby
class Admin::User::RolesController < Admin::User::BaseController def index list render :action => :list end def list @roles = Role.find(:all, :order => :title) end def new @role = Role.new(params[:role]) if request.post? if @role.save flash[:notice] = "Role was successfully created" redirec...
Ruby
class Admin::User::UserController < Admin::User::BaseController def index list render :action => :list end def list @users = User.find(:all) end def show @user = User.find(params[:id]) end def edit @user = User.find(params[:id]) @user.attributes = params[:user] @user.edition_mode = true if r...
Ruby
require 'tab.rb' class Admin::User::BaseController < Admin::BaseController before_filter :tab access_control :DEFAULT => 'admin' private def tab # TABS : one tab rendered for each tabs objects in @tabs instance variable @tabs = [ Tab.new(l('USERS'),"user","index") ] end end
Ruby
class Admin::Newsletter::NewsletterController < Admin::Newsletter::EmailsController before_filter :set_page_title access_control :DEFAULT => 'email' def index @mailings = Mailing.find(:all) end def show @mailing = Mailing.find(params[:id]) end def new @mailing = Mailing.new params[:maili...
Ruby
require 'tab.rb' class Admin::Newsletter::EmailsController < Admin::BaseController before_filter :tab access_control :DEFAULT => 'email' private def tab # TABS : one tab rendered for each tabs objects in @tabs instance variable @tabs = [ Tab.new(l('EMAILS'),"newsletter","index"), Tab.new(l(...
Ruby
require 'faster_csv' class Admin::Newsletter::ImportController < Admin::Newsletter::EmailsController before_filter :set_page_title access_control :DEFAULT => 'email_admin' def index @csv_files = CsvFile.find(:all) end def new @csv_file = CsvFile.new end def show @csv_file = CsvFile.fi...
Ruby
class Admin::Newsletter::ListController < Admin::Newsletter::EmailsController before_filter :set_page_title access_control :DEFAULT => 'email_admin' def index @lists = Mailinglist.find(:all) end def show @list = Mailinglist.find(params[:id]) end def new @list = Mailinglist.new params...
Ruby
class Admin::BaseController < ApplicationController layout 'admin' include AuthenticatedSystemUser before_filter :login_required access_control :DEFAULT => 'user' protected def permission_denied redirect_to :controller => '/account', :action => 'denied' return false end end
Ruby
require 'tab.rb' class Admin::Cms::CmsController < Admin::BaseController before_filter :tab access_control :DEFAULT => 'cms' private def tab # TABS : one tab rendered for each tabs objects in @tabs instance variable @tabs = [ Tab.new(l('ARTICLES'),"pages","index"), Tab.new(l('CATEGORIES'),...
Ruby
class Admin::Cms::CategoriesController < Admin::Cms::CmsController access_control [:edit, :new, :delete] => 'cms_admin' def index list render_action 'list' end def list @categories = Category.root end def show @categories = Category.find_by_permalink(params[:id]) || Category.find(params[:id]) @ar...
Ruby
class Admin::Cms::PagesController < Admin::Cms::CmsController access_control [:publish, :unpublish, :archive, :unarchive, :delete ] => 'cms_admin' cache_sweeper :article_sweeper, :only => [:new, :edit, :tag, :publish, :unpublish, :archive, :unarchive, :delete, :upload_image, :upload_attachment] def in...
Ruby
class Admin::Cms::SearchController < Admin::Cms::CmsController def index end def result if request.post? @articles = Article.private_search(params[:query]) else redirect_to :action => :index end end end
Ruby
class ArticlesController < ApplicationController caches_page :show layout "home" before_filter :get_nav_categories, :except => :test_rss before_filter :get_regions, :except => :test_rss def show @article = Article.ez_find(:first) do |article| article.published == 1 article.permalink ...
Ruby
class RegionController < ApplicationController caches_page :show, :article layout "home" before_filter :get_nav_categories before_filter :get_regions before_filter :get_current_region, :except => "index" before_filter :reaction, :only => "article" def index default_region = Category.find_by_perm...
Ruby
class AccountController < ApplicationController include AuthenticatedSystemUser layout 'login' observer :user_observer def index redirect_to(:action => 'signup') unless logged_in? or User.count > 0 end def login return unless request.post? self.current_user = User.authenticate(params[:login], ...
Ruby
require 'localization_settings' require 'switch_language' require 'lib_cms' require 'additional_tag_functions' require 'caboose_memcached' class ApplicationController < ActionController::Base include LocalizationSettings include ExceptionNotifiable include CabooseMemcached include Franck::SwitchLanguage incl...
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/breakpointer'
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/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/destroy'
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/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
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 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/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
class CreateNewsletterMembers < ActiveRecord::Migration def self.up create_table :newsletter_members, :options => 'DEFAULT CHARSET=UTF8' do |t| t.column :email, :string end end def self.down drop_table :newsletter_members end end
Ruby
class AddIndexes < ActiveRecord::Migration def self.up add_index :articles, :published add_index :articles, :permalink add_index :categories, :permalink add_index :taggings, :taggable_id add_index :taggings, :tag_id add_index :tags, :name end def self.down remove_index :...
Ruby
class CreateMailinglist < ActiveRecord::Migration def self.up create_table :mailinglists, :options => 'DEFAULT CHARSET=UTF8' do |t| t.column "name", :string end create_table :ml_members, :options => 'DEFAULT CHARSET=UTF8' do |t| t.column "email", :string end create_table :mai...
Ruby
class CreateArticles < ActiveRecord::Migration def self.up create_table :articles, :force => true, :options => 'DEFAULT CHARSET=UTF8' do |t| t.column :category_id, :integer t.column :title, :string t.column :author, :string t.column :excerpt, :text t.column :excerpt_html, :text t.column :body...
Ruby
class CreateEmails < ActiveRecord::Migration def self.up create_table :emails do |t| t.column :from, :string t.column :to, :string t.column :last_send_attempt, :integer, :default => 0 t.column :mail, :text end end def self.down drop_table :emails end end
Ruby
class AddAuthenticatedTable < ActiveRecord::Migration def self.up create_table "users", :force => true, :options => 'DEFAULT CHARSET=UTF8' do |t| t.column :login, :string, :limit => 40 t.column :email, :string, :limit => 100 t.column :crypted_password, :string, :limit => 40...
Ruby
class CreateMailings < ActiveRecord::Migration def self.up create_table :mailings do |t| t.column :from, :string t.column :to, :text t.column :subject, :string t.column :body, :text end end def self.down drop_table :mailings end end
Ruby
class CreateCsvFiles < ActiveRecord::Migration def self.up create_table :csv_files, :options => 'DEFAULT CHARSET=UTF8' do |t| t.column "content_type", :string t.column "filename", :string t.column "size", :integer t.column "format", :string end end def self.down drop_tab...
Ruby
class CreateAttachments < ActiveRecord::Migration def self.up create_table :attachments, :options => 'DEFAULT CHARSET=UTF8' do |t| t.column :article_id, :integer t.column :file, :string end end def self.down drop_table :attachments end end
Ruby
class CreateNewsletterMemberSectors < ActiveRecord::Migration def self.up create_table :newsletter_member_sectors, :options => 'DEFAULT CHARSET=UTF8' do |t| t.column :newsletter_member_id, :integer t.column :sector_id, :integer end end def self.down drop_table :newsletter_member_sectors ...
Ruby
class AddStructureForTaggings < ActiveRecord::Migration def self.up create_table :taggings, :force => true, :options => 'DEFAULT CHARSET=UTF8' do |t| t.column :taggable_id, :integer t.column :tag_id, :integer t.column :taggable_type, :string end create_table :tags, :force => true, :options => 'DEFAUL...
Ruby
class AddSessions < ActiveRecord::Migration def self.up create_table :sessions, :force => true, :options => 'DEFAULT CHARSET=UTF8' do |t| t.column :session_id, :string t.column :data, :text t.column :updated_at, :datetime end add_index :sessions, :session_id end def self.down ...
Ruby
class CreateImages < ActiveRecord::Migration def self.up create_table :images, :options => 'DEFAULT CHARSET=UTF8' do |t| t.column :article_id, :integer t.column :name, :string end end def self.down drop_table :images end end
Ruby
class CreateCategories < ActiveRecord::Migration def self.up create_table :categories, :force => true, :options => 'DEFAULT CHARSET=UTF8' do |t| t.column :name, :string t.column :parent_id, :integer t.column :position, :integer t.column :permalink, :string end db_name = ActiveRecord::Base::co...
Ruby
module Franck module CMS end end
Ruby
module AuthenticatedSystem protected def logged_in? current_user end # Accesses the current user from the session. def current_user @current_user ||= session[:user] ? User.find_by_id(session[:user]) : nil end # Store the given user in the session. def current_user=(new_user) session[:user]...
Ruby
module CabooseMemcached def memcache_me(key, timeout=600, &blk) unless defined?CACHE # no memcache return block_given? ? yield : nil end # no block given, just delete the cache unless block_given? CACHE.delete(key) return end # cache hit, block was not evalua...
Ruby
# ============================================================================= # A set of rake tasks for invoking the Capistrano automation utility. # ============================================================================= # Invoke the given actions via Capistrano def cap(*parameters) begin require 'rubyg...
Ruby
desc 'cms init' task :cms_init => [ :create_root_category, :create_roles, :create_admin_user, :activate_all_users ] desc "add email and email_admin roles" task :add_email_role => :environment do Role.find_or_create_by_title("email_admin") Role.find_or_create_by_title("email") end desc 'create...
Ruby
module AuthenticatedTestHelper # Sets the current user in the session from the user fixtures. def login_as(user) @request.session[:user] = users(user).id end # Assert the block redirects to the login # # assert_requires_login(:bob) { get :edit, :id => 1 } # def assert_requires_login(user = nil, ...
Ruby
module AuthenticatedUserTestHelper # Sets the current user in the session from the user fixtures. def login_as(user) @request.session[:user] = users(user).id end # Assert the block redirects to the login # # assert_requires_login(:bob) { get :edit, :id => 1 } # def assert_requires_login(user = n...
Ruby
require 'localization_settings' module Franck module SwitchLanguage def locale if not session['lang'].nil? LocalizationSettings::CONFIG[:default_language] = session['lang'] else session['lang'] = 'fr' end end # store current uri in the session. # we ...
Ruby
module AuthenticatedSystemUser protected def logged_in? current_user end # Accesses the current user from the session. def current_user @current_user ||= session[:user] ? User.find_by_id(session[:user]) : nil end # Store the given user in the session. def current_user=(new_user) session[:u...
Ruby
module Franck module AdditionalTagFunctions def get_article_by_tags(wanted_tags) article = [] article << Article.find_by_tag(wanted_tags) #article << Offer.find_by_tag(wanted_tags) article.flatten! article.compact! article.collect! do |a| tags = a.tags.collect d...
Ruby
class String # Converts a post title to its-title-using-dashes # All special chars are stripped in the process def to_url return if self.nil? result = self.downcase # replace quotes by nothing result.gsub!(/['"]/, '') # strip all non word chars result.gsub!(/\W/, ' ') ...
Ruby
require 'iconv' module LocalizationSettings LOCALIZED_STRINGS = {} def l(symbol, *arguments) language = CONFIG[:default_language] symbol = symbol.to_sym if symbol.is_a? String # translation of an LString is simply a call to to_s return symbol.to_s if symbol.is_a? LString # translation ...
Ruby
#/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/dispatcher" -- otherwise performance is severely impaired req...
Ruby
#!/usr/bin/env 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 FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log ...
Ruby
#!/usr/bin/env 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 FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log ...
Ruby
#!/bin/env ruby require File.dirname(__FILE__) + '/../test_helper' class LocalizationSettingsTest < Test::Unit::TestCase include LocalizationSettings # TODO: shouldn't use production data for tests # require File.dirname(__FILE__) + '/../test_helper' TRANSLATION_TABLE = LOCALIZED_STRINGS['localization_s...
Ruby
class Test::Unit::TestCase include AuthenticatedUserTestHelper end
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
require 'mongrel_cluster/recipes' # ============================================================================= # VARIABLES # ============================================================================= set :svn_user, "franck" set :user, "franck" set :application, "cf" set :repository, "http://svn.dglaymann.com/cf...
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
module LocalizationSettings CONFIG = { # Default language :default_language => 'fr', :web_charset => 'utf-8' } if CONFIG[:web_charset] == 'utf-8' $KCODE = 'u' end end
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 web 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. Configuration is done in config/environment.rb and config/environments/*.rb unless defined?(RAILS_ROOT) root_path = File.join(File.dirname(__FILE__), '..') unless RUBY_PLATFORM =~ /mswin32/ require 'pathname' root_path = Pathname.new(root_path).cleanpath(true).to_s end RAILS...
Ruby
ActionController::Routing::Routes.draw do |map| # The priority is based upon order of creation: first created -> highest priority. # You can have the root of your site routed by hooking up '' # -- just remember to delete public/index.html. map.connect '', :controller => "home" # add home_url helper map.ho...
Ruby
class ArticleSweeper < ActionController::Caching::Sweeper observe Article def after_save(record) self.class::sweep end def after_destroy(record) self.class::sweep end def self.sweep cache_dir = ActionController::Base.page_cache_directory unless cache_dir == RAILS_ROOT+"/public" FileU...
Ruby
module ArticlesHelper end
Ruby
module AdminHelper include Admin::CmsHelper end
Ruby
require 'open-uri' require 'rss' module ApplicationHelper include LocalizationSettings def markdown(text) BlueCloth.new(text.gsub(%r{</?notextile>}, '')).to_html end def filtertext(text) RedCloth.new(text.gsub(%r{</?notextile>}, ''), [:hard_breaks]).to_html end def read_more(text, link, lin...
Ruby
module AgendaHelper end
Ruby
module CategoryHelper end
Ruby
module HomeHelper end
Ruby
module Admin::BaseHelper end
Ruby
module Admin::User::UserHelper def display_roles(roles) html = "" roles.each do |role| html << role.title + ', ' end html.gsub(/,\s$/,"") end def display_roles_checkbox_two_columns(user) html = "" col = [] col[0] = "<div>" col[1] = "<div>" html << "<h2>#{l('Roles')}</h2>" html << "<fieldset ...
Ruby
module Admin::User::RolesHelper end
Ruby
module Admin::CmsHelper def link_if_permit(logicstring, name, options = {}, html_options = nil, *parameters_for_method_reference) if permit? logicstring result = "#{link_to name, options, html_options, *parameters_for_method_reference}" end end # display categories in a tree # options : # controller =>...
Ruby
module Admin::Newsletter::RegionalNewsletterHelper end
Ruby
module Admin::Newsletter::NewsletterHelper end
Ruby
module Admin::Newsletter::EmailsHelper end
Ruby
module Admin::Newsletter::ListHelper end
Ruby
module Admin::Newsletter::ImportHelper end
Ruby
module Admin::Newsletter::HtmlNewsletterHelper def show_current_cached_page(html_newsletter) html = [] html << l('Current ') unless html_newsletter.published_at.nil? html << "(#{html_newsletter.published_at.to_formatted_s(:eu_format)})" end html << " : " cached_page_url = RAILS_ROOT + "/public/cach...
Ruby
module Admin::Cms::CategoriesHelper include Admin::CmsHelper end
Ruby
module Admin::Cms::SearchHelper end
Ruby
module Admin::Cms::PagesHelper include Admin::CmsHelper end
Ruby