示例#1
0
文件: Tweet.php 项目: jvelo/datatext
    public function handler()
    {
        return function ($shortcode) {
            $id = $shortcode->getParameter('id');
            $theme = $shortcode->getParameter('theme') || 'dark';
            Assets::request(new Asset('script', '//platform.twitter.com/widgets.js', ['charset' => 'utf-8']));
            $script = <<<'SCRIPT'
<script type='text/javascript'>
  twttr.widgets.createTweet('%s', document.getElementById('tweet-%s'), { theme: '%s'});
</script>
SCRIPT;
            return sprintf("<div id=\"tweet-%s\"></div>\n" . $script, $id, $id, $id, $theme);
        };
    }
示例#2
0
 public function testCreateAndGetPageWithAssets()
 {
     Shortcodes::register(new Tweet());
     $page = new Page();
     $page->content = "[tweet id=\"20\"]";
     $page->save();
     $this->assertContains("twttr.widgets.createTweet", $page->html_content);
     $this->assertEquals(1, count(Assets::all()));
     $asset = Assets::all()[0];
     $this->assertEquals('script', $asset->getType());
     $this->assertEquals('//platform.twitter.com/widgets.js', $asset->getLocation());
     $page = new Page();
     $page->content = '# datatext';
     $page->save();
     $fetched = Pages::getPage($page->id);
     $this->assertEquals('<h1>datatext</h1>', $fetched['page']['html_content']);
 }
示例#3
0
文件: Pages.php 项目: jvelo/datatext
 public function getPage($id)
 {
     $page = Page::findOrFail($id);
     $assets = Assets::all();
     return ["page" => $page, "assets" => $assets];
 }