Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b37938ef
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,发现更多精彩内容 >>
提交
b37938ef
编写于
10月 19, 2010
作者:
P
Piotr Sarnacki
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactored AppGenerator and PluginNewGenerator to inherit from AppBase.
上级
cfcea1d5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
57 deletion
+79
-57
railties/lib/rails/generators/app_base.rb
railties/lib/rails/generators/app_base.rb
+61
-0
railties/lib/rails/generators/rails/app/app_generator.rb
railties/lib/rails/generators/rails/app/app_generator.rb
+9
-16
railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
...rails/generators/rails/plugin_new/plugin_new_generator.rb
+9
-41
未找到文件。
railties/lib/rails/generators/app_base.rb
0 → 100644
浏览文件 @
b37938ef
require
'digest/md5'
require
'active_support/secure_random'
require
'rails/version'
unless
defined?
(
Rails
::
VERSION
)
require
'rbconfig'
require
'open-uri'
require
'uri'
module
Rails
module
Generators
class
AppBase
<
Base
def
self
.
say_step
(
message
)
@step
=
(
@step
||
0
)
+
1
class_eval
<<-
METHOD
,
__FILE__
,
__LINE__
+
1
def step_
#{
@step
}
#{
"puts"
if
@step
>
1
}
say_status "STEP
#{
@step
}
",
#{
message
.
inspect
}
end
METHOD
end
def
initialize
(
*
args
)
@original_wd
=
Dir
.
pwd
super
end
protected
def
builder
@builder
||=
begin
if
path
=
options
[
:builder
]
if
URI
(
path
).
is_a?
(
URI
::
HTTP
)
contents
=
open
(
path
,
"Accept"
=>
"application/x-thor-template"
)
{
|
io
|
io
.
read
}
else
contents
=
open
(
File
.
expand_path
(
path
,
@original_wd
))
{
|
io
|
io
.
read
}
end
prok
=
eval
(
"proc {
#{
contents
}
}"
,
TOPLEVEL_BINDING
,
path
,
1
)
instance_eval
(
&
prok
)
end
builder_class
=
get_builder_class
builder_class
.
send
(
:include
,
ActionMethods
)
builder_class
.
new
(
self
)
end
end
def
build
(
meth
,
*
args
)
builder
.
send
(
meth
,
*
args
)
if
builder
.
respond_to?
(
meth
)
end
def
create_root
self
.
destination_root
=
File
.
expand_path
(
app_path
,
destination_root
)
valid_const?
empty_directory
'.'
FileUtils
.
cd
(
destination_root
)
unless
options
[
:pretend
]
end
end
end
end
railties/lib/rails/generators/rails/app/app_generator.rb
浏览文件 @
b37938ef
require
'digest/md5'
require
'active_support/secure_random'
require
'rails/version'
unless
defined?
(
Rails
::
VERSION
)
require
'rbconfig'
require
'open-uri'
require
'uri'
require
'rails/generators/app_base'
module
Rails
module
ActionMethods
...
...
@@ -158,7 +153,7 @@ module Generators
RESERVED_NAMES
=
%w[application destroy benchmarker profiler
plugin runner test]
class
AppGenerator
<
Base
class
AppGenerator
<
App
Base
DATABASES
=
%w( mysql oracle postgresql sqlite3 frontbase ibm_db )
JAVASCRIPTS
=
%w( prototype jquery )
...
...
@@ -210,8 +205,6 @@ class AppGenerator < Base
def
initialize
(
*
args
)
raise
Error
,
"Options should be given after the application name. For details run: rails --help"
if
args
[
0
].
blank?
@original_wd
=
Dir
.
pwd
super
if
!
options
[
:skip_active_record
]
&&
!
DATABASES
.
include?
(
options
[
:database
])
...
...
@@ -224,12 +217,8 @@ def initialize(*args)
end
def
create_root
self
.
destination_root
=
File
.
expand_path
(
app_path
,
destination_root
)
valid_app_const?
empty_directory
'.'
set_default_accessors!
FileUtils
.
cd
(
destination_root
)
unless
options
[
:pretend
]
super
end
def
create_root_files
...
...
@@ -339,7 +328,7 @@ def builder
instance_eval
(
&
prok
)
end
builder_class
=
defined?
(
::
AppBuilder
)
?
::
AppBuilder
:
Rails
::
AppBuilder
builder_class
=
get_builder_class
builder_class
.
send
(
:include
,
ActionMethods
)
builder_class
.
new
(
self
)
end
...
...
@@ -388,7 +377,7 @@ def app_const
@app_const
||=
"
#{
app_const_base
}
::Application"
end
def
valid_
app_
const?
def
valid_const?
if
app_const
=~
/^\d/
raise
Error
,
"Invalid application name
#{
app_name
}
. Please give a name which does not start with numbers."
elsif
RESERVED_NAMES
.
include?
(
app_name
)
...
...
@@ -442,6 +431,10 @@ def empty_directory_with_gitkeep(destination, config = {})
empty_directory
(
destination
,
config
)
create_file
(
"
#{
destination
}
/.gitkeep"
)
unless
options
[
:skip_git
]
end
def
get_builder_class
defined?
(
::
AppBuilder
)
?
::
AppBuilder
:
Rails
::
AppBuilder
end
end
end
end
railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
浏览文件 @
b37938ef
require
'rails/generators/app_base'
require
"rails/generators/rails/app/app_generator"
module
Rails
...
...
@@ -70,12 +71,13 @@ def script
end
module
Generators
class
PluginNewGenerator
<
Base
class
PluginNewGenerator
<
App
Base
attr_accessor
:rails_template
add_shebang_option!
argument
:plugin_path
,
:type
=>
:string
alias_method
:app_path
,
:plugin_path
class_option
:builder
,
:type
=>
:string
,
:aliases
=>
"-b"
,
:desc
=>
"Path to a plugin builder (can be a filesystem path or URL)"
...
...
@@ -89,32 +91,17 @@ class PluginNewGenerator < Base
class_option
:help
,
:type
=>
:boolean
,
:aliases
=>
"-h"
,
:group
=>
:rails
,
:desc
=>
"Show this help message and quit"
def
self
.
say_step
(
message
)
@step
=
(
@step
||
0
)
+
1
class_eval
<<-
METHOD
,
__FILE__
,
__LINE__
+
1
def step_
#{
@step
}
#{
"puts"
if
@step
>
1
}
say_status "STEP
#{
@step
}
",
#{
message
.
inspect
}
end
METHOD
end
def
initialize
(
*
args
)
raise
Error
,
"Options should be given after plugin name. For details run: rails plugin --help"
if
args
[
0
].
blank?
@original_wd
=
Dir
.
pwd
super
end
say_step
"Creating gem skeleton"
def
create_root
self
.
destination_root
=
File
.
expand_path
(
plugin_path
,
destination_root
)
valid_plugin_const?
empty_directory
'.'
FileUtils
.
cd
(
destination_root
)
unless
options
[
:pretend
]
super
end
def
create_root_files
...
...
@@ -166,29 +153,6 @@ def self.banner
"rails plugin new
#{
self
.
arguments
.
map
(
&
:usage
).
join
(
' '
)
}
[options]"
end
def
builder
@builder
||=
begin
if
path
=
options
[
:builder
]
if
URI
(
path
).
is_a?
(
URI
::
HTTP
)
contents
=
open
(
path
,
"Accept"
=>
"application/x-thor-template"
)
{
|
io
|
io
.
read
}
else
contents
=
open
(
File
.
expand_path
(
path
,
@original_wd
))
{
|
io
|
io
.
read
}
end
prok
=
eval
(
"proc {
#{
contents
}
}"
,
TOPLEVEL_BINDING
,
path
,
1
)
instance_eval
(
&
prok
)
end
builder_class
=
defined?
(
::
PluginBuilder
)
?
::
PluginBuilder
:
Rails
::
PluginBuilder
builder_class
.
send
(
:include
,
ActionMethods
)
builder_class
.
new
(
self
)
end
end
def
build
(
meth
,
*
args
)
builder
.
send
(
meth
,
*
args
)
if
builder
.
respond_to?
(
meth
)
end
def
name
@name
||=
File
.
basename
(
destination_root
)
end
...
...
@@ -197,7 +161,7 @@ def camelized
@camelized
||=
name
.
gsub
(
/\W/
,
'_'
).
squeeze
(
'_'
).
camelize
end
def
valid_
plugin_
const?
def
valid_const?
if
camelized
=~
/^\d/
raise
Error
,
"Invalid plugin name
#{
name
}
. Please give a name which does not start with numbers."
elsif
RESERVED_NAMES
.
include?
(
name
)
...
...
@@ -220,6 +184,10 @@ def application_definition
end
end
alias
:store_application_definition!
:application_definition
def
get_builder_class
defined?
(
::
PluginBuilder
)
?
::
PluginBuilder
:
Rails
::
PluginBuilder
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录