# Embedding subversion version information into HTML

**URL:** <https://www.ruby-forum.com/t/embedding-subversion-version-information-into-html/99526>\
**Category:** Rails\
**Created:** [July 23, 2006, 8:32pm UTC](https://www.ruby-forum.com/t/embedding-subversion-version-information-into-html/99526 "2006-07-23T20:32:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [July 23, 2006, 8:32pm UTC](https://www.ruby-forum.com/t/embedding-subversion-version-information-into-html/99526/1 "2006-07-23T20:32:09Z")

</div>

Hi,

Say I want to display the subversion release number in the footer of  
each page in order to track what version of a site I’m looking at.

I know subversion has a substitution keyword (LastChangedRevision)  
that inserts the last known revision in which that file .changed.

So, if I stick $LastChangedRevision$ into  
views/layouts/application.rhtml, it’ll show the last time that file  
was changed, not the current version of the repository. W hich isn’t  
quite what I want. Any ideas?

Thanks,  
Joe

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [July 23, 2006, 8:39pm UTC](https://www.ruby-forum.com/t/embedding-subversion-version-information-into-html/99526/2 "2006-07-23T20:39:48Z")

</div>

I haven’t found a solution other than to modify the keyworded file  
every time I commit to svn.

Love to hear another solution, but since svn only commits modified  
files, substitution can only happen when this file is changed.

Jodi

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [July 23, 2006, 11:13pm UTC](https://www.ruby-forum.com/t/embedding-subversion-version-information-into-html/99526/3 "2006-07-23T23:13:37Z")

</div>

Don,

I use `svn info` inside of the checked out directory and then parse  
results.

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [July 24, 2006, 10:34am UTC](https://www.ruby-forum.com/t/embedding-subversion-version-information-into-html/99526/4 "2006-07-24T10:34:49Z")

</div>

Here’s a method we use internally:

def svn\_version  
File.new(".svn/entries").each do |x|  
if md = /^[\s]\*url=".\*tags/REL-([\d.-]+)/.match(x)  
return md[1]  
elsif md = /^[\s]\*url=".\*branches/([^/"]+)/.match(x)  
return md[1]  
elsif md = /^[\s]\*revision="([\d]+)/.match(x)  
return md[1]  
end  
end  
return ‘(unknown version)’  
end

… it does some nice things if you’ve deployed from a tag or a branch,  
as well as just returning the raw revision number.

HTH

- james

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [July 25, 2006, 2:06am UTC](https://www.ruby-forum.com/t/embedding-subversion-version-information-into-html/99526/5 "2006-07-25T02:06:38Z")

</div>

Joe Van D. wrote:

> Hi,
> 
> Say I want to display the subversion release number in the footer of  
> each page in order to track what version of a site I’m looking at.
> 
> I know subversion has a substitution keyword (LastChangedRevision)  
> that inserts the last known revision in which that file .changed.
> 
> So, if I stick $LastChangedRevision$ into  
> views/layouts/application.rhtml, it’ll show the last time that file  
> was changed, not the current version of the repository. W hich isn’t  
> quite what I want. Any ideas?
> 
> Thanks,  
> Joe

You are simply not sing the right keyword, if you want the latest  
revision place $Rev$ or $Revision$ somewhere in your code, the result  
will be: “$Rev: 552 $”  
One thing to keep in mind is that you need to make a change to the file  
where you put the “$Rev$” keyword to make it change.

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [July 25, 2006, 2:21am UTC](https://www.ruby-forum.com/t/embedding-subversion-version-information-into-html/99526/6 "2006-07-25T02:21:39Z")

</div>

Joe Van D. wrote:

> was changed, not the current version of the repository. W hich isn’t  
> quite what I want. Any ideas?

You could use svnversion to crawl your working copy redirect its output  
into a  
separate file that is included in all your views or use it in a sed like  
command  
to change each of your views.

[http://svnbook.red-bean.com/en/1.2/svn.ref.svnversion.re.html](http://svnbook.red-bean.com/en/1.2/svn.ref.svnversion.re.html)

Regards,  
Blair

–  
Blair Z., Ph.D.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subversion training, consulting and support  
[http://www.orcaware.com/svn/](http://www.orcaware.com/svn/)

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [July 24, 2006, 2:27pm UTC](https://www.ruby-forum.com/t/embedding-subversion-version-information-into-html/99526/7 "2006-07-24T14:27:45Z")

</div>

Joe Van D. wrote:

> was changed, not the current version of the repository. W hich isn’t

Hi Joe,  
you can create dynamically partial template when deploying with  
capistrano, for example add this code to deploy.rb

task :after\_update\_code, :roles =\> [:web] do  
put(revision, “#{release\_path}/app/views/layouts/\_version.rhtml”)  
end

and include it in layout with

Revision: \<%= render\_partial(‘/layouts/version’)%\>

hope that helps you,  
Bojan M.

–  
Bojan M.  
Informatika Mihelac, Bojan M. s.p. | [www.informatikamihelac.com](http://www.informatikamihelac.com)  
 → tools, scripts, tricks from our code lab: [http://source.mihelac.org](http://source.mihelac.org)

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [July 25, 2006, 2:25am UTC](https://www.ruby-forum.com/t/embedding-subversion-version-information-into-html/99526/8 "2006-07-25T02:25:11Z")

</div>

On 7/24/06, Julien S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > views/layouts/application.rhtml, it’ll show the last time that file  
> > where you put the “$Rev$” keyword to make it change.  
> > $Rev$ is shorthand for $LastChangedRevision$.

The problem is that I don’t want to have to update the file in order  
to get the repository version.

I think Bojan (thanks!) has the solution.

Joe

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [July 23, 2006, 11:10pm UTC](https://www.ruby-forum.com/t/embedding-subversion-version-information-into-html/99526/9 "2006-07-23T23:10:08Z")

</div>

Can you use File.open to get at the info from your .svn directory?  
If not, you could use open-uri to download the info from a repository.

```
        - dan

```

–  
Dan K. [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.dankohn.com/](http://www.dankohn.com/)tel:+1-415-233-1000
