code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# Uninstall hook code here
| Ruby |
require 'has_parent'
require 'breadcrumbs_helper'
ActiveRecord::Base.send :include, ActsCrummy::HasParent
ActionView::Base.send :include, ActsCrummy::BreadcrumbsHelper
| Ruby |
module Shoulda
module ActiveRecord
module Matchers
def be_child_to(name)
AssociationMatcher.new(:is_child_to, name)
end
class AssociationMatcher
protected
alias_method :old_macro_description, :macro_description
def macro_description
@macro.... | Ruby |
module ActsCrummy #:nodoc:
# This module is mixed into ActiveRecord::Base to provide methods to help define
# the direct hierarcy in the model structure of a project, so that breadcrumbs
# can be rendered dynamically from it.
module HasParent
# the self.included/class << base trick is all for the s... | Ruby |
module ActsCrummy #:nodoc:
# This module is mixed into ActionView::Base to provide the ability to render
# breadcrumbs using the structure from the models.
module BreadcrumbsHelper
DEFAULT_BREADCRUMB_SEPARATOR = ' > '
# Renders breadcrumbs up the model hierarchy starting with <tt>child</tt>,
... | Ruby |
require 'pcr_web_apps/acts_as_address'
require 'pcr_web_apps/has_web'
ActiveRecord::Base.class_eval do
include PcrWebApps::Addresses
include PcrWebApps::Webs
end
| Ruby |
class CreateActsAsAddressTable < ActiveRecord::Migration
def self.up
create_table :base_addresses, :id => false, :force => true do |t|
t.string :line1, :limit => 256, :null => false
t.string :line2, :limit => 256
t.string :city, :null => false, :limit => 128
t.string :state, :null => false... | Ruby |
require_dependency 'rails_generator/base'
require_dependency 'rails_generator/lookup'
# Here only to make the class instantiable in the console
require_dependency "rails_generator"
class ActsAsAddressGenerator < Rails::Generator::Base
#default_options :force_street => false, :force_phone =>false
self.spec = Rail... | Ruby |
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the acts_as_address plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentation for... | Ruby |
# desc "Explaining what the task does"
# task :acts_as_address do
# # Task goes here
# end
| Ruby |
# Uninstall hook code here
| Ruby |
# Install hook code here
| Ruby |
module PcrWebApps
module Webs
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def has_url(options = {})
configuration = { :field_name => :url,
:force => false}
configuration.update(options) if options.is_a?(Hash)
text ... | Ruby |
module PcrWebApps
module Addresses
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def acts_as_address(options={})
configuration = { :force_street => false,
:force_phone => false}
configuration.update(options) if options.is_a?... | Ruby |
# ActsAsAddress
| Ruby |
require 'rubygems'
require 'active_support'
require 'active_support/test_case' | Ruby |
require 'find'
def find_regex_in_file(f, regexp)
file = File.new f, 'r'
lines = file.readlines
file.close()
count = 0
lines.each{
|line|
count += 1
line.scan(regexp){
puts "Line:#{count}\t #{line}"
}
}
end
###########################################
def find_file(path, regex, file_name_patterns... | Ruby |
########################################
#
#
#
#
#
require File.join(File.expand_path(File.dirname(__FILE__)), 'base.rb')
#
def new_action name
content = ruby_template 'action.rbt'
#puts content
result = create_file 'Action', "#{name}.php", content
end
#
def list_action()
# List all APIs.
end
#
d... | Ruby |
########################################
# Author: Healer
# Email: healer_kx@163.com
#
#
#
require File.join(File.expand_path(File.dirname(__FILE__)), 'base.rb')
def gsub_content content, name, group
content.gsub!(/\{%\$name%\}/, name)
content.gsub!(/\{%\$name-low%\}/, name.downcase)
content.gsub!(/\... | Ruby |
########################################
# Author: Healer
# Email: healer_kx@163.com
#
#
#
require File.join(File.expand_path(File.dirname(__FILE__)), 'base.rb')
class Compiler
#
def append_begin
content=<<HCJ_BEGIN
$fragments =
{
'null' :'<strong>Null</strong>',
'undefined' :'<strong>Undefined</stro... | Ruby |
$mode_name, $module_name, *$args = ARGV
class Everest
ModeInstall = "install"
ModeNew = "new"
ModeUpdate = "update"
ModeFind = "find"
ModeDelete = "del"
ModeList = "ls"
ModeClean = "clean"
TypeAction = "action"
TypeWidget ... | Ruby |
########################################
#
#
#
#
#
# scp -P 2001 ~/svn/YContactTranslate/a.log yuzhongmin@172.16.1.97:/opt/webroot/translate.youlianxi.com
config = File.new './scp.config', 'r'
config.readlines.each{
|line|
line.strip!
if (line.length > 0)
value = line[ line.index('=') + 1 .. -1]
value.strip!
... | Ruby |
########################################
#
#
#
#
#
require File.join(File.expand_path(File.dirname(__FILE__)), 'base.rb')
#p mode
#p name
#p args
# ruby api.rb new <name>
def new_api name
end
#ruby api.rb list
def list_api()
# List all APIs.
end
# ruby api.rb del <name>
def del_api name
puts "Delete API #... | Ruby |
########################################
#
#
#
#
#
require 'open-uri'
def read_uri uri
return open(uri) do |http|
body = http.read
return body
end
end
uri, = *ARGV
p read_uri uri | Ruby |
########################################
#
#
#
#
#
require File.join(File.expand_path(File.dirname(__FILE__)), 'base.rb')
require 'nokogiri'
#
def combine_css name
end
#
def find_css source_file, css_file
html = file_content source_file
doc = Nokogiri::HTML(html)
doc.xpath('//body/child::*').each{|a| puts "LI... | Ruby |
def return_using_procnew
a_proc = Proc.new { return "Hi" }
a_proc.call
"Last line in the method"
end
#=> “ Hi”
def return_using_lambda
a_proc = lambda { return "Hi" }
a_proc.call
"Last line in the method"
end
#p return_using_procnew
p Proc.new{}
p '----'
p lambda{}
#=> "Last line in the method" | Ruby |
########################################
#
#
#
#
#
require File.join(File.expand_path(File.dirname(__FILE__)), 'base.rb')
def create_view name
# Write HTML file
content = ruby_template './Rbts/view.rbt'
content.gsub!(/\{%\$name%\}/, name.downcase)
path = project_widget_path group, Everest::TypeView... | Ruby |
#################################################
#
def list_all_smarty_var file_name, regex
if File.exists? file_name
file = File.open file_name, 'r'
content = file.read
regex = /\{%\s*\$[a-zA-Z0-9_]+%\}/ if !regex
content.scan(regex).each do
|w|
yield(w)... | Ruby |
$path_base = '/Users/healer/git/healer.com'
class CSS
#
def combine_css_file css_file_name
css_file_name.gsub!(/"/, '')
css_file_name.gsub!(/'/, '')
fn = File.join($path_base, css_file_name)
if File.exists? fn
p fn
end
end
#
def combine_css_files main_css
path = File.dirname(main_css)
... | Ruby |
class <%= class_name %>Observer < ActiveRecord::Observer
def after_create(<%= file_name %>)
<%= class_name %>Notifier.deliver_signup_notification(<%= file_name %>)
end
def after_save(<%= file_name %>)
<%= class_name %>Notifier.deliver_activation(<%= file_name %>) if <%= file_name %>.recently_activated?
... | Ruby |
class <%= class_name %>Notifier < ActionMailer::Base
def signup_notification(<%= file_name %>)
setup_email(<%= file_name %>)
@subject += 'Please activate your new account'
@body[:url] = "http://YOURSITE/account/activate/#{<%= file_name %>.activation_code}"
end
def activation(<%= file_name %>)
... | Ruby |
class AuthenticatedMailerGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
# Check for class naming collisions.
m.class_collisions class_path, "#{class_name}Notifier", "#{class_name}NotifierTest", "#{class_name}Observer"
# Controller, helper, views, and test directories.
... | Ruby |
class <%= controller_class_name %>Controller < ApplicationController
# Be sure to include AuthenticationSystem in Application Controller instead
include AuthenticatedSystem
# If you want "remember me" functionality, add this before_filter to Application Controller
before_filter :login_from_cookie
# say somet... | Ruby |
module AuthenticatedSystem
protected
# Returns true or false if the user is logged in.
# Preloads @current_<%= file_name %> with the user model if they're logged in.
def logged_in?
current_<%= file_name %> != :false
end
# Accesses the current <%= file_name %> from the session.
def c... | Ruby |
module <%= controller_class_name %>Helper
end | Ruby |
module AuthenticatedTestHelper
# Sets the current <%= file_name %> in the session from the <%= file_name %> fixtures.
def login_as(<%= file_name %>)
@request.session[:<%= file_name %>] = <%= file_name %> ? <%= table_name %>(<%= file_name %>).id : nil
end
def content_type(type)
@request.env['Content-Typ... | Ruby |
require 'digest/sha1'
class <%= class_name %> < ActiveRecord::Base
# Virtual attribute for the unencrypted password
attr_accessor :password
validates_presence_of :login, :email, :first_name, :last_name
validates_presence_of :password, :if => :password_required?
validates_presence_of... | Ruby |
class <%= migration_name %> < ActiveRecord::Migration
def self.up
create_table "<%= table_name %>", :force => true do |t|
t.column :first_name, :string, :limit => 20, :null => false
t.column :last_name, :string, :limit => 20, :null => false
t.column :middle_nam... | Ruby |
class AuthenticatedGenerator < Rails::Generator::NamedBase
attr_reader :controller_name,
:controller_class_path,
:controller_file_path,
:controller_class_nesting,
:controller_class_nesting_depth,
:controller_class_name,
... | Ruby |
puts IO.read(File.join(File.dirname(__FILE__), 'README')) | Ruby |
require 'acts_as_keyed_taggable'
ActiveRecord::Base.send(:include, ActiveRecord::Acts::KeyedTaggable)
require File.dirname(__FILE__) + '/lib/keyed_tagging'
require File.dirname(__FILE__) + '/lib/keyed_tag'
| Ruby |
class KeyedTagging < ActiveRecord::Base
belongs_to :keyed_tag
belongs_to :taggable, :polymorphic => true
def self.tagged_class(taggable)
ActiveRecord::Base.send(:class_name_of_active_record_descendant, taggable.class).to_s
end
def self.find_taggable(tagged_class, tagged_id)
tagged_class.constantiz... | Ruby |
class KeyedTag < ActiveRecord::Base
has_many :keyed_taggings
def self.parse(list)
tag_names = []
# first, pull out the quoted tags
list.gsub!(/\"(.*?)\"\s*/ ) { tag_names << $1; "" }
# then, replace all commas with a space
#list.gsub!(/,/, " ")
# then, get whatever's left
tag_names.c... | Ruby |
module ActiveRecord
module Acts #:nodoc:
module KeyedTaggable #:nodoc:
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def acts_as_keyed_taggable(options = {})
write_inheritable_attribute(:acts_as_keyed_taggable_options, {
... | Ruby |
require 'pcr_web_apps/acts_as_person'
ActiveRecord::Base.class_eval do
include PcrWebApps::Person
end
| Ruby |
class CreateActsAsPersonTable < ActiveRecord::Migration
def self.up
create_table :base_persons, :id => false, :force => true do |t|
t.string :first_name, :limit => 64, :null => false
t.string :initial, :limit => 8
t.string :last_name, :limit => 64, :null => false
t.string :email, :limit =... | Ruby |
require_dependency 'rails_generator/base'
require_dependency 'rails_generator/lookup'
# Here only to make the class instantiable in the console
require_dependency "rails_generator"
class ActsAsPersonGenerator < Rails::Generator::Base
self.spec = Rails::Generator::Spec.new File.basename(__FILE__), __FILE__, nil
d... | Ruby |
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the acts_as_person plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentation for ... | Ruby |
# desc "Explaining what the task does"
# task :acts_as_person do
# # Task goes here
# end
| Ruby |
# Uninstall hook code here
| Ruby |
# Install hook code here
| Ruby |
module PcrWebApps
module Person
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def acts_as_person(options={})
configuration = { :force_last_name => true,
:force_email => true}
configuration.update(options) if options.is_a?(Ha... | Ruby |
require 'rubygems'
require 'active_support'
require 'active_support/test_case' | Ruby |
# desc "Explaining what the task does"
# task :acts_as_countable do
# # Task goes here
# end | Ruby |
# Install hook code here
| Ruby |
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the acts_as_countable plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentation for the acts_as_coun... | Ruby |
# Uninstall hook code here
| Ruby |
# Include hook code here
require 'acts_as_countable'
ActiveRecord::Base.send(:include, Jesse::Acts::Countable)
| Ruby |
class Count < ActiveRecord::Base
belongs_to :countable, :polymorphic => true
def self.find_counts_for_countable(countable_str, countable_id)
find(:first,
:conditions => ["countable_type = ? and countable_id = ?", countable_str, countable_id]
)
end
def self.find_countable(countable_str, ... | Ruby |
# ActsAsCountable
module Jesse
module Acts #:nodoc:
module Countable #:nodoc:
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def acts_as_countable
has_many :counts, :as => :countable, :dependent => :destroy, :order => 'cr... | Ruby |
# desc "Explaining what the task does"
# task :acts_as_guid do
# # Task goes here
# end | Ruby |
class <%= class_name %> < ActiveRecord::Migration
def self.up
create_table :guids, :force => true do |t|
t.column :guid, :string, :null => false
end
add_index "guids", ["guid"], :name => "guids_guid_key", :unique => true
end
def self.down
drop_table :guids
end
end
| Ruby |
class GuidMigrationGenerator < Rails::Generator::NamedBase
def initialize(runtime_args, runtime_options = {})
runtime_args << 'add_guids_table' if runtime_args.empty?
super
end
def manifest
record do |m|
m.migration_template 'migration.rb', 'db/migrate'
end
end
end
| Ruby |
# Install hook code here
| Ruby |
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the acts_as_guid plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentation for the acts_as_guid plug... | Ruby |
# Uninstall hook code here
| Ruby |
require 'acts_as_guid' | Ruby |
require 'active_support'
require 'active_record'
module ActiveRecord
module Acts #:nodoc:
module Guided #:nodoc:
GUID_LENGTH = 10
def self.append_features(base)
super
base.extend(ClassMethods)
end
module ClassMethods
def acts_as_guid(options = {})
# now, finally... | Ruby |
require 'acts_as_node'
require 'asset_tag_helper_patches'
ActiveRecord::Base.send :include, ActsAsNode
ActionView::Base.send :include, ActsAsNodeViewHelper | Ruby |
class ActsAsNodeController < ActionController::Base
def generate_graph(options = {})
@root = params[:class_name].to_s.constantize.find(params[:root].to_i)
children_accessors_hash = YAML.load(params[:children_accessors])
@children_accessors = ({params[:class_name].to_s.to_sym => []}).merge(children_accessors_h... | Ruby |
require "fileutils"
class ActsAsNodeGenerator < Rails::Generator::Base
def manifest
class_path = ''
record do |m|
# Model directory
m.directory File.join('app/controllers', class_path)
# Model classes
m.template 'acts_as_node_controller.rb', File.join('a... | Ruby |
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'fileutils'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the acts_as_node plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentation for t... | Ruby |
require 'fileutils'
desc 'Updates application with the necessary javascripts for unobtrusive_javascript.'
task :update_scripts do
print "Hola"
FileUtils.cp_r Dir['assets/javascripts/jsviz'], 'public/javascripts'
end
desc 'Removes the javascripts for the plugin.'
task :remove_scripts do
FileUtils.rm_r '../../../... | Ruby |
# Uninstall hook code here
| Ruby |
require 'fileutils'
# I show the README file.
puts IO.read(File.join(File.dirname(__FILE__), 'README'))
# Install hook code here
FileUtils.cp_r Dir[File.join(File.dirname(__FILE__), 'assets/javascripts/jsviz')], RAILS_ROOT + '/public/javascripts'
FileUtils.cp_r Dir[File.join(File.dirname(__FILE__), 'assets/javascr... | Ruby |
#
# To change this template, choose Tools | Templates
# and open the template in the editor.
module ActsAsNodeViewHelper
public
NODE_INSTANTIATION = "
var isSVG = layout.svg;
isSVG = false;
if (isSVG) {
var nodeElement = null;
if (dataNode.picture!=null && dataNode.picture.l... | Ruby |
# ActsAsNode
module ActsAsNode
end
| Ruby |
module ActionView::Helpers::AssetTagHelper
alias_method :rails_javascript_include_tag, :javascript_include_tag
# Adds a new option to Rails' built-in <tt>javascript_include_tag</tt>
# helper - <tt>:unobtrusive</tt>. Works in the same way as <tt>:defaults</tt> - specifying
# <tt>:unobtrusive</tt> will make s... | Ruby |
# Include hook code here
require 'active_record'
require "#{File.dirname(__FILE__)}/lib/acts_as_hot_record" | Ruby |
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the acts_as_hot_record plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentation for the acts_as_hot... | Ruby |
# desc "Explaining what the task does"
# task :acts_as_hot_record do
# # Task goes here
# end | Ruby |
# Uninstall hook code here
| Ruby |
# Install hook code here
| Ruby |
# ActsAsHotRecord
# a simple plugin module that flags a record as hot
# and get the records base on its hotness
# @author: Marjun Pagalan
#
module June
module Acts
# ----------------------
# acts_as_hot_record
# flags the record as a hot_record for site_owners/site_admin to show on their home p... | Ruby |
class HotModel < ActiveRecord::Base
acts_as_hot_record
end
class HotModelModified < ActiveRecord::Base
set_table_name 'hot_model_modified'
acts_as_hot_record :level => 100..105 , :force => false
end
| Ruby |
ActiveRecord::Schema.define do
create_table :hot_models, :force => true do |dr|
dr.column :name, :string
dr.column :created_at, :timestamp
dr.column :hotness_level, :integer
dr.column :hotness_expired_at, :datetime
dr.column :hotness_at, :datetime
end
c... | Ruby |
$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'test/unit'
require File.expand_path(File.join(File.dirname(__FILE__), '/../../../../config/environment.rb'))
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
if... | Ruby |
# Make sure that ActiveScaffold has already been included
ActiveScaffold rescue throw "should have included ActiveScaffold plug in first. Please make sure that this overwrite plugging comes alphabetically after the ActiveScaffold plug in"
# Load our overrides
load 'config/core.rb'
load 'config/config_list.rb'
l... | Ruby |
# see active_scaffold/uninstall.rb
| Ruby |
# Workaround a problem with script/plugin and http-based repos.
# See http://dev.rubyonrails.org/ticket/8189
Dir.chdir(Dir.getwd.sub(/vendor.*/, '')) do
##
## Copy over asset files (javascript/css/images) from the plugin directory to public/
##
def copy_files(source_path, destination_path, directory)
source, destin... | Ruby |
module ActiveScaffold::Config
class Core
# configures where the active_scaffold_config_list plugin itself is located. there is no instance version of this.
cattr_accessor :cl_as_plugin_directory
@@cl_as_plugin_directory = File.expand_path(__FILE__).match(/vendor\/plugins\/([^\/]*)/)[1]
# the ac... | Ruby |
module ActiveScaffold::Config
class ConfigList < Form
self.crud_type = :create
def initialize(*args)
super
@available_columns = Array.new
@default_columns = Array.new
end
# global level configuration
# --------------------------
# the ActionLink for this action
... | Ruby |
module ActiveScaffold
module Helpers
module ViewHelpers
# Add the cf_as plugin includes
def active_scaffold_includes_with_cf_as
css = stylesheet_link_tag(ActiveScaffold::Config::Core.asset_path(:stylesheet, 'cf_as-stylesheet.css'))
ie_css = stylesheet_link_tag(ActiveScaffold::Con... | Ruby |
module ActiveScaffold::Actions
module ConfigList
def self.included(base)
#base.verify :method => :post,
# :only => :config_list,
# :redirect_to => { :action => :index }
base.before_filter :exclude_columns
end
def prepare_config_list
... | Ruby |
# Make sure that ActiveScaffold has already been included
ActiveScaffold rescue throw "should have included ActiveScaffold plug in first. Please make sure that this overwrite plugging comes alphabetically after the ActiveScaffold plug in"
# set our directory
$:.unshift(File.dirname(__FILE__))
# Load our overri... | Ruby |
# see active_scaffold/uninstall.rb
| Ruby |
# Workaround a problem with script/plugin and http-based repos.
# See http://dev.rubyonrails.org/ticket/8189
Dir.chdir(Dir.getwd.sub(/vendor.*/, '')) do
##
## Copy over asset files (javascript/css/images) from the plugin directory to public/
##
def copy_files(source_path, destination_path, directory)
source, destin... | Ruby |
module ActiveScaffold::Config
class Core
# configures where the active_scaffold_config_list plugin itself is located. there is no instance version of this.
cattr_accessor :cl_as_plugin_directory
@@cl_as_plugin_directory = File.expand_path(__FILE__).match(/vendor\/plugins\/([^\/]*)/)[1]
# the ac... | Ruby |
module ActiveScaffold::Config
class ConfigList < Form
self.crud_type = :create
def initialize(*args)
super
@available_columns = Array.new
@default_columns = Array.new
@enabled = true
end
# global level configuration
# --------------------------
# the Action... | Ruby |
module ActiveScaffold
module Helpers
module ViewHelpers
# Add the cf_as plugin includes
def active_scaffold_includes_with_cf_as(frontend = :default)
css = stylesheet_link_tag(ActiveScaffold::Config::Core.asset_path('cf_as-stylesheet.css', frontend))
ie_css = stylesheet_link_tag(A... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.