PageRenderTime 1257ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/fuel/packages/parser/classes/view/markdown.php

https://bitbucket.org/codeyash/bootstrap
PHP | 89 lines | 49 code | 16 blank | 24 comment | 4 complexity | d9423fa8cb3996cf99125b07364f41d8 MD5 | raw file
Possible License(s): MIT, Apache-2.0
  1. <?php
  2. /**
  3. * Fuel
  4. *
  5. * Fuel is a fast, lightweight, community driven PHP5 framework.
  6. *
  7. * @package Fuel
  8. * @version 1.5
  9. * @author Fuel Development Team
  10. * @license MIT License
  11. * @copyright 2010 - 2013 Fuel Development Team
  12. * @link http://fuelphp.com
  13. */
  14. namespace Parser;
  15. class View_Markdown extends \View
  16. {
  17. protected static $_parser;
  18. protected function process_file($file_override = false)
  19. {
  20. $file = $file_override ?: $this->file_name;
  21. $contents = '';
  22. if (\Config::get('parser.View_Markdown.allow_php', false))
  23. {
  24. $contents = static::pre_process('php', $file, $this->get_data());
  25. }
  26. else
  27. {
  28. $contents = file_get_contents($file);
  29. }
  30. return static::parser()->transform($contents);
  31. }
  32. protected static function pre_process($_type = 'php', $_view_filename, array $_data = array())
  33. {
  34. if ($_type == 'php')
  35. {
  36. // Import the view variables to local namespace
  37. $_data AND extract($_data, EXTR_REFS);
  38. // Capture the view output
  39. ob_start();
  40. try
  41. {
  42. // Load the view within the current scope
  43. include $_view_filename;
  44. }
  45. catch (\Exception $e)
  46. {
  47. // Delete the output buffer
  48. ob_end_clean();
  49. // Re-throw the exception
  50. throw $e;
  51. }
  52. // Get the captured output and close the buffer
  53. return ob_get_clean();
  54. }
  55. }
  56. public $extension = 'md';
  57. /**
  58. * Returns the Parser lib object
  59. *
  60. * @return Markdown_Parser
  61. */
  62. public static function parser()
  63. {
  64. static $parser = null;
  65. if (is_null($parser))
  66. {
  67. $parser_class = \MARKDOWN_PARSER_CLASS;
  68. $parser = new $parser_class;
  69. }
  70. return $parser;
  71. }
  72. }
  73. // end of file mustache.php