Giter VIP home page Giter VIP logo

passet's Introduction

License Build Status Code Coverage Scrutinizer Code Quality

passet

passetはPHPアプリケーションで利用する静的ファイルを管理するためのライブラリです。

How to install

composer.jsonを書きます。

{
  "require": {
    "passet/passet": "dev-master"
  }
}

composerからインストールします。
php composer.phar install

Usage

passetの使い方を説明します。

Output script tags to html

<?php require 'vendor/autoload.php'; ?>

<div>
  <h1>Example</h1>
  <?php \Passet\Manage::js('/path/to/foo.js')->add(); ?>
  <p>......</p>
  <?php \Passet\Manage::js('/path/to/bar.js')->add(); ?>
</div>

<?php \Passet\Manage::outputJs(); ?>

出力されるHTMLは以下のようになります。

<div>
  <h1>Example</h1>
  <p>......</p>
</div>

<script src="/path/to/foo.js" type="application/javascript"></script>
<script src="/path/to/bar.js" type="application/javascript"></script>

HTMLタグの合間に記載されたコードが、すべて最後の行で出力されます。
これは、テンプレートファイルを分割して、その中にスクリプトタグが書かれたときに、スクリプトタグがHTMLタグの中に埋もれてしまうのを防ぐ効果があります。

inline output

スクリプトタグを出力する際に、コードをインライン展開することが可能です。

// this file name is inline.js
console.log('hello world!!');
<?php require 'vendor/autoload.php'; ?>
<?php \Passet\Manage::js('inline.js')->writeInline()->add(); ?>
<?php \Passet\Manage::outputJs(); ?>

以下のようにjavascriptのコードがインラインで展開されます。

<script type="application/javascript">
// this file name is inline.js
console.log('hello world!!');
</script>

普段、インラインで記述するような簡単なコードでも使い回すことが可能になります。

Output style tags to html

scriptタグ同様にstyleタグを出力することが可能です。

<?php require 'vendor/autoload.php'; ?>

<?php \Passet\Manage::css('/path/to/css')->add(); ?>
<?php \Passet\Manage::css('/path/to/css')->writeInline()->add(); ?>
<?php \Passet\Manage::outputCss(); ?>

Output img tag to html

imgタグはscriptタグやstyleタグのようにまとめと出力する機能はありません。
imgタグはインラインで読み込むかsrcパスを指定して読み込むかを指定して出力することが可能です。

<?php require 'vendor/autoload.php'; ?>

<?php echo \Passet\Manage::img('/path/to/img')->build(); ?>
<?php echo \Passet\Manage::img('/path/to/img')->writeInline()->build(); ?>

出力出来るimageファイルは以下のタイプのものに限定されています。

  • png
  • jpeg
  • gif
  • bmp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.