/** * Get the URL for the cached view. * * Recommended usage is to just pass the entire view name as the first and only arg: * * ``` * $blog_js = $simpleCache->getUrl('blog/save_draft.js'); * $favicon = $simpleCache->getUrl('graphics/favicon.ico'); * ``` * * For backwards compatibility with older versions of Elgg, you can also pass * "js" or "css" as the first arg, with the rest of the view name as the second arg: * * ``` * $blog_js = $simpleCache->getUrl('js', 'blog/save_draft.js'); * ``` * * This automatically registers the view with Elgg's simplecache. * * @param string $view The full view name * @param string $subview If the first arg is "css" or "js", the rest of the view name * * @return string */ function getUrl($view, $subview = '') { // handle `getUrl('js', 'js/blog/save_draft')` if (($view === 'js' || $view === 'css') && 0 === strpos($subview, $view . '/')) { $view = $subview; $subview = ''; } // handle `getUrl('js', 'blog/save_draft')` if (!empty($subview)) { $view = "{$view}/{$subview}"; } $view = $this->views->canonicalizeViewName($view); // should be normalized to canonical form by now: `getUrl('blog/save_draft.js')` $this->registerView($view); return $this->getRoot() . $view; }
public function testCanListViews() { $views = $this->views->listViews('default'); $this->assertTrue(in_array('interpreted.js', $views)); $this->assertTrue(in_array('static.js', $views)); $this->assertEmpty($this->views->listViews('fake_viewtype')); }
public function testCanAlterViewOutput() { $this->hooks->registerHandler('view', 'js/interpreted.js', function ($h, $t, $v, $p) { return '// Hello'; }); $this->assertEquals("// Hello", $this->views->renderView('js/interpreted.js')); }
/** * @dataProvider getExampleNormalizedViews */ public function testDefaultNormalizeBehavior($canonical, $alias) { $this->assertEquals($canonical, $this->views->canonicalizeViewName($alias)); }