merb-gen 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/LICENSE +1 -1
  2. data/Rakefile +27 -9
  3. data/bin/merb-gen +21 -3
  4. data/lib/generators/merb/merb_flat.rb +83 -14
  5. data/lib/generators/merb/merb_full.rb +66 -20
  6. data/lib/generators/merb/merb_very_flat.rb +51 -10
  7. data/lib/generators/migration.rb +5 -2
  8. data/lib/generators/resource_controller.rb +2 -2
  9. data/lib/generators/templates/application/{merb → common}/Rakefile +15 -7
  10. data/lib/generators/templates/application/common/dotgitignore +18 -0
  11. data/lib/generators/templates/application/common/merb.thor +1221 -0
  12. data/lib/generators/templates/application/merb/app/views/exceptions/not_acceptable.html.erb +1 -1
  13. data/lib/generators/templates/application/merb/app/views/exceptions/not_found.html.erb +1 -1
  14. data/lib/generators/templates/application/merb/config/environments/development.rb +1 -0
  15. data/lib/generators/templates/application/merb/config/environments/staging.rb +7 -0
  16. data/lib/generators/templates/application/merb/config/environments/test.rb +2 -1
  17. data/lib/generators/templates/application/merb/config/init.rb +1 -4
  18. data/lib/generators/templates/application/merb/config/router.rb +13 -7
  19. data/lib/generators/templates/application/merb/public/favicon.ico +0 -0
  20. data/lib/generators/templates/application/merb/public/robots.txt +5 -0
  21. data/lib/generators/templates/application/merb_flat/{application.rb → application.rbt} +1 -1
  22. data/lib/generators/templates/application/merb_flat/config/init.rb +119 -2
  23. data/lib/generators/templates/application/merb_flat/test/test_helper.rb +19 -0
  24. data/lib/generators/templates/application/merb_plugin/Rakefile +17 -22
  25. data/lib/generators/templates/application/merb_plugin/spec/spec_helper.rb +0 -1
  26. data/lib/generators/templates/application/merb_plugin/test/test_helper.rb +0 -1
  27. data/lib/generators/templates/application/merb_very_flat/application.rbt +36 -2
  28. data/lib/generators/templates/application/merb_very_flat/test/test_helper.rb +19 -0
  29. data/spec/merb_flat_spec.rb +4 -4
  30. data/spec/spec_helper.rb +0 -1
  31. metadata +16 -7
  32. data/lib/generators/templates/application/merb/merb.thor +0 -822
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007 Yehuda Katz
1
+ Copyright (c) 2008 Jonas Nicklas
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ GEM_EMAIL = "jonas.nicklas@gmail.com"
17
17
 
18
18
  GEM_NAME = "merb-gen"
19
19
  PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
20
- GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.7") + PKG_BUILD
20
+ GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.8") + PKG_BUILD
21
21
 
22
22
  RELEASE_NAME = "REL #{GEM_VERSION}"
23
23
 
@@ -38,8 +38,8 @@ spec = Gem::Specification.new do |s|
38
38
  s.bindir = "bin"
39
39
  s.executables = %w( merb-gen )
40
40
 
41
- s.add_dependency "merb-core", ">= 0.9.7"
42
- s.add_dependency "templater", ">= 0.2.0"
41
+ s.add_dependency "merb-core", ">= 0.9.8"
42
+ s.add_dependency "templater", ">= 0.3.0"
43
43
 
44
44
  s.require_path = 'lib'
45
45
  s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,bin,spec}/**/*")
@@ -50,15 +50,33 @@ Rake::GemPackageTask.new(spec) do |pkg|
50
50
  end
51
51
 
52
52
  desc "Install the gem"
53
- task :install => [:package] do
54
- sh install_command(GEM_NAME, GEM_VERSION)
53
+ task :install do
54
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
55
55
  end
56
56
 
57
- namespace :jruby do
57
+ desc "Uninstall the gem"
58
+ task :uninstall do
59
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
60
+ end
58
61
 
59
- desc "Run :package and install the resulting .gem with jruby"
60
- task :install => :package do
61
- sh jinstall_command(GEM_NAME, GEM_VERSION)
62
+ desc "Create a gemspec file"
63
+ task :gemspec do
64
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
65
+ file.puts spec.to_ruby
62
66
  end
67
+ end
63
68
 
69
+ desc "Run all examples (or a specific spec with TASK=xxxx)"
70
+ Spec::Rake::SpecTask.new('spec') do |t|
71
+ t.spec_opts = ["-cfs"]
72
+ t.spec_files = begin
73
+ if ENV["TASK"]
74
+ ENV["TASK"].split(',').map { |task| "spec/**/#{task}_spec.rb" }
75
+ else
76
+ FileList['spec/**/*_spec.rb']
77
+ end
78
+ end
64
79
  end
