Skip to content

Commit

Permalink
Display app version on 'list' action. Code is a straight copy of Haml.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasn committed Sep 5, 2009
1 parent 70d284d commit 98519fe
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion MIT-LICENSE
@@ -1,6 +1,6 @@
== Forgetmenot ==

Copyright (c) 2007 Thomas Nichols and Greencuisine Ltd.
Copyright (c) 2007-2009 Thomas Nichols and Greencuisine Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions VERSION
@@ -0,0 +1 @@
1.5.2
5 changes: 4 additions & 1 deletion app/views/common/list.rhtml
Expand Up @@ -52,4 +52,7 @@
<%= will_paginate @objects %>

<br />


<div id="footer">
<a href="http://openforgetmenot.com/">Forgetmenot</a> <%= Forgetmenot::VERSION %> Copyright &copy; 2007-2009 Nexus 10 and Greencuisine Ltd.
</div>
10 changes: 10 additions & 0 deletions lib/forgetmenot.rb
@@ -0,0 +1,10 @@

require 'forgetmenot/version'

module Forgetmenot
extend Forgetmenot::Version
# A string representing the version of Forgetmenot.
# A more fine-grained representation is available from Forgetmenot.version.
VERSION = version[:string] unless defined?(Forgetmenot::VERSION)
end

49 changes: 49 additions & 0 deletions lib/forgetmenot/version.rb
@@ -0,0 +1,49 @@
# Thanks to: Forgetmenot -- versioning code copied wholesale.

module Forgetmenot
module Version
# Returns a hash representing the version of Forgetmenot.
# The :major, :minor, and :teeny keys have their respective numbers.
# The :string key contains a human-readable string representation of the version.
# If Forgetmenot is checked out from Git,
# the :rev key will have the revision hash.
def version
return @@version if defined?(@@version)

numbers = File.read(scope('VERSION')).strip.split('.').map { |n| n.to_i }
@@version = {
:major => numbers[0],
:minor => numbers[1],
:teeny => numbers[2]
}
@@version[:string] = [:major, :minor, :teeny].map { |comp| @@version[comp] }.compact.join('.')

if File.exists?(scope('REVISION'))
rev = File.read(scope('REVISION')).strip
rev = nil if rev !~ /^([a-f0-9]+|\(.*\))$/
end

if (rev.nil? || rev == '(unknown)') && File.exists?(scope('.git/HEAD'))
rev = File.read(scope('.git/HEAD')).strip
if rev =~ /^ref: (.*)$/
rev = File.read(scope(".git/#{$1}")).strip
end
end

if rev
@@version[:rev] = rev
unless rev[0] == ?(
@@version[:string] << "."
@@version[:string] << rev[0...7]
end
end

@@version
end

# Returns the path of file relative to the Forgetmenot root.
def scope(file) # :nodoc:
File.expand_path File.join(File.dirname(__FILE__), '..', '..', file)
end
end
end

0 comments on commit 98519fe

Please sign in to comment.