Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
49d069d7
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,发现更多精彩内容 >>
提交
49d069d7
编写于
6月 30, 2012
作者:
C
Carlos Antonio da Silva
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6904 from guilleiguaran/remove-amo-dependency-in-ap
Remove Active Model dependency from Action Pack
上级
4d9be13a
166dbaa7
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
33 addition
and
24 deletion
+33
-24
actionpack/actionpack.gemspec
actionpack/actionpack.gemspec
+1
-1
actionpack/lib/action_controller/model_naming.rb
actionpack/lib/action_controller/model_naming.rb
+12
-0
actionpack/lib/action_controller/record_identifier.rb
actionpack/lib/action_controller/record_identifier.rb
+5
-3
actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
+7
-7
actionpack/lib/action_view/helpers/form_helper.rb
actionpack/lib/action_view/helpers/form_helper.rb
+8
-13
未找到文件。
actionpack/actionpack.gemspec
浏览文件 @
49d069d7
...
...
@@ -18,7 +18,6 @@
s
.
requirements
<<
'none'
s
.
add_dependency
(
'activesupport'
,
version
)
s
.
add_dependency
(
'activemodel'
,
version
)
s
.
add_dependency
(
'rack-cache'
,
'~> 1.2'
)
s
.
add_dependency
(
'builder'
,
'~> 3.0.0'
)
s
.
add_dependency
(
'rack'
,
'~> 1.4.1'
)
...
...
@@ -26,5 +25,6 @@
s
.
add_dependency
(
'journey'
,
'~> 1.0.1'
)
s
.
add_dependency
(
'erubis'
,
'~> 2.7.0'
)
s
.
add_development_dependency
(
'activemodel'
,
version
)
s
.
add_development_dependency
(
'tzinfo'
,
'~> 0.3.33'
)
end
actionpack/lib/action_controller/model_naming.rb
0 → 100644
浏览文件 @
49d069d7
module
ActionController
module
ModelNaming
# Converts the given object to an ActiveModel compliant one.
def
convert_to_model
(
object
)
object
.
respond_to?
(
:to_model
)
?
object
.
to_model
:
object
end
def
model_name_from_record_or_class
(
record_or_class
)
(
record_or_class
.
is_a?
(
Class
)
?
record_or_class
:
convert_to_model
(
record_or_class
).
class
).
model_name
end
end
end
actionpack/lib/action_controller/record_identifier.rb
浏览文件 @
49d069d7
require
'active_support/core_ext/module'
require
'action_controller/model_naming'
module
ActionController
# The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or
...
...
@@ -27,6 +28,8 @@ module ActionController
module
RecordIdentifier
extend
self
include
ModelNaming
JOIN
=
'_'
.
freeze
NEW
=
'new'
.
freeze
...
...
@@ -40,7 +43,7 @@ module RecordIdentifier
# dom_class(post, :edit) # => "edit_post"
# dom_class(Person, :edit) # => "edit_person"
def
dom_class
(
record_or_class
,
prefix
=
nil
)
singular
=
ActiveModel
::
Naming
.
param_key
(
record_or_class
)
singular
=
model_name_from_record_or_class
(
record_or_class
).
param_key
prefix
?
"
#{
prefix
}#{
JOIN
}#{
singular
}
"
:
singular
end
...
...
@@ -73,8 +76,7 @@ def dom_id(record, prefix = nil)
# method that replaces all characters that are invalid inside DOM ids, with valid ones. You need to
# make sure yourself that your dom ids are valid, in case you overwrite this method.
def
record_key_for_dom_id
(
record
)
record
=
record
.
to_model
if
record
.
respond_to?
(
:to_model
)
key
=
record
.
to_key
key
=
convert_to_model
(
record
).
to_key
key
?
key
.
join
(
'_'
)
:
key
end
end
...
...
actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
浏览文件 @
49d069d7
require
'action_controller/model_naming'
module
ActionDispatch
module
Routing
# Polymorphic URL helpers are methods for smart resolution to a named route call when
...
...
@@ -53,6 +55,8 @@ module Routing
# form_for([blog, @post]) # => "/blog/posts/1"
#
module
PolymorphicRoutes
include
ActionController
::
ModelNaming
# Constructs a call to a named RESTful route for the given record and returns the
# resulting URL string. For example:
#
...
...
@@ -154,10 +158,6 @@ def action_prefix(options)
options
[
:action
]
?
"
#{
options
[
:action
]
}
_"
:
''
end
def
convert_to_model
(
object
)
object
.
respond_to?
(
:to_model
)
?
object
.
to_model
:
object
end
def
routing_type
(
options
)
options
[
:routing_type
]
||
:url
end
...
...
@@ -169,7 +169,7 @@ def build_named_route_call(records, inflection, options = {})
if
parent
.
is_a?
(
Symbol
)
||
parent
.
is_a?
(
String
)
parent
else
ActiveModel
::
Naming
.
singular_route_key
(
parent
)
model_name_from_record_or_class
(
parent
).
singular_route_key
end
end
else
...
...
@@ -181,9 +181,9 @@ def build_named_route_call(records, inflection, options = {})
route
<<
record
elsif
record
if
inflection
==
:singular
route
<<
ActiveModel
::
Naming
.
singular_route_key
(
record
)
route
<<
model_name_from_record_or_class
(
record
).
singular_route_key
else
route
<<
ActiveModel
::
Naming
.
route_key
(
record
)
route
<<
model_name_from_record_or_class
(
record
).
route_key
end
else
raise
ArgumentError
,
"Nil location provided. Can't build URI."
...
...
actionpack/lib/action_view/helpers/form_helper.rb
浏览文件 @
49d069d7
...
...
@@ -12,6 +12,7 @@
require
'active_support/core_ext/array/extract_options'
require
'active_support/deprecation'
require
'active_support/core_ext/string/inflections'
require
'action_controller/model_naming'
module
ActionView
# = Action View Form Helpers
...
...
@@ -117,11 +118,7 @@ module FormHelper
include
FormTagHelper
include
UrlHelper
# Converts the given object to an ActiveModel compliant one.
def
convert_to_model
(
object
)
object
.
respond_to?
(
:to_model
)
?
object
.
to_model
:
object
end
include
ActionController
::
ModelNaming
# Creates a form that allows the user to create or update the attributes
# of a specific model object.
...
...
@@ -411,7 +408,7 @@ def form_for(record, options = {}, &proc)
object
=
nil
else
object
=
record
.
is_a?
(
Array
)
?
record
.
last
:
record
object_name
=
options
[
:as
]
||
ActiveModel
::
Naming
.
param_key
(
object
)
object_name
=
options
[
:as
]
||
model_name_from_record_or_class
(
object
).
param_key
apply_form_for_options!
(
record
,
object
,
options
)
end
...
...
@@ -1128,7 +1125,7 @@ def instantiate_builder(record_name, record_object, options)
object_name
=
record_name
else
object
=
record_name
object_name
=
ActiveModel
::
Naming
.
param_key
(
object
)
object_name
=
model_name_from_record_or_class
(
object
).
param_key
end
builder
=
options
[
:builder
]
||
default_form_builder
...
...
@@ -1142,9 +1139,11 @@ def default_form_builder
end
class
FormBuilder
include
ActionController
::
ModelNaming
# The methods which wrap a form helper call.
class_attribute
:field_helpers
self
.
field_helpers
=
FormHelper
.
instance_methods
-
[
:form_for
,
:convert_to_model
]
self
.
field_helpers
=
FormHelper
.
instance_methods
-
[
:form_for
,
:convert_to_model
,
:model_name_from_record_or_class
]
attr_accessor
:object_name
,
:object
,
:options
...
...
@@ -1214,7 +1213,7 @@ def fields_for(record_name, record_object = nil, fields_options = {}, &block)
end
else
record_object
=
record_name
.
is_a?
(
Array
)
?
record_name
.
last
:
record_name
record_name
=
ActiveModel
::
Naming
.
param_key
(
record_object
)
record_name
=
model_name_from_record_or_class
(
record_object
).
param_key
end
index
=
if
options
.
has_key?
(
:index
)
...
...
@@ -1396,10 +1395,6 @@ def nested_child_index(name)
@nested_child_index
[
name
]
||=
-
1
@nested_child_index
[
name
]
+=
1
end
def
convert_to_model
(
object
)
object
.
respond_to?
(
:to_model
)
?
object
.
to_model
:
object
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录