80
+
81
+ desc 'Default: run spec examples'
82
+ task :default => 'spec'
data/bin/merb-gen CHANGED
@@ -3,8 +3,26 @@
3
3
  require 'rubygems'
4
4
  require 'merb-gen'
5
5
 
6
- Merb::BootLoader.after_app_loads do
6
+ if ARGV[0] == "app"
7
7
  Merb::Generators.run_cli(Dir.pwd, 'merb-gen', Merb::VERSION, ARGV)
8
- end
8
+ else
9
+ Merb::BootLoader.after_app_loads do
10
+ Merb::Generators.run_cli(Dir.pwd, 'merb-gen', Merb::VERSION, ARGV)
11
+ end
12
+
13
+ Merb::Config.setup({
14
+ :log_level => :fatal,
15
+ :log_delimiter => " ~ ",
16
+ :log_auto_flush => false,
17
+ :reload_templates => false,
18
+ :reload_classes => false
19
+ })
9
20
 
10
- Merb.start :environment => 'development', :log_level => 'error'
21
+ Merb::BootLoader::Logger.run
22
+ Merb::BootLoader::BuildFramework.run
23
+ Merb::BootLoader::Dependencies.run
24
+
25
+ Merb::BootLoader::BeforeAppLoads.run
26
+ Merb::BootLoader::ReloadClasses.run
27
+ Merb::BootLoader::AfterAppLoads.run
28
+ end
@@ -1,29 +1,98 @@
1
1
  module Merb::Generators
2
-
3
2
  class MerbFlatGenerator < NamedGenerator
4
-
3
+ #
4
+ # ==== Paths
5
+ #
6
+
5
7
  def self.source_root
6
8
  File.join(super, 'application', 'merb_flat')
7
9
  end
8
-
10
+
11
+ def self.common_templates_dir
12
+ File.expand_path(File.join(File.dirname(__FILE__), '..',
13
+ 'templates', 'application', 'common'))
14
+ end
15
+
16
+ def destination_root
17
+ File.join(@destination_root, base_name)
18
+ end
19
+
20
+ def common_templates_dir
21
+ self.class.common_templates_dir
22
+ end
23
+
24
+ #
25
+ # ==== Generator options
26
+ #
27
+
28
+ option :testing_framework, :default => :rspec,
29
+ :desc => 'Testing framework to use (one of: rspec, test_unit).'
30
+ option :orm, :default => :none,
31
+ :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel).'
32
+ option :template_engine, :default => :erb,
33
+ :desc => 'Template engine to prefer for this application (one of: erb, haml).'
34
+
9
35
  desc <<-DESC
10
36
  This generates a flat merb application: all code but config files and
11
37
  templates fits in one application. This is something in between Sinatra
12
38
  and "regular" Merb application.
13
39
  DESC
14
-
40
+
15
41
  first_argument :name, :required => true, :desc => "Application name"
16
-
17
- glob!
18
-
42
+
43
+ #
44
+ # ==== Common directories & files
45
+ #
46
+
19
47
  empty_directory :gems, 'gems'
20
-
21
- def destination_root
22
- File.join(@destination_root, base_name)
48
+ file :thorfile do |file|
49
+ file.source = File.join(common_templates_dir, "merb.thor")
50
+ file.destination = "merb.thor"
51
+ end
52
+
53
+ template :rakefile do |template|
54
+ template.source = File.join(common_templates_dir, "Rakefile")
55
+ template.destination = "Rakefile"
56
+ end
57
+
58
+ template :gitignore do |template|
59
+ template.source = File.join(common_templates_dir, 'dotgitignore')
60
+ template.destination = ".gitignore"
61
+ end
62
+
63
+ directory :test_dir do |directory|
64
+ dir = testing_framework == :rspec ? "spec" : "test"
65
+
66
+ directory.source = File.join(source_root, dir)
67
+ directory.destination = dir
68
+ end
69
+
70
+ #
71
+ # ==== Layout specific things
72
+ #
73
+
74
+ file :readme, "README.txt"
75
+
76
+ template :application, "application.rb"
77
+
78
+ glob! "config"
79
+ glob! "views"
80
+
81
+ def class_name
82
+ self.name.gsub("-", "_").camel_case
23
83
  end
24
-
25
84
  end
26
-
85
+
27
86
  add_private :app_flat, MerbFlatGenerator
28
-
29
- end
87
+
88
+ end
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
@@ -1,39 +1,85 @@
1
1
  module Merb::Generators
2
-
3
2
  class MerbFullGenerator < NamedGenerator
3
+ #
4
+ # ==== Paths
5
+ #
4
6
 
5
7
  def self.source_root
6
8
  File.join(super, 'application', 'merb')
7
9
  end
