Browse files

Limited see also lookup to same library / version

Fixed failing data migration
  • Loading branch information...
1 parent 7ff50be commit 2bc2c2b03d8711af9bef3ccf6c337a4edba1530b @zk committed Oct 10, 2010
View
1 Gemfile
@@ -19,4 +19,5 @@ group :test do
gem "autotest-fsevent", "0.2.3"
gem "autotest-growl", "0.2.6"
gem "rcov", "0.9.9", :require => nil
+ gem "ruby-prof", "0.9.2"
end
View
2 Gemfile.lock
@@ -39,6 +39,7 @@ GEM
rcov (0.9.9)
rdiscount (1.6.5)
ruby-openid (2.1.7)
+ ruby-prof (0.9.2)
rubyforge (2.0.4)
json_pure (>= 1.1.7)
rubytree (0.7.0)
@@ -63,6 +64,7 @@ DEPENDENCIES
rcov (= 0.9.9)
rdiscount (= 1.6.5)
ruby-openid (= 2.1.7)
+ ruby-prof (= 0.9.2)
rubytree (= 0.7.0)
shoulda (= 2.11.3)
will_paginate (= 2.3.12)
View
22 app/controllers/main_controller.rb
@@ -164,13 +164,21 @@ def function
ns = params[:ns]
function_url_name = params[:function]
- @function = Function.find(
- :first,
- :include => [:namespace, {:namespace => :library}],
- :conditions => {
- :namespaces => {:name => ns, :libraries => {:url_friendly_name => lib_url_name}},
- :url_friendly_name => function_url_name}
- )
+ if version
+ @function = Function.find(
+ :first,
+ :include => [:namespace, {:namespace => :library}],
+ :conditions => {
+ :namespaces => {:name => ns, :libraries => {:url_friendly_name => lib_url_name, :version => version}},
+ :url_friendly_name => function_url_name})
+ else
+ @function = Function.find(
+ :first,
+ :include => [:namespace, {:namespace => :library}],
+ :conditions => {
+ :namespaces => {:name => ns, :libraries => {:url_friendly_name => lib_url_name, :current => true}},
+ :url_friendly_name => function_url_name})
+ end
if not @function
logger.error "Couldn't find function id #{params[:id]}"
View
2 app/controllers/management_controller.rb
@@ -15,7 +15,7 @@ def search
high = Chronic.parse(params[:high_date]).utc rescue nil
@results = Example.find(:all, :conditions => ["updated_at > ? and updated_at < ?", low, high], :order => 'updated_at DESC')
- @results = @results.collect{|e| e.function}.select{|f| f.ns =~ /#{params[:namespaces]}/}
+ @results = @results.collect{|e| e.function}.select{|f| f.namespace.name =~ /#{params[:namespaces]}/}
end
def function
View
4 app/controllers/see_also_controller.rb
@@ -43,15 +43,17 @@ def vote
end
def lookup
+ l = params[:library]
q = params[:term]
+ version = Library.find_by_name_and_current(l, true).version
if not q
render :json => []
return
end
name = q + "%"
- @functions = Function.find(:all, :conditions => ['name like ?', name]).sort{|a,b| Levenshtein.distance(q, a.name) <=> Levenshtein.distance(q, b.name)}
+ @functions = Function.find(:all, :conditions => ['name like ? and version = ?', name, version]).sort{|a,b| Levenshtein.distance(q, a.name) <=> Levenshtein.distance(q, b.name)}.uniq
if @functions.size > 10
@functions = @functions[0, 10]
View
7 app/models/library.rb
@@ -21,4 +21,11 @@ def self.current_version_of(library)
Library.find_by_name_and_current(library.name, true)
end
+ def link_opts(use_current_vs_actual_version = true)
+ {:controller => 'main',
+ :action => 'lib',
+ :lib => url_friendly_name,
+ :version => (use_current_vs_actual_version && current ? nil : version)}
+ end
+
end
View
9 app/models/namespace.rb
@@ -3,7 +3,14 @@ class Namespace < ActiveRecord::Base
has_many :functions
def self.versions_of(ns)
- Namespace.find(:all, :conditions => {:name => ns.name})
+ Namespace.find(:all, :include => :library, :conditions => {:name => ns.name, :libraries => {:name => ns.library.name}})
end
+ def link_opts(use_current_vs_actual_version = true)
+ {:controller => 'main',
+ :action => 'ns',
+ :lib => library.url_friendly_name,
+ :version => (use_current_vs_actual_version && library.current ? nil : library.version),
+ :ns => name}
+ end
end
View
1 app/views/main/function.html.erb
@@ -8,6 +8,7 @@ $(document).ready(function() {
CD.VarPage.init({
varId: <%= @function.id %>,
library: "<%= @function.library.name %>",
+ version: "<%= @function.library.version %>",
editExampleFormHTML: '<%= (render :partial => '/examples/edit_example_form').gsub("\n", "")%>',
editCommentFormHTML: '<%= (render :partial => '/comments/edit_comment_form').gsub("\n", "")%>',
})
View
38 app/views/main/lib.html.erb
@@ -1,6 +1,14 @@
<% content_for :title, " - #{@library.name} #{@library.version}" %>
+<script type="text/javascript" charset="utf-8">
+ $(document).ready(function() {
+ $(".versions_nav").click(function() {
+ $(".versions_nav ul").toggle()
+ })
+ })
+</script>
+
<div class="grid_3">
<%= render :partial => 'lib_nav', :locals => {:lib => @library} %>
<%= render :partial => '/lib_namespaces' %>
@@ -14,15 +22,33 @@
</div>
<% end %>
<div class="lib_header">
- <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>
+ <div class="versions_nav">
+ <span>
+ <%= @library.version %>
+ <% if @library.current && params[:version] %>
+ permalink
<% end %>
+ <%= image_tag "arrow_down_16x16.png" %>
+ </span>
+ <ul>
+
+ <% Library.versions_of(@library).each do |l| %>
+ <%
+ classes = []
+ if @library.version == l.version then classes << "selected" end
+ if l.current then classes << "stable" end
+ %>
+ <li>
+ <% if @library.version == l.version && l.current && !params[:version]%>
+ <%= link_to l.version + " permalink", l.link_opts(false), :class => classes.join(' ') %>
+ <% else %>
+ <%= link_to l.version, l.link_opts, :class => classes.join(' ') %>
+ <% end %>
+ </li>
<% end %>
+ </ul>
</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
36 app/views/main/ns.html.erb
@@ -1,5 +1,13 @@
<% if @ns then content_for :title, " - #{@ns.name}" end %>
+<script type="text/javascript" charset="utf-8">
+ $(document).ready(function() {
+ $(".versions_nav").click(function() {
+ $(".versions_nav ul").toggle()
+ })
+ })
+</script>
+
<div class="grid_3">
<%= render :partial => 'lib_nav', :locals => {:lib => @library} %>
<%= render :partial => '/lib_namespaces' %>
@@ -12,6 +20,34 @@
The latest stable version of <%= @ns.name %> is <%= Library.current_version_of(@library).version %>.
</div>
<% end %>
+
+ <div class="versions_nav">
+ <span>
+ <%= @ns.version %>
+ <% if @ns.library.current && params[:version] %>
+ permalink
+ <% end %>
+ <%= image_tag "arrow_down_16x16.png" %>
+ </span>
+ <ul>
+
+ <% Namespace.versions_of(@ns).each do |n| %>
+ <%
+ classes = []
+ if @ns.library.version == n.library.version then classes << "selected" end
+ if n.library.current then classes << "stable" end
+ %>
+ <li>
+ <% if @ns.library.version == n.library.version && n.library.current && !params[:version]%>
+ <%= link_to n.library.version + " permalink", n.link_opts(false), :class => classes.join(' ') %>
+ <% else %>
+ <%= link_to n.library.version, n.link_opts, :class => classes.join(' ') %>
+ <% end %>
+ </li>
+ <% end %>
+ </ul>
+ </div>
+
<% if @ns and @ns.doc != ""%>
<div class="doc">
<h3>DocString</h3>
View
2 app/views/management/function.html.erb
@@ -8,7 +8,7 @@
})
</script>
<h3>
- <span class="ns"><%= link_to @function.ns, :controller => "main", :action => "ns", :lib => @function.library, :ns => @function.ns %></span>/<%= @function.name %>
+ <span class="ns"><%= link_to @function.namespace.name, :controller => "main", :action => "ns", :lib => @function.library, :ns => @function.ns %></span>/<%= @function.name %>
</h3>
<% if @function.arglists.size > 0 %>
View
5 config/routes.rb
@@ -81,12 +81,13 @@
version_regex = /\d+\.[^\/]*/
- map.connect '/:lib', :controller => 'main', :action => 'lib'
+
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', :controller => 'main', :action => 'lib'
map.connect '/:lib/:ns', :controller => 'main', :action => 'ns', :version => nil
map.connect '/:lib/:ns/:function', :controller => 'main', :action => 'function', :version => nil
View
17 db/migrate/20101010021829_add_lib_ns_var_rels.rb
@@ -2,11 +2,11 @@ class AddLibNsVarRels < ActiveRecord::Migration
def self.up
add_column :functions, :namespace_id, :integer
add_column :namespaces, :library_id, :integer
+
+ Namespace.reset_column_information
+ Function.reset_column_information
- functions = Function.find(:all)
- namespaces = Namespace.find(:all)
-
- functions.each do |f|
+ Function.find(:all).each do |f|
ns_id = Namespace.find_by_name_and_version(f.ns, f.version).id rescue nil
if not ns_id
@@ -19,16 +19,17 @@ def self.up
end
end
- namespaces.each do |n|
+ Namespace.find(:all).each do |n|
+
f = Function.find_by_ns_and_version(n.name, n.version)
if not f
f = Function.find_by_ns(n.name)
end
-
+
if f
- l = Library.find_by_name_and_version(f.library, f.version)
+ l = Library.find_by_name_and_version(f.attributes["library"], n.version)
if not l
- l = Library.find_by_name(f.library)
+ l = Library.find_by_name(f.attributes["library"])
end
if l
View
12 db/migrate/20101010212830_add_indexes_to_lib_ns_function.rb
@@ -0,0 +1,12 @@
+class AddIndexesToLibNsFunction < ActiveRecord::Migration
+ def self.up
+ add_index :functions, :namespace_id, :name => 'namespace_id_idx'
+ add_index :namespaces, :library_id, :name => 'library_id_idx'
+ add_index :examples, :function_id, :name => 'function_id_idx'
+ add_index :see_alsos, :from_id, :name => 'from_id_idx'
+ add_index :see_alsos, :to_id, :name => 'to_id_idx'
+ end
+
+ def self.down
+ end
+end
View
11 db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20101010034343) do
+ActiveRecord::Schema.define(:version => 20101010212830) do
create_table "comments", :force => true do |t|
t.integer "commentable_id", :default => 0
@@ -49,6 +49,8 @@
t.integer "user_id"
end
+ add_index "examples", ["function_id"], :name => "function_id_idx"
+
create_table "function_references", :id => false, :force => true do |t|
t.integer "from_function_id"
t.integer "to_function_id"
@@ -71,6 +73,8 @@
t.integer "namespace_id"
end
+ add_index "functions", ["namespace_id"], :name => "namespace_id_idx"
+
create_table "libraries", :force => true do |t|
t.string "name"
t.string "description"
@@ -113,6 +117,8 @@
t.integer "library_id"
end
+ add_index "namespaces", ["library_id"], :name => "library_id_idx"
+
create_table "open_id_authentication_associations", :force => true do |t|
t.integer "issued"
t.integer "lifetime"
@@ -137,6 +143,9 @@
t.datetime "updated_at"
end
+ add_index "see_alsos", ["from_id"], :name => "from_id_idx"
+ add_index "see_alsos", ["to_id"], :name => "to_id_idx"
+
create_table "users", :force => true do |t|
t.string "login"
t.string "email", :null => false
View
12 public/javascripts/cd.js
@@ -434,12 +434,13 @@ CD.SeeAlsos = function() {
initVoteAction(el, "vote_down")
}
- function initAutoComplete(varId, library) {
+ function initAutoComplete(varId, library, version) {
$("#var_name_search").autocomplete({
source: function(req, add) {
params = {
term: req.term,
- library: library
+ library: library,
+ version: version
}
$.getJSON("/see_also/lookup", params, function(data) {
var out = []
@@ -472,8 +473,9 @@ CD.SeeAlsos = function() {
var varId = args.varId
var library = args.library
+ var version = args.version
- initAutoComplete(varId, library)
+ initAutoComplete(varId, library, version)
initItem($(".see_also_item"))
@@ -515,6 +517,7 @@ CD.VarPage = function() {
var editExampleFormHTML = args.editExampleFormHTML
var editCommentFormHTML = args.editCommentFormHTML
var library = args.library
+ var version = args.version
CD.Examples.init({
@@ -523,7 +526,8 @@ CD.VarPage = function() {
CD.SeeAlsos.init({
varId: varId,
- library: library
+ library: library,
+ version: version
})
View
4 test/performance/browsing_test.rb
@@ -6,4 +6,8 @@ class BrowsingTest < ActionController::PerformanceTest
def test_homepage
get '/'
end
+
+ def test_clojure_lib_page
+ get '/clojure_core'
+ end
end

0 comments on commit 2bc2c2b

Please sign in to comment.