implement ref version dropdown
This commit is contained in:
Родитель
2d52963436
Коммит
97bc298a6a
2
Gemfile
2
Gemfile
|
@ -18,6 +18,8 @@ gem 'netrc'
|
|||
gem 'launchy'
|
||||
gem 'rubyzip'
|
||||
gem 'octokit'
|
||||
gem 'dalli'
|
||||
gem 'diff-lcs'
|
||||
|
||||
# Gems used only for assets and not required
|
||||
# in production environments by default.
|
||||
|
|
|
@ -48,6 +48,8 @@ GEM
|
|||
compass-rails (1.0.1)
|
||||
compass (~> 0.12.0)
|
||||
daemons (1.1.8)
|
||||
dalli (2.0.3)
|
||||
diff-lcs (1.1.3)
|
||||
erubis (2.7.0)
|
||||
eventmachine (0.12.10)
|
||||
excon (0.9.6)
|
||||
|
@ -181,6 +183,8 @@ DEPENDENCIES
|
|||
awesome_print
|
||||
coffee-rails (~> 3.2.1)
|
||||
compass-rails
|
||||
dalli
|
||||
diff-lcs
|
||||
excon (~> 0.9.4)
|
||||
factory_girl_rails
|
||||
faraday
|
||||
|
|
9
TODO.txt
9
TODO.txt
|
@ -3,6 +3,7 @@ Content Linking:
|
|||
# linkify front page
|
||||
# get company logo perms
|
||||
* SFC donate page?
|
||||
* change win download repo to msys when they start uploading
|
||||
|
||||
Functionality:
|
||||
|
||||
|
@ -13,10 +14,7 @@ Functionality:
|
|||
* "admonition block" (eg. NOTE at the end of git-blame)
|
||||
|
||||
* Downloads
|
||||
- /download/(mac/win/linux)
|
||||
- show guis
|
||||
- /download/gui/(mac/win/linux)
|
||||
- show guis
|
||||
|
||||
* Version Dropdown
|
||||
* highlight current version
|
||||
|
@ -52,7 +50,6 @@ Functionality:
|
|||
- libgit2 and wrappers
|
||||
|
||||
|
||||
|
||||
--
|
||||
|
||||
* release notes box
|
||||
|
@ -81,3 +78,7 @@ Functionality:
|
|||
* caching, speed
|
||||
|
||||
* 404 page
|
||||
|
||||
--
|
||||
|
||||
* db-ify GUIs?
|
||||
|
|
|
@ -7,6 +7,10 @@ class DocController < ApplicationController
|
|||
def ref
|
||||
end
|
||||
|
||||
def test
|
||||
render 'doc/rebase'
|
||||
end
|
||||
|
||||
def man
|
||||
if params[:version]
|
||||
doc_version = DocVersion.for_version(params[:file], params[:version])
|
||||
|
@ -16,13 +20,27 @@ class DocController < ApplicationController
|
|||
|
||||
@versions = []
|
||||
versions = DocVersion.latest_versions(params[:file])
|
||||
unchanged = []
|
||||
for i in 0..(versions.size-2)
|
||||
v = versions[i]
|
||||
prev = versions[i+1]
|
||||
sha2 = v.doc.blob_sha
|
||||
sha1 = prev.doc.blob_sha
|
||||
@versions << {:name => v.version.name, :time => v.version.committed, :changed => (sha1 == sha2)}
|
||||
if sha1 == sha2
|
||||
unchanged << v.version.name
|
||||
else
|
||||
if unchanged.size > 0
|
||||
if unchanged.size == 1
|
||||
@versions << {:name => "#{unchanged.first} no changes", :changed => false}
|
||||
else
|
||||
@versions << {:name => "#{unchanged.last} → #{unchanged.first} no changes", :changed => false}
|
||||
end
|
||||
unchanged = []
|
||||
end
|
||||
@versions << {:name => v.version.name, :time => v.version.committed, :diff => Doc.get_diff(sha2, sha1), :changed => true}
|
||||
end
|
||||
end
|
||||
@versions = @versions[0,20]
|
||||
|
||||
if doc_version.nil?
|
||||
redirect_to :ref
|
||||
|
|
|
@ -1,7 +1,37 @@
|
|||
require 'diff/lcs'
|
||||
require 'pp'
|
||||
|
||||
# t.text :blob_sha
|
||||
# t.text :plain
|
||||
# t.text :html
|
||||
# t.timestamps
|
||||
class Doc < ActiveRecord::Base
|
||||
has_many :doc_versions
|
||||
|
||||
# returns an array of the differences with 3 entries
|
||||
# 0: additions
|
||||
# 1: subtractions
|
||||
# 2: 8 - (add + sub)
|
||||
def self.get_diff(sha_to, sha_from)
|
||||
key = "diff-#{sha_to}-#{sha_from}"
|
||||
Rails.cache.fetch(key) do
|
||||
doc_to = Doc.where(:blob_sha => sha_to).first.plain.split("\n")
|
||||
doc_from = Doc.where(:blob_sha => sha_from).first.plain.split("\n")
|
||||
diff = Diff::LCS.diff(doc_to, doc_from)
|
||||
total = adds = mins = 0
|
||||
diff.first.each do |change|
|
||||
adds += 1 if change.action == '+'
|
||||
mins += 1 if change.action == '-'
|
||||
total += 1
|
||||
end
|
||||
if total > 8
|
||||
min = (8.0 / total)
|
||||
adds = (adds * min).floor
|
||||
mins = (mins * min).floor
|
||||
[adds, mins, (8 - total)]
|
||||
else
|
||||
[adds, mins, (8 - total)]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ class DocVersion < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.latest_versions(doc_name)
|
||||
for_doc(doc_name).joins(:version).order('versions.vorder DESC').limit(15)
|
||||
for_doc(doc_name).joins(:version).order('versions.vorder DESC')
|
||||
end
|
||||
|
||||
def self.for_version(doc_name, version_name)
|
||||
|
|
|
@ -1,19 +1,29 @@
|
|||
<a class="dropdown-trigger" id="reference-versions-trigger" data-panel-id="previous-versions-dropdown" href="#">Version <%= @version.name %> ▾</a>
|
||||
<span class="light"><%= @file.name %> last updated in <%= @last.version.name %></span>
|
||||
<div class='dropdown-panel left' id='previous-versions-dropdown'>
|
||||
<header>Changes in the <strong><%= @file.name %></strong> manual</header>
|
||||
<ol class='reference-previous-versions'>
|
||||
<% @versions.each do |v| %>
|
||||
<li>
|
||||
<a href="/ref/<%= @file.name %>/<%= v[:name] %>">
|
||||
<span class="version"><%= v[:name] %></span>
|
||||
<% if v[:changed] %>
|
||||
<span class="changes no"><%= @file.name %> unchanged</span>
|
||||
<% else %>
|
||||
<span class="changes yes"><%= @file.name %> updated</span>
|
||||
<% end %>
|
||||
<em class="date"><%= v[:time].strftime("%m/%d/%y") %></em>
|
||||
</a>
|
||||
</li>
|
||||
<% if v[:changed] %>
|
||||
<li>
|
||||
<a href="/ref/<%= @file.name %>/<%= v[:name] %>"><span class="version"><%= v[:name] %></span>
|
||||
<span class="diff">
|
||||
<% v[:diff][0].times do %>
|
||||
<img src="/images/icons/green-dot.png" />
|
||||
<% end %>
|
||||
<% v[:diff][1].times do %>
|
||||
<img src="/images/icons/red-dot.png" />
|
||||
<% end %>
|
||||
<% v[:diff][2].times do %>
|
||||
<img src="/images/icons/grey-dot.png" />
|
||||
<% end %>
|
||||
</span>
|
||||
<em class="date"><%= v[:time].strftime("%m/%d/%y") %></em>
|
||||
</a>
|
||||
</li>
|
||||
<% else %>
|
||||
<li class="no-change"><span><%=raw v[:name] %></span></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<li>
|
||||
<a class="more" href="#">See more previous releases →</a>
|
||||
|
@ -21,6 +31,7 @@
|
|||
</ol>
|
||||
<footer>
|
||||
<span class="light">Check your version of git by running<br></span>
|
||||
<strong>$</strong> git --version
|
||||
<strong>$</strong>
|
||||
<input type="text" class="copyable" value="git --version" />
|
||||
</footer>
|
||||
</div>
|
||||
|
|
|
@ -39,8 +39,7 @@ Gitscm::Application.configure do
|
|||
# Use a different logger for distributed setups
|
||||
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
||||
|
||||
# Use a different cache store in production
|
||||
# config.cache_store = :mem_cache_store
|
||||
config.cache_store = :dalli_store
|
||||
|
||||
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
||||
# config.action_controller.asset_host = "http://assets.example.com"
|
||||
|
|
|
@ -5,6 +5,7 @@ Gitscm::Application.routes.draw do
|
|||
match "/ref" => "doc#ref"
|
||||
match "/ref/:file" => "doc#man"
|
||||
match "/ref/:file/:version" => "doc#man", :version => /[^\/]+/
|
||||
match "/test" => "doc#test"
|
||||
match "/book" => "doc#book"
|
||||
match "/videos" => "doc#videos"
|
||||
match "/doc/ext" => "doc#ext"
|
||||
|
|
Загрузка…
Ссылка в новой задаче