8
-
9
- option :testing_framework, :default => :rspec,
10
- :desc => 'Testing framework to use (one of: rspec, test_unit).'
11
- option :orm, :default => :none,
10
+
11
+ def self.common_templates_dir
12
+ File.expand_path(File.join(File.dirname(__FILE__), '..',
13
+ 'templates', 'application', 'common'))
14
+ end
15
+
16
+ def destination_root
17
+ File.join(@destination_root, base_name)
18
+ end
19
+
20
+ def common_templates_dir
21
+ self.class.common_templates_dir
22
+ end
23
+
24
+ #
25
+ # ==== Generator options
26
+ #
27
+
28
+ option :testing_framework, :default => :rspec,
29
+ :desc => 'Testing framework to use (one of: rspec, test_unit).'
30
+ option :orm, :default => :none,
12
31
  :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel).'
13
32
  option :template_engine, :default => :erb,
14
33
  :desc => 'Template engine to prefer for this application (one of: erb, haml).'
15
-
34
+
16
35
  desc <<-DESC
17
36
  This generates a Merb application with Ruby on Rails like structure.
18
37
  Generator lets you configure your ORM and testing framework of choice.
19
38
  DESC
20
-
21
- glob!
22
-
23
- empty_directory :gems, 'gems'
24
-
39
+
25
40
  first_argument :name, :required => true, :desc => "Application name"
26
-
41
+
42
+ #
43
+ # ==== Common directories & files
44
+ #
45
+
46
+ empty_directory :gems, 'gems'
47
+ file :thorfile do |file|
48
+ file.source = File.join(common_templates_dir, "merb.thor")
49
+ file.destination = "merb.thor"
50
+ end
51
+
52
+ template :rakefile do |template|
53
+ template.source = File.join(common_templates_dir, "Rakefile")
54
+ template.destination = "Rakefile"
55
+ end
56
+
57
+ template :gitignore do |template|
58
+ template.source = File.join(common_templates_dir, 'dotgitignore')
59
+ template.destination = ".gitignore"
60
+ end
61
+
62
+ directory :test_dir do |directory|
63
+ dir = testing_framework == :rspec ? "spec" : "test"
64
+
65
+ directory.source = File.join(source_root, dir)
66
+ directory.destination = dir
67
+ end
68
+
69
+ #
70
+ # ==== Layout specific things
71
+ #
72
+
73
+ glob! "app"
74
+ glob! "autotest"
75
+ glob! "config"
76
+ glob! "public"
77
+
27
78
  invoke :layout do |generator|
28
79
  generator.new(destination_root, options, 'application')
29
80
  end
30
-
31
- def destination_root
32
- File.join(@destination_root, base_name)
33
- end
34
-
35
81
  end
36
-
82
+
37
83
  add_private :app_full, MerbFullGenerator
38
-
39
- end
84
+
85
+ end
@@ -1,31 +1,72 @@
1
1
  module Merb::Generators
2
-
2
+
3
3
  class MerbVeryFlatGenerator < NamedGenerator
4
4
 
5
5
  def self.source_root
6
6
  File.join(super, 'application', 'merb_very_flat')
7
7
  end
8
-
8
+
9
+ def self.common_templates_dir
10
+ File.expand_path(File.join(File.dirname(__FILE__), '..',
11
+ 'templates', 'application', 'common'))
12
+ end
13
+
14
+ def destination_root
15
+ File.join(@destination_root, base_name)
16
+ end
17
+
18
+ def common_templates_dir
19
+ File.expand_path(File.join(File.dirname(__FILE__), '..',
20
+ 'templates', 'application', 'common'))
21
+ end
22
+
23
+
24
+ option :testing_framework, :default => :rspec,
25
+ :desc => 'Testing framework to use (one of: rspec, test_unit).'
26
+ option :orm, :default => :none,
27
+ :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel).'
28
+ option :template_engine, :default => :erb,
29
+ :desc => 'Template engine to prefer for this application (one of: erb, haml).'
30
+
31
+
9
32
  desc <<-DESC
10
33
  This generates a very flat merb application: the whole application
11
34
  fits in one file, very much like Sinatra or Camping.
12
35
  DESC
13
-
36
+
14
37
  first_argument :name, :required => true, :desc => "Application name"
15
-
38
+
16
39
  template :application do |template|
17
40
  template.source = 'application.rbt'
18
41
  template.destination = "#{base_name}.rb"
19
42
  end
20
43
 
