nsweb-generators 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -6
- data/features/nsweb_controller.feature +18 -24
- data/features/nsweb_model.feature +22 -22
- data/features/nsweb_plugin.feature +21 -0
- data/features/step_definitions/setup_steps.rb +2 -3
- data/features/support/env.rb +6 -0
- data/features/support/matchers.rb +7 -0
- data/lib/generators/nsweb.rb +12 -7
- data/lib/generators/nsweb/controller/controller_generator.rb +6 -8
- data/lib/generators/nsweb/model/model_generator.rb +2 -8
- data/lib/generators/nsweb/{engine → plugin}/USAGE +0 -0
- data/lib/generators/nsweb/plugin/plugin_generator.rb +37 -0
- data/lib/generators/nsweb/plugin/templates/engine.rb +8 -0
- data/lib/generators/nsweb/plugin/templates/plugin.rb +8 -0
- data/lib/generators/nsweb/{engine → plugin}/templates/routes.rb +0 -0
- data/lib/generators/nsweb/plugin/templates/tests/rspec.rb +5 -0
- metadata +29 -10
- data/features/nsweb_engine.feature +0 -12
- data/lib/generators/nsweb/engine/engine_generator.rb +0 -33
- data/lib/generators/nsweb/engine/templates/engine.rb +0 -22
- data/lib/generators/nsweb/scaffold/scaffold_generator.rb +0 -0
data/Gemfile
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
|
+
gemspec
|
2
3
|
|
3
|
-
gem 'rails', '3.0.3'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
gem '
|
8
|
-
|
4
|
+
#gem 'rails', '3.0.3'
|
5
|
+
#gem 'sqlite3-ruby', :require => 'sqlite3'
|
6
|
+
#
|
7
|
+
#group :test, :development do
|
8
|
+
# gem 'rspec-rails', '~> 2.0.1'
|
9
|
+
# gem 'cucumber', '~> 0.9.2'
|
10
|
+
#end
|
@@ -1,29 +1,23 @@
|
|
1
1
|
Feature: Nsweb Controller Generator
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
Inside of the Nsweb application
|
3
|
+
As a rails developer
|
4
|
+
I want to generate a controller for a resource
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
When I run "rails g nsweb:controller core Widget"
|
11
|
-
Then I should see the following files
|
12
|
-
| vendor/whizbang_app/core/app/controllers/widgets_controller.rb |
|
13
|
-
| vendor/whizbang_app/core/app/helpers/widgets_helper.rb |
|
6
|
+
Scenario: Generate a controller for a simple resource inside the core engine
|
7
|
+
Given a new rails app
|
8
|
+
Given a core plugin
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
When I run "rails g nsweb:controller core Widget"
|
11
|
+
Then I should see the following files
|
12
|
+
| lib/rails_app/plugins/core/app/controllers/widgets_controller.rb |
|
13
|
+
| lib/rails_app/plugins/core/app/helpers/widgets_helper.rb |
|
18
14
|
|
19
|
-
|
20
|
-
Given a new whizbang app
|
21
|
-
Given a core engine
|
15
|
+
And I should see "resources :widgets" in file "lib/rails_app/plugins/core/config/routes.rb"
|
22
16
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
Scenario: Generate controller with rspec tests
|
18
|
+
Given a new rails app
|
19
|
+
Given a core plugin
|
20
|
+
|
21
|
+
When I run "rails g nsweb:controller core Widget --rspec"
|
22
|
+
Then I should see the following files
|
23
|
+
| spec/lib/rails_app/plugins/core/controllers/widgets_controller_spec.rb |
|
@@ -1,27 +1,27 @@
|
|
1
1
|
Feature: Nsweb Model Generator
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
Inside of the Nsweb application
|
3
|
+
As a rails developer
|
4
|
+
I want to generate a model for a resource
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
Scenario: Generate a model for a simple resource inside the core engine
|
7
|
+
Given a new rails app
|
8
|
+
Given a core plugin
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
When I run "rake db:migrate"
|
15
|
-
Then I should successfully run "rake test"
|
10
|
+
When I run "rails g nsweb:model core Widget myvar:string"
|
11
|
+
Then I should see the following files
|
12
|
+
| lib/rails_app/plugins/core/app/models/widget.rb |
|
13
|
+
| db/migrate |
|
16
14
|
|
17
|
-
|
18
|
-
Given a new whizbang app
|
19
|
-
Given a core engine
|
15
|
+
Then I should successfully run "rake db:migrate"
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
17
|
+
Scenario: Generate a model with rspec tests
|
18
|
+
Given a new rails app
|
19
|
+
Given a core plugin
|
20
|
+
|
21
|
+
When I run "rails g nsweb:model core widget myvar:string --rspec"
|
22
|
+
Then I should see the following files
|
23
|
+
| spec/lib/rails_app/plugins/core/models/widget_spec.rb |
|
24
|
+
|
25
|
+
When I run "rake db:migrate"
|
26
|
+
And I add "gem 'rspec-rails', '>= 2.0.1'" to file "Gemfile"
|
27
|
+
Then I should successfully run "rails g rspec:install"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature: Nsweb Plugin Generator
|
2
|
+
Inside of a rails application
|
3
|
+
As a rails developer
|
4
|
+
I want to generate a plugin
|
5
|
+
|
6
|
+
Scenario: Generate a core plugin
|
7
|
+
Given a new rails app
|
8
|
+
|
9
|
+
When I run "rails g nsweb:plugin core"
|
10
|
+
Then I should see the following files
|
11
|
+
| lib/rails_app/plugins/core.rb |
|
12
|
+
| lib/rails_app/plugins/core/lib/engine.rb |
|
13
|
+
| lib/rails_app/plugins/core/config/routes.rb |
|
14
|
+
|
15
|
+
Scenario: Generate plugin with rspec tests
|
16
|
+
Given a new rails app
|
17
|
+
Given a core plugin
|
18
|
+
|
19
|
+
When I run "rails g nsweb:plugin core --rspec"
|
20
|
+
Then I should see the following files
|
21
|
+
| spec/lib/rails_app/plugins/core_spec.rb |
|
@@ -1,11 +1,10 @@
|
|
1
1
|
Given /^a new ([a-z_]*) app$/ do |app_name|
|
2
2
|
FileUtils.mkdir_p('tmp')
|
3
|
-
system('rm -rf tmp/*')
|
4
3
|
system("rails new tmp/#{app_name}_app")
|
5
4
|
system("ln -s ../../../lib/generators tmp/#{app_name}_app/lib/generators").should be_true
|
6
5
|
@current_directory = File.expand_path("tmp/#{app_name}_app")
|
7
6
|
end
|
8
7
|
|
9
|
-
Given /^a ([a-z_]*)
|
10
|
-
system("cd #{@current_directory} && rails g nsweb:
|
8
|
+
Given /^a ([a-z_]*) plugin$/ do |plugin_name|
|
9
|
+
system("cd #{@current_directory} && rails g nsweb:plugin #{plugin_name}")
|
11
10
|
end
|
data/lib/generators/nsweb.rb
CHANGED
@@ -4,9 +4,10 @@ require 'rails/generators/base'
|
|
4
4
|
module Nsweb
|
5
5
|
module Generators
|
6
6
|
class Base < Rails::Generators::Base #:nodoc:
|
7
|
-
attr_accessor :
|
7
|
+
attr_accessor :plugin_name
|
8
8
|
|
9
|
-
argument :
|
9
|
+
argument :plugin_name, :type => :string, :required => true, :banner => 'PluginName'
|
10
|
+
class_option :rspec, :desc => 'Use RSpec for test files.', :group => 'Test framework', :type => :boolean
|
10
11
|
|
11
12
|
def self.source_root
|
12
13
|
@nsweb_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'nsweb', generator_name, 'templates'))
|
@@ -26,14 +27,18 @@ module Nsweb
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
|
-
def
|
30
|
-
@
|
30
|
+
def plugin_file_name
|
31
|
+
@plugin_file_name ||= plugin_name.underscore
|
31
32
|
end
|
32
33
|
|
33
|
-
def
|
34
|
+
def plugin_path
|
35
|
+
@plugin_path ||= File.join('lib', application_name, 'plugins', plugin_file_name)
|
36
|
+
end
|
37
|
+
|
38
|
+
def plugin_route(routing_code)
|
34
39
|
sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/
|
35
40
|
in_root do
|
36
|
-
inject_into_file File.join(
|
41
|
+
inject_into_file File.join(plugin_path, 'config/routes.rb' ),
|
37
42
|
"\n #{routing_code}\n", { :after => sentinel, :verbose => false }
|
38
43
|
end
|
39
44
|
end
|
@@ -91,7 +96,7 @@ module Nsweb
|
|
91
96
|
end
|
92
97
|
|
93
98
|
def table_name
|
94
|
-
@table_name ||= (
|
99
|
+
@table_name ||= (class_path + [plural_name]).join('_')
|
95
100
|
end
|
96
101
|
|
97
102
|
#def migration_class_name
|
@@ -7,8 +7,6 @@ module Nsweb
|
|
7
7
|
argument :actions, :type => :array, :default => [],
|
8
8
|
:banner => 'action action'
|
9
9
|
|
10
|
-
class_option :rspec, :desc => 'Use RSpec for test files.', :group => 'Test framework', :type => :boolean
|
11
|
-
|
12
10
|
def initialize(*args, &block)
|
13
11
|
super
|
14
12
|
|
@@ -24,21 +22,21 @@ module Nsweb
|
|
24
22
|
end
|
25
23
|
|
26
24
|
def create_controller
|
27
|
-
template 'controller.rb', File.join(
|
25
|
+
template 'controller.rb', File.join(plugin_path, 'app/controllers',
|
28
26
|
"#{plural_file_path}_controller.rb")
|
29
27
|
if test_framework == :rspec
|
30
|
-
template 'tests/rspec.rb', File.join(
|
28
|
+
template 'tests/rspec.rb', File.join('spec', plugin_path, 'controllers',
|
31
29
|
"#{plural_file_path}_controller_spec.rb")
|
32
30
|
else
|
33
31
|
end
|
34
32
|
unless options.skip_helper?
|
35
|
-
template 'helper.rb', File.join(
|
33
|
+
template 'helper.rb', File.join(plugin_path, 'app/helpers',
|
36
34
|
"#{plural_file_path}_helper.rb")
|
37
35
|
end
|
38
36
|
|
39
37
|
#controller_actions.each do |action|
|
40
38
|
# if %w[index show new edit].include?(action)
|
41
|
-
# template "views/#{action}.html.erb", File.join(
|
39
|
+
# template "views/#{action}.html.erb", File.join(plugin_path,
|
42
40
|
# "app/views/#{file_name}/#{action}.html.erb")
|
43
41
|
|
44
42
|
|
@@ -46,10 +44,10 @@ module Nsweb
|
|
46
44
|
#end
|
47
45
|
|
48
46
|
if class_path.length < 0
|
49
|
-
|
47
|
+
plugin_route("resources #{plural_file_name.to_sym.inspect},
|
50
48
|
:controller => '#{(class_path + [plural_name]).join('/')}")
|
51
49
|
else
|
52
|
-
|
50
|
+
plugin_route("resources #{plural_name.to_sym.inspect}")
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
@@ -9,9 +9,6 @@ module Nsweb
|
|
9
9
|
|
10
10
|
argument :attributes, :type => :array, :default => [], :banner => 'field:type field:type'
|
11
11
|
|
12
|
-
class_option :skip_migration, :desc => 'Don\'t generate a migration file for model.', :type => :boolean
|
13
|
-
class_option :rspec, :desc => 'Use RSpec for test files.', :group => 'Test framework', :type => :boolean
|
14
|
-
|
15
12
|
def initialize(*args, &block)
|
16
13
|
super
|
17
14
|
@model_attributes = []
|
@@ -21,13 +18,10 @@ module Nsweb
|
|
21
18
|
end
|
22
19
|
|
23
20
|
def create_model
|
24
|
-
template 'model.rb', File.join(
|
21
|
+
template 'model.rb', File.join(plugin_path, 'app/models', "#{file_path}.rb")
|
25
22
|
if test_framework == :rspec
|
26
|
-
template 'tests/rspec/model.rb', File.join(
|
23
|
+
template 'tests/rspec/model.rb', File.join('spec', plugin_path, 'models',
|
27
24
|
"#{file_path}_spec.rb")
|
28
|
-
else
|
29
|
-
template "tests/#{test_framework}/model.rb", File.join(engine_path, "test/unit/#{singular_name}_test.rb")
|
30
|
-
|
31
25
|
end
|
32
26
|
end
|
33
27
|
|
File without changes
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'generators/nsweb'
|
2
|
+
|
3
|
+
module Nsweb
|
4
|
+
module Generators
|
5
|
+
class PluginGenerator < Base
|
6
|
+
|
7
|
+
def initialize(*args, &block)
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_plugin
|
12
|
+
template 'plugin.rb', "#{plugin_path}.rb"
|
13
|
+
#File.join(plugin_path, "#{plugin_file_name}.rb")
|
14
|
+
if test_framework == :rspec
|
15
|
+
template 'tests/rspec.rb', File.join('spec', "#{plugin_path}_spec.rb")
|
16
|
+
#, "#{plugin_file_name}_spec.rb")
|
17
|
+
else
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_engine
|
22
|
+
template 'engine.rb', File.join(plugin_path, 'lib/engine.rb')
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_routes
|
26
|
+
template 'routes.rb', File.join(plugin_path, 'config/routes.rb')
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def plugin_class_name
|
32
|
+
@plugin_class_name ||= plugin_file_name.camelize
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nsweb-generators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Josh Williams
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-12 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -66,6 +66,22 @@ dependencies:
|
|
66
66
|
version: 3.0.3
|
67
67
|
type: :runtime
|
68
68
|
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3-ruby
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 25
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 3
|
81
|
+
- 1
|
82
|
+
version: 1.3.1
|
83
|
+
type: :runtime
|
84
|
+
version_requirements: *id004
|
69
85
|
description: Generators for Nsweb engines/models/controllers
|
70
86
|
email: jwilliams@shareone.com
|
71
87
|
executables: []
|
@@ -78,10 +94,12 @@ files:
|
|
78
94
|
- .gitignore
|
79
95
|
- Gemfile
|
80
96
|
- features/nsweb_controller.feature
|
81
|
-
- features/nsweb_engine.feature
|
82
97
|
- features/nsweb_model.feature
|
98
|
+
- features/nsweb_plugin.feature
|
83
99
|
- features/step_definitions/common_steps.rb
|
84
100
|
- features/step_definitions/setup_steps.rb
|
101
|
+
- features/support/env.rb
|
102
|
+
- features/support/matchers.rb
|
85
103
|
- lib/generators/nsweb.rb
|
86
104
|
- lib/generators/nsweb/controller/controller_generator.rb
|
87
105
|
- lib/generators/nsweb/controller/templates/actions/create.rb
|
@@ -95,16 +113,17 @@ files:
|
|
95
113
|
- lib/generators/nsweb/controller/templates/helper.rb
|
96
114
|
- lib/generators/nsweb/controller/templates/tests/rspec.rb
|
97
115
|
- lib/generators/nsweb/controller/templates/views/index.html.erb
|
98
|
-
- lib/generators/nsweb/engine/USAGE
|
99
|
-
- lib/generators/nsweb/engine/engine_generator.rb
|
100
|
-
- lib/generators/nsweb/engine/templates/engine.rb
|
101
|
-
- lib/generators/nsweb/engine/templates/routes.rb
|
102
116
|
- lib/generators/nsweb/model/model_generator.rb
|
103
117
|
- lib/generators/nsweb/model/templates/migration.rb
|
104
118
|
- lib/generators/nsweb/model/templates/model.rb
|
105
119
|
- lib/generators/nsweb/model/templates/tests/rspec/model.rb
|
106
120
|
- lib/generators/nsweb/model/templates/tests/testunit/model.rb
|
107
|
-
- lib/generators/nsweb/
|
121
|
+
- lib/generators/nsweb/plugin/USAGE
|
122
|
+
- lib/generators/nsweb/plugin/plugin_generator.rb
|
123
|
+
- lib/generators/nsweb/plugin/templates/engine.rb
|
124
|
+
- lib/generators/nsweb/plugin/templates/plugin.rb
|
125
|
+
- lib/generators/nsweb/plugin/templates/routes.rb
|
126
|
+
- lib/generators/nsweb/plugin/templates/tests/rspec.rb
|
108
127
|
has_rdoc: true
|
109
128
|
homepage: http://projects.hbtesting.org
|
110
129
|
licenses: []
|
@@ -1,12 +0,0 @@
|
|
1
|
-
Feature: Nsweb Engine Generator
|
2
|
-
Inside of a rails application
|
3
|
-
As a rails developer
|
4
|
-
I want to generate an engine
|
5
|
-
|
6
|
-
Scenario: Generate a core engine
|
7
|
-
Given a new rails app
|
8
|
-
|
9
|
-
When I run "rails g nsweb:engine core"
|
10
|
-
Then I should see the following files
|
11
|
-
| vendor/rails_app/core/lib/core.rb |
|
12
|
-
| vendor/rails_app/core/config/routes.rb |
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'generators/nsweb'
|
2
|
-
|
3
|
-
module Nsweb
|
4
|
-
module Generators
|
5
|
-
class EngineGenerator < Base
|
6
|
-
|
7
|
-
attr_accessor :engine_name
|
8
|
-
|
9
|
-
def initialize(*args, &block)
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
13
|
-
def create_engine
|
14
|
-
template 'engine.rb', File.join(engine_path, 'lib', "#{engine_file_name}.rb")
|
15
|
-
end
|
16
|
-
|
17
|
-
def create_routes
|
18
|
-
template 'routes.rb', File.join(engine_path, 'config/routes.rb')
|
19
|
-
end
|
20
|
-
|
21
|
-
protected
|
22
|
-
|
23
|
-
def engine_file_name
|
24
|
-
@engine_file_name ||= engine_name.underscore
|
25
|
-
end
|
26
|
-
|
27
|
-
def engine_class_name
|
28
|
-
@engine_class_name ||= engine_name.camelize
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rails/all'
|
2
|
-
|
3
|
-
module <%= application_name %>
|
4
|
-
module <%= engine_class_name %>
|
5
|
-
class << self
|
6
|
-
def root
|
7
|
-
@root ||= File.dirname(File.expand_path(__FILE__))
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class Engine < Rails::Engine
|
12
|
-
|
13
|
-
config.after_initialize do |app|
|
14
|
-
<%= application_name %>::Plugin.register do |plugin|
|
15
|
-
plugin.name = '<%= engine_file_name %>'
|
16
|
-
plugin.title = '<%= engine_class_name %>'
|
17
|
-
plugin.version = %q{0.0.1}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
File without changes
|