sitegeist / chitchat
用作风格指南属性的随机文本
Requires
- neos/fusion: ~8.0 || 8.2.x-dev || dev-main || dev-master
Requires (Dev)
- php: ^8.1
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2024-08-25 11:39:47 UTC
README
用于风格指南属性的确定随机文本生成器
用于monocle风格指南的表示组件通常有较长的@styleguide.props,难以维护,往往掩盖了实际组件,并且通常不足以提供足够的变化来测试不同的文本长度。
ChitChat生成伪随机文本,可用于风格指南属性。这些文本是使用伪随机数针对每个插入点(融合路径)独特生成的。
该实现受到了js库getlorem(https://github.com/lukehaas/getlorem/)的启发。我们还使用的单词表最初是getlorem的副本。
作者与赞助商
- Melanie Wüst - wuest@sitegeist.de
- Martin Ficzel - ficzel@sitegeist.de
此包的开发和公共发布得到了我们雇主http://www.sitegeist.de的大力赞助。
安装
Sitegeist.ChitChat可通过packagist获取,并可以使用命令composer require sitegeist/chitchat
安装。
我们使用语义化版本控制,每次重大更改都将增加主版本号。
用法
Line
和Text
原型生成伪随机文本。文本很长,并以多个句子结构化。这两个原型都允许通过links
、strong
和em
启用格式化。
prototype(Sitegeist.ChitChat:CardExample) < prototype(Neos.Fusion:Component) {
@styleguide {
title = "ChitChat CardExample"
props {
# a short text without formatting
title = Sitegeist.ChitChat:Line
# a textblock with multiple sentences and some formatting
description = Sitegeist.ChitChat:Text {
length = 250
link = true
strong = true
em = true
}
}
}
title = null
description = null
renderer = afx`
<div>
<h3>{props.title}</p>
<p>{props.description}</p>
</div>
`
}
为了模拟更长的格式化文本,chitchat带来了模拟Html标题、段落和列表的原型。这些原型允许指定预期的content
属性结构。与afx语法结合使用,可以有效地模拟更大的文本。
prototype(Sitegeist.ChitChat:TextExample) < prototype(Neos.Fusion:Component) {
@styleguide {
title = "ChitChat TextExample"
props {
# a block with mutltiple headlines paragraphs and lists
content = afx`
<Sitegeist.ChitChat:H1 />
<Sitegeist.ChitChat:H2 />
<Sitegeist.ChitChat:P />
<Sitegeist.ChitChat:P />
<Sitegeist.ChitChat:P />
<Sitegeist.ChitChat:H3 />
<Sitegeist.ChitChat:UL />
<Sitegeist.ChitChat:H3 />
<Sitegeist.ChitChat:OL />
`
}
}
content = null
renderer = afx`
<div>{props.content}</div>
`
}
基本原型
基本原型Text
和Line
将创建不带块格式化的文本,而
Number
创建整数。
Sitegeist.ChitChat:Text
:(字符串)包含多个句子的长文本块Sitegeist.ChitChat:Line
:(字符串)不带的短文本块Sitegeist.ChitChat:Number
:(整数)
所有原型都具有以下属性
probability
(字符串|null):在设置中配置的概率名称。seed
(字符串|null):除融合路径外的随机性的来源
《Text》和《Line》原型还支持以下内容
dictionary
(字符串|null):在设置中配置的字典名称length
(整数|100或500):文本应具有的最大长度variance
(浮点数|0.5):实际长度可以小于配置的length
的因子。link
(布尔值|false):向某些项目添加链接<a href="#">...</a>
strong
(布尔值|false):使某些项目加粗<strong>...</strong>
em
(布尔值|false):强调某些项目<em>...</em>
《Number》原型还支持以下内容
min
(整数|0):创建的最小数字max
(整数|100):创建的最大数字
文本块融合原型
文本块扩展了基本原型以包含块格式化。否则,它们支持与Text
和Line
相同的属性。
Sitegeist.ChitChat:H1
:(字符串) h1标签中的句子Sitegeist.ChitChat:H2
:(字符串) h2标签中的句子Sitegeist.ChitChat:H3
:(字符串) h3标签中的句子Sitegeist.ChitChat:H4
:(字符串) h4标签中的句子Sitegeist.ChitChat:P
: (字符串) 包含链接、加粗和斜体的p标签中的句子
列表原型
列表原型扩展了基本原型以支持列表格式化。原型具有基本原型的属性,此外属性number
允许指定要生成多少项。
Sitegeist.ChitChat:UL
: (字符串) 包含链接、加粗和斜体的无序列表中的多个句子Sitegeist.ChitChat:OL
: (字符串) 包含链接、加粗和斜体的有序列表中的多个句子
附加属性
number
(int|5) 要生成的项数 ... 默认为5到10之间的随机数
配置
配置允许为以下内容配置备用实现:
Sitegeist: ChitChat: # the dictionary and probability to use if nothing else is specified defaults: dictionary: pseudoLatin probability: predictable # providers for random numbers probablility: predictable: 'Sitegeist\ChitChat\Domain\PredictableProbabilityProvider' random: 'Sitegeist\ChitChat\Domain\RandomProbabilityProvider' # dictionaries dictionaries: pseudoLatin: 'Sitegeist\ChitChat\Domain\PseudoLatinDictionaryProvider'
随机性 vs 可预测性
虽然可预测的文本生成对于稳定的测试很重要,因此是默认设置。前端原型的测试有时会从每次调用都重新生成的完全随机文本中受益。
为此,可以通过设置Setting
或融合路径probability
来配置概率模式。默认情况下,提供random
和predictable
模式。
替换词典或“如何说克林贡语”
要实现自定义词典,您可以提供接口\Sitegeist\ChitChat\Domain\DictionaryProviderInterface
的备用实现。
词典通过Setting.yaml注册
Sitegeist: ChitChat: dictionaries: klingon: 'Vendor\Example\KlingonDictionaryProvider'
并且可以稍后像这样使用
text = Sitegeist.ChitChat:Text {
dictionary = 'klingon'
}
贡献
我们乐意接受贡献。请发送给我们pull请求。