--- /dev/null
+# Copyright 2007-2008 Wincent Colaiuta
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+require 'rake'
+require 'rake/gempackagetask'
+require 'rubygems'
+require 'spec/rake/spectask'
+require 'spec/rake/verify_rcov'
+
+desc 'Prepare release'
+task :release => [:changelog, :gem]
+
+desc 'Update changelog'
+task :changelog do |t|
+ system %{svn log svn://svn.wincent.com/Walrus/trunk > CHANGELOG.txt}
+end
+
+desc 'Run specs with coverage'
+Spec::Rake::SpecTask.new('coverage') do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.rcov = true
+ t.rcov_opts = ['--exclude', "spec"]
+end
+
+desc 'Run specs'
+Spec::Rake::SpecTask.new('spec') do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+end
+
+desc 'Verify that test coverage is above minimum threshold'
+RCov::VerifyTask.new(:verify => :spec) do |t|
+ t.threshold = 99.2 # never adjust expected coverage down, only up
+ t.index_html = 'coverage/index.html'
+end
+
+desc 'Generate specdocs for inclusions in RDoc'
+Spec::Rake::SpecTask.new('specdoc') do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.spec_opts = ['--format', 'rdoc']
+ t.out = 'specdoc.rd'
+end
+
+desc 'Build C extensions'
+task :make => [:jindex, :mkdtemp]
+
+desc 'Build jindex extension'
+task :jindex do |t|
+ system %{cd ext/jindex && ruby ./extconf.rb && make && cp jindex.#{Config::CONFIG['DLEXT']} ../ && cd -}
+end
+
+desc 'Build mkdtemp extension'
+task :mkdtemp do |t|
+ system %{cd ext/mkdtemp && ruby ./extconf.rb && make && cp mkdtemp.#{Config::CONFIG['DLEXT']} ../ && cd -}
+end
+
+SPEC = Gem::Specification.new do |s|
+ s.name = 'walrus'
+ s.version = '0.2'
+ s.author = 'Wincent Colaiuta'
+ s.email = 'win@wincent.com'
+ s.homepage = 'http://walrus.wincent.com/'
+ s.rubyforge_project = 'walrus'
+ s.platform = Gem::Platform::RUBY
+ s.summary = 'Object-oriented templating system'
+ s.description = <<-ENDDESC
+ Walrus is an object-oriented templating system inspired by and similar
+ to the Cheetah Python-powered template engine. It includes a Parser
+ Expression Grammar (PEG) parser generator capable of generating an
+ integrated lexer, "packrat" parser, and Abstract Syntax Tree (AST)
+ builder.
+ ENDDESC
+ s.require_paths = ['lib', 'ext']
+ s.has_rdoc = true
+
+ # TODO: add 'docs' subdirectory, 'README.txt' when they're done
+ s.files = FileList['{bin,lib,spec}/**/*', 'ext/**/*.rb', 'ext/**/*.c'].to_a
+ s.extensions = ['ext/jindex/extconf.rb', 'ext/mkdtemp/extconf.rb']
+ s.executables = ['walrus']
+ s.add_dependency('wopen3', '>= 0.1')
+end
+
+Rake::GemPackageTask.new(SPEC) do |t|
+ t.need_tar = true
+end
+
--- /dev/null
+# Copyright 2007 Wincent Colaiuta
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+require 'mkmf'
+create_makefile('mkdtemp')
+
--- /dev/null
+/*
+Copyright 2007 Wincent Colaiuta
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <ruby.h>
+#include <errno.h>
+#include <unistd.h>
+
+/*
+
+call-seq:
+ Dir.mkdtemp([string]) -> String or nil
+
+This method securely creates temporary directories. It is a wrapper for the mkdtemp() function in the standard C library. It takes an optional String parameter as a template describing the desired form of the directory name; if no template is supplied then "/tmp/temp.XXXXXX" is used as a default.
+
+*/
+static VALUE walrus_dir_mkdtemp_m(int argc, VALUE *argv, VALUE self)
+{
+ VALUE template;
+ if (rb_scan_args(argc, argv, "01", &template) == 0) /* check for 0 mandatory arguments, 1 optional argument */
+ template = Qnil; /* default to nil if no argument passed */
+ if (NIL_P(template))
+ template = rb_str_new2("/tmp/temp.XXXXXX"); /* fallback to this template if passed nil */
+ SafeStringValue(template); /* raises if template is tainted and SAFE level > 0 */
+ VALUE safe = StringValue(template); /* duck typing support */
+ char *path = mkdtemp(RSTRING(safe)->ptr);
+ if (path == NULL)
+ rb_raise(rb_eSystemCallError, "mkdtemp failed (error: %d)", errno);
+ return rb_str_new2(path);
+}
+
+void Init_mkdtemp()
+{
+ rb_define_module_function(rb_cDir, "mkdtemp", walrus_dir_mkdtemp_m, -1);
+}
+