├── DocumentationPlugin.php
├── README.md
├── controllers
└── DocumentationController.php
└── templates
├── index.html
└── settings.html
/DocumentationPlugin.php:
--------------------------------------------------------------------------------
1 | AttributeType::Bool,
54 | 'pathToMarkdown' => AttributeType::String,
55 | 'documentation' => AttributeType::Mixed
56 | );
57 | }
58 |
59 | /**
60 | * Return the plugins settings template.
61 | *
62 | * @return string
63 | */
64 | public function getSettingsHtml()
65 | {
66 | return craft()->templates->render('documentation/settings', array(
67 | 'settings' => $this->getSettings()
68 | ));
69 | }
70 |
71 | /**
72 | * Return if the plugin has a control panel section.
73 | *
74 | * @return bool
75 | */
76 | public function hasCpSection()
77 | {
78 | return true;
79 | }
80 |
81 | /**
82 | * @return array
83 | */
84 | public function registerCpRoutes()
85 | {
86 | return array(
87 | 'documentation' => array(
88 | 'action' => 'documentation/document'
89 | )
90 | );
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Documentation
2 |
3 | This plugin designed specifically to assist the team document this Craft project during each phase. During the projects phases, your developers should use a simple markdown file to create end user documentation, this encourages the "document during development" mentality.
4 |
5 | The final result of this working markdown file will be available in Craft for the clients quick reference.
6 |
7 |
8 |
9 | # Workflow
10 |
11 | This section covers a "typical" workflow while using this plugin.
12 |
13 | 1. The development team will install the plugin.
14 | 2. As the developers are integrating the design, they should add quick notes `on how to add 'x'` for each section.
15 | 3. Since database syncing between environments is still a thing, you should check the `working` markdown file in with version control.
16 | 4. Enter the path to the markdown file under the [plugin settings](settings/plugins/documentation), this should be in the documentation plugins directory (*i.e 'plugins/documentation/markdown/projectname.md'*).
17 |
18 |
19 |
20 | # Preparing for production
21 |
22 | This section covers how to move the documentation into production.
23 |
24 | 1. Proof read the working markdown file for accuracy and any bugs (after all, projects change during development).
25 | 2. Copy the content of the markdown file, make sure you copy the markdown itself not the HTML.
26 | 3. Enter the contents into the "Documentation Markdown" field in [plugin settings](settings/plugins/documentation).
27 | 4. Turn on the setting to "Use The Database".
--------------------------------------------------------------------------------
/controllers/DocumentationController.php:
--------------------------------------------------------------------------------
1 | plugins->getPlugin('documentation');
20 |
21 | $settings = $plugin->getSettings();
22 |
23 | $this->plugin = $plugin;
24 |
25 | $this->settings = $settings;
26 | }
27 |
28 | /**
29 | * Render the documentation template.
30 | *
31 | * @throws HttpException
32 | */
33 | public function actionDocument()
34 | {
35 | // are we using the database?
36 | if ($this->settings->useDatabase) {
37 | $documentation = $this->settings->documentation;
38 | }
39 | else {
40 | $file = $this->settings->pathToMarkdown;
41 |
42 | $documentation = $this->getFileContents($file);
43 | }
44 |
45 | // render the template, pass the markdown!
46 | $this->renderTemplate('documentation/index', array(
47 | 'documentation' => $documentation,
48 | ));
49 | }
50 |
51 | /**
52 | * Get the markdown file contents.
53 | *
54 | * @param $file
55 | * @return string
56 | */
57 | protected function getFileContents($file)
58 | {
59 | $directory = craft()->path->getPluginsPath() . 'documentation/';
60 |
61 | $path = $directory . $file;
62 |
63 | // can we find the file path?
64 | if ($this->settings->pathToMarkdown != '' && file_exists($path)) {
65 | return file_get_contents($path);
66 | }
67 | else {
68 | return file_get_contents($directory . 'README.md');
69 | }
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/templates/index.html:
--------------------------------------------------------------------------------
1 | {% extends "_layouts/cp" %}
2 |
3 | {% set title = siteName ~ ' Documentation' %}
4 |
5 | {% block content %}
6 | {{ documentation | markdown }}
7 | {% endblock %}
--------------------------------------------------------------------------------
/templates/settings.html:
--------------------------------------------------------------------------------
1 | {% import "_includes/forms" as forms %}
2 |
3 | {{ forms.textField({
4 | label: "Path to the markdown file"|t,
5 | id: 'pathToMarkdown',
6 | name: 'pathToMarkdown',
7 | instructions: "Path to the markdown file (this is relative to the documentation plugin path)"|t,
8 | placeholder: "markdown/project-name.md",
9 | value: settings.pathToMarkdown,
10 | }) }}
11 |
12 |
13 |
14 | {{ forms.lightswitchField({
15 | label: "Use Database"|t,
16 | id: 'useDatabase',
17 | name: 'useDatabase',
18 | instructions: "Switch to using the database instead of the markdown file."|t,
19 | on: settings.useDatabase,
20 | }) }}
21 |
22 | {{ forms.textareaField({
23 | label: "Documentation Markdown"|t,
24 | id: 'documentation',
25 | name: 'documentation',
26 | instructions: "Enter your markdown content to save."|t,
27 | value: settings.documentation,
28 | rows: '30'
29 | }) }}
30 |
31 |
--------------------------------------------------------------------------------