public
Description: A few tools I've written to aid development and production of my WordPress theme, Tarski.
Homepage: http://tarskitheme.com/
Clone URL: git://github.com/ionfish/tarski-utilities.git
tarski-utilities / Rakefile
100644 120 lines (95 sloc) 3.192 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Standard library
require 'yaml'
require 'time'
 
# Gem libraries
require 'rubygems'
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
 
# Project libraries
require 'lib/setup'
 
CONFIG = YAML::load(File.open("conf/config.yml"))
VDATA = TarskiUtils::version_info("conf/version.yml")
 
PUBPATH = CONFIG["pubpath"]
TVERSION = ENV['v'] || VDATA.first.first
TDIR = "tarski"
SVN_URL = CONFIG["svn_url"]
GIT_REPO = CONFIG["git_repo"]
 
desc "Creates a zip archive, and updates the version feed and changelog."
task :update => [:zip, :feed, :changelog]
 
desc "Update the version feed to notify Tarski users of the new release."
task :feed do
  require 'lib/tarski_version'
  puts "Generating version feed..."
  TarskiVersion.new(VDATA, CONFIG["feed"]).publish_feed("#{PUBPATH}/version.atom")
  puts "Done."
end
 
desc "Generate the hooks documentation page."
task :hooks => :download do
  require 'erb'
  require 'lib/tarski_docs'
  
  puts "Generating hooks documentation..."
  TarskiDocs.new(Dir.pwd + '/' + TDIR).read.write("#{PUBPATH}/hooks.html")
  
  puts "Cleaning up checked-out files..."
  `rm -rf tarski/`
  puts "Done."
end
 
desc "Generate a new changelog HTML file."
task :changelog do
  require 'rdiscount'
  require 'rubypants'
  require 'hpricot'
  require 'open-uri'
  
  puts "Reading changelog..."
  
  struct = File.open("conf/changelog-structure.html", "r") do |file|
    Hpricot(file.read)
  end
  
  doc = open("#{SVN_URL}/trunk/CHANGELOG") do |file|
    # The changelog is provided in Markdown format, so it needs to be
    # passed through BlueCloth before being read into Hpricot.
    Hpricot(Markdown.new(file.read).to_html)
  end
  
  vlinks = Array.new
  
  puts "Generating HTML..."
  
  (doc/"h1").remove
  
  (doc/"h3").each do |header|
    version = header.inner_html.scan(/^Version (\d(?:\.\d)+)/)[0][0]
    header.set_attribute('id', "v#{version}")
    vlinks << "<li><a href=\"#v#{version}\">Version #{version}</a></li>"
  end
  
  struct.at("#changelog-updated").inner_html = "Last updated #{Time.now.strftime("%B %d %Y")}"
  struct.at("#version-links").inner_html = vlinks.join("\n")
  struct.search("#version-links").after(doc.to_html)
  
  File.open("#{PUBPATH}/changelog.html", "w+") do |changelog|
    changelog.puts(RubyPants.new(struct.to_html).to_html)
  end
  
  puts "Done."
end
 
desc "Create a zip file of the lastest release in the downloads directory."
task :zip => :download do
  puts "Creating zip file..."
  %x{zip -rm #{PUBPATH}/downloads/tarski_#{TVERSION}.zip #{TDIR}}
  puts "Done."
end
 
desc "Export the latest release files."
task :download do
  %x{rm -rf #{TDIR}}
  Rake::Task['git_export'].invoke
end
 
desc "Export the latest release from the Subversion repository."
task :svn_export do
  puts "Downloading Tarski files..."
  %x{svn export #{SVN_URL}/releases/#{TVERSION} #{TDIR}}
end
 
desc "Export the latest release from a Git repository."
task :git_export do
  here = Dir.pwd
  there = "#{here}/#{TDIR}"
  puts "Cloning Git repository..."
  %x{git clone #{GIT_REPO} #{there}}
  Dir.chdir(there)
  %x{git checkout -b #{TVERSION} #{TVERSION}}
  puts "Pruning .git directory..."
  %x{rm -rf #{there}/.git/}
  Dir.chdir(here)
end