diff --git a/.craftplugin b/.craftplugin
new file mode 100644
index 0000000..84cc4de
--- /dev/null
+++ b/.craftplugin
@@ -0,0 +1 @@
+{"pluginName":"usermanual","pluginDescription":"Craft User Manual allows developers (or even content editors) to provide CMS documentation using Craft's built-in sections (singles, channels, or structures) to create a 'User Manual' or 'Help' section directly in the control panel.","pluginVersion":"2.0.0","pluginAuthorName":"Rob Erskine","pluginVendorName":"hillholliday","pluginAuthorUrl":"https://twitter.com/erskinerob","pluginAuthorGithub":"hillholliday","codeComments":"","pluginComponents":["settings","twigextensions","variables"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"}
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..bde3e77
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+; top-most EditorConfig file
+root = true
+
+; Unix-style newlines
+[*]
+indent_style = space
+indent_size = 2
+end_of_line = LF
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.php]
+indent_style = space
+indent_size = 4
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a17970c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,32 @@
+# CRAFT ENVIRONMENT
+.env.php
+.env.sh
+.env
+
+# COMPOSER
+/vendor
+
+# BUILD FILES
+/bower_components/*
+/node_modules/*
+/build/*
+/yarn-error.log
+
+# MISC FILES
+.cache
+.DS_Store
+.idea
+.project
+.settings
+*.esproj
+*.sublime-workspace
+*.sublime-project
+*.tmproj
+*.tmproject
+.vscode/*
+!.vscode/settings.json
+!.vscode/tasks.json
+!.vscode/launch.json
+!.vscode/extensions.json
+config.codekit3
+prepros-6.config
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..74cebcb
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,9 @@
+# usermanual Changelog
+
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
+
+## 2.0.0 - 2018-08-24
+### Added
+- Initial Craft 3 release
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..96a4c99
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,9 @@
+The MIT License (MIT)
+
+Copyright (c) 2018 Rob Erskine
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/README.md b/README.md
index 5102121..5e8e7e0 100644
--- a/README.md
+++ b/README.md
@@ -1,34 +1,67 @@
-# Craft User Manual
+# Craft User Manual plugin for Craft CMS 3.x
Craft User Manual allows developers (or even content editors) to provide CMS documentation using Craft's built-in sections (singles, channels, or structures) to create a "User Manual" or "Help" section directly in the control panel.
-![How it works](http://cl.ly/image/2a3g0J3h3d3j/Craft-User-Manual-2.5.jpg)
+![Screenshot](resources/img/screenshot.jpg)
----
+## Requirements
+
+This plugin requires Craft CMS 3.0.0-beta.23 or later.
## Installation
-1. Copy the included **usermanual** folder into craft/plugins.
-2. Navigate to Plugins in the Craft CP.
-3. Click the Install button in the row for the **User Manual** plugin.
+
+To install the plugin, follow these instructions.
+
+1. Open your terminal and go to your Craft project:
+
+ cd /path/to/project
+
+2. Then tell Composer to load the plugin:
+
+ composer require hillholliday/usermanual
+
+3. In the Control Panel, go to Settings → Plugins and click the “Install” button for usermanual.
+
4. Select the section the plugin should use as the **User Manual** page in the CP.
* (Optional) - Replace the plugin's name to something your user's will understand.
* (Optional) - Use more than the default `body` fieldhandle by setting up custom template overrides.
+
5. Click the **User Manual** link in the CP nav.
+## Configuration
+
+* All settings may be optionally configured using a [config file](http://buildwithcraft.com/docs/plugins/plugin-settings#config-file). The values, contained in [`config.php`](https://github.com/hillholliday/Craft-User-Manual/blob/master/usermanual/config.php), are described below:
+
+
+### pluginNameOverride
+Intuitive, human-readable plugin name for the end user.
+
+
+### templateOverride
+For more control over the output, you may optionally override the default template.
+
+Path is relative to ../craft/templates/.
+
+
+### section
+Entries in this section must have associated urls.
+
## Some notes
* The plugin currently only pulls in the `body` field from each entry in the selected section, unless you're using a template override.
* While the **User Manual** section works best with `Structures`, you can certainly get away with using a one-off `Single`.
* If you're running _Craft Client_ or _Craft Pro_ make sure your content editors don't have permission to edit whatever section you've selected to use as your **User Manual**
* Only sections with entry URLs may be used as your **User Manual** section.
-* All settings may be optionally configured using a [config file](http://buildwithcraft.com/docs/plugins/plugin-settings#config-file). See [`config.php`](https://github.com/hillholliday/Craft-User-Manual/blob/master/usermanual/config.php) for possible values.
## Thanks
This plugin was inspired by the team over at [70kft](http://70kft.com/) for their work on [Craft-Help](https://github.com/70kft/craft-help). While their plugin is definitely more flexible in terms of writing custom markdown in separate files, we wanted to create something that would make it easier for anyone to edit documentation without making any changes to the server. This works particularly well for larger projects where more than one person (especially non-devs) are writing documentation for how to use the CMS.
## Releases
+* **2.0.0** - Craft3 version of Craft User Manual.
* **1.1.1** - Adding in RTL language support
* **1.1.0** - Merging in @timkelty's work which includes template overrides, updated error prompts, and other misc improvements
* **1.0.1** - Adding support for plugin custom icons in Craft 2.5
* **1.0.0** - Initital release of Craft User Manual.
We hope this plugin is useful, and we'd love to hear any suggestions or issues you may have. [@erskinerob](https://twitter.com/erskinerob).
+
+Brought to you by [Rob Erskine](https://twitter.com/erskinerob)
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..ff603e4
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,40 @@
+{
+ "name": "hillholliday/Craft-User-Manual",
+ "description": "Craft User Manual allows developers (or even content editors) to provide CMS documentation using Craft's built-in sections (singles, channels, or structures) to create a `User Manual` or `Help` section directly in the control panel.",
+ "type": "craft-plugin",
+ "version": "2.0.0",
+ "keywords": [
+ "craft",
+ "cms",
+ "craftcms",
+ "craft-plugin",
+ "usermanual"
+ ],
+ "support": {
+ "docs": "https://github.com/hillholliday/Craft-User-Manual/blob/master/README.md",
+ "issues": "https://github.com/hillholliday/Craft-User-Manual/issues"
+ },
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Rob Erskine",
+ "homepage": "https://twitter.com/erskinerob"
+ }
+ ],
+ "require": {
+ "craftcms/cms": "^3.0.0-RC1"
+ },
+ "autoload": {
+ "psr-4": {
+ "hillholliday\\usermanual\\": "src/"
+ }
+ },
+ "extra": {
+ "name": "User Manual",
+ "handle": "usermanual",
+ "hasCpSettings": true,
+ "hasCpSection": true,
+ "changelogUrl": "https://raw.githubusercontent.com/hillholliday/Craft-User-Manual/master/CHANGELOG.md",
+ "class": "hillholliday\\usermanual\\UserManual"
+ }
+}
diff --git a/resources/img/screenshot.jpg b/resources/img/screenshot.jpg
new file mode 100644
index 0000000..88b5f94
Binary files /dev/null and b/resources/img/screenshot.jpg differ
diff --git a/src/UserManual.php b/src/UserManual.php
new file mode 100644
index 0000000..c0cedb5
--- /dev/null
+++ b/src/UserManual.php
@@ -0,0 +1,226 @@
+name = $this->getName();
+
+ // Register twig extensions
+ $this->_addTwigExtensions();
+
+ // Register CP routes
+ Event::on(
+ UrlManager::class,
+ UrlManager::EVENT_REGISTER_CP_URL_RULES,
+ [$this, 'registerCpUrlRules']
+ );
+
+ // Register variables
+ Event::on(
+ CraftVariable::class,
+ CraftVariable::EVENT_INIT,
+ function (Event $event) {
+ /** @var CraftVariable $variable */
+ $variable = $event->sender;
+ $variable->set('userManual', UserManualVariable::class);
+ }
+ );
+
+ // Plugin Install event
+ Event::on(
+ Plugins::class,
+ Plugins::EVENT_AFTER_INSTALL_PLUGIN,
+ [$this, 'afterInstallPlugin']
+ );
+
+ Craft::info(
+ Craft::t(
+ 'usermanual',
+ '{name} plugin loaded',
+ ['name' => $this->name]
+ ),
+ __METHOD__
+ );
+ }
+
+ /**
+ * Returns the user-facing name of the plugin, which can override the name
+ * in composer.json
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ $pluginName = Craft::t('usermanual', 'User Manual');
+ $pluginNameOverride = $this->getSettings()->pluginNameOverride;
+
+ return ($pluginNameOverride)
+ ? $pluginNameOverride
+ : $pluginName;
+ }
+
+ public function registerCpUrlRules(RegisterUrlRulesEvent $event)
+ {
+ $rules = [
+ 'usermanual/' => ['template' => 'usermanual/index'],
+ ];
+
+ $event->rules = array_merge($event->rules, $rules);
+ }
+
+ public function afterInstallPlugin(PluginEvent $event)
+ {
+ $isCpRequest = Craft::$app->getRequest()->isCpRequest;
+
+ if ($event->plugin === $this && $isCpRequest) {
+ Craft::$app->controller->redirect(UrlHelper::cpUrl('settings/plugins/usermanual/'))->send();
+ }
+ }
+
+ // Protected Methods
+ // =========================================================================
+
+ /**
+ * @inheritdoc
+ */
+ protected function createSettingsModel()
+ {
+ return new Settings();
+ }
+
+ /**
+ * @inheritdoc
+ */
+ protected function settingsHtml(): string
+ {
+ $options = [[
+ 'label' => '',
+ 'value' => '',
+ ]];
+ foreach (Craft::$app->sections->getAllSections() as $section) {
+ $siteSettings = Craft::$app->sections->getSectionSiteSettings($section['id']);
+ $hasUrls = false;
+ foreach ($siteSettings as $siteSetting) {
+ if ($siteSetting->hasUrls) {
+ $hasUrls = true;
+ }
+ }
+
+ if (!$hasUrls) {
+ continue;
+ }
+ $options[] = [
+ 'label' => $section['name'],
+ 'value' => $section['id'],
+ ];
+ }
+
+ return Craft::$app->view->renderTemplate(
+ 'usermanual/settings',
+ [
+ 'settings' => $this->getSettings(),
+ 'options' => $options,
+ 'siteTemplatesPath' => Craft::$app->getPath()->getSiteTemplatesPath(),
+ ]
+ );
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getSettings()
+ {
+ $settings = parent::getSettings();
+ $config = Craft::$app->config->getConfigFromFile('usermanual');
+
+ foreach ($settings as $settingName => $settingValue) {
+ $settingValueOverride = null;
+ foreach ($config as $configName => $configValue) {
+ if ($configName === $settingName) {
+ $settingValueOverride = $configValue;
+ }
+ }
+ $settings->$settingName = $settingValueOverride ?? $settingValue;
+ }
+
+ // Allow handles from config
+ if (!is_numeric($settings->section)) {
+ $section = Craft::$app->getSections()->getSectionByHandle('homepage');
+ if ($section) {
+ $settings->section = $section->id;
+ }
+ }
+
+ return $settings;
+ }
+
+ // Private Methods
+ // =========================================================================
+
+ private function _addTwigExtensions()
+ {
+ Craft::$app->view->twig->addExtension(new UserManualTwigExtension);
+ }
+}
diff --git a/src/assetbundles/usermanual/UserManualAsset.php b/src/assetbundles/usermanual/UserManualAsset.php
new file mode 100644
index 0000000..916f65b
--- /dev/null
+++ b/src/assetbundles/usermanual/UserManualAsset.php
@@ -0,0 +1,51 @@
+sourcePath = "@hillholliday/usermanual/assetbundles/usermanual/dist";
+
+ $this->depends = [
+ CpAsset::class,
+ ];
+
+ $this->js = [
+ 'js/UserManual.js',
+ ];
+
+ $this->css = [
+ 'css/UserManual.css',
+ ];
+
+ parent::init();
+ }
+}
diff --git a/usermanual/resources/css/help.css b/src/assetbundles/usermanual/dist/css/UserManual.css
old mode 100755
new mode 100644
similarity index 91%
rename from usermanual/resources/css/help.css
rename to src/assetbundles/usermanual/dist/css/UserManual.css
index 62b85d5..6855935
--- a/usermanual/resources/css/help.css
+++ b/src/assetbundles/usermanual/dist/css/UserManual.css
@@ -1,5 +1,17 @@
-/*
- * lifted from craft-help from the super smart devs over at 70kft https://github.com/70kft/craft-help
+/**
+ * usermanual plugin for Craft CMS
+ *
+ * usermanual CSS
+ *
+ * @author Rob Erskine
+ * @copyright Copyright (c) 2018 Rob Erskine
+ * @link https://twitter.com/erskinerob
+ * @package Usermanual
+ * @since 2.0.0
+ */
+
+ /*
+ * lifted from craft-help from the super smart devs over at 70kft https://github.com/70kft/craft-help
*/
#user-manual {
diff --git a/src/assetbundles/usermanual/dist/img/UserManual-icon.svg b/src/assetbundles/usermanual/dist/img/UserManual-icon.svg
new file mode 100644
index 0000000..c8afbcd
--- /dev/null
+++ b/src/assetbundles/usermanual/dist/img/UserManual-icon.svg
@@ -0,0 +1,52 @@
+
+
+
+
diff --git a/src/assetbundles/usermanual/dist/js/UserManual.js b/src/assetbundles/usermanual/dist/js/UserManual.js
new file mode 100644
index 0000000..a4366fd
--- /dev/null
+++ b/src/assetbundles/usermanual/dist/js/UserManual.js
@@ -0,0 +1,11 @@
+/**
+ * usermanual plugin for Craft CMS
+ *
+ * usermanual JS
+ *
+ * @author Rob Erskine
+ * @copyright Copyright (c) 2018 Rob Erskine
+ * @link https://twitter.com/erskinerob
+ * @package Usermanual
+ * @since 2.0.0
+ */
diff --git a/src/config.php b/src/config.php
new file mode 100644
index 0000000..e51ccde
--- /dev/null
+++ b/src/config.php
@@ -0,0 +1,32 @@
+ null,
+ 'templateOverride' => null,
+ 'section' => null, // section ID (int) or handle (string)
+];
diff --git a/usermanual/resources/icon-mask.svg b/src/icon-mask.svg
similarity index 100%
rename from usermanual/resources/icon-mask.svg
rename to src/icon-mask.svg
diff --git a/usermanual/resources/icon.svg b/src/icon.svg
similarity index 100%
rename from usermanual/resources/icon.svg
rename to src/icon.svg
diff --git a/src/models/Settings.php b/src/models/Settings.php
new file mode 100644
index 0000000..e05a003
--- /dev/null
+++ b/src/models/Settings.php
@@ -0,0 +1,59 @@
+
+ {% set help = craft.entries.sectionId(sectionSelected) %}
+
+ {% nav page in help %}
+ {% set active = page.slug == craft.request.lastSegment or loop.first and craft.request.lastSegment == 'usermanual' %}
+