Browse files

Made a good dent in the lib version UI.

  • Loading branch information...
1 parent 3351acd commit c6ee8111dfd4ac123a5a397d6dd1ca7fa2e4a043 @zk committed Oct 6, 2010
View
75 app/controllers/main_controller.rb
@@ -28,16 +28,15 @@ def index
end
def lib
-
name = params[:lib]
version = params[:version]
@library = nil
if version and version != 'current'
- @library = Library.find_by_name_and_version(name, version)
+ @library = Library.find_by_url_friendly_name_and_version(name, version)
else
- @library = Library.find_by_name(name)
+ @library = Library.find_by_url_friendly_name_and_current(name, true)
end
if not @library
@@ -136,15 +135,15 @@ def lib_search
def ns
- #lib_name = params[:lib]
- #version = params[:version]
+ lib_name = params[:lib]
+ version = params[:version]
ns_name = params[:ns]
@library = nil
if version and version != 'current'
- @library = Library.find_by_name_and_version(lib_name, version)
+ @library = Library.find_by_url_friendly_name_and_version(lib_name, version)
else
- @library = Library.find_by_name(lib_name)
+ @library = Library.find_by_url_friendly_name_and_current(lib_name, true)
end
@ns = nil
@@ -160,27 +159,50 @@ def ns
return
end
end
+
+ def function
+ lib_url_name = params[:lib]
+ version = params[:version]
+
+ ns = params[:ns]
+ function_url_name = params[:function]
- def function_short_link
- @function = Function.find(params[:id]) rescue nil
-
+ @library = Library.find_by_url_friendly_name(lib_url_name)
+ @ns = Namespace.find_by_name(ns)
+ @function = nil
+ if version and version != 'current'
+ @function = Function.find(
+ :first,
+ :conditions => {
+ :library => @library.name,
+ :version => version,
+ :ns => ns,
+ :url_friendly_name => function_url_name}
+ )
+ else
+ @function = Function.find(
+ :first,
+ :conditions => {
+ :library => @library.name,
+ :ns => ns,
+ :url_friendly_name => function_url_name}
+ )
+ end
+
if not @function
logger.error "Couldn't find function id #{params[:id]}"
render :template => 'public/404.html', :layout => false, :status => 404
return
end
-
- @ns = Namespace.find_by_name(@function.ns)
-
- @library = Library.find_by_name(@function.library)
+
if not @library
logger.error "Couldn't find library by function #{@function.to_yaml}"
render :template => 'public/404.html', :layout => false, :status => 404
return
end
-
+
@example = Example.new
@comment = Comment.new
@@ -204,7 +226,28 @@ def function_short_link
end
- render :template => '/main/function'
+ end
+
+ def function_short_link
+ @function = Function.find(params[:id]) rescue nil
+ @library = Library.find_by_name_and_version(@function.library, @function.version)
+
+ version = (params[:version] || @function.version)
+
+ if not @function
+ logger.error "Couldn't find function id #{params[:id]}"
+
+ render :template => 'public/404.html', :layout => false, :status => 404
+ return
+ end
+
+ redirect_to :controller => 'main',
+ :action => 'function',
+ :lib => @library.url_friendly_name,
+ :version => (@library.current ? 'current' : @library.version),
+ :ns => @function.ns,
+ :function => @function.url_friendly_name
+
end
def search_autocomplete
View
2 app/models/function.rb
@@ -55,7 +55,7 @@ def self.in_library(lib)
end
def self.in_library_and_ns(lib, ns)
- Function.find(:all, :conditions => {:library => lib.name, :ns => ns, :version => lib.version}, :select => 'library,ns,name, weight, id', :order => 'name ASC, weight DESC')
+ Function.find(:all, :conditions => {:library => lib.name, :ns => ns, :version => lib.version}, :order => 'name ASC, weight DESC')
end
def self.versions_of(function)
View
4 app/models/library.rb
@@ -12,4 +12,8 @@ def self.versions(name)
Library.find_all_by_name(name).map{|l| l.version}
end
+ def self.versions_of(library)
+ Library.find(:all, :conditions => {:name => library.name})
+ end
+
end
View
47 app/views/_lib_namespaces.html.erb
@@ -1,13 +1,16 @@
<%
-lib_name = (params[:lib].gsub("^", "/") rescue nil || @function.library || nil)
-library = Library.find_by_name(lib_name)
-current_ns = @function.ns rescue nil || params[:ns] || ""
-if library
+if not @library
+ @library = Library.find_by_url_friendly_name(params[:lib])
+end
- require 'tree'
- _nss = Function.find(:all, :conditions => {:library => library.name}, :select => 'distinct(ns),ns').map(&:ns).sort
+current_ns = params[:ns]
+if @library
+
+ require 'tree'
+ _nss = Function.find(:all, :conditions => {:library => @library.name}, :select => 'distinct(ns),ns').map(&:ns).sort
+
@ns_flat_list = _nss
_nss = _nss.map do |ns|
@@ -58,27 +61,31 @@ if library
<% if @ns_flat_list.index(c.content) %>
<li>
<span<%= (current_ns == c.content ? " class=\"current_ns\"" : "")%>>
- <%= link_to ns, {:controller => 'main', :action => 'ns', :lib => lib.name, :version => lib.version, :ns => c.content} %>
- </span>
- <% if c.children.size > 0 then generate_level(lib, current_ns, c) end %>
- </li>
- <% else %>
- <li><%= if ns.size <= 22 then ns else ("..." + ns[ns.size-22, ns.size]) end %>
- <% if c.children.size > 0 then generate_level(lib, current_ns, c) end %>
- </li>
- <% end %>
- <%
- end
- %>
+ <%= link_to ns,
+ :controller => 'main',
+ :action => 'ns',
+ :lib => lib.url_friendly_name,
+ :version => (params[:version] ? params[:version] : lib.version),
+ :ns => c.content %>
+ </span>
+ <% if c.children.size > 0 then generate_level(lib, current_ns, c) end %>
+ </li>
+ <% else %>
+ <li>
+ <%= if ns.size <= 22 then ns else ("..." + ns[ns.size-22, ns.size]) end %>
+ <% if c.children.size > 0 then generate_level(lib, current_ns, c) end %>
+ </li>
+ <% end %>
+ <% end %>
</ul>
<%
-end
+ end
_nss = treeify(Tree::TreeNode.new("ROOT", "root node"), _nss)
%>
<div class="namespaces">
<h3>Namespaces</h3>
- <% generate_level(library, current_ns, _nss) %>
+ <% generate_level(@library, current_ns, _nss) %>
</div>
<% end %>
View
2 app/views/layouts/_header.html.erb
@@ -47,7 +47,7 @@
<div class="grid_8">
<% if params[:lib] %>
- <h1><a href="/">ClojureDocs</a><span class="version">(alpha)</span> :: <a class="lib_name" href="/<%= params[:lib] %>"><%= params[:lib] %></a></h1>
+ <h1><a href="/">ClojureDocs</a><span class="version">(alpha)</span> :: <a class="lib_name" href="/<%= @library.url_friendly_name %>"><%= @library.name %></a></h1>
<% else %>
<h1><a href="/">ClojureDocs</a><span class="version">(alpha)</span></h1>
<% end %>
View
4 app/views/main/_lib_nav.html.erb
@@ -1,6 +1,6 @@
<div class="lib_nav">
- <h2><%= link_to lib.name, :controller => 'main', :action => 'lib', :lib => lib.name %></h2>
+ <h2><%= link_to lib.name, :controller => 'main', :action => 'lib', :lib => lib.url_friendly_name %></h2>
<% if lib.name == "Clojure Core"%>
<ul class="level_0">
<li>
@@ -10,7 +10,7 @@
<li><a href="/quickref/varsonly/Clojure%20Core">Vars Only</a></li>
</ul>
</li>
- <li><a href="/Clojure%20Core">Alphabetical</a></li>
+ <li><a href="/clojure_core">Alphabetical</a></li>
</ul>
<% end %>
</div>
View
10 app/views/main/function.html.erb
@@ -31,7 +31,13 @@ $(document).ready(function() {
<% if @function.version == f.version %>
<span class="selected"><%= f.version %></span>
<% else %>
- <a href="<%= f.href %>"><%= f.version %></a>
+ <%= link_to f.version,
+ :controller => 'main',
+ :action => 'function',
+ :lib => @library.url_friendly_name,
+ :version => f.version,
+ :ns => f.ns,
+ :function => f.url_friendly_name %>
<% end %>
<% end %>
<!-- <a href="/v/<%= @function.id %>">short link to this var</a> -->
@@ -46,7 +52,7 @@ $(document).ready(function() {
<span class="ns">
<%= link_to @function.ns, :controller => "main",
:action => "ns",
- :lib => @function.library,
+ :lib => @library.url_friendly_name,
:ns => @function.ns,
:version => @function.version %>
</span>
View
2 app/views/main/index.html.erb
@@ -6,7 +6,7 @@
<div class="core_libraries">
<h2>Core Language</h2>
<div class="library">
- <h3><a href="/Clojure%20Core">Clojure Core</a></h3>
+ <h3><a href="/clojure_core">Clojure Core</a></h3>
<a href="/quickref/Clojure%20Core">Quick Reference</a><br />
<a href="http://clojure.org">http://clojure.org</a><br />
<p>Clojure is a dynamic programming language that targets the Java Virtual Machine (and the CLR).</p>
View
10 app/views/main/lib.html.erb
@@ -8,7 +8,15 @@
</div>
<div class="grid_10">
<div class="lib_header">
- <%= @library.version %>
+ <div class="short_link versions_nav">
+ <% Library.versions_of(@library).each do |l| %>
+ <% if @library.version == l.version %>
+ <span class="selected"><%= l.version %></span>
+ <% else %>
+ <a href="/<%= l.url_friendly_name %>/<%= l.version %>"><%= l.version %></a>
+ <% end %>
+ <% end %>
+ </div>
<% if @library.site_url then %><p><a href="<%= @library.site_url %>"><%= @library.site_url %></a></p><% end %>
<% if @library.description then %>
<p><%= @library.description %></p>
View
10 app/views/main/ns.html.erb
@@ -24,7 +24,15 @@
<h5><%= g[0] %></h5>
<div class="functions">
<% g[1].each do |f| %>
- <span class="function"><a href="<%= f.href %>"><%= f[:name] %></a></span>
+ <span class="function">
+ <%= link_to f[:name],
+ :controller => 'main',
+ :action => 'function',
+ :lib => @library.url_friendly_name,
+ :version => params[:version],
+ :ns => f[:ns],
+ :function => f[:url_friendly_name] %>
+ </span>
<% end %>
</div>
<div class="clear"></div>
View
13 app/views/see_also/_see_also_content.html.erb
@@ -1,5 +1,6 @@
<%
f = sa.to_function
+lib = Library.find_by_name(f.library)
belongs_to_user = current_user_session && (current_user == sa.user)
%>
<div>
@@ -14,9 +15,15 @@ belongs_to_user = current_user_session && (current_user == sa.user)
<a class="delete" id="delete_<%=sa.id%>" href="#"><%= image_tag "trash_stroke_12x12.png", :alt => "delete" %></a>
<% end %>
</div>
- <a href="<%= f.href %>">
- <span class="ns"><%= f.ns %>/</span><span class="name"><%= f.name %></span>
- </a>
+
+ <%= link_to "<span class='ns'>#{f.ns}/</span><span class='name'>#{f.name}</span>",
+ :controller => 'main',
+ :action => 'function',
+ :lib => lib.url_friendly_name,
+ :version => 'current',
+ :ns => f.ns,
+ :function => f.url_friendly_name %>
+
<p class="shortdoc"><%= f.shortdoc %></p>
<div class="clear"></div>
</div>
View
6 config/routes.rb
@@ -79,13 +79,11 @@
map.connect '/management/:lib/function', :controller => 'management', :action => 'function'
map.connect '/management/:lib', :controller => 'management'
- # ex.
- # /Clojure%20Core -> lib page,
- # /Clojure%20Core/clojure.core -> ns page,
- # /Clojure%20Core/clojure.core/bigdec -> var page
+
map.connect '/:lib', :controller => 'main', :action => 'lib'
map.connect '/:lib/:version', :controller => 'main', :action => 'lib'
map.connect '/:lib/:version/:ns', :controller => 'main', :action => 'ns'
+ map.connect '/:lib/:version/:ns/:function', :controller => 'main', :action => 'function'
# See how all your routes lay out with "rake routes"
View
12 db/migrate/20101005183717_add_versions.rb
@@ -3,11 +3,23 @@ def self.up
add_column :functions, :version, :string
add_column :namespaces, :version, :string
add_column :libraries, :version, :string
+ add_column :libraries, :current, :boolean
+
+ cclib = Library.find_by_name("Clojure Core")
+ cclib.version = "1.2.0"
+ cclib.current = true
+ cclib.save
+
+ Function.find_all_by_library("Clojure Core").each do |f|
+ f.version = "1.2.0"
+ f.save
+ end
end
def self.down
remove_column :functions, :version
remove_column :namespaces, :version
remove_column :libraries, :version
+ remove_column :libraries, :current
end
end
View
1 db/schema.rb
@@ -82,6 +82,7 @@
t.string "copyright"
t.string "license"
t.string "version"
+ t.boolean "current"
t.string "url_friendly_name"
end

0 comments on commit c6ee811

Please sign in to comment.