Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 2a006163c7decb91acf58137507a5a228d4ca88b 1 parent 0b51e2b
Zachary Kim authored
19 app/controllers/main_controller.rb
View
@@ -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
27 app/models/function.rb
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
2  app/views/_lib_namespaces.html.erb
View
@@ -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 %>
70 app/views/main/function.html.erb
View
@@ -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>
9 app/views/main/ns.html.erb
View
@@ -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>
2  app/views/see_also/_see_also_content.html.erb
View
@@ -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 %>
11 config/routes.rb
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"
17 db/migrate/20101005183717_add_versions.rb
View
@@ -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
16 db/migrate/20101006031711_seo_urls.rb
View
@@ -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
BIN  public/images/arrow_down_16x16.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  public/images/arrow_down_alt1_16x16.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 public/stylesheets/main.css
View
@@ -230,7 +230,7 @@ h2.section_header {
}
.function_links {
- width: 80%;
+ width: 60%;
float: left;
}
@@ -244,18 +244,23 @@ h2.section_header {
font-weight: 300;
}
+.function_header {
+ position: relative;
+}
+
.function_header h1 {
display: inline;
}
.function_header h2 {
- display: inline;
font-size: 12pt;
color: #777;
- float: right;
+ position: absolute;
+ top: 0px;
+ right: 0px;
}
-.function_header span.ns a {
+.function_header .ns a {
color: #777;
font-size: 14pt;
}
@@ -897,25 +902,66 @@ span.version {
}
-.versions_nav a {
- color: #aaa;
+.versions_nav {
+ font-size: 14pt;
+ float: right;
}
-.versions_nav a .selected {
- font-weight: bold;
+.versions_nav span {
+ padding-right: 3px;
+}
+
+.versions_nav span img {
+ margin-bottom: -1px;
+}
+
+.versions_nav span:hover {
+ background-color: #eee;
+ cursor: pointer;
+}
+
+.versions_nav ul {
+ position: absolute;
+ right: 0px;
+ display: none;
+ border: solid #eee 1px;
+ background-color: white;
+ z-index: 1;
+}
+
+.versions_nav ul a {
color: black;
+ display: block;
+ padding: 5px;
+ background-color: #ffaaaa;
}
-.versions_nav a .current {
- background-color: #ffffaa;
+.versions_nav ul a:hover {
+ text-decoration: none;
+ background-color: #ff0000;
+ color: white;
}
+.versions_nav .selected {
+ color: black;
+}
+
+.versions_nav ul a.stable {
+ background-color: #88ff88;
+}
+
+.versions_nav ul a.stable:hover {
+ background-color: #00aa00;
+}
+
+
.version_warning {
text-align: center;
padding: 10px;
- background-color: #ffffaa;
+ background-color: #ff0000;
border: solid #ccc 1px;
margin-bottom: 5px;
+ color: white;
}
Please sign in to comment.
Something went wrong with that request. Please try again.