Here is a sample record from a YAML-based snippet management system I created years ago:
- caption: fieldset msie5
tinycap: fieldset
domain: html
desc: fieldset and legend tag
wwbody: |
<fieldset>
<legend>legend</legend>
</fieldset>
You can repeat that or something like it for all the snippets you want to manage. This particular system stores the snippets as an array of name-value pairs (Perl people would call this an AoH). If you do not need all this extra information, just two name-value pairs will suffice (e.g., caption + body).
The nice thing about this system: YAML indentation prevents "delimiter collision" problems. You never have to use clumsyescapesequences inside your snippet body.
Text Editor or IDE alternative
Note: Increasingly, text editors and IDEs support flexible snippet management options natively, so you may want to consider using the format of a text editor rather than re-inventing your own. If you do re-invent your own, you can write a script to translate your YAML format into the native format of a text editor if you later decide you want to do that.
使用模板。我们可能不会混合将 HTML 放入 .po 文件或数据层中,因为转义和双重转义(JavaScript 转义)而是保持不同的表示(视图)和持久(存储)层。 HTML是表示和视图,因此属于表示层。
Use templates. We probably shan't mix to put HTML in .po files or in the data layer since escape and double escape (JavaScript escape) rather keep distinct presentation (view) and persistence (storage) layers. HTML is presentation and view, hence belongs to the presentation layer.
发布评论
评论(2)
示例
这是我几年前创建的基于 YAML 的代码片段管理系统的示例记录:
您可以对您想要管理的所有代码片段重复该记录或类似的内容。这个特定的系统将片段存储为名称-值对的数组(Perl 人们将其称为 AoH)。如果您不需要所有这些额外信息,只需两个名称/值对就足够了(例如,标题+正文)。
这个系统的优点是:YAML 缩进可以防止“分隔符冲突”问题。你永远不必使用笨拙 转义 序列在代码片段体内。
文本编辑器或 IDE 替代方案
注意:越来越多的文本编辑器和 IDE 原生支持灵活的代码片段管理选项,因此您可能需要考虑使用文本编辑器的格式,而不是重新发明自己的格式。如果您确实重新发明了自己的格式,则可以编写一个脚本将 YAML 格式转换为文本编辑器的本机格式(如果您稍后决定这样做)。
另请参阅:
Example
Here is a sample record from a YAML-based snippet management system I created years ago:
You can repeat that or something like it for all the snippets you want to manage. This particular system stores the snippets as an array of name-value pairs (Perl people would call this an AoH). If you do not need all this extra information, just two name-value pairs will suffice (e.g., caption + body).
The nice thing about this system: YAML indentation prevents "delimiter collision" problems. You never have to use clumsy escape sequences inside your snippet body.
Text Editor or IDE alternative
Note: Increasingly, text editors and IDEs support flexible snippet management options natively, so you may want to consider using the format of a text editor rather than re-inventing your own. If you do re-invent your own, you can write a script to translate your YAML format into the native format of a text editor if you later decide you want to do that.
See also:
使用模板。我们可能不会混合将 HTML 放入
.po
文件或数据层中,因为转义和双重转义(JavaScript 转义)而是保持不同的表示(视图)和持久(存储)层。 HTML是表示和视图,因此属于表示层。Use templates. We probably shan't mix to put HTML in
.po
files or in the data layer since escape and double escape (JavaScript escape) rather keep distinct presentation (view) and persistence (storage) layers. HTML is presentation and view, hence belongs to the presentation layer.