module Linkr::Views def layout xhtml_html do head do title "linkr - don't you wanna share a link ?" %w(prototype controls effects linkr).each do |s| script :src => R(Static, "#{s}.js"), :type => 'text/javascript' end link :rel => 'stylesheet', :href => R(Static, 'style.css'), :type => 'text/css' link :rel => 'alternate', :type => 'application/rss+xml', :title => 'New links', :href => "http:#{URL(Feed)}" link :rel => 'alternate', :type => 'application/rss+xml', :title => "New links tagged with #{@tag}", :href => "http:#{URL(Feed, @tag)}" if @tag end body do div.header! do h1 { a 'linkr', :href => R(List) } ul.menu! do li { form(:action => URL('/search'), :method => 'get') { input :name => 'query', :size => 10, :value => (@query || 'search'), :class => 'blank', :onfocus => "this.removeClassName('blank');if(this.value=='search'){this.value=''}", :onblur => "this.addClassName('blank');if(this.value==''){this.value='search'}" }} li { a.submit! 'submit a link', :href => R(New) } if @user end if @state.notice div.notice! @state.notice; script "new Effect.Highlight('notice')" @state.notice = nil end end self << yield div.footer! do p { text "Logged in as "; a @user, :href => R(List, 'users', @user) } span.copyright! do text ' Made for fun by ' a 'Marc-André Cournoyer', :href => 'http://macournoyer.wordpress.com' end end end end end def list h2 @title if @title ol.links! do @links.each_with_index do |link, rank| li.link do div.rank rank + 1 + (@page ? (@page-1) * per_page : 0) if @user vote = link.votes.find_by_user(@user) div.vote do link_to_vote link, 'up', vote.to_s == 'up' link_to_vote link, 'down', vote.to_s == 'down' end end div.meta do div.title { a link.title, :href => link.url; span.info " (#{link.tags})" } div.info do text "#{link.score} points, submited #{ago link.created_at} by " a link.user, :href => R(List, 'users', link.user) text " (#{a pluralize(link.comments.size, 'comment'), :href => R(Links, link.id)})" end end end end if @page a '< Previous page', :href => "?page=#{@page-1}" unless @page == 1 text ' ' a 'Next page >', :href => "?page=#{@page+1}" unless @links.size < per_page end end div.tags! do a 'all', :href => R(List); text ' ' divisor = (@tags.values.max / 40) + 1 if @tags.size > 0 @tags.each do |tag, count| a tag, :href => R(List, 'tags', tag), :style => "font-size: #{count / divisor + 12}px" text ' ' end end end def _rss builder = Builder::XmlMarkup.new(:indent => 2) builder.instruct! xml = builder.rss(:version => "2.0") do |rss| rss.channel do |channel| channel.title "Linkr - #{@title}" channel.link "http:#{URL('/')}" channel.pubDate @links.first.created_at channel.lastBuildDate @links.first.created_at for link in @links channel.item do |item| item.title link.title item.link link.url description = "Submitted by #{link.user} in #{link.tags}" for comment in link.comments description += "
#{comment.user}: #{comment.body}
" end item.description description item.pubDate link.created_at end end end end text xml end def new h2 "Why don't you submit a link ?" errors_for @link if @link form :action => R(New), :method => 'post' do p { text_field :link, :title, :size => 40 } p { text_field :link, :url, :size => 60 } p { text_field :link, :tags, :optional => true; span.info ' (separate by spaces)' } p do label 'comments (optional)', :for => 'link_description'; br textarea.link_description!(:name => 'description', :cols => 40, :rows => 8) { @link.description } end p { input :type => 'submit' } end div.auto_complete.tag_list!(:style => 'display:none') { text '' } script "new Autocompleter.Local('link_tags', 'tag_list', ['#{@tags.join %(',')}'], " + "{tokens: ' ', fullSearch: true, frequency: 0, minChars: 1});" + "document.forms[0][#{@link.title ? 2 : 0}].focus();", :type => 'text/javascript' p.bookmarklet do text 'Drag the following link to your toolbar to submit with a single click: ' a 'linkr-it!', :href => "javascript:location.href='http:#{URL(New)}?url='+" + "encodeURIComponent(location.href)+'&title='+" + "encodeURIComponent(document.title)" end end def view h2 @link.title a @link.url, :href => @link.url div.info do text 'Submited by ' a @link.user, :href => R(List, 'users', @link.user) text ' ' + ago(@link.created_at); br label 'tags: ', :for => 'link_tags' span.link_tags! @link.tags.blank? ? 'none' : @link.tags script "new Ajax.InPlaceEditor('link_tags', '#{URL(Links, @link.id)}')" if @user end @link.comments.each do |comment| div.comment do h3(:id => "comment#{comment.id}") do a comment.user, :href => R(List, 'users', comment.user) end div.info ago(comment.created_at) markup comment.body end end if @user h3 "Any comments #{@user} ?" div.info { text '('; a 'textile', :href => 'http://hobix.com/textile/'; text ' enabled)' } errors_for @comment if @comment form :action => R(Comments, @link.id), :method => 'post' do textarea :name => 'comment_body', :cols => 40, :rows => 8 p { input :type => 'submit' } end end end end