php - Pass asset as string to CodeIgniter Carabiner library -
carabiner take paths in it's js() , css() functions:
$this->load->library('carabiner'); $this->carabiner->js('some/file/in/script/dir'); $this->carabiner->css('some/file/in/style/dir'); $this->carabiner->display(); i'm looking homecoming scripts , styles setting homecoming flag in $this->load->view() , pass off carabiner in function js_string(), example...
$custom_js = $this->load->view("js_with_php_in_it", null, true); $this->carabiner->js_string($custom_js); i've solved problem in convoluted way creating carabiner method called from_string($type, $str) takes either 'js', or 'css' it's first parameter, , string second:
function from_string($type, $str){ //we'll name file using this. $uniq = uniqid(); //create temporary file in system's /tmp directory. $tmpasset = tempnam("/tmp", $uniq); //carabiner requires scripts relative $config['script_dir'] //create symbolic link in directory because can't pass absolutes. $this->symbolicasset = "assets/{$type}/{$uniq}"; //open file named unique id in /tmp , set writing. $handle = fopen($tmpasset, "w"); //write script or style temporary file. fwrite($handle, $str); //point symlink @ symlink($tmpasset, $this->symbolicasset); //pass directory off $this->carabiner->css() or $this->carabiner->js() $this->$type($uniq); } i unlink() temporary file in carabiner's __destruct()... but, quite hate solution obvious overhead reasons: i'm creating temporary file containing same contents original because of carabiner's strict asset directory rules. has modified carabiner in past enable parse strings?
this feature missing in library, have used library in major projects after seeing question made modifications in library take javascripts , css styles string or array of strings groups not create temporary file create in pages script tag , styles here how library work now.
javascript strings
// script passed string $this->carabiner->js_string('alert("test script")'); // script passed array $this->carabiner->js_string(array('alert("test script")','alert("test script")'); // script passed string grouping name $this->carabiner->js_string('alert("test script")','group_name'); // script passed array grouping name $this->carabiner->js_string(array('alert("test script")','alert("test script")','group_name'); //load javascript along javascript files without grouping name $this->carabiner->display('js'); //load javascript along javascript files grouping name $this->carabiner->display('group_name'); css style strings
// style passed string $this->carabiner->css_string('p{background:red}'); // styles passed array $this->carabiner->css_string(array('p{background:red}','p{background:red}'); // style passed string grouping name $this->carabiner->css_string('p{background:red}','css_group_name'); // style passed array grouping name $this->carabiner->css_string(array('p{background:red}','p{background:red}','css_group_name'); //load style along javascript files without grouping name $this->carabiner->display('css'); //load styles along javascript files grouping name $this->carabiner->display('css_group_name'); here git repo created , sent request pull git repo
php codeigniter carabiner
No comments:
Post a Comment