Skip to content

Instantly share code, notes, and snippets.

@lmarburger
Created January 2, 2009 16:04
Show Gist options
  • Save lmarburger/42585 to your computer and use it in GitHub Desktop.
Save lmarburger/42585 to your computer and use it in GitHub Desktop.
# <div class="pagination clearfix first">
# <span class="pages">
# <a href="/wines/page/0" class="previous">Previous</a>
# <span>Page 1 of 14</span>
# <a href="/wines/page/1" class="next">Next</a>
# </span>
# <span class="goto">
# <label>Go to page:<input id="page" name="page" type="text"></label>
# <button class="go" type="submit">
# <span class="goto">Go</span>
# </button>
# </span>
# </div>
def pagination(page, total_pages)
first_or_last = if page <= 0
'first'
elsif page >= total_pages - 1
'last'
end
content_tag(:div, :class => "pagination clearfix#{first_or_last ? " #{first_or_last}" : '' }") do
content_tag(:span, :class => "pages") do
link_to('Previous', wines_page_path([page - 1, 0].max), :class => 'previous', :method => :post) +
content_tag(:span, "Page #{page + 1} of #{total_pages}") +
link_to('Next', wines_page_path([page + 1, total_pages].min), :class => 'next', :method => :post)
end +
content_tag(:span, :class => "goto") do
content_tag(:label) do
'Go to page:' +
text_field_tag('page')
end +
button_tag('Go', :class => 'go')
end
end
end
# <div class="relevancy">
# <span class="fill" style="border-bottom-width:94px; height:36px;"></span>
# <span class="value" style="top:42px;">
# <span>72<sup>%</sup></span>
# Match
# </span>
# </div>
def search_relevancy(relevancy)
content_tag(:div, :class => 'relevancy') do
content_tag(:span, nil, :class => 'fill', :style => relevancy_fill_style_value(relevancy)) +
content_tag(:span, :class => 'value', :style => relevancy_value_style_value(relevancy)) do
content_tag(:span, "#{relevancy}#{content_tag(:sup, '%')}") +
' Match'
end
end
end
private
def relevancy_fill_style_value(relevancy)
border_bottom_width = (relevancy * 1.3).round
height = 130 - border_bottom_width
"border-bottom-width:#{border_bottom_width}px; height:#{height}px;"
end
def relevancy_value_style_value(relevancy)
value_on_top = relevancy < 50
position = if value_on_top
relevancy * 1.3 + 3
else
(100 - relevancy) * 1.3 + 6
end.round
"#{value_on_top ? 'bottom' : 'top'}:#{position}px;#{value_on_top ? 'color:#444;' : ''}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment