Permalink
Browse files

Basic UI for switching versions, prettier urls

  • Loading branch information...
1 parent c6ee811 commit 0b51e2b268737cc3f0311a6594aae6c33302bd9f @zk committed Oct 7, 2010
View
23 app/controllers/main_controller.rb
@@ -166,28 +166,23 @@ def function
ns = params[:ns]
function_url_name = params[:function]
-
- @library = Library.find_by_url_friendly_name(lib_url_name)
- @ns = Namespace.find_by_name(ns)
- @function = nil
+
+ @library = nil
if version and version != 'current'
- @function = Function.find(
- :first,
- :conditions => {
- :library => @library.name,
- :version => version,
- :ns => ns,
- :url_friendly_name => function_url_name}
- )
+ @library = Library.find_by_url_friendly_name_and_version(lib_url_name, version)
else
- @function = Function.find(
+ @library = Library.find_by_url_friendly_name_and_current(lib_url_name, true)
+ end
+
+ @ns = Namespace.find_by_name(ns)
+ @function = Function.find(
:first,
:conditions => {
:library => @library.name,
+ :version => @library.version,
:ns => ns,
:url_friendly_name => function_url_name}
)
- end
if not @function
logger.error "Couldn't find function id #{params[:id]}"
View
17 app/models/function.rb
@@ -59,8 +59,23 @@ def self.in_library_and_ns(lib, ns)
end
def self.versions_of(function)
- Function.find(:all, :conditions => {:library => function.library,
+ Function.find(:all, :conditions => {:library => function.library_.name,
:ns => function.ns,
:name => function.name})
end
+
+ # not ready to make the leap to a has_many / belongs_to yet, so this
+ # will have to do for now
+ def library_
+ Library.find_by_name_and_version(library, version)
+ end
+
+ def link_opts(use_current_vs_actual_version = true)
+ {:controller => 'main',
+ :action => 'function',
+ :lib => library_.url_friendly_name,
+ :version => (use_current_vs_actual_version && library_.current ? 'current' : version),
+ :ns => ns,
+ :function => url_friendly_name}
+ end
end
View
4 app/models/library.rb
@@ -16,4 +16,8 @@ def self.versions_of(library)
Library.find(:all, :conditions => {:name => library.name})
end
+ def self.current_version_of(library)
+ Library.find_by_name_and_current(library.name, true)
+ end
+
end
View
24 app/views/main/function.html.erb
@@ -19,6 +19,12 @@ $(document).ready(function() {
 
</div>
<div class="grid_11">
+ <% if not @function.library_.current %>
+ <div class="version_warning">
+ You're viewing version <%= @function.version %> of this var.
+ The current version is <%= Library.current_version_of(@library).version %>.
+ </div>
+ <% end %>
<a name="top"></a>
<div class="function_links">
<a href="#doc" class="scroll">doc</a>
@@ -29,15 +35,17 @@ $(document).ready(function() {
<div class="short_link versions_nav">
<% Function.versions_of(@function).each do |f| %>
<% if @function.version == f.version %>
- <span class="selected"><%= f.version %></span>
+ <% if f.library_.current %>
+ <%= link_to "<span class='selected current'>#{f.version}</span>", f.link_opts(false) %>
+ <% else %>
+ <span class="selected"><%= f.version %></span>
+ <% end %>
<% else %>
- <%= link_to f.version,
- :controller => 'main',
- :action => 'function',
- :lib => @library.url_friendly_name,
- :version => f.version,
- :ns => f.ns,
- :function => f.url_friendly_name %>
+ <% if f.library_.current %>
+ <%= link_to "<span class='current'>#{f.version}</span>", f.link_opts %>
+ <% else %>
+ <%= link_to f.version, f.link_opts %>
+ <% end %>
<% end %>
<% end %>
<!-- <a href="/v/<%= @function.id %>">short link to this var</a> -->
View
17 public/stylesheets/main.css
@@ -898,11 +898,24 @@ span.version {
}
.versions_nav a {
- color: #ccc;
+ color: #aaa;
}
-.versions_nav .selected {
+.versions_nav a .selected {
font-weight: bold;
+ color: black;
+}
+
+.versions_nav a .current {
+ background-color: #ffffaa;
+}
+
+.version_warning {
+ text-align: center;
+ padding: 10px;
+ background-color: #ffffaa;
+ border: solid #ccc 1px;
+ margin-bottom: 5px;
}

0 comments on commit 0b51e2b

Please sign in to comment.