Skip to content

Instantly share code, notes, and snippets.

@woodie
Created March 30, 2011 19:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woodie/895046 to your computer and use it in GitHub Desktop.
Save woodie/895046 to your computer and use it in GitHub Desktop.
Pagination in mirah/dubious
import stdlib.*
import models.*
import dubious.*
class EmailsController < ApplicationController
def index
set = 30
@index = Integer.parseInt(params.get(:page) || "1")
offset = set * (@index - 1)
@emails = Message.all.is_hidden(false).
sort('published', true).limit(set).offset(offset).run
@page_section = 'Emails'
render list_erb, main_erb
end
def doGet(request, response)
action_response(response, action_request(request, 'get'))
end
def_edb(list_erb, 'views/emails.html.erb')
def_edb(main_erb, 'views/layouts/main.html.erb')
end
import com.google.appengine.ext.mirah.db.Model
import com.google.appengine.api.datastore.*
import java.util.List
import java.util.Date
class Message < Model
property :title, String
property :published, Date
property :link, Link
property :summary, Text
property :is_reply, Boolean
property :is_featured, Boolean
property :is_hidden, Boolean
end
<div style="font-family: sans-serif; text-align: left;">
<% tidy_formatter = TimeConversion.new('tidy') %>
<b style="color: gray;">Emails:</b>
<ul>
<% @emails.each do |e| %>
<li><%= link_to e.title, e.link %>
<span style="color: gray;">
(<%= tidy_formatter.format(e.published) %>)</li>
<% end %>
</ul>
<br/>
Page:
<% 1.upto(6) do |i| %>
<% if i == @index %>
&nbsp;<b><%= "#{i}" %></b>
<% else %>
&nbsp;<%= link_to "#{i}", "/emails?page=#{i}" %>
<% end %>
<% end %>
</div>
// Generated from message.mirah
// Also See: https://github.com/mirah/mirah_model/blob/master/src/model.mirah
package models;
public class Message extends com.google.appengine.ext.mirah.db.Model {
private java.lang.String title;
private java.util.Date published;
private java.lang.String link;
private java.lang.String summary;
private boolean is_reply;
private boolean is_featured;
private boolean is_hidden;
public static void main(java.lang.String[] argv) {
public Message() {
super();
}
public Message(java.lang.String key_name) {
super(key_name);
}
public Message(com.google.appengine.ext.mirah.db.Model parent) {
super(parent);
}
public Message(com.google.appengine.api.datastore.Key parent) {
super(parent);
}
public Message(com.google.appengine.ext.mirah.db.Model parent, java.lang.String key_name) {
super(parent, key_name);
}
public Message(com.google.appengine.api.datastore.Key parent, java.lang.String key_name) {
super(parent, key_name);
}
public static models.Message get(com.google.appengine.api.datastore.Key key) {
models.Message m = null;
try {
m = new models.Message();
models.Message temp$1 = m;
temp$1._read_from(com.google.appengine.ext.mirah.db.Model._datastore().get(key));
return m;
}
catch (com.google.appengine.api.datastore.EntityNotFoundException tmp$ex$2000) {
return null;
}
}
public static models.Message get(java.lang.String key_name) {
return models.Message.get(com.google.appengine.api.datastore.KeyFactory.createKey("Message", key_name));
}
public static models.Message get(long id) {
return models.Message.get(com.google.appengine.api.datastore.KeyFactory.createKey("Message", id));
}
public static models.Message get(com.google.appengine.api.datastore.Key parent, java.lang.String key_name) {
return models.Message.get(com.google.appengine.api.datastore.KeyFactory.createKey(parent, "Message", key_name));
}
public static models.Message get(com.google.appengine.api.datastore.Key parent, long id) {
return models.Message.get(com.google.appengine.api.datastore.KeyFactory.createKey(parent, "Message", id));
}
public static models.Message get(com.google.appengine.ext.mirah.db.Model parent, java.lang.String key_name) {
return models.Message.get(com.google.appengine.api.datastore.KeyFactory.createKey(parent.key(), "Message", key_name));
}
public static models.Message get(com.google.appengine.ext.mirah.db.Model parent, long id) {
return models.Message.get(com.google.appengine.api.datastore.KeyFactory.createKey(parent.key(), "Message", id));
}
public static models.Message.Query all() {
return new models.Message.Query();
}
public void _read_from(com.google.appengine.api.datastore.Entity e) {
java.lang.Object __xform_tmp_1 = null;
java.lang.Object __xform_tmp_2 = null;
java.lang.Object __xform_tmp_3 = null;
java.lang.Object __xform_tmp_4 = null;
java.lang.Object __xform_tmp_5 = null;
java.lang.Object __xform_tmp_6 = null;
java.lang.Object __xform_tmp_7 = null;
this.entity_set(e);
__xform_tmp_1 = e.getProperty("title");
this.title = ((java.lang.String)(__xform_tmp_1));
__xform_tmp_2 = e.getProperty("published");
this.published = ((java.util.Date)(__xform_tmp_2));
__xform_tmp_3 = e.getProperty("link");
this.link = (__xform_tmp_3 != null) ? (((com.google.appengine.api.datastore.Link)(__xform_tmp_3)).getValue()) : (((java.lang.String)(null)));
__xform_tmp_4 = e.getProperty("summary");
this.summary = (__xform_tmp_4 != null) ? (((com.google.appengine.api.datastore.Text)(__xform_tmp_4)).getValue()) : (((java.lang.String)(null)));
__xform_tmp_5 = e.getProperty("is_reply");
this.is_reply = (__xform_tmp_5 != null) ? (((java.lang.Boolean)(__xform_tmp_5)).booleanValue()) : (false);
__xform_tmp_6 = e.getProperty("is_featured");
this.is_featured = (__xform_tmp_6 != null) ? (((java.lang.Boolean)(__xform_tmp_6)).booleanValue()) : (false);
__xform_tmp_7 = e.getProperty("is_hidden");
this.is_hidden = (__xform_tmp_7 != null) ? (((java.lang.Boolean)(__xform_tmp_7)).booleanValue()) : (false);
}
public java.util.Map properties() {
java.util.Map result = null;
result = super.properties();
result.put("title", this.title());
result.put("published", this.published());
result.put("link", this.link());
result.put("summary", this.summary());
result.put("is_reply", java.lang.Boolean.valueOf(this.is_reply()));
result.put("is_featured", java.lang.Boolean.valueOf(this.is_featured()));
result.put("is_hidden", java.lang.Boolean.valueOf(this.is_hidden()));
return result;
}
public models.Message update(java.util.Map properties) {
if (properties.containsKey("title")) {
this.title_set(properties.get("title"));
}
if (properties.containsKey("published")) {
this.published_set(properties.get("published"));
}
if (properties.containsKey("link")) {
this.link_set(properties.get("link"));
}
if (properties.containsKey("summary")) {
this.summary_set(properties.get("summary"));
}
if (properties.containsKey("is_reply")) {
this.is_reply_set(properties.get("is_reply"));
}
if (properties.containsKey("is_featured")) {
this.is_featured_set(properties.get("is_featured"));
}
if (properties.containsKey("is_hidden")) {
this.is_hidden_set(properties.get("is_hidden"));
}
return this;
}
public void _save_to(com.google.appengine.api.datastore.Entity e) {
com.google.appengine.api.datastore.Entity temp$1 = e;
temp$1.setProperty("title", this.title);
com.google.appengine.api.datastore.Entity temp$2 = e;
temp$2.setProperty("published", this.published);
com.google.appengine.api.datastore.Entity temp$3 = e;
temp$3.setProperty("link", (this.link != null) ? (new com.google.appengine.api.datastore.Link(this.link)) : (null));
com.google.appengine.api.datastore.Entity temp$4 = e;
temp$4.setProperty("summary", (this.summary != null) ? (new com.google.appengine.api.datastore.Text(this.summary)) : (null));
com.google.appengine.api.datastore.Entity temp$5 = e;
temp$5.setProperty("is_reply", new java.lang.Boolean(this.is_reply));
com.google.appengine.api.datastore.Entity temp$6 = e;
temp$6.setProperty("is_featured", new java.lang.Boolean(this.is_featured));
com.google.appengine.api.datastore.Entity temp$7 = e;
temp$7.setProperty("is_hidden", new java.lang.Boolean(this.is_hidden));
}
public java.lang.String title() {
return this.title;
}
public java.lang.String title_set(java.lang.String value) {
return this.title = value;
}
public java.lang.String title_set(java.lang.Object value) {
return this.title_set(this.coerce_string(value));
}
public java.util.Date published() {
return this.published;
}
public java.util.Date published_set(java.util.Date value) {
return this.published = value;
}
public java.util.Date published_set(java.lang.Object value) {
return this.published_set(this.coerce_date(value));
}
public java.lang.String link() {
return this.link;
}
public java.lang.String link_set(java.lang.String value) {
return this.link = value;
}
public java.lang.String link_set(java.lang.Object value) {
return this.link_set(this.coerce_string(value));
}
public java.lang.String summary() {
return this.summary;
}
public java.lang.String summary_set(java.lang.String value) {
return this.summary = value;
}
public java.lang.String summary_set(java.lang.Object value) {
return this.summary_set(this.coerce_string(value));
}
public boolean is_reply() {
return this.is_reply;
}
public boolean is_reply_set(boolean value) {
return this.is_reply = value;
}
public boolean is_reply_set(java.lang.Object value) {
return this.is_reply_set(this.coerce_boolean(value));
}
public boolean is_featured() {
return this.is_featured;
}
public boolean is_featured_set(boolean value) {
return this.is_featured = value;
}
public boolean is_featured_set(java.lang.Object value) {
return this.is_featured_set(this.coerce_boolean(value));
}
public boolean is_hidden() {
return this.is_hidden;
}
public boolean is_hidden_set(boolean value) {
return this.is_hidden = value;
}
public boolean is_hidden_set(java.lang.Object value) {
return this.is_hidden_set(this.coerce_boolean(value));
}
public static class Query extends com.google.appengine.ext.mirah.db.DQuery {
public Query() {
}
public java.lang.String kind() {
return "Message";
}
public models.Message first() {
java.util.Iterator it = null;
com.google.appengine.api.datastore.Entity e = null;
models.Message m = null;
it = this._prepare().asIterator();
if (it.hasNext()) {
e = ((com.google.appengine.api.datastore.Entity)(it.next()));
m = new models.Message();
models.Message temp$1 = m;
temp$1._read_from(e);
return m;
}
else {
return ((models.Message)(null));
}
}
public models.Message[] run() {
java.util.List entities = null;
models.Message[] models = null;
java.util.Iterator it = null;
int i = 0;
com.google.appengine.api.datastore.Entity e = null;
models.Message m = null;
entities = this._prepare().asList(this._options());
models = new models.Message[entities.size()];
it = entities.iterator();
i = 0;
label1:
while (it.hasNext()) {
label2:
{
e = ((com.google.appengine.api.datastore.Entity)(it.next()));
m = new models.Message();
models.Message temp$3 = m;
temp$3._read_from(e);
models[i] = m;
i = (i + 1);
}
}
return models;
}
public models.Message.Query sort(java.lang.String name) {
return this.sort(name, false);
}
public models.Message.Query sort(java.lang.String name, boolean descending) {
this._sort(name, descending);
return this;
}
public void title(java.lang.String value) {
this._query().addFilter("title", this._eq_op(), value);
}
public void published(java.util.Date value) {
this._query().addFilter("published", this._eq_op(), value);
}
public void link(java.lang.String value) {
this._query().addFilter("link", this._eq_op(), (value != null) ? (new com.google.appengine.api.datastore.Link(value)) : (null));
}
public void summary(java.lang.String value) {
this._query().addFilter("summary", this._eq_op(), (value != null) ? (new com.google.appengine.api.datastore.Text(value)) : (null));
}
public void is_reply(boolean value) {
this._query().addFilter("is_reply", this._eq_op(), new java.lang.Boolean(value));
}
public void is_featured(boolean value) {
this._query().addFilter("is_featured", this._eq_op(), new java.lang.Boolean(value));
}
public void is_hidden(boolean value) {
this._query().addFilter("is_hidden", this._eq_op(), new java.lang.Boolean(value));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment