Skip to content

Instantly share code, notes, and snippets.

@chadhietala
Created December 15, 2012 18:14
Show Gist options
  • Select an option

  • Save chadhietala/4297775 to your computer and use it in GitHub Desktop.

Select an option

Save chadhietala/4297775 to your computer and use it in GitHub Desktop.
Wordpress Layouts Code Examples
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