rareloop/primer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rareloop/primer

Composer 安装命令:

composer require rareloop/primer

包简介

README 文档

README

Latest Stable Version CI Coveralls Downloads

Primer is an extensible Design System/Pattern Library written in PHP. By default it utilises Twig for templating and Markdown/YAML for Documentation.

Installation

To create a new Primer project run the following command:

composer create-project rareloop/primer my-primer-folder --remove-vcs

Usage

The easiest way to get up and running is to use the inbuilt PHP Standalone Server:

composer server

And then open the following URL in your browser http://localhost:8080.

If you need to specify the port you can pass this as an argument to the command:

composer server 1234

Getting Started

Primer has three separate sections:

  1. Documents - A place to store the written documentation for your Design System.
  2. Patterns - A Pattern Library that catalogues all the components within your system.
  3. Templates - A way to view the various Page Templates available in your system.

Patterns

Patterns are the building blocks of your system and Primer provides a simple way to view your entire catalogue, a selection or just a single item. Patterns are located in the resources/patterns folder and are themselves a folder that contain all it's related files.

Anatomy of a pattern

Each Pattern has an implicit id and title.

The id is the path used to identify it under the patterns folder, e.g. elements/forms/input.

A patterns title is built from the name of the pattern's folder, e.g. elements/lists/ordered-list => Ordered List.

Each pattern folder can contain the following:

  • A template A Twig template used to build the pattern's HTML (template.twig)
  • One or more data files A file to provide the state data required by the template file

State Data

Out of the box, Primer supports State Data in two formats, PHP or JSON.

PHP State Data

PHP State Data files are named data.php and must return an array of key/values. This data is then passed to your Twig template at render time.

<?php

return [
    'title' => 'Page Title',
];

JSON State Data

State Data can also be provided as JSON files which are named data.json. This data is then passed to your Twig template at render time.

{
    "title": "Page Title"
}

Alternative State Data

When building a Pattern Library it is important to be able to easily test the different states a component can be in and Primer makes this easy. Alternative states can be provided by adding additional files to your Pattern folder in the format:

data~statename.(php|json)

For example to show the error state for an input component you could create a file called data~error.php.

Including patterns within one another

Any pattern can be included within another by using the standard Twig include and referencing the Pattern with it's id, e.g.

{% include 'components/common/site-header' %}

Templates

Templates can be built up using a mix of custom HTML and Pattern includes and are stored in resources/templates. If required additional grouping/nesting can be achieved by adding folders.

All templates should extend from primer-base.twig and your custom content should be added to the templateContent block, e.g.

{% extends 'primer-base.twig' %}

{% block templateContent %}
    <h1>Example Template</h1>
    <p>This is an example page template that extends from the <code>primer-base.twig</code> file.</p>
{% endblock %}

Documents

Primer provides a simple way to present your Design System Documentation using MarkDown files.

To add a new Documentation Page, simply add a Markdown file (with the .md extension) to resources/docs folder. You can create grouping/nesting by including folders in the structure.

Meta Data

By default Primer will give your Page a title based on the filename but this can be overwritten by adding YAML FrontMatter to your file. For example, to specify the Title and Description you could do the following:

---
title: Page Title
description: This is a description
---
# Heading 1

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Hic placeat iusto animi architecto quasi, praesentium.

Both title & description are keywords that Primer knows how to handle but you are free to add any additional meta data to the FrontMatter that you like. All Markdown files are also passed through the Twig Environment, so custom meta can be used to dynamically generate HTML.

---
title: Page Title
description: This is a description
colours:
    - ff0000
    - 00ff00
    - 0000ff
---
# Colours

<ul>
{% for colour in colours %}
    <li>{{ colour }}</li>
{% endfor %}
</ul>

These are the colours we use!

Adding Frontend Assets

Primer is un-opinionated about what Frontend stack you choose to use. Once you're ready to add CSS and JavaScript assets to your HTML, you should do this in the views/primer-base.twig file. This is a common ancestor that all Primer requests use which will ensure your Patterns and Templates will render as you'd expect.

rareloop/primer 适用场景与选型建议

rareloop/primer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 53 次下载、GitHub Stars 达 43, 最近一次更新时间为 2019 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 rareloop/primer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rareloop/primer 我们能提供哪些服务?
定制开发 / 二次开发

基于 rareloop/primer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 53
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 43
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 43
  • Watchers: 6
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-05-10