Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
bac0826b
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,发现更多精彩内容 >>
提交
bac0826b
编写于
9月 24, 2010
作者:
P
Piotr Sarnacki
提交者:
José Valim
9月 24, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor namespaced generators to use module_namespacing block helper
Signed-off-by:
N
José Valim
<
jose.valim@gmail.com
>
上级
e8363408
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
24 addition
and
17 deletion
+24
-17
Gemfile
Gemfile
+2
-0
activerecord/lib/rails/generators/active_record/model/model_generator.rb
...b/rails/generators/active_record/model/model_generator.rb
+2
-2
activerecord/lib/rails/generators/active_record/model/templates/model.rb
...b/rails/generators/active_record/model/templates/model.rb
+2
-0
activerecord/lib/rails/generators/active_record/model/templates/module.rb
.../rails/generators/active_record/model/templates/module.rb
+2
-0
railties/lib/rails/generators/named_base.rb
railties/lib/rails/generators/named_base.rb
+10
-13
railties/lib/rails/generators/rails/controller/controller_generator.rb
...rails/generators/rails/controller/controller_generator.rb
+1
-1
railties/lib/rails/generators/rails/controller/templates/controller.rb
...rails/generators/rails/controller/templates/controller.rb
+2
-0
railties/lib/rails/generators/rails/helper/helper_generator.rb
...ies/lib/rails/generators/rails/helper/helper_generator.rb
+1
-1
railties/lib/rails/generators/rails/helper/templates/helper.rb
...ies/lib/rails/generators/rails/helper/templates/helper.rb
+2
-0
未找到文件。
Gemfile
浏览文件 @
bac0826b
...
...
@@ -8,6 +8,8 @@ end
gem
"
rails
"
,
:path
=>
File
.
dirname
(
__FILE__
)
gem
"
thor
"
,
:git
=>
"git://github.com/drogus/thor.git"
gem
"
rake
"
,
">= 0.8.7"
gem
"
mocha
"
,
">= 0.9.8"
gem
"
rdoc
"
,
">= 2.5.10"
...
...
activerecord/lib/rails/generators/active_record/model/model_generator.rb
浏览文件 @
bac0826b
...
...
@@ -17,12 +17,12 @@ def create_migration_file
end
def
create_model_file
namespaced_
template
'model.rb'
,
File
.
join
(
'app/models'
,
class_path
,
"
#{
file_name
}
.rb"
)
template
'model.rb'
,
File
.
join
(
'app/models'
,
class_path
,
"
#{
file_name
}
.rb"
)
end
def
create_module_file
return
if
class_path
.
empty?
namespaced_
template
'module.rb'
,
File
.
join
(
'app/models'
,
"
#{
class_path
.
join
(
'/'
)
}
.rb"
)
if
behavior
==
:invoke
template
'module.rb'
,
File
.
join
(
'app/models'
,
"
#{
class_path
.
join
(
'/'
)
}
.rb"
)
if
behavior
==
:invoke
end
hook_for
:test_framework
...
...
activerecord/lib/rails/generators/active_record/model/templates/model.rb
浏览文件 @
bac0826b
<
% module_namespacing
do
-
%>
class <%= class_name %>
<
<
%= parent_class_name.classify %>
<% attributes.select {|attr| attr.reference? }.each do |attribute| -%>
belongs_to :<%=
attribute
.
name
%>
<% end -%>
end
<
% end
-
%>
activerecord/lib/rails/generators/active_record/model/templates/module.rb
浏览文件 @
bac0826b
<
% module_namespacing
do
-
%>
module <%= class_path.map(&:camelize).join('::') %>
def
self
.
table_name_prefix
'<%= class_path.join('
_
') %>_'
end
end
<
% end
-
%>
railties/lib/rails/generators/named_base.rb
浏览文件 @
bac0826b
...
...
@@ -17,6 +17,16 @@ def initialize(args, *options) #:nodoc:
end
protected
def
module_namespacing
(
&
block
)
inside_namespace
do
content
=
capture
(
&
block
)
if
namespaced?
content
=
indent
(
content
)
content
=
wrap_with_namespace
(
content
)
end
concat
(
content
)
end
end
def
indent
(
content
,
multiplier
=
2
)
spaces
=
" "
*
multiplier
...
...
@@ -27,19 +37,6 @@ def wrap_with_namespace(content)
"module
#{
namespace
.
name
}
\n
#{
content
}
\n
end
\n
"
end
def
namespaced_template
(
source
,
*
args
,
&
block
)
inside_namespace
do
template
(
source
,
*
args
)
do
|
content
|
content
=
block
.
call
(
content
)
if
block_given?
if
namespace
content
=
indent
(
content
)
content
=
wrap_with_namespace
(
content
)
end
content
end
end
end
def
inside_namespace
@inside_namespace
=
true
if
namespaced?
result
=
yield
...
...
railties/lib/rails/generators/rails/controller/controller_generator.rb
浏览文件 @
bac0826b
...
...
@@ -5,7 +5,7 @@ class ControllerGenerator < NamedBase
check_class_collision
:suffix
=>
"Controller"
def
create_controller_files
namespaced_
template
'controller.rb'
,
File
.
join
(
'app/controllers'
,
class_path
,
"
#{
file_name
}
_controller.rb"
)
template
'controller.rb'
,
File
.
join
(
'app/controllers'
,
class_path
,
"
#{
file_name
}
_controller.rb"
)
end
def
add_routes
...
...
railties/lib/rails/generators/rails/controller/templates/controller.rb
浏览文件 @
bac0826b
<
% module_namespacing
do
-
%>
class <%= class_name %>
Controller
<
ApplicationController
<
% for
action
in
actions
-
%>
def <%= action %>
...
...
@@ -5,3 +6,4 @@ def <%= action %>
<
% end
-
%>
end
<% end -%>
railties/lib/rails/generators/rails/helper/helper_generator.rb
浏览文件 @
bac0826b
...
...
@@ -4,7 +4,7 @@ class HelperGenerator < NamedBase
check_class_collision
:suffix
=>
"Helper"
def
create_helper_files
namespaced_
template
'helper.rb'
,
File
.
join
(
'app/helpers'
,
class_path
,
"
#{
file_name
}
_helper.rb"
)
template
'helper.rb'
,
File
.
join
(
'app/helpers'
,
class_path
,
"
#{
file_name
}
_helper.rb"
)
end
hook_for
:test_framework
...
...
railties/lib/rails/generators/rails/helper/templates/helper.rb
浏览文件 @
bac0826b
<
% module_namespacing
do
-
%>
module <%= class_name %>
Helper
end
<
% end
-
%>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录