sitegeist/chitchat

用作风格指南属性的随机文本

安装: 5,164

依赖项: 3

建议者: 0

安全性: 0

星星: 2

关注者: 4

分支: 0

开放问题: 0

类型:neos-package

v1.2.0 2023-06-11 12:39 UTC

README

用于风格指南属性的确定随机文本生成器

用于monocle风格指南的表示组件通常有较长的@styleguide.props,难以维护,往往掩盖了实际组件,并且通常不足以提供足够的变化来测试不同的文本长度。

ChitChat生成伪随机文本,可用于风格指南属性。这些文本是使用伪随机数针对每个插入点(融合路径)独特生成的。

该实现受到了js库getlorem(https://github.com/lukehaas/getlorem/)的启发。我们还使用的单词表最初是getlorem的副本。

作者与赞助商

此包的开发和公共发布得到了我们雇主http://www.sitegeist.de的大力赞助。

安装

Sitegeist.ChitChat可通过packagist获取,并可以使用命令composer require sitegeist/chitchat安装。

我们使用语义化版本控制,每次重大更改都将增加主版本号。

用法

LineText原型生成伪随机文本。文本很长,并以多个句子结构化。这两个原型都允许通过linksstrongem启用格式化。

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>
    `
}

基本原型

基本原型TextLine将创建不带块格式化的文本,而
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):创建的最大数字

文本块融合原型

文本块扩展了基本原型以包含块格式化。否则,它们支持与TextLine相同的属性。

  • 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来配置概率模式。默认情况下,提供randompredictable模式。

替换词典或“如何说克林贡语”

要实现自定义词典,您可以提供接口\Sitegeist\ChitChat\Domain\DictionaryProviderInterface的备用实现。

词典通过Setting.yaml注册

Sitegeist:
  ChitChat:
    dictionaries:
      klingon: 'Vendor\Example\KlingonDictionaryProvider'

并且可以稍后像这样使用

text = Sitegeist.ChitChat:Text {
  dictionary = 'klingon'
} 

贡献

我们乐意接受贡献。请发送给我们pull请求。