src/Dflydev/Twig/Extension/GitHubGist/GistTwigExtension.php
public function gist($id, $file = null)
    {
        if ($this->cache()->exists($id)) {
            $gist = $this->cache()->get($id);
        } else {
            $gist = $this->transport()->fetchGist($id);
            $this->cache()->set($id, $gist);
        }
        $files = array();
        foreach ($gist['files'] as $name => $fileInfo) {
            if ($file === null) {
                $files[$name] = $fileInfo;
            } else {
                if ($file == $name) {
                    $files[$name] = $fileInfo;
                    break;
                }
            }
        }

        if (!count($files)) {
            return '';
        }

        $urlExtra = $file ? '?file='.$file : '';
        $output = '';
        $output .= '<script src="https://gist.github.com/'.$id.'.js'.$urlExtra.'"></script>';
        $output .= '<noscript>';
        foreach ($files as $name => $fileInfo) {
            $language = strtolower($fileInfo['language']);
            $output .= '<pre><code class="language-'.$language.' '.$language.'">';
            $output .= htmlentities($fileInfo['content']);
            $output .= '</code></pre>';
        }
        $output .= '</noscript>';

        return $output;
    }
public function gist($id, $file = null)
    {
        if ($this->cache()->exists($id)) {
            $gist = $this->cache()->get($id);
        } else {
            $gist = $this->transport()->fetchGist($id);
            $this->cache()->set($id, $gist);
        }
        $files = array();
        foreach ($gist['files'] as $name => $fileInfo) {
            if ($file === null) {
                $files[$name] = $fileInfo;
            } else {
                if ($file == $name) {
                    $files[$name] = $fileInfo;
                    break;
                }
            }
        }

        if (!count($files)) {
            return '';
        }

        $urlExtra = $file ? '?file='.$file : '';
        $output = '';
        $output .= '<script src="https://gist.github.com/'.$id.'.js'.$urlExtra.'"></script>';
        $output .= '<noscript>';
        foreach ($files as $name => $fileInfo) {
            $language = strtolower($fileInfo['language']);
            $output .= '<pre><code class="language-'.$language.' '.$language.'">';
            $output .= htmlentities($fileInfo['content']);
            $output .= '</code></pre>';
        }
        $output .= '</noscript>';

        return $output;
    }
public function gist ( $ id , $ file = null ) { if ( $ this -> cache ( ) -> exists ( $ id ) ) { $ gist = $ this -> cache ( ) -> get ( $ id ) ; } else { $ gist = $ this -> transport ( ) -> fetchGist ( $ id ) ; $ this -> cache ( ) -> set ( $ id , $ gist ) ; } $ files = array ( ) ; foreach ( $ gist [ 'files' ] as $ name => $ fileInfo ) { if ( $ file === null ) { $ files [ $ name ] = $ fileInfo ; } else { if ( $ file == $ name ) { $ files [ $ name ] = $ fileInfo ; break ; } } } if ( ! count ( $ files ) ) { return '' ; } $ urlExtra = $ file ? '?file=' . $ file : '' ; $ output = '' ; $ output .= '<script src="https://gist.github.com/' . $ id . '.js' . $ urlExtra . '"></script>' ; $ output .= '<noscript>' ; foreach ( $ files as $ name => $ fileInfo ) { $ language = strtolower ( $ fileInfo [ 'language' ] ) ; $ output .= '<pre><code class="language-' . $ language . ' ' . $ language . '">' ; $ output .= htmlentities ( $ fileInfo [ 'content' ] ) ; $ output .= '</code></pre>' ; } $ output .= '</noscript>' ; return $ output ; }
Get the HTML content for a GitHub Gist

@param string $id   ID
@param string $file File

@return string
Get the HTML content for a GitHub Gist