This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"/>} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Portfolio | |
class Project < StaticModel::Base | |
set_data_file File.join('data', 'projects.yml') | |
def to_s | |
"#{title}" | |
end | |
def category_classes | |
classes = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def template_exists?(template_path) | |
ActionView::Template.new(template_path, self.view_paths) | |
rescue ActionView::MissingTemplate | |
false | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
named_scope :by_letter, lambda {|l| | |
{:conditions => ["UPPER(SUBSTR(title,0)) = ?", l]} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
named_scope :by_letter, lambda {|l| | |
{:conditions => ["UPPER(SUBSTR(title,1,1)) = ?", l.to_s.upcase]} | |
} | |
## in controller | |
Book.by_letter(params[:l]).paginate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Portfolio | |
class Project < StaticModel::Base | |
set_data_file File.join('data', 'projects.yml') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |