Class: Murlsh::UrlBody
- Inherits:
-
Builder::XmlMarkup
- Object
- Builder::XmlMarkup
- Murlsh::UrlBody
- Includes:
- BuildMd5, Markup
- Defined in:
- lib/murlsh/url_body.rb
Overview
Url list page builder.
Instance Method Summary (collapse)
-
- (Object) add_form
Url add form builder.
-
- (Object) build
Url list page body builder.
-
- (Object) clear
Clear div builder.
-
- (Object) each {|build| ... }
Yield body for Rack.
-
- (Object) feed_link
Feed link builder.
-
- (Object) headd
Head builder.
-
- (Object) home_link
Home link builder.
-
- (UrlBody) initialize(config, req, result_set, content_type = 'text/html'))
constructor
A new instance of UrlBody.
-
- (Object) js
Required javascript builder.
-
- (Object) next_href
Get the url of the next page or nil if this is the last.
-
- (Object) page_href(page)
Get the href of a page in the same result set as this page.
-
- (Object) paging_nav
Paging navigation.
-
- (Object) powered_by
Powered by builder.
-
- (Object) prev_href
Get the url of the previous page or nil if this is the first.
-
- (Object) quick_search
Quick search list builder.
-
- (Object) search_form
Search form builder.
-
- (Object) titlee
Title builder.
Methods included from Markup
#atom, #css, #form_input, #javascript, #metas, #murlsh_img
Methods included from BuildMd5
Constructor Details
- (UrlBody) initialize(config, req, result_set, content_type = 'text/html'))
A new instance of UrlBody
11 12 13 14 15 |
# File 'lib/murlsh/url_body.rb', line 11 def initialize(config, req, result_set, content_type='text/html') @config, @req, @result_set, @content_type = config, req, result_set, content_type super(:indent => @config['html_indent'] || 0) end |
Instance Method Details
- (Object) add_form
Url add form builder.
173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/murlsh/url_body.rb', line 173 def add_form form(:action => '', :method => 'post') { fieldset(:id => 'add') { self.p { form_input :id => 'url', :label => 'Add URL', :size => 32 } self.p { form_input :id => 'via', :label => 'Via', :size => 32 } self.p { form_input :type => 'password', :id => 'auth', :label => 'Password', :size => 16 form_input :id => 'submit', :type => 'button', :value => 'Add' } } } end |
- (Object) build
Url list page body builder.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/murlsh/url_body.rb', line 38 def build if defined?(@body) @body else declare! :DOCTYPE, :html @body = html(:lang => 'en') { headd body { self.p(:id => 'menu') { home_link ; text! ' | ' ; feed_link } search_form quick_search ul(:id => 'urls') { last = nil @result_set.results.each do |mu| li { unless mu.(last) avatar_url = Murlsh::Plugin.hooks('avatar').inject( nil) do |url_so_far,plugin| plugin.run(url_so_far, mu, @config) end div(:class => 'icon') { murlsh_img :src => avatar_url, :text => mu.name } if avatar_url div(mu.name, :class => 'name') if @config.fetch('show_names', false) and mu.name end if mu.thumbnail_url murlsh_img :src => mu.thumbnail_url, :text => mu.title_stripped, :class => 'thumb' end a mu.title_stripped, :href => mu.url, :class => 'm' Murlsh::Plugin.hooks('url_display_add') do |p| p.run self, mu, @config end last = mu } end } clear paging_nav add_form powered_by js div '', :id => 'bottom' } } end end |
- (Object) clear
Clear div builder.
188 |
# File 'lib/murlsh/url_body.rb', line 188 def clear; div(:style => 'clear : both') { }; end |
- (Object) each {|build| ... }
Yield body for Rack.
35 |
# File 'lib/murlsh/url_body.rb', line 35 def each; yield build; end |
- (Object) feed_link
Feed link builder.
126 127 128 |
# File 'lib/murlsh/url_body.rb', line 126 def feed_link a 'Feed', :href => @config.fetch('feed_file'), :class => 'feed' end |
- (Object) headd
Head builder.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/murlsh/url_body.rb', line 97 def headd head { titlee :http-equiv' => 'Content-Type', :content => @content_type (@config.find_all { |k,v| k =~ /^meta_tag_/ and v }. map { |k,v| [k.sub('meta_tag_', ''), v] }) css(@config['css_compressed'] || @config['css_files']) atom @config.fetch('feed_file') link :rel => 'first', :href => page_href(1) if p_href = prev_href link :rel => 'prev', :href => p_href end if n_href = next_href link :rel => 'next', :href => n_href end } end |
- (Object) home_link
Home link builder.
123 |
# File 'lib/murlsh/url_body.rb', line 123 def home_link; a 'Home', :href => @config.fetch('root_url'); end |
- (Object) js
Required javascript builder.
199 |
# File 'lib/murlsh/url_body.rb', line 199 def js; javascript(@config['js_compressed'] || @config['js_files']); end |
- (Object) next_href
Get the url of the next page or nil if this is the last.
32 |
# File 'lib/murlsh/url_body.rb', line 32 def next_href; page_href(@result_set.next_page); end |
- (Object) page_href(page)
Get the href of a page in the same result set as this page.
Return nil if page is invalid.
20 21 22 23 24 25 26 |
# File 'lib/murlsh/url_body.rb', line 20 def page_href(page) if page.to_i >= 1 query = @req.params.dup query['p'] = page Murlsh.build_query(query) end end |
- (Object) paging_nav
Paging navigation.
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/murlsh/url_body.rb', line 160 def paging_nav self.p { text! "Page #{@result_set.page}/#{@result_set.total_pages}" if p_href = prev_href text! ' | '; a 'previous', :href => p_href end if n_href = next_href text! ' | '; a 'next', :href => n_href end } end |
- (Object) powered_by
Powered by builder.
191 192 193 194 195 196 |
# File 'lib/murlsh/url_body.rb', line 191 def powered_by self.p { text! 'Powered by ' a 'murlsh', :href => 'http://github.com/mmb/murlsh/' } end |
- (Object) prev_href
Get the url of the previous page or nil if this is the first.
29 |
# File 'lib/murlsh/url_body.rb', line 29 def prev_href; page_href(@result_set.prev_page); end |
- (Object) quick_search
Quick search list builder.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/murlsh/url_body.rb', line 131 def quick_search if @config['quick_search'] self.p { text! 'Quick search: ' # can specify keys to be sorted first in quick_search_order config # key, those keys will be first in given order, any keys not there # will follow in natural sorted order order = @config['quick_search_order'] || [] order += (@config['quick_search'].keys - order).sort order.each do |k| if v = @config['quick_search'][k] a "/#{k}", :href => "?q=#{URI.escape(v)}" ; text! ' ' end end } end end |
- (Object) search_form
Search form builder.
150 151 152 153 154 155 156 157 |
# File 'lib/murlsh/url_body.rb', line 150 def search_form form(:action => '', :method => 'get') { fieldset { form_input :id => 'q', :size => 32, :value => @req['q'] form_input :type => 'submit', :value => 'Search' } } end |
- (Object) titlee
Title builder.
117 118 119 120 |
# File 'lib/murlsh/url_body.rb', line 117 def titlee title(@config.fetch('page_title', '') + (@req['q'] ? " /#{@req['q']}" : '')) end |