Skip to content

Instantly share code, notes, and snippets.

@IskanderHaziev
Forked from timurvafin/1. Interface
Created February 22, 2011 14:09
Show Gist options
  • Save IskanderHaziev/838714 to your computer and use it in GitHub Desktop.
Save IskanderHaziev/838714 to your computer and use it in GitHub Desktop.
Post.fetch # fetch post from remote resources and save to the Post
Post::Tumblr.fetch # fetch post from Tumblr and save to the Post
# skinnycms/app/models/post.rb
class Post < ActiveRecord::Base
cattr_accessor :plugins
def fetch
plugins.each do |plugin|
Post.constantize(plugin).fetch
end
end
end
# skinnycms/app/models/post/base.rb
class Post::Base
end
# skinnycms_wordpress/init.rb
require 'app/models/post/wordpress'
Post.plugins << 'wordpress'
# skinnycms_wordpress/app/models/post/wordpress.rb
class Post::Wordpress < Post::Base
def self.fetch
end
end
# skinnycms/app/controllers/posts_controller.rb
class PostsController << ApplicationController
def index
@posts = Post.all
end
def videos
@posts = Post.where(:post_type => 'video').all
end
def posts_from_tumblr
@posts = Post.where(:source => 'tumblr').all
end
def images_from_tumblr
@posts = Post.where(:source => 'tumblr', :post_type => 'image').all
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment