Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f1828319
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,发现更多精彩内容 >>
提交
f1828319
编写于
6月 07, 2011
作者:
S
Stefan Sprenger
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use namespace if it's a mountable engine
上级
1a06530a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
61 addition
and
12 deletion
+61
-12
railties/lib/rails/engine/commands.rb
railties/lib/rails/engine/commands.rb
+1
-0
railties/lib/rails/generators.rb
railties/lib/rails/generators.rb
+10
-0
railties/lib/rails/generators/named_base.rb
railties/lib/rails/generators/named_base.rb
+1
-3
railties/lib/rails/railtie.rb
railties/lib/rails/railtie.rb
+5
-0
railties/test/railties/generators_test.rb
railties/test/railties/generators_test.rb
+44
-9
未找到文件。
railties/lib/rails/engine/commands.rb
浏览文件 @
f1828319
...
...
@@ -15,6 +15,7 @@
case
command
when
'generate'
,
'destroy'
require
'rails/generators'
Rails
::
Generators
.
namespace
=
engine
.
railtie_namespace
engine
.
load_generators
require
"rails/commands/
#{
command
}
"
...
...
railties/lib/rails/generators.rb
浏览文件 @
f1828319
...
...
@@ -90,6 +90,16 @@ def self.options #:nodoc:
@options
||=
DEFAULT_OPTIONS
.
dup
end
def
self
.
namespace
@namespace
||=
if
defined?
(
Rails
)
&&
Rails
.
application
Rails
.
application
.
class
.
parents
.
detect
{
|
n
|
n
.
respond_to?
(
:_railtie
)
}
end
end
def
self
.
namespace
=
(
namespace
)
@namespace
||=
namespace
end
# Hold configured generators fallbacks. If a plugin developer wants a
# generator group to fallback to another group in case of missing generators,
# they can add a fallback.
...
...
railties/lib/rails/generators/named_base.rb
浏览文件 @
f1828319
...
...
@@ -63,9 +63,7 @@ def inside_template?
end
def
namespace
@namespace
||=
if
defined?
(
Rails
)
&&
Rails
.
application
Rails
.
application
.
class
.
parents
.
detect
{
|
n
|
n
.
respond_to?
(
:_railtie
)
}
end
Rails
::
Generators
.
namespace
end
def
namespaced?
...
...
railties/lib/rails/railtie.rb
浏览文件 @
f1828319
require
'rails/initializable'
require
'rails/configuration'
require
'active_support/inflector'
require
'active_support/core_ext/module/introspection'
module
Rails
# Railtie is the core of the Rails framework and provides several hooks to extend
...
...
@@ -192,5 +193,9 @@ def load_tasks(app)
def
load_generators
(
app
)
self
.
class
.
generators
.
each
{
|
block
|
block
.
call
(
app
)
}
end
def
railtie_namespace
@railtie_namespace
||=
self
.
class
.
parents
.
detect
{
|
n
|
n
.
respond_to?
(
:_railtie
)
}
end
end
end
railties/test/railties/generators_test.rb
浏览文件 @
f1828319
...
...
@@ -30,11 +30,13 @@ def rails(cmd)
`
#{
Gem
.
ruby
}
#{
require_environment
}
#{
RAILS_FRAMEWORK_ROOT
}
/bin/rails
#{
cmd
}
`
end
def
build_engine
def
build_engine
(
is_mountable
=
false
)
FileUtils
.
mkdir_p
(
engine_path
)
FileUtils
.
rm_r
(
engine_path
)
rails
(
"plugin new
#{
engine_path
}
--full --mountable"
)
mountable
=
is_mountable
?
"--mountable"
:
""
rails
(
"plugin new
#{
engine_path
}
--full
#{
mountable
}
"
)
Dir
.
chdir
(
engine_path
)
do
File
.
open
(
"Gemfile"
,
"w"
)
do
|
f
|
...
...
@@ -52,32 +54,65 @@ def build_engine
end
end
def
build_mountable_engine
build_engine
(
true
)
end
def
setup
build_engine
end
def
test_controllers_are_correctly_namespaced
def
test_controllers_are_correctly_namespaced_when_engine_is_mountable
build_mountable_engine
Dir
.
chdir
(
engine_path
)
do
bundled_rails
(
"g controller topics"
)
assert_file
"app/controllers/foo_bar/topics_controller.rb"
,
/
FooBar::
TopicsController/
assert_file
"app/controllers/foo_bar/topics_controller.rb"
,
/
module FooBar\n class
TopicsController/
assert_no_file
"app/controllers/topics_controller.rb"
end
end
def
test_models_are_correctly_namespaced
def
test_models_are_correctly_namespaced_when_engine_is_mountable
build_mountable_engine
Dir
.
chdir
(
engine_path
)
do
bundled_rails
(
"g model topic"
)
assert_file
"app/models/foo_bar/topic.rb"
,
/
FooBar::
Topic/
assert_file
"app/models/foo_bar/topic.rb"
,
/
module FooBar\n class
Topic/
assert_no_file
"app/models/topic.rb"
end
end
def
test_helpers_are_correctly_namespaced
def
test_helpers_are_correctly_namespaced_when_engine_is_mountable
build_mountable_engine
Dir
.
chdir
(
engine_path
)
do
bundled_rails
(
"g helper topics"
)
assert_file
"app/helpers/foo_bar/topics_helper.rb"
,
/
FooBar::
TopicsHelper/
assert_file
"app/helpers/foo_bar/topics_helper.rb"
,
/
module FooBar\n module
TopicsHelper/
assert_no_file
"app/helpers/topics_helper.rb"
end
end
def
test_controllers_are_not_namespaced_when_engine_is_not_mountable
build_engine
Dir
.
chdir
(
engine_path
)
do
bundled_rails
(
"g controller topics"
)
assert_file
"app/controllers/topics_controller.rb"
,
/class TopicsController/
assert_no_file
"app/controllers/foo_bar/topics_controller.rb"
end
end
def
test_models_are_not_namespaced_when_engine_is_not_mountable
build_engine
Dir
.
chdir
(
engine_path
)
do
bundled_rails
(
"g model topic"
)
assert_file
"app/models/topic.rb"
,
/class Topic/
assert_no_file
"app/models/foo_bar/topic.rb"
end
end
def
test_helpers_are_not_namespaced_when_engine_is_not_mountable
build_engine
Dir
.
chdir
(
engine_path
)
do
bundled_rails
(
"g helper topics"
)
assert_file
"app/helpers/topics_helper.rb"
,
/module TopicsHelper/
assert_no_file
"app/helpers/foo_bar/topics_helper.rb"
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录