Class: Murlsh::UrlBody
- Inherits:
-
Builder::XmlMarkup
- Object
- Builder::XmlMarkup
- Murlsh::UrlBody
- Includes:
- Markup
- Defined in:
- lib/murlsh/url_body.rb
Overview
Url list page builder.
Instance Method Summary collapse
-
#add_form ⇒ Object
Url add form builder.
-
#build ⇒ Object
Url list page body builder.
-
#clear ⇒ Object
Clear div builder.
-
#each {|build| ... } ⇒ Object
Yield body for Rack.
-
#feed_link ⇒ Object
Feed link builder.
-
#headd ⇒ Object
Head builder.
-
#home_link ⇒ Object
Home link builder.
-
#initialize(config, req, result_set, content_type = 'text/html') ⇒ UrlBody
constructor
A new instance of UrlBody.
-
#js ⇒ Object
Required javascript builder.
-
#menu ⇒ Object
Menu builder.
-
#next_href ⇒ Object
Get the url of the next page or nil if this is the last.
-
#page_href(page) ⇒ Object
Get the href of a page in the same result set as this page.
-
#paging_nav ⇒ Object
Paging navigation.
-
#powered_by ⇒ Object
Powered by builder.
-
#prev_href ⇒ Object
Get the url of the previous page or nil if this is the first.
-
#quick_search ⇒ Object
Quick search list builder.
-
#random_link ⇒ Object
Random link builder.
-
#search_form ⇒ Object
Search form builder.
-
#titlee ⇒ Object
Title builder.
Methods included from Markup
#atom, #css, #form_input, #javascript, #metas, #murlsh_img
Constructor Details
#initialize(config, req, result_set, content_type = 'text/html') ⇒ UrlBody
Returns a new instance of UrlBody.
10 11 12 13 14 |
# File 'lib/murlsh/url_body.rb', line 10 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
#add_form ⇒ Object
Url add form builder.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/murlsh/url_body.rb', line 188 def add_form form(:action => 'url', :method => 'post') { fieldset(:id => 'add') { self.p { form_input :id => 'url', :label => 'Add URL', :size => 32, :required => '' } self.p { form_input :id => 'title', :label => 'Title', :size => 32 } self.p { form_input :id => 'via', :label => 'Via', :size => 32 } self.p { form_input :type => 'password', :id => 'auth', :label => 'Password', :size => 16, :required => '' form_input :id => 'submit', :type => 'button', :value => 'Add' } } } end |
#build ⇒ Object
Url list page body builder.
37 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 95 96 97 |
# File 'lib/murlsh/url_body.rb', line 37 def build if defined?(@body) @body else declare! :DOCTYPE, :html @body = html(:lang => 'en') { headd body { search_form quick_search ul(:id => 'urls') { last = nil @result_set.results.each do |mu| ::Murlsh::Plugin.hooks('url_display_pre') do |p| p.run mu, @req, @config end li(:id => "liu#{mu.id}") { 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 and not mu.same_thumbnail?(last) 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 |
#clear ⇒ Object
Clear div builder.
207 |
# File 'lib/murlsh/url_body.rb', line 207 def clear; div(:style => 'clear : both') { }; end |
#each {|build| ... } ⇒ Object
Yield body for Rack.
34 |
# File 'lib/murlsh/url_body.rb', line 34 def each; yield build; end |
#feed_link ⇒ Object
Feed link builder.
138 139 140 |
# File 'lib/murlsh/url_body.rb', line 138 def feed_link a 'Feed', :href => @config.fetch('feed_file'), :class => 'feed' end |
#headd ⇒ Object
Head builder.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/murlsh/url_body.rb', line 100 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 |
#home_link ⇒ Object
Home link builder.
135 |
# File 'lib/murlsh/url_body.rb', line 135 def home_link; a 'Home', :href => @config.fetch('root_url'); end |
#js ⇒ Object
Required javascript builder.
218 |
# File 'lib/murlsh/url_body.rb', line 218 def js; javascript(@config['js_compressed'] || @config['js_files']); end |
#menu ⇒ Object
Menu builder.
126 127 128 129 130 131 132 |
# File 'lib/murlsh/url_body.rb', line 126 def self.p(:id => 'menu') { home_link ; text! ' | ' feed_link ; text! ' | ' random_link } end |
#next_href ⇒ Object
Get the url of the next page or nil if this is the last.
31 |
# File 'lib/murlsh/url_body.rb', line 31 def next_href; page_href(@result_set.next_page); end |
#page_href(page) ⇒ Object
Get the href of a page in the same result set as this page.
Return nil if page is invalid.
19 20 21 22 23 24 25 |
# File 'lib/murlsh/url_body.rb', line 19 def page_href(page) if page.to_i >= 1 query = @req.params.dup query['p'] = page ::Murlsh.build_query(query) end end |
#paging_nav ⇒ Object
Paging navigation.
175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/murlsh/url_body.rb', line 175 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 |
#powered_by ⇒ Object
Powered by builder.
210 211 212 213 214 215 |
# File 'lib/murlsh/url_body.rb', line 210 def powered_by self.p { text! 'Powered by ' a 'murlsh', :href => 'https://github.com/mmb/murlsh' } end |
#prev_href ⇒ Object
Get the url of the previous page or nil if this is the first.
28 |
# File 'lib/murlsh/url_body.rb', line 28 def prev_href; page_href(@result_set.prev_page); end |
#quick_search ⇒ Object
Quick search list builder.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/murlsh/url_body.rb', line 146 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 |
#random_link ⇒ Object
Random link builder.
143 |
# File 'lib/murlsh/url_body.rb', line 143 def random_link; a 'Random', :href => 'random', :rel => 'nofollow'; end |
#search_form ⇒ Object
Search form builder.
165 166 167 168 169 170 171 172 |
# File 'lib/murlsh/url_body.rb', line 165 def search_form form(:action => @config.fetch('root_url'), :method => 'get') { fieldset { form_input :id => 'q', :size => 32 form_input :type => 'submit', :value => 'Search' } } end |
#titlee ⇒ Object
Title builder.
120 121 122 123 |
# File 'lib/murlsh/url_body.rb', line 120 def titlee title(@config.fetch('page_title', '') + (@req['q'] ? " /#{@req['q']}" : '')) end |