Parent

Included Modules

Class Index [+]

Quicksearch

Ferret::Browser::Controller

Constants

APP_DIR
STATIC_DIR

Public Class Methods

new(reader, path, vars) click to toggle source
    # File lib/ferret/browser.rb, line 89
89:     def initialize(reader, path, vars)
90:       @reader = reader
91:       @path = path
92:       vars.each_pair {|key, val| instance_eval("@#{key} = val")}
93:       @controller_path = pathify(self.class.to_s.gsub(/.*:/, ''))
94:     end

Public Instance Methods

method_missing(meth_id, *args) click to toggle source
    # File lib/ferret/browser.rb, line 96
96:     def method_missing(meth_id, *args)
97:       render(:action => meth_id)
98:     end

Protected Instance Methods

load_page(page) click to toggle source
     # File lib/ferret/browser.rb, line 102
102:     def load_page(page)
103:       File.read(File.join(APP_DIR, page))
104:     end
paginate(idx, max, url, &b) click to toggle source

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", "&#171; Previous")
140:       else
141:         res << "<a href=\"/#{url}/0\" onclick=\"return false;\" " +
142:                 "class=\"disabled\" title=\"Disabled\">&#171; 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 << '&nbsp;&#8230;&nbsp;'
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 << '&nbsp;&#8230;&nbsp;'
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 &#187;")
161:       else
162:         res << "<a href=\"/#{url}/#{max-1}\" onclick=\"return false;\" " +
163:                 "class=\"disabled\" title=\"Disabled\"}\">Next &#187;</a>"
164:       end
165:       res << '</div>'
166:     end
render(options = {}) click to toggle source
     # 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

Private Instance Methods

pathify(str) click to toggle source
     # File lib/ferret/browser.rb, line 169
169:     def pathify(str)
170:       str.gsub(/Controller$/, '').gsub(/([a-z])([A-Z])/) {"#{$1}-#{$2}"}.downcase
171:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.