Giter Club home page Giter Club logo

hmvcassets's Introduction

HMVCAssets

Assest on modules

Intermezzo HMVCAssets

Do you think about HMVC Assets on Codeigniter? HMVC is a MVC in a plant in the modules, how when you build web with the HMVC usually. How about Assests? Maybe the css and js? How about we merge in a modules. is it really helpful? you no longer waste time long to scroll up and down to look for file assets which should be loaded in your modules.

Getting Started

Prerequisites

Install HMVC from wiredesignz

Installing

Step 1

Copy and paste, sourcecode below on "application/third_party/MX/Loader.php" . If do not want to elaborate, simply download the file Loader.php

/** Load a module Assets **/
public function assets($extention=null){
		/** 
			Load a module Assets
			Inspirated from Mr.Bimo and Friends @Togu Inovasi Teknologi.
			Code Writer: [email protected]
			how to use?
			Step 1
			load css : $this->load->assets('css');
			load js : $this->load->assets('js');
			Step 2
			Create folder "assets", put "*.css/*.js" in "assets".
		**/
		$filecache = array('css'=>'','js'=>'');
		$path= 'application/modules/'.$this->_module.'/assets/';
		$pathcache='cacheassets';
		/*detect path assets in modules*/
		if (file_exists($path)) {
			/*list file path assets*/
			$list = glob('./'.$path.'*.'.$extention, GLOB_BRACE);
			foreach ($list as $key) {
				/*open file content and minify sourcecode*/
				if ($extention=='css') {
					$bcss = $filecache['css'].file_get_contents($key);
					$bcss = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $bcss);
				    $bcss = str_replace(["\r\n","\r","\n","\t",'  ','    ','     '], '', $bcss);
				    $bcss = preg_replace(['(( )+{)','({( )+)'], '{', $bcss);
				    $bcss = preg_replace(['(( )+})','(}( )+)','(;( )*})'], '}', $bcss);
				    $bcss = preg_replace(['(;( )+)','(( )+;)'], ';', $bcss);
					$filecache['css']= $bcss;
				}
				if ($extention=='js') {
					$bjs = $filecache['js'].file_get_contents($key);
					$bjs = preg_replace("/((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/", "", $bjs);
				    $bjs = str_replace(["\r\n","\r","\t","\n",'  ','    ','     '], '', $bjs);
				    $bjs = preg_replace(['(( )+\))','(\)( )+)'], ')', $bjs);
					$filecache['js']=$bjs;
				}
			}
			if (array_key_exists($extention, $filecache)) {
				if ($filecache[$extention]!='') {
					/*auto create path cache*/
					if (!file_exists('./'.$pathcache)) {
						mkdir('./'.$pathcache);
					}
					/*create file on path cache*/
					$errormessage = "Unable to open file ".$extention." on ".$pathcache ."!";
					$filename= $pathcache.'/'.md5($path).'.'.$extention;
					$fw = fopen('./'.$filename, "w") or die($errormessage);
					$txt = $filecache[$extention];
					fwrite($fw, $txt);
					fclose($fw);
					/*write script on html*/
					if ($extention=='css') {
						echo '<link rel="stylesheet" type="text/css" href="'.base_url($filename).'">';
					}
					if ($extention=='js') {
						echo '<script type="text/javascript" src="'.base_url($filename).'" ></script>';
					}
				}
			}
		}
	}

Step 2

Load assets on template views

<!DOCTYPE html>
<html>
  <head>
      <?php $this->load->assets('css'); ?>
  </head>
  <body>
      <?php $this->load->assets('js'); ?>
  </body>
</html>

Step 3

Create folder "assets" on your modular, put your".css/.js" in "assets".

Notice

while reading the folder, the system of reading with sort by alphabetical order, so rename files in "assets" which file you first load.

Thanks

hmvcassets's People

Contributors

karebet avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

uahm93

hmvcassets's Issues

Images loading issue

Hi,
i follow your way of including js,css file . How can i load images specify in css file

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.