Created
December 15, 2012 18:14
-
-
Save chadhietala/4297775 to your computer and use it in GitHub Desktop.
Wordpress Layouts Code Examples
This file contains hidden or 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 'shotgun' | |
| require 'sinatra' | |
| require 'mongo' | |
| require 'json/pure' | |
| uri = URI.parse(ENV['MONGOLAB_URI']) | |
| conn = Mongo::Connection.from_uri(ENV['MONGOLAB_URI']) | |
| db = conn.db(uri.path.gsub(/^\//, '')) | |
| PAGE_SIZE = 20 | |
| get '/' do | |
| File.read(File.join('public', 'index.html')) | |
| end | |
| get '/themes/:page' do | |
| page = params[:page].to_i | |
| content_type :json | |
| templates = db['templates'] | |
| return templates.find.skip(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).to_a.to_json | |
| end | |
| get '/themes/:parent_category/:page' do | |
| page = params[:page].to_i | |
| content_type :json | |
| templates = db['templates'] | |
| return templates.find({'parent_category' => params[:parent_category]}).skip(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).to_a.to_json | |
| end | |
| get '/themes/child/:child_category/:page' do | |
| page = params[:page].to_i | |
| content_type :json | |
| templates = db['templates'] | |
| templates.find({'child_category' => params[:child_category]}).skip(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).to_a.to_json | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment