Permalink
Browse files

Modified routing so that omitting a version number now points to the

stable version of a lib / ns / var.

Version UI done for var page, need to add to lib / ns pages.
  • Loading branch information...
1 parent 0b51e2b commit 2a006163c7decb91acf58137507a5a228d4ca88b @zk committed Oct 8, 2010
@@ -33,7 +33,7 @@ def lib
@library = nil
- if version and version != 'current'
+ if version
@library = Library.find_by_url_friendly_name_and_version(name, version)
else
@library = Library.find_by_url_friendly_name_and_current(name, true)
@@ -140,14 +140,14 @@ def ns
ns_name = params[:ns]
@library = nil
- if version and version != 'current'
+ if version
@library = Library.find_by_url_friendly_name_and_version(lib_name, version)
else
@library = Library.find_by_url_friendly_name_and_current(lib_name, true)
end
@ns = nil
- if version and version != 'current'
+ if version
@ns = Namespace.find_by_name_and_version(ns_name, version)
else
@ns = Namespace.find_by_name(ns_name)
@@ -168,7 +168,7 @@ def function
function_url_name = params[:function]
@library = nil
- if version and version != 'current'
+ if version
@library = Library.find_by_url_friendly_name_and_version(lib_url_name, version)
else
@library = Library.find_by_url_friendly_name_and_current(lib_url_name, true)
@@ -239,7 +239,7 @@ def function_short_link
redirect_to :controller => 'main',
:action => 'function',
:lib => @library.url_friendly_name,
- :version => (@library.current ? 'current' : @library.version),
+ :version => (@library.current ? nil : @library.version),
:ns => @function.ns,
:function => @function.url_friendly_name
@@ -255,17 +255,22 @@ def search_autocomplete
end
q = '"' + q + '*"'
+
+ core_current_version = (Library.find_by_name_and_current("Clojure Core", true).version rescue nil || "1.2.0")
+ contrib_current_version = (Library.find_by_name_and_current("Clojure Contrib", true).version rescue nil || "1.2.0")
+
- @functions = Function.search("@name #{q} @library (\"Clojure Core\" | \"Clojure Contrib\")", :field_weights => {
+ @functions = Function.search("@name #{q} @library (\"Clojure Core\" | \"Clojure Contrib\") @version (\"#{core_current_version}\" | \"#{contrib_current_version}\")", :field_weights => {
:name => 100,
:library => 1,
:ns => 1,
- :doc => -1
+ :doc => -1,
}, :match_mode => :extended)
@functions.delete(nil)
if @functions != nil and @functions.size > 0
+ # sort clojure core & contrib higher than other libs
@functions.sort!{|a,b|
aval = 0
bval = 0
View
@@ -27,6 +27,7 @@ class Function < ActiveRecord::Base
indexes doc
indexes library
indexes ns
+ indexes version
end
#:nocov:
@@ -74,8 +75,32 @@ 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),
+ :version => (use_current_vs_actual_version && library_.current ? nil : version),
:ns => ns,
:function => url_friendly_name}
end
+
+ def all_versions_examples
+ Function.versions_of(self).reduce([]) do |coll, f|
+ coll + f.examples
+ end
+ end
+
+ def all_versions_see_alsos
+ Function.versions_of(self).reduce([]) do |coll, f|
+ coll + f.see_alsos
+ end.sort{|a,b| b.vote_score <=> a.vote_score}
+ end
+
+ def stable_version
+ stable_lib = Library.find_by_name_and_current(library, true)
+ if not stable_lib
+ return nil
+ end
+
+ Function.find(:first, :conditions => {:library => library,
+ :ns => ns,
+ :name => name,
+ :version => stable_lib.version})
+ end
end
@@ -65,7 +65,7 @@ if @library
:controller => 'main',
:action => 'ns',
:lib => lib.url_friendly_name,
- :version => (params[:version] ? params[:version] : lib.version),
+ :version => params[:version],
:ns => c.content %>
</span>
<% if c.children.size > 0 then generate_level(lib, current_ns, c) end %>
@@ -21,8 +21,8 @@ $(document).ready(function() {
<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 %>.
+ You're viewing version <%= @function.version %> of <%= @function.name %>.
+ The latest stable version of <%= @library.name %> is <%= Library.current_version_of(@library).version %>.
</div>
<% end %>
<a name="top"></a>
@@ -32,26 +32,48 @@ $(document).ready(function() {
<a href="#examples" class="scroll">examples</a>
<a href="#comments" class="scroll">comments</a>
</div>
- <div class="short_link versions_nav">
+
+ <script type="text/javascript" charset="utf-8">
+ $(document).ready(function() {
+ $(".versions_nav").click(function() {
+ $(".versions_nav ul").toggle()
+ })
+ })
+ </script>
+
+
+ <div class="versions_nav">
+ <span>
+ <%= @function.version %>
+ <% if @function.library_.current && params[:version] %>
+ permalink
+ <% end %>
+ <%= image_tag "arrow_down_16x16.png" %>
+ </span>
+ <ul>
+ <!-- <% if @function.stable_version %>
+ <li>
+ <%= link_to 'stable', @function.stable_version.link_opts, :class => 'stable' %>
+ </li>
+ <% end %> -->
<% Function.versions_of(@function).each do |f| %>
- <% if @function.version == f.version %>
- <% 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 %>
- <% if f.library_.current %>
- <%= link_to "<span class='current'>#{f.version}</span>", f.link_opts %>
+ <%
+ classes = []
+ if @function.version == f.version then classes << "selected" end
+ if f.library_.current then classes << "stable" end
+ %>
+ <li>
+ <% if @function.version == f.version && f.library_.current && !params[:version]%>
+ <%= link_to f.version + " permalink", f.link_opts(false), :class => classes.join(' ') %>
<% else %>
- <%= link_to f.version, f.link_opts %>
+ <%= link_to f.version, f.link_opts, :class => classes.join(' ') %>
<% end %>
- <% end %>
+ </li>
<% end %>
+ </ul>
<!-- <a href="/v/<%= @function.id %>">short link to this var</a> -->
</div>
<div class="clear"></div>
-
<div class="function_header">
<h1>
<%= @function.name %>
@@ -64,9 +86,6 @@ $(document).ready(function() {
:ns => @function.ns,
:version => @function.version %>
</span>
- <% if @function.added %>
- <span class="added">(since <%= @function.added %>)</span>
- <% end %>
</h2>
<div class="clear"></div>
@@ -81,6 +100,7 @@ $(document).ready(function() {
</ul>
</div>
<% end %>
+
<% if @function.doc %>
<div class="doc">
@@ -97,16 +117,16 @@ $(document).ready(function() {
<div class="examples">
<h3>
<a class="internal_nav scroll" href="#examples" name="examples">
- <span id="examples_count"><%= @function.examples.size %></span> <span id="examples_desc">Example<% if @function.examples.size != 1 then %>s<% end %></span>
+ <span id="examples_count"><%= @function.all_versions_examples.size %></span> <span id="examples_desc">Example<% if @function.all_versions_examples.size != 1 then %>s<% end %></span>
</a>
<a class="top scroll" href="#top">top</a>
</h3>
- <% if @function.examples.size == 0 %>
+ <% if @function.all_versions_examples.size == 0 %>
<ul id="var_examples">
</ul>
<% else %>
<ul id="var_examples">
- <% @function.examples.each do |e| %>
+ <% @function.all_versions_examples.each do |e| %>
<li>
<%= render :partial => '/examples/example', :locals => {:e => e} %>
</li>
@@ -126,7 +146,7 @@ $(document).ready(function() {
<div style="text-align: right">
<a class="cancel" href="" style="float: left">Cancel</a>
<!-- <input class="preview_example" type="button" value="Preview" /> -->
- <%= f.submit 'Add example'%>
+ <%= f.submit 'Add example' %>
</div>
<input type="hidden" name="isexample" value="true" />
<input type="hidden" name="var_id" value="<%= @function.id %>" />
@@ -143,16 +163,14 @@ $(document).ready(function() {
<a href="" id="add_new_example">Add an example.</a>
<% else %>
Log in to add / edit an example.
- <% end %>
-
+ <% end %>
</div>
-
<div class="see_alsos">
<h3>See Also <a class="top scroll" href="#top">top</a></h3>
<ul>
- <% @function.see_alsos_sorted.each do |sa| %>
+ <% @function.all_versions_see_alsos.each do |sa| %>
<li class="see_also_item" id="see_also_item_<%=sa.id%>">
<%= render :partial => "/see_also/see_also_content", :locals => {:sa => sa} %>
</li>
@@ -6,6 +6,15 @@
&nbsp;
</div>
<div class="grid_10">
+ <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 %>/<%= @ns.name %>"><%= l.version %></a>
+ <% end %>
+ <% end %>
+ </div>
<% if @ns and @ns.doc != ""%>
<div class="doc">
<h3>DocString</h3>
@@ -20,7 +20,7 @@ belongs_to_user = current_user_session && (current_user == sa.user)
:controller => 'main',
:action => 'function',
:lib => lib.url_friendly_name,
- :version => 'current',
+ :version => nil,
:ns => f.ns,
:function => f.url_friendly_name %>
View
@@ -79,11 +79,16 @@
map.connect '/management/:lib/function', :controller => 'management', :action => 'function'
map.connect '/management/:lib', :controller => 'management'
+ version_regex = /\d+\.[^\/]*/
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'
+ map.connect '/:lib/:version', :controller => 'main', :action => 'lib', :requirements => {:version => version_regex}
+ map.connect '/:lib/:version/:ns', :controller => 'main', :action => 'ns', :requirements => {:version => version_regex}
+ map.connect '/:lib/:version/:ns/:function', :controller => 'main', :action => 'function', :requirements => {:version => version_regex}
+
+ map.connect '/:lib', :controller => 'main', :action => 'lib', :version => nil
+ map.connect '/:lib/:ns', :controller => 'main', :action => 'ns', :version => nil
+ map.connect '/:lib/:ns/:function', :controller => 'main', :action => 'function', :version => nil
# See how all your routes lay out with "rake routes"
@@ -1,5 +1,7 @@
class AddVersions < ActiveRecord::Migration
+
def self.up
+
add_column :functions, :version, :string
add_column :namespaces, :version, :string
add_column :libraries, :version, :string
@@ -10,10 +12,25 @@ def self.up
cclib.current = true
cclib.save
+ cont_lib = Library.find_by_name("Clojure Contrib")
+ cont_lib.version = "1.2.0"
+ cont_lib.current = true
+ cont_lib.save
+
Function.find_all_by_library("Clojure Core").each do |f|
f.version = "1.2.0"
f.save
end
+
+ Function.find_all_by_library("Clojure Contrib").each do |f|
+ f.version = "1.2.0"
+ f.save
+ end
+
+ Namespace.find(:all, :conditions => ["name LIKE ?", "clojure.%"]).each do |n|
+ n.version = "1.2.0"
+ n.save
+ end
end
def self.down
@@ -2,6 +2,22 @@ class SeoUrls < ActiveRecord::Migration
def self.up
add_column :libraries, :url_friendly_name, :string
add_column :functions, :url_friendly_name, :string
+
+
+ #Dosen't seem to matter in the other migrations, but this is req'd for save to work
+ Library.reset_column_information
+ Function.reset_column_information
+
+ Library.find(:all).each do |l|
+ l.url_friendly_name = l.name.gsub("?","_q").gsub("/","_").gsub(" ","_").downcase
+ l.save
+ end
+
+ Function.find(:all).each do |f|
+ f.url_friendly_name = f.name.gsub("?","_q").gsub("/","_").gsub(" ","_").downcase
+ f.save
+ end
+
end
def self.down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 2a00616

Please sign in to comment.