daveliu (owner)

Revisions

gist: 121960 Download_button fork
public
Description:
my template
Public Clone URL: git://gist.github.com/121960.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
git :init
 
run "echo 'TODO add readme content' > README"
run "touch tmp/.gitignore log/.gitignore"
run "cp config/database.yml config/example_database.yml"
 
file ".gitignore", <<-END
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
END
 
 
# Delete unnecessary files
  run "rm README"
  run "rm public/index.html"
  run "rm public/favicon.ico"
  run "rm public/robots.txt"
  run "rm -f public/javascripts/*"
 
# Download JQuery
  run "curl -L http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js > public/javascripts/jquery.js"
  
file 'app/views/layouts/_flashes.html.erb',
%q{<div id="flash">
<% flash.each do |key, value| -%>
<div id="flash_<%= key %>"><%=h value %></div>
<% end -%>
</div>
}
 
file 'public/javascripts/application.js',
%q{function log() {
if (window && window.console && window.console.log)
for(var i=0, len = arguments.length; i < len; i++)
console.log(arguments[i]);
}
$(document).ready(function(){}
}
 
file 'config/initializers/app_config.rb'
file 'config/initializers/concerns.rb',
%q{class << ActiveRecord::Base
def concerned_with(*concerns)
concerns.each do |concern|
require_dependency "#{name.underscore}/#{concern}"
end
end
end
}
 
file 'config/initializers/active_record.rb',
%q{class ActiveRecord::Base
extend Searchable
end
class ActiveRecord::ConnectionAdapters::AbstractAdapter
@@queries = []
cattr_accessor :queries
def log_info_with_trace(sql, name, runtime)
return unless @logger and @logger.debug?
self.queries << sql
log_info_without_trace(sql, name, runtime)
end
alias_method_chain :log_info, :trace
end
}
 
file 'app/helpers/application_helper.rb',
%q{module ApplicationHelper
def body_class
"#{controller.controller_name} #{controller.controller_name}-#{controller.action_name}"
end
end
}
 
file 'app/views/layouts/application.html.erb',
%q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title><%= PROJECT_NAME.humanize %></title>
<%= stylesheet_link_tag 'application' %>
<%= javascript_include_tag 'jquery' %>
</head>
<body class="<%= body_class %>">
<%= render :partial => 'layouts/flashes' -%>
<%= yield %>
</body>
</html>
}
 
 
file 'lib/searchable.rb',
%q{
#searchable_by :login, :email
module Searchable
def searchable_by(*column_names)
@search_columns = []
[column_names].flatten.each do |name|
@search_columns << name
end
end
 
def search(query, fields=nil, options={})
return [] if query.blank?
with_scope :find => {
:conditions => search_conditions(query, fields) } do
find :all, options
end
end
 
def search_conditions(query, fields=nil)
fields ||= @search_columns
# split the query by commas as well as spaces, just in case
words = query.split(",").map(&:split).flatten
binds = {} # bind symbols
or_frags = [] # OR fragments
count = 1 # to keep count on the symbols and OR fragments
words.each do |word|
like_frags = [fields].flatten.map { |f| "LOWER(#{f}) LIKE :word#{count}" }
or_frags << "(#{like_frags.join(" OR ")})"
binds["word#{count}".to_sym] = "%#{word.to_s.downcase}%"
count += 1
end
[or_frags.join(" AND "), binds]
end
end
}
 
plugin 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git'
plugin 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git'
 
git :add => ".", :commit => "-m 'initial commit'"