Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
5c418af9
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,发现更多精彩内容 >>
提交
5c418af9
编写于
7月 24, 2017
作者:
R
Rafael França
提交者:
GitHub
7月 24, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #29853 from lugray/move_generator_namespacing_to_base
Move generator namespacing to Base
上级
6f0729b6
fee24f21
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
36 deletion
+37
-36
railties/lib/rails/generators/base.rb
railties/lib/rails/generators/base.rb
+37
-0
railties/lib/rails/generators/named_base.rb
railties/lib/rails/generators/named_base.rb
+0
-36
未找到文件。
railties/lib/rails/generators/base.rb
浏览文件 @
5c418af9
...
...
@@ -16,6 +16,9 @@ class Base < Thor::Group
include
Thor
::
Actions
include
Rails
::
Generators
::
Actions
class_option
:skip_namespace
,
type: :boolean
,
default:
false
,
desc:
"Skip namespace (affects only isolated applications)"
add_runtime_options!
strict_args_position!
...
...
@@ -271,6 +274,40 @@ def extract_last_module(nesting) # :doc:
end
end
# Wrap block with namespace of current application
# if namespace exists and is not skipped
def
module_namespacing
(
&
block
)
# :doc:
content
=
capture
(
&
block
)
content
=
wrap_with_namespace
(
content
)
if
namespaced?
concat
(
content
)
end
def
indent
(
content
,
multiplier
=
2
)
# :doc:
spaces
=
" "
*
multiplier
content
.
each_line
.
map
{
|
line
|
line
.
blank?
?
line
:
"
#{
spaces
}#{
line
}
"
}.
join
end
def
wrap_with_namespace
(
content
)
# :doc:
content
=
indent
(
content
).
chomp
"module
#{
namespace
.
name
}
\n
#{
content
}
\n
end
\n
"
end
def
namespace
# :doc:
Rails
::
Generators
.
namespace
end
def
namespaced?
# :doc:
!
options
[
:skip_namespace
]
&&
namespace
end
def
namespace_dirs
@namespace_dirs
||=
namespace
.
name
.
split
(
"::"
).
map
(
&
:underscore
)
end
def
namespaced_path
# :doc:
@namespaced_path
||=
namespace_dirs
.
join
(
"/"
)
end
# Use Rails default banner.
def
self
.
banner
# :doc:
"rails generate
#{
namespace
.
sub
(
/^rails:/
,
''
)
}
#{
arguments
.
map
(
&
:usage
).
join
(
' '
)
}
[options]"
.
gsub
(
/\s+/
,
" "
)
...
...
railties/lib/rails/generators/named_base.rb
浏览文件 @
5c418af9
...
...
@@ -6,8 +6,6 @@ module Rails
module
Generators
class
NamedBase
<
Base
argument
:name
,
type: :string
class_option
:skip_namespace
,
type: :boolean
,
default:
false
,
desc:
"Skip namespace (affects only isolated applications)"
def
initialize
(
args
,
*
options
)
#:nodoc:
@inside_template
=
nil
...
...
@@ -45,24 +43,6 @@ def singular_name # :doc:
file_name
end
# Wrap block with namespace of current application
# if namespace exists and is not skipped
def
module_namespacing
(
&
block
)
# :doc:
content
=
capture
(
&
block
)
content
=
wrap_with_namespace
(
content
)
if
namespaced?
concat
(
content
)
end
def
indent
(
content
,
multiplier
=
2
)
# :doc:
spaces
=
" "
*
multiplier
content
.
each_line
.
map
{
|
line
|
line
.
blank?
?
line
:
"
#{
spaces
}#{
line
}
"
}.
join
end
def
wrap_with_namespace
(
content
)
# :doc:
content
=
indent
(
content
).
chomp
"module
#{
namespace
.
name
}
\n
#{
content
}
\n
end
\n
"
end
def
inside_template
# :doc:
@inside_template
=
true
yield
...
...
@@ -74,18 +54,6 @@ def inside_template? # :doc:
@inside_template
end
def
namespace
# :doc:
Rails
::
Generators
.
namespace
end
def
namespaced?
# :doc:
!
options
[
:skip_namespace
]
&&
namespace
end
def
namespace_dirs
@namespace_dirs
||=
namespace
.
name
.
split
(
"::"
).
map
(
&
:underscore
)
end
def
file_path
# :doc:
@file_path
||=
(
class_path
+
[
file_name
]).
join
(
"/"
)
end
...
...
@@ -102,10 +70,6 @@ def namespaced_class_path # :doc:
@namespaced_class_path
||=
namespace_dirs
+
@class_path
end
def
namespaced_path
# :doc:
@namespaced_path
||=
namespace_dirs
.
join
(
"/"
)
end
def
class_name
# :doc:
(
class_path
+
[
file_name
]).
map!
(
&
:camelize
).
join
(
"::"
)
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录