Skip to content

Commit

Permalink
Basic UI for switching versions, prettier urls
Browse files Browse the repository at this point in the history
  • Loading branch information
zk committed Oct 8, 2010
1 parent c6ee811 commit 0b51e2b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 25 deletions.
23 changes: 9 additions & 14 deletions app/controllers/main_controller.rb
Expand Up @@ -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]}"
Expand Down
17 changes: 16 additions & 1 deletion app/models/function.rb
Expand Up @@ -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
4 changes: 4 additions & 0 deletions app/models/library.rb
Expand Up @@ -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
24 changes: 16 additions & 8 deletions app/views/main/function.html.erb
Expand Up @@ -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>
Expand All @@ -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> -->
Expand Down
17 changes: 15 additions & 2 deletions public/stylesheets/main.css
Expand Up @@ -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.