承接 kagagnon/bem-blade 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

kagagnon/bem-blade

Composer 安装命令:

composer require kagagnon/bem-blade

包简介

Blade shortcodes to generate BEM class

README 文档

README

Install via composer with

$ composer install kagagnon/bem-blade

After successfully installing BEM Blade, add the service provider in your app configs.

KAGagnon\BEMBlade\BEMServiceProvider::class,

The service provider will boot and register new directives in the Blade engine.

Optional configurations

You can publish the config file with the following command:

$ php artisan vendor:publish --provider="KAGagnon\BEMBlade\BEMServiceProvider" --tag="config"

You can then change your element and modifier separators to your liking.

<?php
return [

    /**
     * Separator between block and element
     *
     * Default: '__'
     */
    'element_separator' => '__',

    /**
     * Separator between modifer and block/element
     *
     * Default: '--'
     */
    'modifier_separator' => '--',

    /**
     * Should @bem create a tag element
     *
     * Default: false
     */
    'create_tag' => false,

    /**
     * If create_tag is true, what's the default tag name
     *
     * Default: 'div'
     */
    'default_tag' => 'div',

    /**
     * Prefix of BEM classes.
     *
     * Default: ''
     */
    'block_prefix' => '',
];

How to use

Blocks

You can create a new block with the directive @bem( $block_name ). Once the block if finished, you can use @endbem to close the block. BEM block can be nest for sub-module. So this:

@bem( 'block' )
    @bem( 'other-block )
    @endbem
@endbem

is a valid syntax.

Classes

To generate a class, you can use @bemclass( [ string|array $element, [ string|array $modifiers ] ] ).

  • Passing no arguments generate the block name.
  • Passing a string as first argument generate the block name with an element.
  • Passing an array as first argument generate the block name with the modifiers.
  • Passing a string and an array generate a block name with an element and its modifiers.
  • Passing 2 strings generate a block name with an element and explode the string on spaces to generate the modifiers.

Check the examples below:

@bem( 'cup' ) // Init Block "cup"
    @bemclass() // Generate : cup
    @bemclass( [ 'glass' ] ) // Generate : cup cup--glass

    @bem( 'spoon' ) // Init Block "spoon"
        @bemclass // Generate : spoon
        @bemclass( [ 'metallic', 'cold' ] ) // Generate : spoon spoon--metallic spoon--cold
        @bemclass( 'sugar' ) // Generate : spoon__sugar
        @bemclass( 'sugar', 'half-tea-spoon' ) // Generate : spoon__sugar spoon__sugar--half-tea-spoon
    @endbem

    @bemclass( 'tea' ) // Generate : cup__tea
    @bemclass( 'coffee' ) // Generate : cup_coffee
    @bemclass( 'coffee' , 'with-sugar' ) // Generate : cup__coffee cup__coffee--with-sugar
    @bemclass( 'coffee' , [ 'with-sugar', 'with-milk'] ) // Generate : cup__coffee cup__coffee--with-sugar cup__coffee--with-milk
    @bemclass( 'coffee' , 'with-sugar with-milk no-foam' ) // Generate : cup__coffee cup__coffee--with-sugar cup__coffee--with-milk cup__coffee--no-foam
@endbem

HTML example

@bem( 'article' )
   <div class="@bemclass">
       <h1 class="@bemclass( 'title' )">Article Name</h1>

       <p class="@bemclass( 'content' )">Article text...</p>

       @bem( 'meta' )
           <div class="@bemclass">
               <a href="..." class="@bemclass( 'link', 'inactive' )">0 comments</a>
               <a href="..." class="@bemclass( 'link', 'clear danger' )">Delete</a>
               <a href="..." class="@bemclass( 'link' )">Edit</a>
           </div>
       @endbem
   </div>
@endbem

Result to :

<div class="article">
   <h1 class="article__title">Article Name</h1>

   <p class="article__content">Article text...</p>

   <div class="meta">
       <a href="..." class="meta__link--inactive">0 comments</a>
       <a href="..." class="meta__link--clear meta__link--danger">Delete</a>
       <a href="..." class="meta__link">Edit</a>
   </div>
</div>

Create node with @bem

You can pass argument to @bem to automatically generate an HTML tag. To do so, you can pass the tag name as second argument and, optionally, an array of attributes.

You can also skip the tag name and pass an array as second argument. That will create an HTML element base on the default_tag configuration.

Additionally, if you set create_tag to true, @bem() will always create a tag base on the default_tag configuration if only 1 argument is passed.

To pass modifiers to the tag, simply pass _modifiers in the array: an array for multi-modifiers ou a string for single modifier.

Example

{{-- We assume `create_tag` is set to true --}}
@bem( 'block' ) // <div class="block">
@endbem         // </div>

@bem( 'block', 'article' ) // <article class="block">
@endbem                    // </article>

@bem( 'block', 'quote', [ 'data-inspiration', 'class' => 'js-action' ] ) // <quote class="js-action block" data-inspiration >
@endbem                                                                  //</quote>

@bem( 'block', [ 'id' => "anchor" ] ) // <div class="block" id="anchor">
@endbem                               // </div>

@bem( 'block', [ 'id' => "anchor", '_modifiers' => 'modifier' ] ) // <div class="block block--modifier" id="anchor">
@endbem                               // </div>

@bem( 'block', [ '_modifiers' => [ 'modifier1', 'modifier2' ] ] ) // <div class="block block--modifier1 block--modifier2">
@endbem                               // </div>

kagagnon/bem-blade 适用场景与选型建议

kagagnon/bem-blade 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 589 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「shortcode」 「blade」 「BEM」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 kagagnon/bem-blade 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 589
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-28