latest_branch 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ +++ 1.0.0 2007-04-15
2
+
3
+ + 1 major enhancement:
4
+ + Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,17 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/alias_all_projects
6
+ bin/latest_branch
7
+ lib/latest_branch.rb
8
+ lib/latest_branch/version.rb
9
+ scripts/txt2html
10
+ setup.rb
11
+ test/test_helper.rb
12
+ test/test_latest_branch.rb
13
+ website/index.html
14
+ website/index.txt
15
+ website/javascripts/rounded_corners_lite.inc.js
16
+ website/stylesheets/screen.css
17
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,9 @@
1
+ Return the most-recently-updated folder starting with a common prefix.
2
+
3
+ This is useful where your project branches all start with the same name as the project, e.g.
4
+ $RAILS_APPS/wizzo -- trunk
5
+ $RAILS_APPS/wizzo_feature1 -- branch for feature1
6
+ $RAILS_APPS/wizzo_feature2 -- branch for feature2
7
+
8
+ $ latest_branch --app=wizzo
9
+ --> returns absolute folder path for most recently modified folder
data/Rakefile ADDED
@@ -0,0 +1,74 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ require 'hoe'
11
+ include FileUtils
12
+ require File.join(File.dirname(__FILE__), 'lib', 'latest_branch', 'version')
13
+
14
+ AUTHOR = "nicwilliams" # can also be an array of Authors
15
+ EMAIL = "drnicwilliams@gmail.com"
16
+ DESCRIPTION = "Return the most-recently-updated folder starting with a common prefix."
17
+ GEM_NAME = "latest_branch" # what ppl will type to install your gem
18
+ RUBYFORGE_PROJECT = "drnicutilities" # The unix name for your project
19
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
20
+
21
+
22
+ NAME = "latest_branch"
23
+ REV = nil # UNCOMMENT IF REQUIRED: File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
24
+ VERS = ENV['VERSION'] || (LatestBranch::VERSION::STRING + (REV ? ".#{REV}" : ""))
25
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
26
+ RDOC_OPTS = ['--quiet', '--title', "latest_branch documentation",
27
+ "--opname", "index.html",
28
+ "--line-numbers",
29
+ "--main", "README",
30
+ "--inline-source"]
31
+
32
+ class Hoe
33
+ def extra_deps
34
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
35
+ end
36
+ end
37
+
38
+ # Generate all the Rake tasks
39
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
40
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
41
+ p.author = AUTHOR
42
+ p.description = DESCRIPTION
43
+ p.email = EMAIL
44
+ p.summary = DESCRIPTION
45
+ p.url = HOMEPATH
46
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
47
+ p.test_globs = ["test/**/test_*.rb"]
48
+ p.clean_globs = CLEAN #An array of file patterns to delete on clean.
49
+
50
+ # == Optional
51
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
52
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
53
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
54
+ end
55
+
56
+
57
+ desc 'Generate website files'
58
+ task :website_generate do
59
+ Dir['website/**/*.txt'].each do |txt|
60
+ sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
61
+ end
62
+ end
63
+
64
+ desc 'Upload website files to rubyforge'
65
+ task :website_upload do
66
+ config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
67
+ host = "#{config["username"]}@rubyforge.org"
68
+ remote_dir = "/var/www/gforge-projects/#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
69
+ local_dir = 'website'
70
+ sh %{rsync -av #{local_dir}/ #{host}:#{remote_dir}}
71
+ end
72
+
73
+ desc 'Generate and upload website files'
74
+ task :website => [:website_generate, :website_upload]
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Nic Williams on 2007-04-15.
4
+ # Copyright (c) 2007. All rights reserved.
5
+
6
+ require 'optparse'
7
+
8
+ default_root = ENV['RAILS_APPS'] if ENV['RAILS_APPS']
9
+ default_root ||= File.join(ENV['HOME'], 'rails_apps') if ENV['HOME']
10
+ OPTIONS = {
11
+ :path => default_root,
12
+ :prefix => ''
13
+ }
14
+ parser = OptionParser.new do |opts|
15
+ opts.banner = <<BANNER
16
+ Creates aliases to all your projects' latest branch folders (see latest_branch application.)
17
+ This is useful where your project branches all start with the same name as the project, e.g.
18
+ $RAILS_APPS/wizzo -- trunk
19
+ $RAILS_APPS/wizzo_feature1 -- branch for feature1
20
+ $RAILS_APPS/wizzo_feature2 -- branch for feature2
21
+
22
+ ~$ alias_all_projects --path=$RAILS_APPS
23
+ ~$ wizzo
24
+ .../wizzo_feature1$ ...
25
+
26
+ Usage: #{File.basename($0)} [options]
27
+
28
+ Options are:
29
+ BANNER
30
+ opts.separator ""
31
+ opts.on("-p", "--path=PATH", String,
32
+ "Path where your project folders are found.",
33
+ "Default: ENV['RAILS_APPS'], or ENV['HOME'] + '/rails_apps'") { |OPTIONS[:path]| }
34
+ opts.on("--prefix=PREFIX", String,
35
+ "Prefix for all aliases created.",
36
+ "Default: None") { |OPTIONS[:prefix]| }
37
+ opts.on("-h", "--help",
38
+ "Show this help message.") { puts opts; exit }
39
+ opts.parse!(ARGV)
40
+ unless OPTIONS[:path]
41
+ puts opts; exit
42
+ end
43
+ end
44
+
45
+ path = File.expand_path OPTIONS[:path]
46
+ prefix = OPTIONS[:prefix]
47
+
48
+ projects = Dir["#{path}/**/Rakefile"].map {|folder| folder.gsub(path + '/','').split('/').first}.uniq
49
+ cmds = []
50
+ projects.each do |project|
51
+ cmds << "alias #{prefix}#{project}='cd \`latest_branch --app=#{project} --path=#{path}\`'"
52
+ end
53
+ File.open(File.expand_path('~/.project_aliases'),'w') do |file|
54
+ cmds.each do |cmd|
55
+ file << cmd + "\n"
56
+ end
57
+ end
data/bin/latest_branch ADDED
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Nic Williams on 2007-04-15.
4
+ # Copyright (c) 2007. All rights reserved.
5
+
6
+ require 'optparse'
7
+
8
+ default_path = ENV['RAILS_APPS'] if ENV['RAILS_APPS']
9
+ default_path ||= File.join(ENV['HOME'], 'rails_apps') if ENV['HOME']
10
+ OPTIONS = {
11
+ :app => nil,
12
+ :path => default_path,
13
+ :ignore => 'pkg'
14
+ }
15
+ parser = OptionParser.new do |opts|
16
+ opts.banner = <<BANNER
17
+ Return the most-recently-updated folder starting with a common prefix.
18
+ This is useful where your project branches all start with the same name as the project, e.g.
19
+ $RAILS_APPS/wizzo -- trunk
20
+ $RAILS_APPS/wizzo_feature1 -- branch for feature1
21
+ $RAILS_APPS/wizzo_feature2 -- branch for feature2
22
+
23
+ $ latest_branch --app=wizzo
24
+ --> returns absolute folder path for most recently modified folder
25
+
26
+ Usage: #{File.basename($0)} --app=APP_NAME [other options]
27
+
28
+ Options are:
29
+ BANNER
30
+ opts.separator ""
31
+ opts.on("-a", "--app=APP_NAME", String,
32
+ "All branches must start with APP_NAME_<branchname> to be found.",
33
+ "Default: none") { |OPTIONS[:app]| }
34
+ opts.on("-p", "--path=PATH", String,
35
+ "Path where your project folders are found.",
36
+ "Default: ENV['RAILS_APPS'], or ENV['HOME'] + '/rails_apps'") { |OPTIONS[:path]| }
37
+ opts.on("-i", "--ignore=IGNORE1[,IGNORE2]", String,
38
+ "Paths that contain IGNORE1 or IGNORE2, etc, will not be included",
39
+ "E.g. --ignore=pkg will ignore pkg folders generated when building gems",
40
+ "Default: pkg,vendor") { |OPTIONS[:ignore]| }
41
+ opts.on("-h", "--help",
42
+ "Show this help message.") { puts opts; exit }
43
+ opts.parse!(ARGV)
44
+ unless OPTIONS[:app] && OPTIONS[:path]
45
+ puts opts; exit
46
+ end
47
+ end
48
+
49
+ app = OPTIONS[:app]
50
+ path = File.expand_path OPTIONS[:path]
51
+
52
+ folders = Dir["#{path}/#{app}*/**/Rakefile"].map {|folder| folder.gsub('/Rakefile','')}.uniq
53
+ OPTIONS[:ignore].split(',').each do |ignore_me|
54
+ folders.reject! { |folder| folder =~ /#{ignore_me}/ }
55
+ end
56
+ dates = folders.inject({}) { |mem, folder| mem[File.mtime(folder)] = folder; mem}
57
+ latest = dates[dates.keys.sort.last]
58
+ print latest
@@ -0,0 +1,9 @@
1
+ module LatestBranch #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ Dir[File.join(File.dirname(__FILE__), 'latest_branch/**/*.rb')].sort.each { |lib| require lib }
data/scripts/txt2html ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'redcloth'
5
+ require 'syntax/convertors/html'
6
+ require 'erb'
7
+ require File.dirname(__FILE__) + '/../lib/latest_branch/version.rb'
8
+
9
+ version = LatestBranch::VERSION::STRING
10
+ download = 'http://rubyforge.org/projects/dr_nic_utilities'
11
+
12
+ class Fixnum
13
+ def ordinal
14
+ # teens
15
+ return 'th' if (10..19).include?(self % 100)
16
+ # others
17
+ case self % 10
18
+ when 1: return 'st'
19
+ when 2: return 'nd'
20
+ when 3: return 'rd'
21
+ else return 'th'
22
+ end
23
+ end
24
+ end
25
+
26
+ class Time
27
+ def pretty
28
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
29
+ end
30
+ end
31
+
32
+ def convert_syntax(syntax, source)
33
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
34
+ end
35
+
36
+ if ARGV.length >= 1
37
+ src, template = ARGV
38
+ template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
39
+
40
+ else
41
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
42
+ exit!
43
+ end
44
+
45
+ template = ERB.new(File.open(template).read)
46
+
47
+ title = nil
48
+ body = nil
49
+ File.open(src) do |fsrc|
50
+ title_text = fsrc.readline
51
+ body_text = fsrc.read
52
+ syntax_items = []
53
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
54
+ ident = syntax_items.length
55
+ element, syntax, source = $1, $2, $3
56
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
57
+ "syntax-temp-#{ident}"
58
+ }
59
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
60
+ body = RedCloth.new(body_text).to_html
61
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
62
+ end
63
+ stat = File.stat(src)
64
+ created = stat.ctime
65
+ modified = stat.mtime
66
+
67
+ $stdout << template.result(binding)