merb-gen 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -3
- data/lib/generators/controller.rb +2 -2
- data/lib/generators/helper.rb +1 -1
- data/lib/generators/layout.rb +1 -1
- data/lib/generators/merb/merb_full.rb +3 -1
- data/lib/generators/merb/merb_very_flat.rb +3 -1
- data/lib/generators/merb.rb +1 -1
- data/lib/generators/merb_plugin.rb +1 -1
- data/lib/generators/model.rb +1 -1
- data/lib/generators/resource.rb +2 -2
- data/lib/generators/resource_controller.rb +6 -2
- data/lib/generators/templates/application/merb/autotest/merb_rspec.rb +1 -2
- data/lib/generators/templates/application/merb/config/environments/development.rb +2 -1
- data/lib/generators/templates/application/merb/config/init.rb +11 -0
- data/lib/generators/templates/application/merb_flat/spec/spec_helper.rb +17 -0
- data/lib/generators/templates/application/merb_very_flat/spec/spec_helper.rb +17 -0
- data/lib/generators/templates/component/resource_controller/app/controllers/%file_name%.rb +8 -8
- data/lib/merb-gen/generator.rb +3 -4
- data/lib/merb-gen.rb +1 -2
- data/spec/resource_controller_spec.rb +7 -0
- data/spec/spec_helper.rb +2 -1
- metadata +8 -5
- data/lib/merb-gen/spec_helper.rb +0 -65
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.
|
20
|
+
GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.5") + 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.
|
42
|
-
s.add_dependency "templater", ">= 0.1.
|
41
|
+
s.add_dependency "merb-core", ">= 0.9.5"
|
42
|
+
s.add_dependency "templater", ">= 0.1.5"
|
43
43
|
|
44
44
|
s.require_path = 'lib'
|
45
45
|
s.autorequire = GEM_NAME
|
@@ -10,8 +10,8 @@ module Merb::Generators
|
|
10
10
|
Generates a new controller.
|
11
11
|
DESC
|
12
12
|
|
13
|
-
option :testing_framework, :desc => 'Testing framework to use (one of:
|
14
|
-
option :template_engine, :
|
13
|
+
option :testing_framework, :desc => 'Testing framework to use (one of: rspec, test_unit)'
|
14
|
+
option :template_engine, :desc => 'Template engine to use (one of: erb, haml, markaby, etc...)'
|
15
15
|
|
16
16
|
first_argument :name, :required => true, :desc => "controller name"
|
17
17
|
|
data/lib/generators/helper.rb
CHANGED
@@ -10,7 +10,7 @@ module Merb::Generators
|
|
10
10
|
Generates a new helper.
|
11
11
|
DESC
|
12
12
|
|
13
|
-
option :testing_framework, :desc => 'Testing framework to use (one of:
|
13
|
+
option :testing_framework, :desc => 'Testing framework to use (one of: rspec, test_unit)'
|
14
14
|
|
15
15
|
first_argument :name, :required => true, :desc => "helper name"
|
16
16
|
|
data/lib/generators/layout.rb
CHANGED
@@ -11,7 +11,7 @@ module Merb::Generators
|
|
11
11
|
DESC
|
12
12
|
|
13
13
|
#option :testing_framework, :desc => 'Testing framework to use (one of: rspec, test_unit)'
|
14
|
-
option :template_engine, :
|
14
|
+
option :template_engine, :desc => 'Specify what template engine should be used (one of: erb, haml...)'
|
15
15
|
|
16
16
|
first_argument :name, :required => true, :desc => "layout name"
|
17
17
|
|
@@ -7,9 +7,11 @@ module Merb::Generators
|
|
7
7
|
end
|
8
8
|
|
9
9
|
option :testing_framework, :default => :rspec,
|
10
|
-
:desc => 'Testing framework to use (one of:
|
10
|
+
:desc => 'Testing framework to use (one of: rspec, test_unit).'
|
11
11
|
option :orm, :default => :none,
|
12
12
|
:desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel).'
|
13
|
+
option :template_engine, :default => :erb,
|
14
|
+
:desc => 'Template engine to prefer for this application (one of: erb, haml).'
|
13
15
|
|
14
16
|
desc <<-DESC
|
15
17
|
This generates a Merb application with Ruby on Rails like structure.
|
@@ -17,6 +17,8 @@ module Merb::Generators
|
|
17
17
|
source('application.rbt')
|
18
18
|
destination("#{base_name}.rb")
|
19
19
|
end
|
20
|
+
|
21
|
+
file :spec_helper, 'spec/spec_helper.rb', 'spec/spec_helper.rb'
|
20
22
|
|
21
23
|
def class_name
|
22
24
|
self.name.camel_case
|
@@ -26,4 +28,4 @@ module Merb::Generators
|
|
26
28
|
|
27
29
|
add_private :app_very_flat, MerbVeryFlatGenerator
|
28
30
|
|
29
|
-
end
|
31
|
+
end
|
data/lib/generators/merb.rb
CHANGED
@@ -2,7 +2,7 @@ module Merb::Generators
|
|
2
2
|
|
3
3
|
class MerbGenerator < Generator
|
4
4
|
|
5
|
-
option :testing_framework, :default => :rspec, :desc => 'Testing framework to use (one of:
|
5
|
+
option :testing_framework, :default => :rspec, :desc => 'Testing framework to use (one of: rspec, test_unit)'
|
6
6
|
option :orm, :default => :none, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
|
7
7
|
option :flat, :as => :boolean, :desc => "Generate a flat application: one file + configs + templates directory."
|
8
8
|
option :very_flat, :as => :boolean, :desc => "Generate a very flat, Sinatra-like one file application."
|
@@ -6,7 +6,7 @@ module Merb::Generators
|
|
6
6
|
File.join(super, 'application', 'merb_plugin')
|
7
7
|
end
|
8
8
|
|
9
|
-
option :testing_framework, :default => :rspec, :desc => 'Testing framework to use (one of:
|
9
|
+
option :testing_framework, :default => :rspec, :desc => 'Testing framework to use (one of: rspec, test_unit)'
|
10
10
|
option :orm, :default => :none, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
|
11
11
|
option :bin, :as => :boolean # TODO: explain this
|
12
12
|
|
data/lib/generators/model.rb
CHANGED
@@ -11,7 +11,7 @@ module Merb::Generators
|
|
11
11
|
of the application uses.
|
12
12
|
DESC
|
13
13
|
|
14
|
-
option :testing_framework, :desc => 'Testing framework to use (one of:
|
14
|
+
option :testing_framework, :desc => 'Testing framework to use (one of: rspec, test_unit)'
|
15
15
|
option :orm, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
|
16
16
|
|
17
17
|
first_argument :name, :required => true, :desc => "model name"
|
data/lib/generators/resource.rb
CHANGED
@@ -6,7 +6,7 @@ module Merb::Generators
|
|
6
6
|
Generates a new resource.
|
7
7
|
DESC
|
8
8
|
|
9
|
-
first_argument :name, :required => true, :desc => "resource name"
|
9
|
+
first_argument :name, :required => true, :desc => "resource name (singular)"
|
10
10
|
second_argument :attributes, :as => :hash, :default => {}, :desc => "space separated resource model properties in form of name:type. Example: state:string"
|
11
11
|
|
12
12
|
invoke :model do |generator|
|
@@ -22,7 +22,7 @@ module Merb::Generators
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def model_name
|
25
|
-
name
|
25
|
+
name
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
@@ -10,9 +10,9 @@ module Merb::Generators
|
|
10
10
|
Generates a new resource controller.
|
11
11
|
DESC
|
12
12
|
|
13
|
-
option :testing_framework, :desc => 'Testing framework to use (one of:
|
13
|
+
option :testing_framework, :desc => 'Testing framework to use (one of: rspec, test_unit)'
|
14
14
|
option :orm, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
|
15
|
-
option :template_engine, :
|
15
|
+
option :template_engine, :desc => 'Template Engine to use (one of: erb, haml, markaby, etc...)'
|
16
16
|
|
17
17
|
first_argument :name, :required => true,
|
18
18
|
:desc => "model name"
|
@@ -61,6 +61,10 @@ module Merb::Generators
|
|
61
61
|
plural_model.singularize
|
62
62
|
end
|
63
63
|
|
64
|
+
def resource_path
|
65
|
+
chunks.map{ |c| c.snake_case }.join('/')
|
66
|
+
end
|
67
|
+
|
64
68
|
# TODO: fix this for Datamapper, so that it returns the primary keys for the model
|
65
69
|
def params_for_get
|
66
70
|
"params[:id]"
|
@@ -14,8 +14,7 @@ class Autotest::MerbRspec < Autotest
|
|
14
14
|
super
|
15
15
|
|
16
16
|
# Ignore any happenings in these directories
|
17
|
-
add_exception %r%^\./(?:doc|log|public|tmp)%
|
18
|
-
|
17
|
+
add_exception %r%^\./(?:doc|log|public|tmp|\.git|\.hg|\.svn|framework|gems|schema|\.DS_Store|autotest|bin|.*\.sqlite3)%
|
19
18
|
# Ignore SCM directories and custom Autotest mappings
|
20
19
|
%w[.svn .hg .git .autotest].each { |exception| add_exception(exception) }
|
21
20
|
|
@@ -92,6 +92,17 @@ end
|
|
92
92
|
<%= "# " unless testing_framework == :test_unit %>use_test :test_unit
|
93
93
|
<%= "# " unless testing_framework == :rspec %>use_test :rspec
|
94
94
|
|
95
|
+
|
96
|
+
#
|
97
|
+
# ==== Choose which template engine to use by default
|
98
|
+
#
|
99
|
+
|
100
|
+
# Merb can generate views for different template engines, choose your favourite as the default.
|
101
|
+
|
102
|
+
<%= "# " unless template_engine == :erb %>use_template_engine :erb
|
103
|
+
<%= "# " unless template_engine == :haml %>use_template_engine :haml
|
104
|
+
|
105
|
+
|
95
106
|
#
|
96
107
|
# ==== Set up your basic configuration
|
97
108
|
#
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "spec"
|
3
|
+
require "merb-core"
|
4
|
+
|
5
|
+
Merb::Config.use do |c|
|
6
|
+
c[:session_store] = "memory"
|
7
|
+
end
|
8
|
+
|
9
|
+
Merb.start_environment(:testing => true,
|
10
|
+
:adapter => 'runner',
|
11
|
+
:environment => ENV['MERB_ENV'] || 'test')
|
12
|
+
|
13
|
+
Spec::Runner.configure do |config|
|
14
|
+
config.include(Merb::Test::ViewHelper)
|
15
|
+
config.include(Merb::Test::RouteHelper)
|
16
|
+
config.include(Merb::Test::ControllerHelper)
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "spec"
|
3
|
+
require "merb-core"
|
4
|
+
|
5
|
+
Merb::Config.use do |c|
|
6
|
+
c[:session_store] = "memory"
|
7
|
+
end
|
8
|
+
|
9
|
+
Merb.start_environment(:testing => true,
|
10
|
+
:adapter => 'runner',
|
11
|
+
:environment => ENV['MERB_ENV'] || 'test')
|
12
|
+
|
13
|
+
Spec::Runner.configure do |config|
|
14
|
+
config.include(Merb::Test::ViewHelper)
|
15
|
+
config.include(Merb::Test::RouteHelper)
|
16
|
+
config.include(Merb::Test::ControllerHelper)
|
17
|
+
end
|
@@ -1,42 +1,42 @@
|
|
1
1
|
<% with_modules(modules) do -%>
|
2
2
|
class <%= class_name %> < Application
|
3
3
|
|
4
|
-
# GET /<%=
|
4
|
+
# GET /<%= resource_path %>
|
5
5
|
def index
|
6
6
|
render
|
7
7
|
end
|
8
8
|
|
9
|
-
# GET /<%=
|
9
|
+
# GET /<%= resource_path %>/:id
|
10
10
|
def show
|
11
11
|
render
|
12
12
|
end
|
13
13
|
|
14
|
-
# GET /<%=
|
14
|
+
# GET /<%= resource_path %>/new
|
15
15
|
def new
|
16
16
|
render
|
17
17
|
end
|
18
18
|
|
19
|
-
# GET /<%=
|
19
|
+
# GET /<%= resource_path %>/:id/edit
|
20
20
|
def edit
|
21
21
|
render
|
22
22
|
end
|
23
23
|
|
24
|
-
# GET /<%=
|
24
|
+
# GET /<%= resource_path %>/:id/delete
|
25
25
|
def delete
|
26
26
|
render
|
27
27
|
end
|
28
28
|
|
29
|
-
# POST /<%=
|
29
|
+
# POST /<%= resource_path %>
|
30
30
|
def create
|
31
31
|
render
|
32
32
|
end
|
33
33
|
|
34
|
-
# PUT /<%=
|
34
|
+
# PUT /<%= resource_path %>/:id
|
35
35
|
def update
|
36
36
|
render
|
37
37
|
end
|
38
38
|
|
39
|
-
# DELETE /<%=
|
39
|
+
# DELETE /<%= resource_path %>/:id
|
40
40
|
def destroy
|
41
41
|
render
|
42
42
|
end
|
data/lib/merb-gen/generator.rb
CHANGED
@@ -12,10 +12,9 @@ module Merb
|
|
12
12
|
|
13
13
|
def initialize(*args)
|
14
14
|
super
|
15
|
-
options[:orm] ||= Merb.
|
16
|
-
options[:testing_framework] ||= Merb.
|
17
|
-
|
18
|
-
options[:orm] = :none if options[:orm] == :merb_default # FIXME: temporary until this is fixed in merb-core
|
15
|
+
options[:orm] ||= Merb.orm
|
16
|
+
options[:testing_framework] ||= Merb.test_framework
|
17
|
+
options[:template_engine] ||= Merb.template_engine
|
19
18
|
end
|
20
19
|
|
21
20
|
# Inside a template, wraps a block of code properly in modules, keeping the indentation correct
|
data/lib/merb-gen.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'merb-core'
|
3
3
|
require 'sha1'
|
4
|
-
gem 'templater', '>= 0.1.
|
4
|
+
gem 'templater', '>= 0.1.5'
|
5
5
|
require 'templater'
|
6
6
|
|
7
7
|
path = File.join(File.dirname(__FILE__))
|
@@ -9,7 +9,6 @@ path = File.join(File.dirname(__FILE__))
|
|
9
9
|
require path / "merb-gen" / "generator"
|
10
10
|
require path / "merb-gen" / "named_generator"
|
11
11
|
require path / "merb-gen" / "namespaced_generator"
|
12
|
-
require path / "merb-gen" / "spec_helper"
|
13
12
|
require path / "generators" / "merb"
|
14
13
|
require path / "generators" / "merb" / "merb_full"
|
15
14
|
require path / "generators" / "merb" / "merb_flat"
|
@@ -29,6 +29,13 @@ describe Merb::Generators::ResourceControllerGenerator do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
describe "#resource_path" do
|
33
|
+
it "should snake case and slash separate the full controller name" do
|
34
|
+
@generator.name = "Monkey::BlahWorld::ProjectPictures"
|
35
|
+
@generator.singular_model == "monkey/blah_world/project_picture"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
32
39
|
it "should create a controller" do
|
33
40
|
@generator.should create('/tmp/app/controllers/stuff.rb')
|
34
41
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,9 +5,10 @@ require 'rubygems'
|
|
5
5
|
require 'spec'
|
6
6
|
require 'merb-core'
|
7
7
|
require 'merb-gen'
|
8
|
+
require 'templater/spec/helpers'
|
8
9
|
|
9
10
|
Spec::Runner.configure do |config|
|
10
|
-
config.include
|
11
|
+
config.include Templater::Spec::Helpers
|
11
12
|
end
|
12
13
|
|
13
14
|
shared_examples_for "named generator" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb-gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
@@ -9,7 +9,7 @@ autorequire: merb-gen
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-08-
|
12
|
+
date: 2008-08-26 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
23
|
+
version: 0.9.5
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: templater
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.1.
|
33
|
+
version: 0.1.5
|
34
34
|
version:
|
35
35
|
description: Generators suite for Merb.
|
36
36
|
email: jonas.nicklas@gmail.com
|
@@ -109,6 +109,8 @@ files:
|
|
109
109
|
- lib/generators/templates/application/merb_flat/config/framework.rb
|
110
110
|
- lib/generators/templates/application/merb_flat/config/init.rb
|
111
111
|
- lib/generators/templates/application/merb_flat/README.txt
|
112
|
+
- lib/generators/templates/application/merb_flat/spec
|
113
|
+
- lib/generators/templates/application/merb_flat/spec/spec_helper.rb
|
112
114
|
- lib/generators/templates/application/merb_flat/views
|
113
115
|
- lib/generators/templates/application/merb_flat/views/foo.html.erb
|
114
116
|
- lib/generators/templates/application/merb_plugin
|
@@ -128,6 +130,8 @@ files:
|
|
128
130
|
- lib/generators/templates/application/merb_plugin/TODO
|
129
131
|
- lib/generators/templates/application/merb_very_flat
|
130
132
|
- lib/generators/templates/application/merb_very_flat/application.rbt
|
133
|
+
- lib/generators/templates/application/merb_very_flat/spec
|
134
|
+
- lib/generators/templates/application/merb_very_flat/spec/spec_helper.rb
|
131
135
|
- lib/generators/templates/component
|
132
136
|
- lib/generators/templates/component/controller
|
133
137
|
- lib/generators/templates/component/controller/app
|
@@ -253,7 +257,6 @@ files:
|
|
253
257
|
- lib/merb-gen/generator.rb
|
254
258
|
- lib/merb-gen/named_generator.rb
|
255
259
|
- lib/merb-gen/namespaced_generator.rb
|
256
|
-
- lib/merb-gen/spec_helper.rb
|
257
260
|
- lib/merb-gen.rb
|
258
261
|
- bin/merb-gen
|
259
262
|
- spec/controller_spec.rb
|
data/lib/merb-gen/spec_helper.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
module Merb
|
2
|
-
module Test
|
3
|
-
module GeneratorHelper
|
4
|
-
class InvokeMatcher
|
5
|
-
def initialize(expected)
|
6
|
-
@expected = expected
|
7
|
-
end
|
8
|
-
|
9
|
-
def matches?(actual)
|
10
|
-
@actual = actual
|
11
|
-
# Satisfy expectation here. Return false or raise an error if it's not met.
|
12
|
-
found = nil
|
13
|
-
@actual.invocations.each { |i| found = i if i.class == @expected }
|
14
|
-
|
15
|
-
if @with
|
16
|
-
return found && (@with == found.arguments)
|
17
|
-
else
|
18
|
-
return found
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def with(*arguments)
|
23
|
-
@with = arguments
|
24
|
-
return self
|
25
|
-
end
|
26
|
-
|
27
|
-
def failure_message
|
28
|
-
"expected #{@actual.inspect} to invoke #{@expected.inspect} with #{@with}, but it didn't"
|
29
|
-
end
|
30
|
-
|
31
|
-
def negative_failure_message
|
32
|
-
"expected #{@actual.inspect} not to invoke #{@expected.inspect} with #{@with}, but it did"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def invoke(expected)
|
37
|
-
InvokeMatcher.new(expected)
|
38
|
-
end
|
39
|
-
|
40
|
-
class CreateMatcher
|
41
|
-
def initialize(expected)
|
42
|
-
@expected = expected
|
43
|
-
end
|
44
|
-
|
45
|
-
def matches?(actual)
|
46
|
-
@actual = actual
|
47
|
-
# Satisfy expectation here. Return false or raise an error if it's not met.
|
48
|
-
@actual.actions.map{|t| t.destination }.include?(@expected)
|
49
|
-
end
|
50
|
-
|
51
|
-
def failure_message
|
52
|
-
"expected #{@actual.inspect} to create #{@expected.inspect}, but it didn't"
|
53
|
-
end
|
54
|
-
|
55
|
-
def negative_failure_message
|
56
|
-
"expected #{@actual.inspect} not to create #{@expected.inspect}, but it did"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def create(expected)
|
61
|
-
CreateMatcher.new(expected)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|