Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4ca97650
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4ca97650
编写于
1月 19, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow railties to specify generators paths.
上级
9acf0af5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
67 addition
and
15 deletion
+67
-15
railties/lib/rails/application.rb
railties/lib/rails/application.rb
+5
-1
railties/lib/rails/generators.rb
railties/lib/rails/generators.rb
+24
-14
railties/lib/rails/railtie.rb
railties/lib/rails/railtie.rb
+15
-0
railties/test/generators_test.rb
railties/test/generators_test.rb
+7
-0
railties/test/plugins/framework_extension_test.rb
railties/test/plugins/framework_extension_test.rb
+16
-0
未找到文件。
railties/lib/rails/application.rb
浏览文件 @
4ca97650
...
...
@@ -8,7 +8,7 @@ class Application
class
<<
self
attr_writer
:config
alias
configure
class_eval
delegate
:initialize!
,
:load_tasks
,
:root
,
:to
=>
:instance
delegate
:initialize!
,
:load_tasks
,
:
load_generators
,
:
root
,
:to
=>
:instance
private
:new
def
instance
...
...
@@ -82,6 +82,10 @@ def load_tasks
end
end
def
load_generators
plugins
.
each
{
|
p
|
p
.
load_generators
}
end
def
initializers
initializers
=
Bootstrap
.
new
(
self
).
initializers
plugins
.
each
{
|
p
|
initializers
+=
p
.
initializers
}
...
...
railties/lib/rails/generators.rb
浏览文件 @
4ca97650
...
...
@@ -168,7 +168,7 @@ def self.invoke(namespace, args=ARGV, config={})
# Show help message with available generators.
def
self
.
help
traverse_load_paths
!
lookup
!
namespaces
=
subclasses
.
map
{
|
k
|
k
.
namespace
}
namespaces
.
sort!
...
...
@@ -226,22 +226,10 @@ def self.invoke_fallbacks_for(name, base) #:nodoc:
nil
end
# This will try to load any generator in the load path to show in help.
def
self
.
traverse_load_paths!
#:nodoc:
$LOAD_PATH
.
each
do
|
base
|
Dir
[
File
.
join
(
base
,
"{generators,rails_generators}"
,
"**"
,
"*_generator.rb"
)].
each
do
|
path
|
begin
require
path
rescue
Exception
=>
e
# No problem
end
end
end
end
# Receives namespaces in an array and tries to find matching generators
# in the load path.
def
self
.
lookup
(
namespaces
)
#:nodoc:
load_generators_from_railties!
paths
=
namespaces_to_paths
(
namespaces
)
paths
.
each
do
|
path
|
...
...
@@ -261,6 +249,28 @@ def self.lookup(namespaces) #:nodoc:
end
end
# This will try to load any generator in the load path to show in help.
def
self
.
lookup!
#:nodoc:
load_generators_from_railties!
$LOAD_PATH
.
each
do
|
base
|
Dir
[
File
.
join
(
base
,
"{generators,rails_generators}"
,
"**"
,
"*_generator.rb"
)].
each
do
|
path
|
begin
require
path
rescue
Exception
=>
e
# No problem
end
end
end
end
# Allow generators to be loaded from custom paths.
def
self
.
load_generators_from_railties!
#:nodoc:
return
if
defined?
(
@generators_from_railties
)
||
Rails
.
application
.
nil?
@generators_from_railties
=
true
Rails
.
application
.
load_generators
end
# Convert namespaces to paths by replacing ":" for "/" and adding
# an extra lookup. For example, "rails:model" should be searched
# in both: "rails/model/model_generator" and "rails/model_generator".
...
...
railties/lib/rails/railtie.rb
浏览文件 @
4ca97650
...
...
@@ -35,13 +35,28 @@ def self.rake_tasks(&blk)
@rake_tasks
end
def
self
.
generators
(
&
blk
)
@generators
||=
[]
@generators
<<
blk
if
blk
@generators
end
def
rake_tasks
self
.
class
.
rake_tasks
end
def
generators
self
.
class
.
generators
end
def
load_tasks
return
unless
rake_tasks
rake_tasks
.
each
{
|
blk
|
blk
.
call
}
end
def
load_generators
return
unless
generators
generators
.
each
{
|
blk
|
blk
.
call
}
end
end
end
railties/test/generators_test.rb
浏览文件 @
4ca97650
...
...
@@ -148,6 +148,13 @@ def self.name() 'NewGenerator' end
Rails
::
Generators
.
subclasses
.
delete
(
klass
)
end
def
test_load_generators_from_railties
Rails
::
Generators
::
ModelGenerator
.
expects
(
:start
).
with
([
"Account"
],
{})
Rails
::
Generators
.
send
(
:remove_instance_variable
,
:@generators_from_railties
)
Rails
.
application
.
expects
(
:load_generators
)
Rails
::
Generators
.
invoke
(
"model"
,
[
"Account"
])
end
def
test_rails_root_templates
template
=
File
.
join
(
Rails
.
root
,
"lib"
,
"templates"
,
"active_record"
,
"model"
,
"model.rb"
)
...
...
railties/test/plugins/framework_extension_test.rb
浏览文件 @
4ca97650
...
...
@@ -30,6 +30,22 @@ class MyTie < Rails::Railtie
AppTemplate
::
Application
.
load_tasks
assert
$ran_block
end
test
"generators block is executed when MyApp.load_generators is called"
do
$ran_block
=
false
class
MyTie
<
Rails
::
Railtie
generators
do
$ran_block
=
true
end
end
require
"
#{
app_path
}
/config/environment"
assert
!
$ran_block
AppTemplate
::
Application
.
load_generators
assert
$ran_block
end
end
class
ActiveRecordExtensionTest
<
Test
::
Unit
::
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录