Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f1d74871
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,体验更适合开发者的 AI 搜索 >>
提交
f1d74871
编写于
4月 13, 2018
作者:
D
David Heinemeier Hansson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename from Active Text to Action Text
This is more like Action View than Active Model.
上级
3bc244ab
变更
27
隐藏空白更改
内联
并排
Showing
27 changed file
with
69 addition
and
69 deletion
+69
-69
README.md
README.md
+3
-3
Rakefile
Rakefile
+1
-1
actiontext.gemspec
actiontext.gemspec
+2
-2
app/helpers/action_text/tag_helper.rb
app/helpers/action_text/tag_helper.rb
+4
-4
app/javascript/actiontext/attachment_upload.js
app/javascript/actiontext/attachment_upload.js
+0
-0
app/javascript/actiontext/index.js
app/javascript/actiontext/index.js
+0
-0
lib/action_text.rb
lib/action_text.rb
+2
-2
lib/action_text/attachable.rb
lib/action_text/attachable.rb
+5
-5
lib/action_text/attachables/content_attachment.rb
lib/action_text/attachables/content_attachment.rb
+3
-3
lib/action_text/attachables/missing_attachable.rb
lib/action_text/attachables/missing_attachable.rb
+2
-2
lib/action_text/attachables/remote_image.rb
lib/action_text/attachables/remote_image.rb
+2
-2
lib/action_text/attachment.rb
lib/action_text/attachment.rb
+3
-3
lib/action_text/attachments/caching.rb
lib/action_text/attachments/caching.rb
+1
-1
lib/action_text/attachments/minification.rb
lib/action_text/attachments/minification.rb
+2
-2
lib/action_text/attachments/trix_conversion.rb
lib/action_text/attachments/trix_conversion.rb
+2
-2
lib/action_text/attribute.rb
lib/action_text/attribute.rb
+2
-2
lib/action_text/content.rb
lib/action_text/content.rb
+8
-8
lib/action_text/engine.rb
lib/action_text/engine.rb
+13
-13
lib/action_text/fragment.rb
lib/action_text/fragment.rb
+2
-2
lib/action_text/html_conversion.rb
lib/action_text/html_conversion.rb
+1
-1
lib/action_text/plain_text_conversion.rb
lib/action_text/plain_text_conversion.rb
+1
-1
lib/action_text/serialization.rb
lib/action_text/serialization.rb
+1
-1
lib/action_text/trix_attachment.rb
lib/action_text/trix_attachment.rb
+3
-3
lib/action_text/version.rb
lib/action_text/version.rb
+1
-1
test/dummy/app/controllers/application_controller.rb
test/dummy/app/controllers/application_controller.rb
+3
-3
test/dummy/config/application.rb
test/dummy/config/application.rb
+1
-1
test/unit/content_test.rb
test/unit/content_test.rb
+1
-1
未找到文件。
README.md
浏览文件 @
f1d74871
# Acti
ve
Text
# Acti
on
Text
🤸♂️💰📝
...
...
@@ -10,7 +10,7 @@ Assumes a Rails 5.2+ application with Active Storage and Webpacker installed.
```ruby
# Gemfile
gem "activetext", github: "basecamp/activetext", require: "acti
ve
_text"
gem "activetext", github: "basecamp/activetext", require: "acti
on
_text"
gem "mini_magick" # for Active Storage variants
```
...
...
@@ -32,7 +32,7 @@ Assumes a Rails 5.2+ application with Active Storage and Webpacker installed.
import "activetext"
```
1.
Declare text columns as Acti
ve
Text attributes:
1.
Declare text columns as Acti
on
Text attributes:
```ruby
# app/models/message.rb
...
...
Rakefile
浏览文件 @
f1d74871
...
...
@@ -8,7 +8,7 @@ require 'rdoc/task'
RDoc
::
Task
.
new
(
:rdoc
)
do
|
rdoc
|
rdoc
.
rdoc_dir
=
'rdoc'
rdoc
.
title
=
'Acti
ve
Text'
rdoc
.
title
=
'Acti
on
Text'
rdoc
.
options
<<
'--line-numbers'
rdoc
.
rdoc_files
.
include
(
'README.md'
)
rdoc
.
rdoc_files
.
include
(
'lib/**/*.rb'
)
...
...
acti
ve
text.gemspec
→
acti
on
text.gemspec
浏览文件 @
f1d74871
$:
.
push
File
.
expand_path
(
"lib"
,
__dir__
)
# Maintain your gem's version:
require
"acti
ve
_text/version"
require
"acti
on
_text/version"
# Describe your gem and declare its dependencies:
Gem
::
Specification
.
new
do
|
s
|
s
.
name
=
"activetext"
s
.
version
=
Acti
ve
Text
::
VERSION
s
.
version
=
Acti
on
Text
::
VERSION
s
.
authors
=
[
"Javan Makhmali"
,
"Sam Stephenson"
]
s
.
email
=
[
"javan@javan.us"
,
"sstephenson@gmail.com"
]
s
.
summary
=
"Edit and display rich text in Rails applications"
...
...
app/helpers/acti
ve
_text/tag_helper.rb
→
app/helpers/acti
on
_text/tag_helper.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
module
TagHelper
cattr_accessor
(
:id
,
instance_accessor:
false
)
{
0
}
def
rich_text_field_tag
(
name
,
value
=
nil
,
options
=
{})
options
=
options
.
symbolize_keys
options
[
:input
]
||=
"trix_input_
#{
Acti
ve
Text
::
TagHelper
.
id
+=
1
}
"
options
[
:input
]
||=
"trix_input_
#{
Acti
on
Text
::
TagHelper
.
id
+=
1
}
"
options
[
:data
]
||=
{}
options
[
:data
][
:direct_upload_url
]
=
rails_direct_uploads_url
options
[
:data
][
:blob_url_template
]
=
rails_service_blob_url
(
":signed_id"
,
":filename"
)
...
...
@@ -19,7 +19,7 @@ def rich_text_field_tag(name, value = nil, options = {})
end
module
ActionView::Helpers
class
Tags::Acti
ve
Text
<
Tags
::
Base
class
Tags::Acti
on
Text
<
Tags
::
Base
delegate
:dom_id
,
to:
ActionView
::
RecordIdentifier
def
render
...
...
@@ -36,7 +36,7 @@ def editable_value
module
FormHelper
def
rich_text_field
(
object_name
,
method
,
options
=
{})
Tags
::
Acti
ve
Text
.
new
(
object_name
,
method
,
self
,
options
).
render
Tags
::
Acti
on
Text
.
new
(
object_name
,
method
,
self
,
options
).
render
end
end
...
...
app/javascript/acti
ve
text/attachment_upload.js
→
app/javascript/acti
on
text/attachment_upload.js
浏览文件 @
f1d74871
文件已移动
app/javascript/acti
ve
text/index.js
→
app/javascript/acti
on
text/index.js
浏览文件 @
f1d74871
文件已移动
lib/acti
ve
_text.rb
→
lib/acti
on
_text.rb
浏览文件 @
f1d74871
require
"active_record"
require
"acti
ve
_text/engine"
require
"acti
on
_text/engine"
require
"nokogiri"
module
Acti
ve
Text
module
Acti
on
Text
extend
ActiveSupport
::
Autoload
mattr_accessor
(
:renderer
)
...
...
lib/acti
ve
_text/attachable.rb
→
lib/acti
on
_text/attachable.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
module
Attachable
extend
ActiveSupport
::
Concern
...
...
@@ -8,12 +8,12 @@ class << self
def
from_node
(
node
)
if
attachable
=
attachable_from_sgid
(
node
[
"sgid"
])
attachable
elsif
attachable
=
Acti
ve
Text
::
Attachables
::
ContentAttachment
.
from_node
(
node
)
elsif
attachable
=
Acti
on
Text
::
Attachables
::
ContentAttachment
.
from_node
(
node
)
attachable
elsif
attachable
=
Acti
ve
Text
::
Attachables
::
RemoteImage
.
from_node
(
node
)
elsif
attachable
=
Acti
on
Text
::
Attachables
::
RemoteImage
.
from_node
(
node
)
attachable
else
Acti
ve
Text
::
Attachables
::
MissingAttachable
Acti
on
Text
::
Attachables
::
MissingAttachable
end
end
...
...
@@ -33,7 +33,7 @@ def attachable_from_sgid(sgid)
class_methods
do
def
from_attachable_sgid
(
sgid
)
Acti
ve
Text
::
Attachable
.
from_attachable_sgid
(
sgid
,
only:
self
)
Acti
on
Text
::
Attachable
.
from_attachable_sgid
(
sgid
,
only:
self
)
end
end
...
...
lib/acti
ve
_text/attachables/content_attachment.rb
→
lib/acti
on
_text/attachables/content_attachment.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
module
Attachables
class
ContentAttachment
include
ActiveModel
::
Model
...
...
@@ -25,11 +25,11 @@ def attachable_plain_text_representation(caption)
end
def
to_partial_path
"acti
ve
_text/attachables/content_attachment"
"acti
on
_text/attachables/content_attachment"
end
def
to_trix_content_attachment_partial_path
"acti
ve
_text/attachables/content_attachments/
#{
name
.
underscore
}
"
"acti
on
_text/attachables/content_attachments/
#{
name
.
underscore
}
"
end
end
end
...
...
lib/acti
ve
_text/attachables/missing_attachable.rb
→
lib/acti
on
_text/attachables/missing_attachable.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
module
Attachables
module
MissingAttachable
extend
ActiveModel
::
Naming
def
self
.
to_partial_path
"acti
ve
_text/attachables/missing_attachable"
"acti
on
_text/attachables/missing_attachable"
end
end
end
...
...
lib/acti
ve
_text/attachables/remote_image.rb
→
lib/acti
on
_text/attachables/remote_image.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
module
Attachables
class
RemoteImage
extend
ActiveModel
::
Naming
...
...
@@ -37,7 +37,7 @@ def attachable_plain_text_representation(caption)
end
def
to_partial_path
"acti
ve
_text/attachables/remote_image"
"acti
on
_text/attachables/remote_image"
end
end
end
...
...
lib/acti
ve
_text/attachment.rb
→
lib/acti
on
_text/attachment.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
class
Attachment
include
Attachments
::
TrixConversion
,
Attachments
::
Minification
,
Attachments
::
Caching
...
...
@@ -12,7 +12,7 @@ def fragment_by_canonicalizing_attachments(content)
end
def
from_node
(
node
,
attachable
=
nil
)
new
(
node
,
attachable
||
Acti
ve
Text
::
Attachable
.
from_node
(
node
))
new
(
node
,
attachable
||
Acti
on
Text
::
Attachable
.
from_node
(
node
))
end
def
from_attachables
(
attachables
)
...
...
@@ -34,7 +34,7 @@ def from_attributes(attributes, attachable = nil)
private
def
node_from_attributes
(
attributes
)
if
attributes
=
process_attributes
(
attributes
).
presence
Acti
ve
Text
::
HtmlConversion
.
create_element
(
TAG_NAME
,
attributes
)
Acti
on
Text
::
HtmlConversion
.
create_element
(
TAG_NAME
,
attributes
)
end
end
...
...
lib/acti
ve
_text/attachments/caching.rb
→
lib/acti
on
_text/attachments/caching.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
module
Attachments
module
Caching
def
cache_key
(
*
args
)
...
...
lib/acti
ve
_text/attachments/minification.rb
→
lib/acti
on
_text/attachments/minification.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
module
Attachments
module
Minification
extend
ActiveSupport
::
Concern
class_methods
do
def
fragment_by_minifying_attachments
(
content
)
Fragment
.
wrap
(
content
).
replace
(
Acti
ve
Text
::
Attachment
::
SELECTOR
)
do
|
node
|
Fragment
.
wrap
(
content
).
replace
(
Acti
on
Text
::
Attachment
::
SELECTOR
)
do
|
node
|
node
.
tap
{
|
n
|
n
.
inner_html
=
""
}
end
end
...
...
lib/acti
ve
_text/attachments/trix_conversion.rb
→
lib/acti
on
_text/attachments/trix_conversion.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
module
Attachments
module
TrixConversion
extend
ActiveSupport
::
Concern
...
...
@@ -24,7 +24,7 @@ def to_trix_attachment(content = trix_attachment_content)
private
def
trix_attachment_content
if
partial_path
=
attachable
.
try
(
:to_trix_content_attachment_partial_path
)
Acti
ve
Text
.
renderer
.
render
(
partial:
partial_path
,
object:
self
,
as:
model_name
.
element
)
Acti
on
Text
.
renderer
.
render
(
partial:
partial_path
,
object:
self
,
as:
model_name
.
element
)
end
end
end
...
...
lib/acti
ve
_text/attribute.rb
→
lib/acti
on
_text/attribute.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
module
Attribute
extend
ActiveSupport
::
Concern
class_methods
do
def
has_rich_text
(
attribute_name
)
serialize
(
attribute_name
,
Acti
ve
Text
::
Content
)
serialize
(
attribute_name
,
Acti
on
Text
::
Content
)
has_many_attached
"
#{
attribute_name
}
_attachments"
...
...
lib/acti
ve
_text/content.rb
→
lib/acti
on
_text/content.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
class
Content
include
Serialization
...
...
@@ -7,7 +7,7 @@ class Content
delegate
:blank?
,
:empty?
,
:html_safe
,
:present?
,
to: :to_s
def
initialize
(
content
=
nil
)
@fragment
=
Acti
ve
Text
::
Attachment
.
fragment_by_canonicalizing_attachments
(
content
)
@fragment
=
Acti
on
Text
::
Attachment
.
fragment_by_canonicalizing_attachments
(
content
)
end
def
links
...
...
@@ -22,17 +22,17 @@ def attachments
def
attachables
@attachables
||=
attachment_nodes
.
map
do
|
node
|
Acti
ve
Text
::
Attachable
.
from_node
(
node
)
Acti
on
Text
::
Attachable
.
from_node
(
node
)
end
end
def
append_attachables
(
attachables
)
attachments
=
Acti
ve
Text
::
Attachment
.
from_attachables
(
attachables
)
attachments
=
Acti
on
Text
::
Attachment
.
from_attachables
(
attachables
)
self
.
class
.
new
([
self
.
to_s
.
presence
,
*
attachments
].
compact
.
join
(
"
\n
"
))
end
def
render_attachments
(
**
options
,
&
block
)
fragment
.
replace
(
Acti
ve
Text
::
Attachment
::
SELECTOR
)
do
|
node
|
fragment
.
replace
(
Acti
on
Text
::
Attachment
::
SELECTOR
)
do
|
node
|
block
.
call
(
attachment_for_node
(
node
,
**
options
))
end
end
...
...
@@ -48,7 +48,7 @@ def to_trix_html
def
to_html
render_attachments
do
|
attachment
|
attachment
.
node
.
tap
do
|
node
|
node
.
inner_html
=
Acti
ve
Text
.
renderer
.
render
(
attachment
)
node
.
inner_html
=
Acti
on
Text
.
renderer
.
render
(
attachment
)
end
end
.
to_html
end
...
...
@@ -73,11 +73,11 @@ def ==(other)
private
def
attachment_nodes
@attachment_nodes
||=
fragment
.
find_all
(
Acti
ve
Text
::
Attachment
::
SELECTOR
)
@attachment_nodes
||=
fragment
.
find_all
(
Acti
on
Text
::
Attachment
::
SELECTOR
)
end
def
attachment_for_node
(
node
,
with_full_attributes:
true
)
attachment
=
Acti
ve
Text
::
Attachment
.
from_node
(
node
)
attachment
=
Acti
on
Text
::
Attachment
.
from_node
(
node
)
with_full_attributes
?
attachment
.
with_full_attributes
:
attachment
end
end
...
...
lib/acti
ve
_text/engine.rb
→
lib/acti
on
_text/engine.rb
浏览文件 @
f1d74871
require
"rails/engine"
module
Acti
ve
Text
module
Acti
on
Text
class
Engine
<
Rails
::
Engine
isolate_namespace
Acti
ve
Text
config
.
eager_load_namespaces
<<
Acti
ve
Text
isolate_namespace
Acti
on
Text
config
.
eager_load_namespaces
<<
Acti
on
Text
initializer
"acti
ve
_text.attribute"
do
initializer
"acti
on
_text.attribute"
do
ActiveSupport
.
on_load
(
:active_record
)
do
include
Acti
ve
Text
::
Attribute
include
Acti
on
Text
::
Attribute
end
end
initializer
"acti
ve
_text.active_storage_extension"
do
initializer
"acti
on
_text.active_storage_extension"
do
require
"active_storage/blob"
class
ActiveStorage::Blob
include
Acti
ve
Text
::
Attachable
include
Acti
on
Text
::
Attachable
def
previewable_attachable?
representable?
...
...
@@ -23,21 +23,21 @@ def previewable_attachable?
end
end
initializer
"acti
ve
_text.helper"
do
initializer
"acti
on
_text.helper"
do
ActiveSupport
.
on_load
(
:action_controller_base
)
do
helper
Acti
ve
Text
::
TagHelper
helper
Acti
on
Text
::
TagHelper
end
end
initializer
"acti
ve
_text.config"
do
initializer
"acti
on
_text.config"
do
config
.
after_initialize
do
|
app
|
Acti
ve
Text
.
renderer
||=
ApplicationController
.
renderer
Acti
on
Text
.
renderer
||=
ApplicationController
.
renderer
# FIXME: ApplicationController should have a per-request specific renderer
# that's been set with the request.env env, and Acti
ve
Text should just piggyback off
# that's been set with the request.env env, and Acti
on
Text should just piggyback off
# that by default rather than doing this work directly.
ApplicationController
.
before_action
do
Acti
veText
.
renderer
=
Active
Text
.
renderer
.
new
(
request
.
env
)
Acti
onText
.
renderer
=
Action
Text
.
renderer
.
new
(
request
.
env
)
end
end
end
...
...
lib/acti
ve
_text/fragment.rb
→
lib/acti
on
_text/fragment.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
class
Fragment
class
<<
self
def
wrap
(
fragment_or_html
)
...
...
@@ -13,7 +13,7 @@ def wrap(fragment_or_html)
end
def
from_html
(
html
)
new
(
Acti
ve
Text
::
HtmlConversion
.
fragment_for_html
(
html
.
to_s
.
strip
))
new
(
Acti
on
Text
::
HtmlConversion
.
fragment_for_html
(
html
.
to_s
.
strip
))
end
end
...
...
lib/acti
ve
_text/html_conversion.rb
→
lib/acti
on
_text/html_conversion.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
module
HtmlConversion
extend
self
...
...
lib/acti
ve
_text/plain_text_conversion.rb
→
lib/acti
on
_text/plain_text_conversion.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
module
PlainTextConversion
extend
self
...
...
lib/acti
ve
_text/serialization.rb
→
lib/acti
on
_text/serialization.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
module
Serialization
extend
ActiveSupport
::
Concern
...
...
lib/acti
ve
_text/trix_attachment.rb
→
lib/acti
on
_text/trix_attachment.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
class
TrixAttachment
TAG_NAME
=
"figure"
SELECTOR
=
"[data-trix-attachment]"
...
...
@@ -19,7 +19,7 @@ def from_attributes(attributes)
trix_attachment_attributes
=
attributes
.
except
(
"caption"
)
trix_attributes
=
attributes
.
slice
(
"caption"
)
node
=
Acti
ve
Text
::
HtmlConversion
.
create_element
(
TAG_NAME
)
node
=
Acti
on
Text
::
HtmlConversion
.
create_element
(
TAG_NAME
)
node
[
"data-trix-attachment"
]
=
JSON
.
generate
(
trix_attachment_attributes
)
node
[
"data-trix-attributes"
]
=
JSON
.
generate
(
trix_attributes
)
if
trix_attributes
.
any?
...
...
@@ -54,7 +54,7 @@ def attributes
end
def
to_html
Acti
ve
Text
::
HtmlConversion
.
node_to_html
(
node
)
Acti
on
Text
::
HtmlConversion
.
node_to_html
(
node
)
end
def
to_s
...
...
lib/acti
ve
_text/version.rb
→
lib/acti
on
_text/version.rb
浏览文件 @
f1d74871
module
Acti
ve
Text
module
Acti
on
Text
VERSION
=
'0.1.0'
end
test/dummy/app/controllers/application_controller.rb
浏览文件 @
f1d74871
class
ApplicationController
<
ActionController
::
Base
before_action
:set_acti
ve
_text_renderer
before_action
:set_acti
on
_text_renderer
private
def
set_acti
ve
_text_renderer
Acti
ve
Text
.
renderer
=
self
.
class
.
renderer
.
new
(
request
.
env
)
def
set_acti
on
_text_renderer
Acti
on
Text
.
renderer
=
self
.
class
.
renderer
.
new
(
request
.
env
)
end
end
test/dummy/config/application.rb
浏览文件 @
f1d74871
...
...
@@ -3,7 +3,7 @@
require
'rails/all'
Bundler
.
require
(
*
Rails
.
groups
)
require
"acti
ve
_text"
require
"acti
on
_text"
module
Dummy
class
Application
<
Rails
::
Application
...
...
test/unit/content_test.rb
浏览文件 @
f1d74871
require_relative
'../test_helper'
module
Acti
ve
Text
module
Acti
on
Text
class
ContentTest
<
ActiveSupport
::
TestCase
test
"plain text conversion"
do
message
=
Message
.
create!
(
subject:
"Greetings"
,
content:
"<h1>Hello world</h1>"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录