Skip to content

Instantly share code, notes, and snippets.

require 'lib/portfolio'
require 'vendor/sinatra/lib/sinatra'
require 'RedCloth'
set :views, 'views'
set :public, 'public'
helpers do
def project_image(project, size = :medium)
%{<img src="/images/projects/#{project.slug}_#{size}.jpg" alt="#{project}"/>}
module Portfolio
class Project < StaticModel::Base
set_data_file File.join('data', 'projects.yml')
def to_s
"#{title}"
end
def category_classes
classes = []
@quirkey
quirkey / snippet.rb
Created December 17, 2008 16:24 — forked from mrb/snippet.rb
module ActionView
module Helpers
class InstanceTag
def to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0")
options = options.stringify_keys
options["type"] = "checkbox"
options["value"] = checked_value
if options.has_key?("checked")
cv = options.delete "checked"
checked = cv == true || cv == "checked"
Let's make a list of Sinatra-based apps!
Apps:
- http://github.com/cschneid/irclogger "Sinatra based irclogger.com"
- http://github.com/rtomayko/wink "minimalist blogging engine"
- http://github.com/foca/integrity "The easy and fun Continuous Integration server"
- http://github.com/sr/git-wiki "git-powered wiki"
- http://github.com/entp/seinfeld "Seinfeld-inspired productivity calendar to track your public github commits."
- http://github.com/karmi/marley "Marley, the blog engine without <textareas>."
- http://github.com/ichverstehe/gaze "Serve up your Markdown files with this tiny Sinatra app!"
def template_exists?(template_path)
ActionView::Template.new(template_path, self.view_paths)
rescue ActionView::MissingTemplate
false
end
def i_can_delete_your_time(hash)
hash.delete(:time)
end
h = {:time => 'i need this'}
h #=> {:time => 'i need this'}
i_can_delete_your_time(h)
named_scope :by_letter, lambda {|l|
{:conditions => ["UPPER(SUBSTR(title,0)) = ?", l]}
}
named_scope :by_letter, lambda {|l|
{:conditions => ["UPPER(SUBSTR(title,1,1)) = ?", l.to_s.upcase]}
}
## in controller
Book.by_letter(params[:l]).paginate
module Portfolio
class Project < StaticModel::Base
set_data_file File.join('data', 'projects.yml')
if Book.exists?(:title => title)
book = Book.find_by_title(title)
...
if book = Book.find_by_title(title)
...
eval("obj.#{methods[key]}")
obj.send(methods[key])