├── README.md ├── app ├── controllers │ └── static_pages │ │ ├── admin_pages_controller.rb │ │ └── pages_controller.rb └── models │ └── static_pages │ └── page.rb ├── assets ├── javascripts │ ├── admin │ │ └── models │ │ │ └── page.js.es6 │ └── discourse │ │ ├── admin-pages-route-map.js.es6 │ │ ├── controllers │ │ └── admin-plugins-pages-index.js.es6 │ │ ├── initializers │ │ └── static-pages-menu.js.es6 │ │ ├── models │ │ └── page.js.es6 │ │ ├── pages-route-map.js.es6 │ │ ├── routes │ │ ├── admin-plugins-pages-edit.js.es6 │ │ ├── admin-plugins-pages-index.js.es6 │ │ ├── admin-plugins-pages-new.js.es6 │ │ └── pages-show.js.es6 │ │ └── templates │ │ ├── admin │ │ ├── plugins-pages-edit.hbs │ │ ├── plugins-pages-form.hbs │ │ ├── plugins-pages-index.hbs │ │ ├── plugins-pages-new.hbs │ │ └── plugins-pages.hbs │ │ ├── connectors │ │ └── site-map-links │ │ │ └── static-pages.hbs │ │ └── pages │ │ └── show.hbs └── stylesheets │ └── static_pages.scss ├── config ├── locales │ ├── client.en.yml │ └── server.en.yml ├── routes.rb └── settings.yml ├── db └── migrate │ └── 20151005185946_create_pages.rb ├── lib ├── pages.rb └── pages │ └── engine.rb └── plugin.rb /README.md: -------------------------------------------------------------------------------- 1 | # discourse-static-pages 2 | 3 | Static pages plugin for Discourse 4 | 5 | ## Installation 6 | 7 | Follow the Discourse plugin [installation guide](https://meta.discourse.org/t/install-a-plugin/19157) using `git clone https://github.com/nukomeet/discourse-static-pages.git`. 8 | 9 | ## Development 10 | 11 | ``` 12 | cd plugins 13 | git clone https://github.com/nukomeet/discourse-static-pages.git 14 | ``` 15 | -------------------------------------------------------------------------------- /app/controllers/static_pages/admin_pages_controller.rb: -------------------------------------------------------------------------------- 1 | module StaticPages 2 | class AdminPagesController < Admin::AdminController 3 | requires_plugin 'static-pages' 4 | 5 | def index 6 | render_json_dump(pages: Page.all) 7 | end 8 | 9 | def create 10 | page = Page.new(page_params) 11 | page.save! 12 | render_json_dump(page: page) 13 | end 14 | 15 | def show 16 | page = Page.find(params[:id]) 17 | render_json_dump(page: page) 18 | end 19 | 20 | def update 21 | page = Page.find(params[:id]) 22 | page.update_attributes!(page_params) 23 | render_json_dump(page: page) 24 | end 25 | 26 | def destroy 27 | page = Page.find(params[:id]) 28 | page.delete 29 | render nothing: true, status: 204 30 | end 31 | 32 | private 33 | 34 | def page_params 35 | params.require(:page).permit(:title, :body) 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /app/controllers/static_pages/pages_controller.rb: -------------------------------------------------------------------------------- 1 | module StaticPages 2 | class PagesController < ApplicationController 3 | def index 4 | render_json_dump(pages: Page.all) 5 | end 6 | 7 | def show 8 | page = Page.find(params[:id]) 9 | render_json_dump(page: page) 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/models/static_pages/page.rb: -------------------------------------------------------------------------------- 1 | module StaticPages 2 | class Page < ActiveRecord::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /assets/javascripts/admin/models/page.js.es6: -------------------------------------------------------------------------------- 1 | export default { 2 | findAll() { 3 | return Discourse.ajax('/pages/admin/pages'); 4 | }, 5 | 6 | findById(id) { 7 | return Discourse.ajax(`/pages/admin/pages/${id}`); 8 | }, 9 | 10 | create(model) { 11 | return Discourse.ajax('/pages/admin/pages', { 12 | method: 'POST', 13 | contentType: 'application/json', 14 | data: JSON.stringify({ page: model }) 15 | }); 16 | }, 17 | 18 | update(model) { 19 | return Discourse.ajax(`/pages/admin/pages/${model.id}`, { 20 | method: 'PATCH', 21 | contentType: 'application/json', 22 | data: JSON.stringify({ page: model }) 23 | }) 24 | }, 25 | 26 | delete(model) { 27 | return Discourse.ajax(`/pages/admin/pages/${model.id}`, { 28 | method: 'DELETE' 29 | }); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /assets/javascripts/discourse/admin-pages-route-map.js.es6: -------------------------------------------------------------------------------- 1 | export default { 2 | resource: 'admin.adminPlugins', 3 | path: '/plugins', 4 | map() { 5 | this.route('pages', function () { 6 | this.route('new'); 7 | this.route('edit', { path: ':id/edit' }); 8 | }); 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /assets/javascripts/discourse/controllers/admin-plugins-pages-index.js.es6: -------------------------------------------------------------------------------- 1 | import Page from '../../admin/models/page'; 2 | 3 | export default Ember.ArrayController.extend({ 4 | sortProperties: ['updated_at'], 5 | sortAscending: false, 6 | 7 | actions: { 8 | refresh() { 9 | Page.findAll() 10 | .then((result) => { 11 | this.set('model', result.pages); 12 | }); 13 | }, 14 | 15 | delete(model) { 16 | if (confirm('Are you sure?')) { 17 | this.set('model', this.get('model').filter((page) => page !== model)); 18 | Page.delete(model); 19 | } 20 | } 21 | } 22 | }); 23 | -------------------------------------------------------------------------------- /assets/javascripts/discourse/initializers/static-pages-menu.js.es6: -------------------------------------------------------------------------------- 1 | import HamburgerMenuComponent from 'discourse/components/hamburger-menu'; 2 | import Page from '../../discourse/models/page'; 3 | 4 | export default { 5 | name: 'static-pages-menu', 6 | 7 | initialize: function() { 8 | HamburgerMenuComponent.reopen({ 9 | didInsertElement() { 10 | Page.findAll() 11 | .then((result) => { 12 | this.set('staticPages', result.pages); 13 | }); 14 | 15 | this.set('staticPages', [{ title: 'Testing', id: 123 }]); 16 | } 17 | }); 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /assets/javascripts/discourse/models/page.js.es6: -------------------------------------------------------------------------------- 1 | export default { 2 | findAll() { 3 | return Discourse.ajax('/pages'); 4 | }, 5 | 6 | findById(id) { 7 | return Discourse.ajax(`/pages/${id}`); 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /assets/javascripts/discourse/pages-route-map.js.es6: -------------------------------------------------------------------------------- 1 | export default { 2 | resource: 'pages', 3 | path: '/pages', 4 | map() { 5 | this.route('show', { path: ':id' }); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /assets/javascripts/discourse/routes/admin-plugins-pages-edit.js.es6: -------------------------------------------------------------------------------- 1 | import Page from '../../admin/models/page'; 2 | 3 | export default Discourse.Route.extend({ 4 | actions: { 5 | update() { 6 | const { id, title, body } = this.controller.model; 7 | 8 | Page.update({ id, title, body }) 9 | .then(() => { 10 | this.transitionTo('adminPlugins.pages.index'); 11 | }) 12 | .catch(() => { 13 | alert('Error updating page.'); 14 | }); 15 | }, 16 | 17 | cancel() { 18 | this.transitionTo('adminPlugins.pages.index'); 19 | } 20 | }, 21 | 22 | model(params) { 23 | return Page.findById(params.id).then((result) => { 24 | return result.page; 25 | }); 26 | } 27 | }); 28 | -------------------------------------------------------------------------------- /assets/javascripts/discourse/routes/admin-plugins-pages-index.js.es6: -------------------------------------------------------------------------------- 1 | import Page from '../../admin/models/page'; 2 | 3 | export default Discourse.Route.extend({ 4 | model() { 5 | return Page.findAll().then((result) => { 6 | return result.pages; 7 | }); 8 | }, 9 | 10 | setupController(controller, model) { 11 | controller.setProperties({ model }); 12 | } 13 | }); 14 | -------------------------------------------------------------------------------- /assets/javascripts/discourse/routes/admin-plugins-pages-new.js.es6: -------------------------------------------------------------------------------- 1 | import Page from '../../admin/models/page'; 2 | 3 | export default Discourse.Route.extend({ 4 | actions: { 5 | create() { 6 | const { title, body } = this.controller.model; 7 | 8 | Page.create({ title, body }) 9 | .then(() => { 10 | this.transitionTo('adminPlugins.pages.index'); 11 | }) 12 | .catch(() => { 13 | alert('Error creating page.'); 14 | }); 15 | }, 16 | 17 | cancel() { 18 | this.transitionTo('adminPlugins.pages.index'); 19 | } 20 | }, 21 | 22 | model() { 23 | return {}; 24 | } 25 | }); 26 | -------------------------------------------------------------------------------- /assets/javascripts/discourse/routes/pages-show.js.es6: -------------------------------------------------------------------------------- 1 | import Page from '../models/page'; 2 | 3 | export default Discourse.Route.extend({ 4 | model(params) { 5 | return Page.findById(params.id).then((result) => { 6 | return result.page; 7 | }); 8 | }, 9 | 10 | setupController(controller, model) { 11 | model.body = new Handlebars.SafeString(Discourse.Markdown.cook(model.body)); 12 | controller.setProperties({ model }); 13 | } 14 | }); 15 | -------------------------------------------------------------------------------- /assets/javascripts/discourse/templates/admin/plugins-pages-edit.hbs: -------------------------------------------------------------------------------- 1 |
13 | -------------------------------------------------------------------------------- /assets/javascripts/discourse/templates/admin/plugins-pages-form.hbs: -------------------------------------------------------------------------------- 1 |{{i18n 'static_pages.page'}} | 6 |{{i18n 'static_pages.created'}} | 7 |{{i18n 'static_pages.updated'}} | 8 |{{i18n 'static_pages.actions'}} | 9 |
---|---|---|---|
15 | {{page.title}} 16 | | 17 |18 | {{page.created_at}} 19 | | 20 |21 | {{page.updated_at}} 22 | | 23 |24 | {{#link-to 'pages.show' page.id class="btn"}}{{i18n 'static_pages.view'}}{{/link-to}} 25 | {{#link-to 'adminPlugins.pages.edit' page.id class="btn btn-primary"}}{{i18n 'static_pages.edit'}}{{/link-to}} 26 | 27 | | 28 |