Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0bb95968
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,发现更多精彩内容 >>
提交
0bb95968
编写于
6月 25, 2009
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More code refactoring.
上级
d5bdf31d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
54 addition
and
36 deletion
+54
-36
railties/lib/generators/base.rb
railties/lib/generators/base.rb
+25
-30
railties/lib/generators/erb/mailer/templates/view.erb
railties/lib/generators/erb/mailer/templates/view.erb
+1
-1
railties/lib/generators/rails/mailer/mailer_generator.rb
railties/lib/generators/rails/mailer/mailer_generator.rb
+1
-2
railties/lib/generators/rails/observer/observer_generator.rb
railties/lib/generators/rails/observer/observer_generator.rb
+1
-1
railties/lib/generators/rails/plugin/plugin_generator.rb
railties/lib/generators/rails/plugin/plugin_generator.rb
+1
-1
railties/lib/generators/test_unit/mailer/templates/fixture
railties/lib/generators/test_unit/mailer/templates/fixture
+1
-1
railties/test/generators/app_generator_test.rb
railties/test/generators/app_generator_test.rb
+24
-0
未找到文件。
railties/lib/generators/base.rb
浏览文件 @
0bb95968
...
...
@@ -2,6 +2,11 @@
module
Rails
module
Generators
DEFAULTS
=
{
:test_framework
=>
'test_unit'
,
:template_engine
=>
'erb'
}
class
Error
<
Thor
::
Error
end
...
...
@@ -113,39 +118,29 @@ def self.add_shebang_option!
end
end
# Small macro to add test_framework option and invoke it.
# Invoke a generator based on the given name. If a class option does not
# exist for the current name, it's created.
#
def
self
.
add_and_invoke_test_framework_option!
class_option
:test_framework
,
:type
=>
:string
,
:aliases
=>
"-t"
,
:default
=>
"test_unit"
,
:desc
=>
"Test framework to be invoked by this generator"
,
:banner
=>
"NAME"
define_method
:invoke_test_framework
do
return
unless
options
[
:test_framework
]
name
=
"
#{
options
[
:test_framework
]
}
:generators:
#{
self
.
class
.
generator_name
}
"
begin
invoke
name
rescue
Thor
::
UndefinedTaskError
say
"Could not find and invoke '
#{
name
}
'."
def
self
.
invoke_for
(
*
names
)
names
.
each
do
|
name
|
unless
class_options
[
name
]
aliases
=
"-"
+
name
.
to_s
.
gsub
(
/_framework$/
,
''
).
split
(
'_'
).
last
[
0
,
1
]
class_option
name
,
:type
=>
:string
,
:default
=>
DEFAULTS
[
name
],
:banner
=>
"NAME"
,
:aliases
=>
aliases
,
:desc
=>
"
#{
name
.
to_s
.
humanize
}
to be used"
end
end
end
# Small macro to add template engine option and invoke it.
#
def
self
.
add_and_invoke_template_engine_option!
class_option
:template_engine
,
:type
=>
:string
,
:aliases
=>
"-e"
,
:default
=>
"erb"
,
:desc
=>
"Template engine to be invoked by this generator"
,
:banner
=>
"NAME"
define_method
:invoke_template_engine
do
return
unless
options
[
:template_engine
]
name
=
"
#{
options
[
:template_engine
]
}
:generators:
#{
self
.
class
.
generator_name
}
"
begin
invoke
name
rescue
Thor
::
UndefinedTaskError
say
"Could not find and invoke '
#{
name
}
'."
end
class_eval
<<-
METHOD
,
__FILE__
,
__LINE__
def invoke_
#{
name
}
return unless options[
#{
name
.
inspect
}
]
task = "
\#
{options[
#{
name
.
inspect
}
]}:generators:
\#
{self.class.generator_name}"
begin
invoke task
rescue Thor::UndefinedTaskError
say "Could not find and invoke '
\#
{task}'."
end
end
METHOD
end
end
...
...
railties/lib/generators/erb/mailer/templates/view.erb
浏览文件 @
0bb95968
<%=
class_name
%>
#
<%=
@action
%>
Find me in
<%=
@path
%>
Find me in
app/views/
<%=
@path
%>
railties/lib/generators/rails/mailer/mailer_generator.rb
浏览文件 @
0bb95968
...
...
@@ -11,8 +11,7 @@ def create_mailer_file
template
"mailer.rb"
,
File
.
join
(
'app/models'
,
class_path
,
"
#{
file_name
}
.rb"
)
end
add_and_invoke_template_engine_option!
add_and_invoke_test_framework_option!
invoke_for
:template_engine
,
:test_framework
end
end
end
railties/lib/generators/rails/observer/observer_generator.rb
浏览文件 @
0bb95968
...
...
@@ -9,7 +9,7 @@ def create_observer_file
template
'observer.rb'
,
File
.
join
(
'app/models'
,
class_path
,
"
#{
file_name
}
_observer.rb"
)
end
add_and_invoke_test_framework_option!
invoke_for
:test_framework
end
end
end
railties/lib/generators/rails/plugin/plugin_generator.rb
浏览文件 @
0bb95968
...
...
@@ -27,7 +27,7 @@ def create_lib_files
directory
'lib'
end
add_and_invoke_test_framework_option!
invoke_for
:test_framework
def
create_tasks_files
return
unless
options
[
:with_tasks
]
...
...
railties/lib/generators/test_unit/mailer/templates/fixture
浏览文件 @
0bb95968
<%= class_name %>#<%= @action %>
Find me in <%= @path %>
Find me in
app/views/
<%= @path %>
railties/test/generators/app_generator_test.rb
浏览文件 @
0bb95968
...
...
@@ -4,6 +4,16 @@
class
AppGeneratorTest
<
GeneratorsTestCase
def
setup
super
Rails
::
Generators
::
AppGenerator
.
instance_variable_set
(
'@desc'
,
nil
)
end
def
teardown
super
Rails
::
Generators
::
AppGenerator
.
instance_variable_set
(
'@desc'
,
nil
)
end
def
test_application_skeleton_is_created
run_generator
...
...
@@ -120,6 +130,20 @@ def test_template_is_executed_when_supplied
assert_match
/It works!/
,
silence
(
:stdout
){
generator
.
invoke
(
:all
)
}
end
def
test_usage_read_from_file
File
.
expects
(
:read
).
returns
(
"USAGE FROM FILE"
)
assert_equal
"USAGE FROM FILE"
,
Rails
::
Generators
::
AppGenerator
.
desc
end
def
test_default_usage
File
.
expects
(
:exist?
).
returns
(
false
)
assert_match
/Create rails files for app generator/
,
Rails
::
Generators
::
AppGenerator
.
desc
end
def
test_default_namespace
assert_match
"rails:generators:app"
,
Rails
::
Generators
::
AppGenerator
.
namespace
end
protected
def
run_generator
(
args
=
[])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录