Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Stop poluting World.

In other words, updated to Cucumber 0.3 and changed way
helpers get loaded for features.
  • Loading branch information...
commit 88935b8a60b0d90777f124771401de9e70ba0220 1 parent c04778f
@luislavena luislavena authored
View
50 features/support/file_templates.rb → features/support/file_template_helpers.rb
@@ -1,5 +1,6 @@
-def template_rakefile
-<<-EOF
+module FileTemplateHelpers
+ def template_rakefile
+ <<-EOF
# add rake-compiler lib dir to the LOAD_PATH
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '../..', 'lib'))
@@ -9,10 +10,10 @@ def template_rakefile
# load rakefile extensions (tasks)
Dir['tasks/*.rake'].each { |f| import f }
EOF
-end
+ end
-def template_rake_gemspec(gem_name)
-<<-EOF
+ def template_rake_gemspec(gem_name)
+ <<-EOF
require 'rake/gempackagetask'
SPEC = Gem::Specification.new do |s|
s.name = "#{gem_name}"
@@ -37,52 +38,55 @@ def template_rake_gemspec(gem_name)
pkg.need_tar = false
end
EOF
-end
+ end
-def template_rake_extension(extension_name, gem_spec = nil)
-<<-EOF
+ def template_rake_extension(extension_name, gem_spec = nil)
+ <<-EOF
require 'rake/extensiontask'
Rake::ExtensionTask.new("#{extension_name}"#{', SPEC' if gem_spec})
EOF
-end
+ end
-def template_rake_extension_with_platform(extension_name, platform)
-<<-EOF
+ def template_rake_extension_with_platform(extension_name, platform)
+ <<-EOF
require 'rake/extensiontask'
Rake::ExtensionTask.new("#{extension_name}", SPEC) do |ext|
ext.platform = "#{platform}"
end
EOF
-end
+ end
-def template_rake_extension_cross_compile(extension_name, gem_spec = nil)
-<<-EOF
+ def template_rake_extension_cross_compile(extension_name, gem_spec = nil)
+ <<-EOF
require 'rake/extensiontask'
Rake::ExtensionTask.new("#{extension_name}"#{', SPEC' if gem_spec}) do |ext|
ext.cross_compile = true
end
EOF
-end
+ end
-def template_extconf(extension_name)
-<<-EOF
+ def template_extconf(extension_name)
+ <<-EOF
require 'mkmf'
create_makefile("#{extension_name}")
EOF
-end
+ end
-def template_source_c(extension_name)
-<<-EOF
+ def template_source_c(extension_name)
+ <<-EOF
#include "source.h"
void Init_#{extension_name}()
{
printf("source.c of extension #{extension_name}\\n");
}
EOF
-end
+ end
-def template_source_h
-<<-EOF
+ def template_source_h
+ <<-EOF
#include "ruby.h"
EOF
+ end
end
+
+World(FileTemplateHelpers)
View
81 features/support/generator_helpers.rb
@@ -0,0 +1,81 @@
+module GeneratorHelpers
+ def generate_scaffold_structure
+ # create folder structure
+ FileUtils.mkdir_p "lib"
+ FileUtils.mkdir_p "tasks"
+ FileUtils.mkdir_p "tmp"
+
+ # create Rakefile loader
+ File.open("Rakefile", 'w') do |rakefile|
+ rakefile.puts template_rakefile.strip
+ end
+ end
+
+ def generate_gem_task(gem_name)
+ # create generic gem task
+ File.open("tasks/gem.rake", 'w') do |gem_rake|
+ gem_rake.puts template_rake_gemspec(gem_name)
+ end
+ end
+
+ def generate_extension_task_for(extension_name, platform = nil)
+ # create folder structure
+ FileUtils.mkdir_p "ext/#{extension_name}"
+
+ return if File.exist?("tasks/#{extension_name}.rake")
+
+ # Building a gem?
+ if File.exist?("tasks/gem.rake") then
+ File.open("tasks/gem.rake", 'a+') do |ext_in_gem|
+ if platform
+ ext_in_gem.puts template_rake_extension_with_platform(extension_name, platform)
+ else
+ ext_in_gem.puts template_rake_extension(extension_name, true)
+ end
+ end
+ else
+ # create specific extension rakefile
+ File.open("tasks/#{extension_name}.rake", 'w') do |ext_rake|
+ ext_rake.puts template_rake_extension(extension_name)
+ end
+ end
+ end
+
+ def generate_cross_compile_extension_task_for(extension_name)
+ # create folder structure
+ FileUtils.mkdir_p "ext/#{extension_name}"
+
+ return if File.exist?("tasks/#{extension_name}.rake")
+
+ # create specific extension rakefile
+ # Building a gem?
+ if File.exist?("tasks/gem.rake") then
+ File.open("tasks/gem.rake", 'a+') do |ext_in_gem|
+ ext_in_gem.puts template_rake_extension_cross_compile(extension_name, true)
+ end
+ else
+ File.open("tasks/#{extension_name}.rake", 'w') do |ext_rake|
+ ext_rake.puts template_rake_extension_cross_compile(extension_name)
+ end
+ end
+ end
+
+ def generate_source_code_for(extension_name)
+ # source C file
+ File.open("ext/#{extension_name}/source.c", 'w') do |c|
+ c.puts template_source_c(extension_name)
+ end
+
+ # header H file
+ File.open("ext/#{extension_name}/source.h", 'w') do |h|
+ h.puts template_source_h
+ end
+
+ # extconf.rb file
+ File.open("ext/#{extension_name}/extconf.rb", 'w') do |ext|
+ ext.puts template_extconf(extension_name)
+ end
+ end
+end
+
+World(GeneratorHelpers)
View
77 features/support/generators.rb
@@ -1,77 +0,0 @@
-def generate_scaffold_structure
- # create folder structure
- FileUtils.mkdir_p "lib"
- FileUtils.mkdir_p "tasks"
- FileUtils.mkdir_p "tmp"
-
- # create Rakefile loader
- File.open("Rakefile", 'w') do |rakefile|
- rakefile.puts template_rakefile.strip
- end
-end
-
-def generate_gem_task(gem_name)
- # create generic gem task
- File.open("tasks/gem.rake", 'w') do |gem_rake|
- gem_rake.puts template_rake_gemspec(gem_name)
- end
-end
-
-def generate_extension_task_for(extension_name, platform = nil)
- # create folder structure
- FileUtils.mkdir_p "ext/#{extension_name}"
-
- return if File.exist?("tasks/#{extension_name}.rake")
-
- # Building a gem?
- if File.exist?("tasks/gem.rake") then
- File.open("tasks/gem.rake", 'a+') do |ext_in_gem|
- if platform
- ext_in_gem.puts template_rake_extension_with_platform(extension_name, platform)
- else
- ext_in_gem.puts template_rake_extension(extension_name, true)
- end
- end
- else
- # create specific extension rakefile
- File.open("tasks/#{extension_name}.rake", 'w') do |ext_rake|
- ext_rake.puts template_rake_extension(extension_name)
- end
- end
-end
-
-def generate_cross_compile_extension_task_for(extension_name)
- # create folder structure
- FileUtils.mkdir_p "ext/#{extension_name}"
-
- return if File.exist?("tasks/#{extension_name}.rake")
-
- # create specific extension rakefile
- # Building a gem?
- if File.exist?("tasks/gem.rake") then
- File.open("tasks/gem.rake", 'a+') do |ext_in_gem|
- ext_in_gem.puts template_rake_extension_cross_compile(extension_name, true)
- end
- else
- File.open("tasks/#{extension_name}.rake", 'w') do |ext_rake|
- ext_rake.puts template_rake_extension_cross_compile(extension_name)
- end
- end
-end
-
-def generate_source_code_for(extension_name)
- # source C file
- File.open("ext/#{extension_name}/source.c", 'w') do |c|
- c.puts template_source_c(extension_name)
- end
-
- # header H file
- File.open("ext/#{extension_name}/source.h", 'w') do |h|
- h.puts template_source_h
- end
-
- # extconf.rb file
- File.open("ext/#{extension_name}/extconf.rb", 'w') do |ext|
- ext.puts template_extconf(extension_name)
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.