2013-02-04 13:35:42 -06:00
|
|
|
require 'yaml'
|
2012-09-18 17:51:53 +01:00
|
|
|
require 'bonsai'
|
|
|
|
require 'liquid'
|
|
|
|
require 'maruku'
|
|
|
|
require 'json'
|
2012-12-16 13:06:03 +00:00
|
|
|
require 'ronn'
|
|
|
|
require 'tempfile'
|
2013-03-24 14:01:19 +02:00
|
|
|
require 'yaml'
|
2012-09-18 17:51:53 +01:00
|
|
|
|
|
|
|
module ExtraFilters
|
|
|
|
def markdownify(input)
|
|
|
|
Maruku.new(input).to_html
|
|
|
|
end
|
|
|
|
|
|
|
|
def sanitize(input)
|
|
|
|
input.gsub(/[^a-zA-Z0-9_]/,"")
|
|
|
|
end
|
|
|
|
|
|
|
|
def json(input)
|
|
|
|
input.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def unique(input)
|
|
|
|
@n = (@n || 0) + 1
|
|
|
|
input + @n.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Liquid::Template.register_filter(ExtraFilters)
|
|
|
|
|
|
|
|
|
|
|
|
task :serve do
|
|
|
|
begin
|
|
|
|
Bonsai.log "Press Control+C to quit"
|
|
|
|
|
|
|
|
require 'rack'
|
|
|
|
require 'sinatra'
|
|
|
|
require 'watch'
|
|
|
|
require 'launchy'
|
|
|
|
|
|
|
|
Bonsai.root_dir = Dir.pwd
|
|
|
|
|
|
|
|
server = fork {
|
|
|
|
app = Rack::Builder.app {
|
2012-12-10 22:25:11 +00:00
|
|
|
map "/jq" do
|
|
|
|
use Bonsai::StaticPassThrough, :root => Bonsai.root_dir + "/output", :urls => ["/"]
|
|
|
|
end
|
2012-09-18 17:51:53 +01:00
|
|
|
run Bonsai::DevelopmentServer
|
|
|
|
}
|
|
|
|
Rack::Handler.default.run(app, :Port => 5000) do
|
2013-05-06 15:03:14 +01:00
|
|
|
Launchy.open("http://localhost:5000/jq/")
|
2012-09-18 17:51:53 +01:00
|
|
|
end
|
|
|
|
}
|
|
|
|
Watch.new("{content,templates,public}/**/*") { Bonsai::Exporter.process! }
|
|
|
|
rescue Interrupt
|
|
|
|
Process.kill("QUIT", server)
|
|
|
|
Process.wait(server)
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
2012-09-19 01:03:05 +01:00
|
|
|
|
|
|
|
task :build do
|
|
|
|
Bonsai.root_dir = Dir.pwd
|
|
|
|
Bonsai::Exporter.publish!
|
|
|
|
end
|
2012-12-16 13:06:03 +00:00
|
|
|
|
2013-05-09 02:18:28 +01:00
|
|
|
$BINARIES = {
|
|
|
|
:osx32 => "--host=i686-apple-darwin10 CFLAGS='-m32 -g -O'",
|
|
|
|
:osx64 => "--host=i686-apple-darwin10 CFLAGS='-m64 -g -O'",
|
|
|
|
:win32 => "--host=i686-w64-mingw32 CFLAGS='-g -O'",
|
|
|
|
:win64 => "--host=x86_64-w64-mingw32 CFLAGS='-g -O'",
|
|
|
|
:linux32 => "--host=x86_64-linux-gnu CFLAGS='-m32 -g -O'",
|
|
|
|
:linux64 => "--host=x86_64-linux-gnu CFLAGS='-m64 -g -O'"
|
|
|
|
}
|
|
|
|
|
|
|
|
$BINARIES.each do |name, args|
|
|
|
|
file "../build/#{name}" do |t|
|
2014-06-04 18:15:44 -05:00
|
|
|
sh "../scripts/crosscompile -j4 #{name} #{args}"
|
2013-05-09 02:18:28 +01:00
|
|
|
end
|
|
|
|
task :binaries => ["../build/#{name}"]
|
|
|
|
end
|
|
|
|
|
|
|
|
task :binaries => ["output/download"] do
|
|
|
|
$BINARIES.each do |name, args|
|
|
|
|
FileUtils.cp_r "../build/#{name}", "output/download/"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-16 13:06:03 +00:00
|
|
|
def load_manual
|
|
|
|
YAML::ENGINE.yamler = 'syck'
|
|
|
|
YAML::load(File.open("content/3.manual/manual.yml"))
|
|
|
|
end
|
|
|
|
|
|
|
|
task :manpage do
|
|
|
|
Tempfile.open "manpage" do |f|
|
|
|
|
manual = load_manual
|
|
|
|
f.puts manual['manpage_intro']
|
|
|
|
f.puts manual['body']
|
|
|
|
manual['sections'].each do |section|
|
|
|
|
|
|
|
|
f.puts "## #{section['title'].upcase}\n"
|
|
|
|
f.puts section['body']
|
|
|
|
f.puts ""
|
|
|
|
(section['entries'] || []).each do |entry|
|
|
|
|
f.puts "### #{entry['title']}\n"
|
|
|
|
f.puts entry['body']
|
|
|
|
f.puts ""
|
2012-12-16 17:11:40 +00:00
|
|
|
(entry['examples'] || []).each do |example|
|
|
|
|
f.puts " jq '#{example['program']}'"
|
|
|
|
f.puts " #{example['input']}"
|
|
|
|
f.puts " => #{example['output'].join(", ")}"
|
|
|
|
f.puts
|
|
|
|
end
|
2012-12-16 13:06:03 +00:00
|
|
|
end
|
|
|
|
f.puts ""
|
|
|
|
end
|
2012-12-20 12:25:50 +00:00
|
|
|
f.puts manual['manpage_epilogue']
|
2012-12-16 13:06:03 +00:00
|
|
|
f.close
|
|
|
|
puts Ronn::Document.new(f.path).convert('roff').gsub(/<\/?code>/,"")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-09 20:27:12 +01:00
|
|
|
task :manpage_default => ["default_manpage.md"] do
|
|
|
|
puts Ronn::Document.new("default_manpage.md").convert('roff').gsub(/<\/?code>/,"")
|
|
|
|
end
|
|
|
|
|
2012-12-16 13:06:03 +00:00
|
|
|
task :mantests do
|
|
|
|
load_manual['sections'].each do |section|
|
|
|
|
(section['entries'] || []).each do |entry|
|
|
|
|
(entry['examples'] || []).each do |example|
|
|
|
|
puts example['program'].gsub("\n", " ")
|
|
|
|
puts example['input']
|
|
|
|
example['output'].each do |s| puts s end
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-05-09 20:27:12 +01:00
|
|
|
|
2013-05-11 14:48:39 +01:00
|
|
|
directory "output/download/source"
|
|
|
|
task :tarball => ["output/download/source"] do
|
2013-05-11 14:57:58 +01:00
|
|
|
sh "cd ..; ./configure && make dist && make distclean"
|
2013-05-11 14:48:39 +01:00
|
|
|
sh "cp ../jq-*.tar.gz output/download/source"
|
|
|
|
end
|
|
|
|
|
|
|
|
task :dist => [:build, :binaries, :tarball]
|