Object
# File lib/ferret/browser.rb, line 102 102: def load_page(page) 103: File.read(File.join(APP_DIR, page)) 104: end
takes an optional block to set optional attributes in the links
# File lib/ferret/browser.rb, line 126 126: def paginate(idx, max, url, &b) 127: return '' if max == 0 128: url = url.gsub(%{^/?(.*?)/?$}, '\1') 129: b ||= lambda{} 130: link = lambda {|*args| 131: i, title, text = args 132: "<a href=\"/#{url}/#{i}#{'?' + @query_string if @query_string}\" " + 133: "#{'onclick="return false;"' if (i == idx)} " + 134: "class=\"#{'disabled ' if (i == idx)}#{b.call(i)}\" " + 135: "title=\"#{title||"Go to page #{i}"}\">#{text||i}</a>" 136: } 137: res = '<div class="nav">' 138: if (idx > 0) 139: res << link.call(idx - 1, "Go to previous page", "« Previous") 140: else 141: res << "<a href=\"/#{url}/0\" onclick=\"return false;\" " + 142: "class=\"disabled\" title=\"Disabled\">« Previous</a>" 143: end 144: if idx < 10 145: idx.times {|i| res << link.call(i)} 146: else 147: (0..2).each {|i| res << link.call(i)} 148: res << ' … ' 149: ((idx-4)...idx).each {|i| res << link.call(i)} 150: end 151: res << link.call(idx, 'Current Page') 152: if idx > (max - 10) 153: ((idx+1)...max).each {|i| res << link.call(i)} 154: else 155: ((idx+1)..(idx+4)).each {|i| res << link.call(i)} 156: res << ' … ' 157: ((max-3)...max).each {|i| res << link.call(i)} 158: end 159: if (idx < (max - 1)) 160: res << link.call(idx + 1, "Go to next page", "Next »") 161: else 162: res << "<a href=\"/#{url}/#{max-1}\" onclick=\"return false;\" " + 163: "class=\"disabled\" title=\"Disabled\"}\">Next »</a>" 164: end 165: res << '</div>' 166: end
# File lib/ferret/browser.rb, line 106 106: def render(options = {}) 107: options = { 108: :controller => @controller_path, 109: :action => :index, 110: :status => 200, 111: :content_type => 'text/html', 112: :env => nil, 113: :layout => 'views/layout.rhtml', 114: }.update(options) 115: 116: path = "views/#{options[:controller]}/#{options[:action]}.rhtml" 117: content = ERB.new(load_page(path)).result(lambda{}) 118: if options[:layout] 119: content = ERB.new(load_page(options[:layout])).result(lambda{}) 120: end 121: 122: return options[:status], options[:content_type], content 123: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.