File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Tapetry Asset Plugin
2+
3+ ## Install
4+
5+ To install run: ` composer require tapestry-cloud/code-example-plugin `
6+
7+ Next you need to update your site configuration to include the path to your code examples folder:
8+
9+ ``` php
10+ // ...
11+
12+ 'plugins' => [
13+ 'code_example_path' => __DIR__ . '/code_examples/'
14+ ],
15+
16+ // ...
17+ ```
18+
19+ Finally within your site Kernel.php you need to register the plugin's service provider:
20+
21+ ``` php
22+ <?php
23+
24+ use Tapestry\Modules\Kernel\KernelInterface;
25+
26+ class Kernel implements KernelInterface
27+ {
28+ /**
29+ * @var Tapestry
30+ */
31+ private $tapestry;
32+
33+ public function __construct(Tapestry $tapestry)
34+ {
35+ $this->tapestry = $tapestry;
36+ }
37+
38+ /**
39+ * This method is executed by Tapestry when the Kernel is registered.
40+ *
41+ * @return void
42+ */
43+ public function register()
44+ {
45+ // Use project autoloader
46+ require_once(__DIR__ . '/vendor/autoload.php');
47+ }
48+
49+ /**
50+ * This method of executed by Tapestry as part of the build process.
51+ *
52+ * @return void
53+ */
54+ public function boot()
55+ {
56+ $this->tapestry->register(\TapestryCloud\CodeExample\ServiceProvider::class);
57+ }
58+ }
59+ ```
60+
61+ ## Usage
62+
63+ This plugin adds the ` $this->codeExample('example.php') ` helper, which will output your code examples with their html entities encoded.
Original file line number Diff line number Diff line change @@ -34,11 +34,10 @@ public function register(Engine $engine)
3434 */
3535 public function codeExample ($ file )
3636 {
37- $ this ->codeExamplesPath = __DIR__ . '/../source/_code-examples/ ' . $ file ;
38- if (! file_exists ($ this ->codeExamplesPath )) {
39- throw new \Exception ('File [ ' . $ this ->codeExamplesPath .'] does not exist. ' );
37+ if (!file_exists ($ this ->codeExamplesPath . $ file )) {
38+ throw new \Exception ('File [ ' . $ this ->codeExamplesPath . $ file . '] does not exist. ' );
4039 }
4140
42- return htmlentities (file_get_contents ($ this ->codeExamplesPath ));
41+ return htmlentities (file_get_contents ($ this ->codeExamplesPath . $ file ));
4342 }
4443}
You can’t perform that action at this time.
0 commit comments