21
- file :spec_helper, 'spec/spec_helper.rb', 'spec/spec_helper.rb'
22
-
44
+ template :gitignore do |template|
45
+ template.source = File.join(common_templates_dir, 'dotgitignore')
46
+ template.destination = ".gitignore"
47
+ end
48
+
49
+ directory :test_dir do |directory|
50
+ dir = testing_framework == :rspec ? "spec" : "test"
51
+
52
+ directory.source = dir
53
+ directory.destination = dir
54
+ end
55
+
56
+ template :rakefile do |template|
57
+ template.source = File.join(common_templates_dir, "Rakefile")
58
+ template.destination = "Rakefile"
59
+ end
60
+
61
+ file :thorfile do |file|
62
+ file.source = File.join(common_templates_dir, "merb.thor")
63
+ file.destination = "merb.thor"
64
+ end
65
+
23
66
  def class_name
24
- self.name.camel_case
67
+ self.name.gsub("-", "_").camel_case
25
68
  end
26
-
27
69
  end
28
-
70
+
29
71
  add_private :app_very_flat, MerbVeryFlatGenerator
30
-
31
72
  end
@@ -34,7 +34,8 @@ module Merb::Generators
34
34
 
35
35
  def version
36
36
  # TODO: handle ActiveRecord timestamped migrations
37
- format("%03d", current_migration_nr + 1)
37
+ n = options[:delete] ? current_migration_nr : current_migration_nr + 1
38
+ format("%03d", n)
38
39
  end
39
40
 
40
41
  protected
@@ -44,7 +45,9 @@ module Merb::Generators
44
45
  end
45
46
 
46
47
  def current_migration_nr
47
- current_migration_number = Dir["#{destination_directory}/*"].map{|f| File.basename(f).match(/^(\d+)/)[0].to_i }.max.to_i
48
+ current_migration_number = Dir["#{destination_directory}/*"].map do |f|
49
+ File.basename(f).match(/^(\d+)/)[0].to_i
50
+ end.max.to_i
48
51
  end
49
52
 
50
53
  end
@@ -33,13 +33,13 @@ module Merb::Generators
33
33
  end
34
34
 
35
35
  [:index, :show, :edit, :new].each do |view|
36
- template "view_#{view}_none".to_sym, :orm => :none do |template|
36
+ template "view_#{view}_none".to_sym do |template|
37
37
  template.source = "app/views/%file_name%/#{view}.html.erb"
38
38
  template.destination = "app/views" / base_path / "#{file_name}/#{view}.html.erb"
39
39
  end
40
40
  end
41
41
 
42
- template :controller_spec, :testing_framework => :rspec, :orm => :none do |template|
42
+ template :controller_spec, :testing_framework => :rspec do |template|
43
43
  template.source = 'spec/controllers/%file_name%_spec.rb'
44
44
  template.destination = "spec/controllers" / base_path / "#{file_name}_spec.rb"
45
45
  end
@@ -1,12 +1,9 @@
1
1
  require 'rubygems'
2
- require 'rake'
3
2
  require 'rake/rdoctask'
4
- require 'rake/testtask'
5
- require 'spec/rake/spectask'
6
- require 'fileutils'
7
3
 
8
- require "merb-core"
4
+ require 'merb-core'
9
5
  require 'merb-core/tasks/merb'
6
+
10
7
  include FileUtils
11
8
 
12
9
  # Load the basic runtime dependencies; this will include
@@ -22,12 +19,23 @@ tasks_path = File.join(File.dirname(__FILE__), "lib", "tasks")
22
19
  rake_files = Dir["#{tasks_path}/*.rake"]
23
20
  rake_files.each{|rake_file| load rake_file }
24
21
 
25
- desc "start runner environment"
22
+ desc "Start runner environment"
26
23
  task :merb_env do
27
24
  Merb.start_environment(:environment => init_env, :adapter => 'runner')
28
25
  end
29
26
 
27
+ <% if testing_framework.to_sym == :rspec %>
28
+ require 'spec/rake/spectask'
29
+ require "merb-core/test/tasks/spectasks"
30
+ desc 'Default: run spec examples'
31
+ task :default => 'spec'
32
+ <% end %>
33
+
34
+ <% if testing_framework.to_sym == :test_unit %>
35
+ require 'rake/testtask'
36
+ <% end %>
37
+
30
38
  ##############################################################################
31
39
  # ADD YOUR CUSTOM TASKS IN /lib/tasks
32
40
  # NAME YOUR RAKE FILES file_name.rake
33
- ##############################################################################
41
+ ##############################################################################
@@ -0,0 +1,18 @@
1
+ .DS_Store
2
+ log/*
3
+ tmp/*
4
+ TAGS
5
+ *~
6
+ .#*
7
+ schema/schema.rb
8
+ schema/*_structure.sql
9
+ schema/*.sqlite3
10
+ schema/*.sqlite
11
+ schema/*.db
12
+ *.sqlite
13
+ *.sqlite3
14
+ *.db
15
+ src/*
16
+ .hgignore
17
+ .hg/*
18
+ .svn/*