thorero-gen 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +21 -0
- data/Rakefile +65 -0
- data/TODO +13 -0
- data/bin/merb-gen +10 -0
- data/lib/merb-gen.rb +37 -0
- data/lib/merb-gen/controller.rb +69 -0
- data/lib/merb-gen/freezer.rb +19 -0
- data/lib/merb-gen/generator.rb +55 -0
- data/lib/merb-gen/helper.rb +53 -0
- data/lib/merb-gen/merb.rb +27 -0
- data/lib/merb-gen/merb/merb_flat.rb +31 -0
- data/lib/merb-gen/merb/merb_full.rb +35 -0
- data/lib/merb-gen/merb/merb_very_flat.rb +33 -0
- data/lib/merb-gen/merb_plugin.rb +33 -0
- data/lib/merb-gen/migration.rb +69 -0
- data/lib/merb-gen/model.rb +67 -0
- data/lib/merb-gen/part_controller.rb +55 -0
- data/lib/merb-gen/resource.rb +32 -0
- data/lib/merb-gen/resource_controller.rb +91 -0
- data/lib/merb-gen/session_migration.rb +44 -0
- data/lib/merb-gen/slice.rb +25 -0
- data/lib/merb-gen/slice/full.rb +31 -0
- data/lib/merb-gen/slice/thin.rb +31 -0
- data/lib/merb-gen/slice/very_thin.rb +31 -0
- data/spec/controller_spec.rb +94 -0
- data/spec/merb_spec.rb +28 -0
- data/spec/migration_spec.rb +47 -0
- data/spec/model_spec.rb +95 -0
- data/spec/resource_controller_spec.rb +98 -0
- data/spec/spec_helper.rb +7 -0
- data/templates/application/merb/Rakefile +76 -0
- data/templates/application/merb/app/controllers/application.rb +2 -0
- data/templates/application/merb/app/controllers/exceptions.rb +13 -0
- data/templates/application/merb/app/helpers/global_helpers.rb +5 -0
- data/templates/application/merb/app/views/exceptions/internal_server_error.html.erb +216 -0
- data/templates/application/merb/app/views/exceptions/not_acceptable.html.erb +63 -0
- data/templates/application/merb/app/views/exceptions/not_found.html.erb +47 -0
- data/templates/application/merb/app/views/layout/application.html.erb +11 -0
- data/templates/application/merb/autotest/discover.rb +1 -0
- data/templates/application/merb/autotest/merb.rb +149 -0
- data/templates/application/merb/autotest/merb_rspec.rb +166 -0
- data/templates/application/merb/config/environments/development.rb +7 -0
- data/templates/application/merb/config/environments/production.rb +7 -0
- data/templates/application/merb/config/environments/rake.rb +7 -0
- data/templates/application/merb/config/environments/test.rb +6 -0
- data/templates/application/merb/config/init.rb +164 -0
- data/templates/application/merb/config/rack.rb +12 -0
- data/templates/application/merb/config/router.rb +35 -0
- data/templates/application/merb/public/images/merb.jpg +0 -0
- data/templates/application/merb/public/merb.fcgi +22 -0
- data/templates/application/merb/public/stylesheets/master.css +119 -0
- data/templates/application/merb/spec/spec.opts +0 -0
- data/templates/application/merb/spec/spec_helper.rb +13 -0
- data/templates/application/merb/test/test_helper.rb +14 -0
- data/templates/application/merb_flat/README.txt +10 -0
- data/templates/application/merb_flat/application.rb +15 -0
- data/templates/application/merb_flat/config/framework.rb +7 -0
- data/templates/application/merb_flat/config/init.rb +18 -0
- data/templates/application/merb_flat/views/foo.html.erb +3 -0
- data/templates/application/merb_plugin/LICENSE +20 -0
- data/templates/application/merb_plugin/README +4 -0
- data/templates/application/merb_plugin/Rakefile +59 -0
- data/templates/application/merb_plugin/TODO +5 -0
- data/templates/application/merb_plugin/lib/%base_name%.rb +18 -0
- data/templates/application/merb_plugin/lib/%base_name%/merbtasks.rb +6 -0
- data/templates/application/merb_plugin/spec/%base_name%_spec.rb +7 -0
- data/templates/application/merb_plugin/spec/spec_helper.rb +2 -0
- data/templates/application/merb_plugin/test/%base_name%_test.rb +0 -0
- data/templates/application/merb_plugin/test/test_helper.rb +2 -0
- data/templates/application/merb_very_flat/application.rbt +17 -0
- data/templates/application/slice/full/LICENSE +20 -0
- data/templates/application/slice/full/README +170 -0
- data/templates/application/slice/full/Rakefile +48 -0
- data/templates/application/slice/full/TODO +15 -0
- data/templates/application/slice/full/app/controllers/application.rb +5 -0
- data/templates/application/slice/full/app/controllers/main.rb +7 -0
- data/templates/application/slice/full/app/helpers/application_helper.rb +64 -0
- data/templates/application/slice/full/app/views/layout/%underscored_base_name%.html.erb +16 -0
- data/templates/application/slice/full/app/views/main/index.html.erb +1 -0
- data/templates/application/slice/full/lib/%base_name%.rb +78 -0
- data/templates/application/slice/full/lib/%base_name%/merbtasks.rb +166 -0
- data/templates/application/slice/full/lib/%base_name%/slicetasks.rb +18 -0
- data/templates/application/slice/full/public/javascripts/master.js +0 -0
- data/templates/application/slice/full/public/stylesheets/master.css +2 -0
- data/templates/application/slice/full/spec/%base_name%_spec.rb +130 -0
- data/templates/application/slice/full/spec/controllers/main_spec.rb +61 -0
- data/templates/application/slice/full/spec/spec_helper.rb +44 -0
- data/templates/application/slice/full/stubs/app/controllers/application.rb +2 -0
- data/templates/application/slice/full/stubs/app/controllers/main.rb +2 -0
- data/templates/application/slice/thin/LICENSE +20 -0
- data/templates/application/slice/thin/README +130 -0
- data/templates/application/slice/thin/Rakefile +46 -0
- data/templates/application/slice/thin/TODO +7 -0
- data/templates/application/slice/thin/application.rb +36 -0
- data/templates/application/slice/thin/lib/%base_name%.rb +93 -0
- data/templates/application/slice/thin/lib/%base_name%/merbtasks.rb +106 -0
- data/templates/application/slice/thin/lib/%base_name%/slicetasks.rb +18 -0
- data/templates/application/slice/thin/public/javascripts/master.js +0 -0
- data/templates/application/slice/thin/public/stylesheets/master.css +2 -0
- data/templates/application/slice/thin/stubs/application.rb +9 -0
- data/templates/application/slice/thin/views/layout/%underscored_base_name%.html.erb +16 -0
- data/templates/application/slice/thin/views/main/index.html.erb +1 -0
- data/templates/application/slice/very_thin/LICENSE +20 -0
- data/templates/application/slice/very_thin/README +110 -0
- data/templates/application/slice/very_thin/Rakefile +46 -0
- data/templates/application/slice/very_thin/TODO +7 -0
- data/templates/application/slice/very_thin/application.rb +36 -0
- data/templates/application/slice/very_thin/lib/%base_name%.rb +89 -0
- data/templates/application/slice/very_thin/lib/%base_name%/merbtasks.rb +106 -0
- data/templates/application/slice/very_thin/lib/%base_name%/slicetasks.rb +18 -0
- data/templates/component/controller/app/controllers/%file_name%.rb +11 -0
- data/templates/component/controller/app/views/%file_name%/index.html.erb +1 -0
- data/templates/component/controller/spec/controllers/%file_name%_spec.rb +7 -0
- data/templates/component/controller/test/controllers/%file_name%_test.rb +17 -0
- data/templates/component/freezer/script/frozen_merb +43 -0
- data/templates/component/helper/app/helpers/%file_name%_helper.rb +7 -0
- data/templates/component/helper/spec/helpers/%file_name%_helper_spec.rb +5 -0
- data/templates/component/migration/activerecord/schema/migrations/%file_name%.rb +19 -0
- data/templates/component/migration/datamapper/schema/migrations/%file_name%.rb +7 -0
- data/templates/component/migration/sequel/schema/migrations/%file_name%.rb +24 -0
- data/templates/component/model/activerecord/app/models/%file_name%.rb +2 -0
- data/templates/component/model/datamapper/app/models/%file_name%.rb +6 -0
- data/templates/component/model/none/app/models/%file_name%.rb +5 -0
- data/templates/component/model/rspec/spec/models/%file_name%_spec.rb +7 -0
- data/templates/component/model/sequel/app/models/%file_name%.rb +2 -0
- data/templates/component/model/test_unit/test/models/%file_name%_test.rb +9 -0
- data/templates/component/part_controller/app/parts/%file_name%_part.rb +9 -0
- data/templates/component/part_controller/app/parts/views/%file_name%_part/index.html.erb +3 -0
- data/templates/component/resource_controller/activerecord/app/controllers/%file_name%.rb +57 -0
- data/templates/component/resource_controller/activerecord/app/views/%file_name%/edit.html.erb +3 -0
- data/templates/component/resource_controller/activerecord/app/views/%file_name%/index.html.erb +3 -0
- data/templates/component/resource_controller/activerecord/app/views/%file_name%/new.html.erb +3 -0
- data/templates/component/resource_controller/activerecord/app/views/%file_name%/show.html.erb +3 -0
- data/templates/component/resource_controller/datamapper/app/controllers/%file_name%.rb +59 -0
- data/templates/component/resource_controller/datamapper/app/views/%file_name%/edit.html.erb +21 -0
- data/templates/component/resource_controller/datamapper/app/views/%file_name%/index.html.erb +24 -0
- data/templates/component/resource_controller/datamapper/app/views/%file_name%/new.html.erb +20 -0
- data/templates/component/resource_controller/datamapper/app/views/%file_name%/show.html.erb +14 -0
- data/templates/component/resource_controller/none/app/controllers/%file_name%.rb +36 -0
- data/templates/component/resource_controller/none/app/views/%file_name%/edit.html.erb +3 -0
- data/templates/component/resource_controller/none/app/views/%file_name%/index.html.erb +3 -0
- data/templates/component/resource_controller/none/app/views/%file_name%/new.html.erb +3 -0
- data/templates/component/resource_controller/none/app/views/%file_name%/show.html.erb +3 -0
- data/templates/component/resource_controller/sequel/app/controllers/%file_name%.rb +59 -0
- data/templates/component/resource_controller/sequel/app/views/%file_name%/edit.html.erb +3 -0
- data/templates/component/resource_controller/sequel/app/views/%file_name%/index.html.erb +3 -0
- data/templates/component/resource_controller/sequel/app/views/%file_name%/new.html.erb +3 -0
- data/templates/component/resource_controller/sequel/app/views/%file_name%/show.html.erb +3 -0
- data/templates/component/session_migration/activerecord/schema/migrations/%version%_sessions.rb +12 -0
- data/templates/component/session_migration/sequel/schema/migrations/%version%_sessions.rb +16 -0
- metadata +362 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 Yehuda Katz
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
==== merb-gen
|
2
|
+
|
3
|
+
merb-gen is a part of the Merb More package. It provides application, plugin, and component
|
4
|
+
generators for Merb.
|
5
|
+
|
6
|
+
==== Usage
|
7
|
+
|
8
|
+
To generate directory structure for a new merb app, run merb-gen app <app-name>.
|
9
|
+
For instance, <tt>merb-gen app foo</tt> would create a new foo merb app inside of the foo directory.
|
10
|
+
|
11
|
+
Use <tt>--flat</tt> to generate a flattened application (very simple directory structure)
|
12
|
+
and <tt>--very-flat</tt> to generate a single file application.
|
13
|
+
|
14
|
+
To generate a new merb plugin, run merb-gen plugin <plugin_name>.
|
15
|
+
|
16
|
+
To see what generators are available, run merb-gen generators.
|
17
|
+
|
18
|
+
==== Custom generators
|
19
|
+
|
20
|
+
If you want to create your custom generators to use with Merb, and don't want to create a gem,
|
21
|
+
you should put them in ~/.rubigen/merb_generators/.
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require "extlib"
|
4
|
+
require 'merb-core/tasks/merb_rake_helper'
|
5
|
+
require "spec/rake/spectask"
|
6
|
+
|
7
|
+
##############################################################################
|
8
|
+
# Package && release
|
9
|
+
##############################################################################
|
10
|
+
RUBY_FORGE_PROJECT = "thorero"
|
11
|
+
PROJECT_URL = "http://merbivore.com"
|
12
|
+
PROJECT_SUMMARY = "Merb gen: generators suite for Merb."
|
13
|
+
PROJECT_DESCRIPTION = PROJECT_SUMMARY
|
14
|
+
|
15
|
+
GEM_AUTHOR = "Jonas Nicklas"
|
16
|
+
GEM_EMAIL = "jonas.nicklas@gmail.com"
|
17
|
+
|
18
|
+
GEM_NAME = "thorero-gen"
|
19
|
+
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
20
|
+
GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.4") + PKG_BUILD
|
21
|
+
|
22
|
+
RELEASE_NAME = "REL #{GEM_VERSION}"
|
23
|
+
|
24
|
+
require "extlib/tasks/release"
|
25
|
+
|
26
|
+
spec = Gem::Specification.new do |s|
|
27
|
+
s.rubyforge_project = RUBY_FORGE_PROJECT
|
28
|
+
s.name = GEM_NAME
|
29
|
+
s.version = GEM_VERSION
|
30
|
+
s.platform = Gem::Platform::RUBY
|
31
|
+
s.has_rdoc = true
|
32
|
+
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
33
|
+
s.summary = PROJECT_SUMMARY
|
34
|
+
s.description = PROJECT_DESCRIPTION
|
35
|
+
s.author = GEM_AUTHOR
|
36
|
+
s.email = GEM_EMAIL
|
37
|
+
s.homepage = PROJECT_URL
|
38
|
+
s.bindir = "bin"
|
39
|
+
s.executables = %w( merb-gen )
|
40
|
+
|
41
|
+
s.add_dependency "merb-core", ">= 0.9.4"
|
42
|
+
s.add_dependency "templater", ">= 0.1.2"
|
43
|
+
|
44
|
+
s.require_path = 'lib'
|
45
|
+
s.autorequire = GEM_NAME
|
46
|
+
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,bin,spec,templates}/**/*")
|
47
|
+
end
|
48
|
+
|
49
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
50
|
+
pkg.gem_spec = spec
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "Install the gem"
|
54
|
+
task :install => [:package] do
|
55
|
+
sh %{#{sudo} gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}
|
56
|
+
end
|
57
|
+
|
58
|
+
namespace :jruby do
|
59
|
+
|
60
|
+
desc "Run :package and install the resulting .gem with jruby"
|
61
|
+
task :install => :package do
|
62
|
+
sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{GEM_NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Merb-gen is now ported to templater, instead of rubigen. Some things are left to do, including:
|
2
|
+
|
3
|
+
* Integrate with Merb::Config[:framework], so that stuff gets placed in the correct directories
|
4
|
+
* Allow some system for plugins to add their own generators.
|
5
|
+
* Move ORM specific templates/code into respective plugin (this requires a change in templater so that absolute paths can be specified for templates)
|
6
|
+
* Move test_unit stuff into merb-test-unit
|
7
|
+
* Move part controller generator into merb-parts
|
8
|
+
* Automatically infer ORM and testing framework (this should be easy, really)
|
9
|
+
* Add migration generators
|
10
|
+
* Add generators for session migrations
|
11
|
+
* Change ActiveRecord migrations to use new datestamp format
|
12
|
+
|
13
|
+
* Fix remaining stuff in templater (see separate TODO)
|
data/bin/merb-gen
ADDED
data/lib/merb-gen.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'merb-core'
|
3
|
+
require 'sha1'
|
4
|
+
gem 'templater', '>= 0.1.2'
|
5
|
+
require 'templater'
|
6
|
+
|
7
|
+
path = File.join(File.dirname(__FILE__), "merb-gen")
|
8
|
+
|
9
|
+
require path / "generator"
|
10
|
+
require path / "merb"
|
11
|
+
require path / "merb" / "merb_full"
|
12
|
+
require path / "merb" / "merb_flat"
|
13
|
+
require path / "merb" / "merb_very_flat"
|
14
|
+
require path / "slice"
|
15
|
+
require path / "slice" / "full"
|
16
|
+
require path / "slice" / "thin"
|
17
|
+
require path / "slice" / "very_thin"
|
18
|
+
require path / "merb_plugin"
|
19
|
+
require path / "controller"
|
20
|
+
require path / "helper"
|
21
|
+
require path / "part_controller"
|
22
|
+
require path / "migration"
|
23
|
+
require path / "session_migration"
|
24
|
+
require path / "model"
|
25
|
+
require path / "resource_controller"
|
26
|
+
require path / "resource"
|
27
|
+
require path / "freezer"
|
28
|
+
|
29
|
+
# Require all generators that plugins have added to merb, after the app has loaded.
|
30
|
+
Merb::BootLoader.after_app_loads do
|
31
|
+
# TODO: remove this if statement once generator hooks are added to merb-core proper
|
32
|
+
if Merb.respond_to?(:generators)
|
33
|
+
Merb.generators.each do |file|
|
34
|
+
require file
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Merb::Generators
|
2
|
+
|
3
|
+
class ControllerGenerator < ComponentGenerator
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
File.join(super, 'controller')
|
7
|
+
end
|
8
|
+
|
9
|
+
desc <<-DESC
|
10
|
+
Generates a new controller.
|
11
|
+
DESC
|
12
|
+
|
13
|
+
option :testing_framework, :desc => 'Testing framework to use (one of: spec, test_unit)'
|
14
|
+
|
15
|
+
first_argument :name, :required => true, :desc => "controller name"
|
16
|
+
|
17
|
+
invoke :helper
|
18
|
+
|
19
|
+
template :controller do
|
20
|
+
source('app/controllers/%file_name%.rb')
|
21
|
+
destination("app/controllers/#{file_name}.rb")
|
22
|
+
end
|
23
|
+
|
24
|
+
template :index do
|
25
|
+
source('app/views/%file_name%/index.html.erb')
|
26
|
+
destination("app/views/#{file_name}/index.html.erb")
|
27
|
+
end
|
28
|
+
|
29
|
+
template :controller_spec, :testing_framework => :rspec do
|
30
|
+
source('spec/controllers/%file_name%_spec.rb')
|
31
|
+
destination("spec/controllers/#{file_name}_spec.rb")
|
32
|
+
end
|
33
|
+
|
34
|
+
template :controller_test_unit, :testing_framework => :test_unit do
|
35
|
+
source('test/controllers/%file_name%_test.rb')
|
36
|
+
destination("test/controllers/#{file_name}_test.rb")
|
37
|
+
end
|
38
|
+
|
39
|
+
def controller_modules
|
40
|
+
chunks[0..-2]
|
41
|
+
end
|
42
|
+
|
43
|
+
def controller_class_name
|
44
|
+
chunks.last
|
45
|
+
end
|
46
|
+
|
47
|
+
def full_class_name
|
48
|
+
chunks.join('::')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_class_name
|
52
|
+
controller_class_name + "Test"
|
53
|
+
end
|
54
|
+
|
55
|
+
def file_name
|
56
|
+
controller_class_name.snake_case
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
|
61
|
+
def chunks
|
62
|
+
name.gsub('/', '::').split('::').map { |c| c.camel_case }
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
add :controller, ControllerGenerator
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Merb::Generators
|
2
|
+
|
3
|
+
class FreezerGenerator < ComponentGenerator
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
File.join(super, 'freezer')
|
7
|
+
end
|
8
|
+
|
9
|
+
desc <<-DESC
|
10
|
+
Generates Merb freezer scripts.
|
11
|
+
DESC
|
12
|
+
|
13
|
+
template :freezer, 'script/frozen_merb', 'script/frozen_merb'
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
add :freezer, FreezerGenerator
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Merb
|
2
|
+
|
3
|
+
module Generators
|
4
|
+
|
5
|
+
extend Templater::Manifold
|
6
|
+
|
7
|
+
desc <<-DESC
|
8
|
+
Generate components for your application or entirely new applications.
|
9
|
+
DESC
|
10
|
+
|
11
|
+
class Generator < Templater::Generator
|
12
|
+
|
13
|
+
def initialize(*args)
|
14
|
+
super
|
15
|
+
options[:orm] ||= Merb.orm_generator_scope
|
16
|
+
options[:testing_framework] ||= Merb.test_framework_generator_scope
|
17
|
+
|
18
|
+
options[:orm] = :none if options[:orm] == :merb_default # FIXME: temporary until this is fixed in merb-core
|
19
|
+
end
|
20
|
+
|
21
|
+
# Inside a template, wraps a block of code properly in modules, keeping the indentation correct
|
22
|
+
# TODO: spec me
|
23
|
+
def with_modules(modules, options={}, &block)
|
24
|
+
indent = options[:indent] || 0
|
25
|
+
text = capture(&block)
|
26
|
+
modules.each_with_index do |mod, i|
|
27
|
+
concat((" " * (indent + i)) + "module #{mod}\n", block.binding)
|
28
|
+
end
|
29
|
+
text = text.to_a.map{ |line| (" " * modules.size) + line }.join
|
30
|
+
concat(text, block.binding)
|
31
|
+
modules.reverse.each_with_index do |mod, i|
|
32
|
+
concat((" " * (indent + modules.size - i - 1)) + "end # #{mod}\n", block.binding)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.source_root
|
37
|
+
File.join(File.dirname(__FILE__), '..', '..', 'templates')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class ApplicationGenerator < Generator
|
42
|
+
def self.source_root
|
43
|
+
File.join(super, 'application')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class ComponentGenerator < Generator
|
48
|
+
def self.source_root
|
49
|
+
File.join(super, 'component')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Merb::Generators
|
2
|
+
|
3
|
+
class HelperGenerator < ComponentGenerator
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
File.join(super, 'helper')
|
7
|
+
end
|
8
|
+
|
9
|
+
desc <<-DESC
|
10
|
+
Generates a new helper.
|
11
|
+
DESC
|
12
|
+
|
13
|
+
option :testing_framework, :desc => 'Testing framework to use (one of: spec, test_unit)'
|
14
|
+
|
15
|
+
first_argument :name, :required => true, :desc => "helper name"
|
16
|
+
|
17
|
+
template :helper do
|
18
|
+
source('app/helpers/%file_name%_helper.rb')
|
19
|
+
destination("app/helpers/#{file_name}_helper.rb")
|
20
|
+
end
|
21
|
+
|
22
|
+
template :helper_spec, :testing_framework => :rspec do
|
23
|
+
source('spec/helpers/%file_name%_helper_spec.rb')
|
24
|
+
destination("spec/helpers/#{file_name}_helper_spec.rb")
|
25
|
+
end
|
26
|
+
|
27
|
+
def helper_modules
|
28
|
+
chunks[0..-2]
|
29
|
+
end
|
30
|
+
|
31
|
+
def helper_class_name
|
32
|
+
chunks.last
|
33
|
+
end
|
34
|
+
|
35
|
+
def full_class_name
|
36
|
+
chunks.join('::')
|
37
|
+
end
|
38
|
+
|
39
|
+
def file_name
|
40
|
+
helper_class_name.snake_case
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def chunks
|
46
|
+
name.gsub('/', '::').split('::').map { |c| c.camel_case }
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
add :helper, HelperGenerator
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Merb::Generators
|
2
|
+
|
3
|
+
class MerbGenerator < ApplicationGenerator
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
File.join(super, 'merb')
|
7
|
+
end
|
8
|
+
|
9
|
+
option :testing_framework, :default => :rspec, :desc => 'Testing framework to use (one of: spec, test_unit)'
|
10
|
+
option :orm, :default => :none, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
|
11
|
+
option :flat, :as => :boolean, :desc => "Generate a flat application: one file + configs + templates directory."
|
12
|
+
option :very_flat, :as => :boolean, :desc => "Generate a very flat, Sinatra-like one file application."
|
13
|
+
|
14
|
+
desc <<-DESC
|
15
|
+
Generates a merb application.
|
16
|
+
DESC
|
17
|
+
|
18
|
+
first_argument :name, :required => true, :desc => "Application name"
|
19
|
+
|
20
|
+
invoke :app_full, :flat => nil, :very_flat => nil
|
21
|
+
invoke :app_flat, :flat => true
|
22
|
+
invoke :app_very_flat, :very_flat => true
|
23
|
+
end
|
24
|
+
|
25
|
+
add :app, MerbGenerator
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Merb::Generators
|
2
|
+
|
3
|
+
class MerbFlatGenerator < ApplicationGenerator
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
File.join(super, 'merb_flat')
|
7
|
+
end
|
8
|
+
|
9
|
+
desc <<-DESC
|
10
|
+
This generates a flat merb application: all code but config files and
|
11
|
+
templates fits in one application. This is something in between Sinatra
|
12
|
+
and "regular" Merb application.
|
13
|
+
DESC
|
14
|
+
|
15
|
+
first_argument :name, :required => true, :desc => "Application name"
|
16
|
+
|
17
|
+
glob!
|
18
|
+
|
19
|
+
def app_name
|
20
|
+
self.name.snake_case
|
21
|
+
end
|
22
|
+
|
23
|
+
def destination_root
|
24
|
+
File.join(@destination_root, app_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
add_private :app_flat, MerbFlatGenerator
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Merb::Generators
|
2
|
+
|
3
|
+
class MerbFullGenerator < ApplicationGenerator
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
File.join(super, 'merb')
|
7
|
+
end
|
8
|
+
|
9
|
+
option :testing_framework, :default => :rspec,
|
10
|
+
:desc => 'Testing framework to use (one of: spec, test_unit).'
|
11
|
+
option :orm, :default => :none,
|
12
|
+
:desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel).'
|
13
|
+
|
14
|
+
desc <<-DESC
|
15
|
+
This generates a Merb application with Ruby on Rails like structure.
|
16
|
+
Generator lets you configure your ORM and testing framework of choice.
|
17
|
+
DESC
|
18
|
+
|
19
|
+
glob!
|
20
|
+
|
21
|
+
first_argument :name, :required => true, :desc => "Application name"
|
22
|
+
|
23
|
+
def app_name
|
24
|
+
self.name.snake_case
|
25
|
+
end
|
26
|
+
|
27
|
+
def destination_root
|
28
|
+
File.join(@destination_root, app_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
add_private :app_full, MerbFullGenerator
|
34
|
+
|
35
|
+
end
|