Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nukomeet/discourse-static-pages
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: ShareLex/discourse-static-pages
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 11 commits
  • 29 files changed
  • 3 contributors

Commits on Jun 8, 2016

  1. Add fr locale.

    bzg committed Jun 8, 2016
    Copy the full SHA
    38c88d6 View commit details

Commits on Jul 5, 2016

  1. Copy the full SHA
    eb088ee View commit details

Commits on Jul 12, 2016

  1. Copy the full SHA
    0acd62b View commit details
  2. Merge pull request #6 from LeoMcA/master

    Update to use new plugin api
    bzg authored Jul 12, 2016
    Copy the full SHA
    d990330 View commit details
  3. Copy the full SHA
    8f0484a View commit details

Commits on Nov 8, 2016

  1. Copy the full SHA
    bc2e44a View commit details

Commits on Nov 9, 2016

  1. Fix previous commit

    bzg committed Nov 9, 2016
    Copy the full SHA
    a699b68 View commit details

Commits on Dec 16, 2016

  1. Copy the full SHA
    b8927af View commit details
  2. added styling to pages [fixes #3]

    LeoMcA committed Dec 16, 2016
    Copy the full SHA
    5686ed7 View commit details

Commits on Dec 19, 2016

  1. Copy the full SHA
    5480ceb View commit details
  2. Copy the full SHA
    07d6cf5 View commit details
Showing with 234 additions and 54 deletions.
  1. +2 −2 README.md
  2. +5 −1 app/controllers/static_pages/admin_pages_controller.rb
  3. +6 −0 app/controllers/static_pages/pages_controller.rb
  4. +13 −0 app/models/static_pages/page.rb
  5. +11 −5 assets/javascripts/admin/models/page.js.es6
  6. +0 −1 assets/javascripts/discourse/admin-pages-route-map.js.es6
  7. +1 −1 assets/javascripts/discourse/controllers/admin-plugins-pages-index.js.es6
  8. +19 −0 assets/javascripts/discourse/helpers/cook.js.es6
  9. +10 −10 assets/javascripts/discourse/initializers/static-pages-menu.js.es6
  10. +37 −0 assets/javascripts/discourse/initializers/static-pages-routing.js.es6
  11. +4 −2 assets/javascripts/discourse/models/page.js.es6
  12. +5 −7 assets/javascripts/discourse/pages-route-map.js.es6
  13. +7 −2 assets/javascripts/discourse/routes/admin-plugins-pages-edit.js.es6
  14. +0 −4 assets/javascripts/discourse/routes/admin-plugins-pages-index.js.es6
  15. +9 −2 assets/javascripts/discourse/routes/admin-plugins-pages-new.js.es6
  16. +4 −3 assets/javascripts/discourse/routes/pages-show.js.es6
  17. +17 −1 assets/javascripts/discourse/templates/admin/plugins-pages-form.hbs
  18. +11 −4 assets/javascripts/discourse/templates/admin/plugins-pages-index.hbs
  19. +3 −1 assets/javascripts/discourse/templates/admin/plugins-pages.hbs
  20. +0 −5 assets/javascripts/discourse/templates/connectors/site-map-links/static-pages.hbs
  21. +4 −1 assets/javascripts/discourse/templates/pages/show.hbs
  22. +18 −0 assets/stylesheets/static_pages.scss
  23. +2 −0 config/locales/client.en.yml
  24. +20 −0 config/locales/client.fr.yml
  25. +3 −0 config/locales/server.fr.yml
  26. +1 −0 config/routes.rb
  27. +6 −0 db/migrate/20160922130233_add_stylesheet_to_static_pages_pages.rb
  28. +6 −0 db/migrate/20161216200136_add_path_to_static_pages_pages.rb
  29. +10 −2 plugin.rb
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,11 +4,11 @@ Static pages plugin for Discourse

## Installation

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`.
Follow the Discourse plugin [installation guide](https://meta.discourse.org/t/install-a-plugin/19157) using `git clone https://github.com/Sharelex/discourse-static-pages.git`.

## Development

```
cd plugins
git clone https://github.com/nukomeet/discourse-static-pages.git
git clone https://github.com/Sharelex/discourse-static-pages.git
```
6 changes: 5 additions & 1 deletion app/controllers/static_pages/admin_pages_controller.rb
Original file line number Diff line number Diff line change
@@ -6,6 +6,10 @@ def index
render_json_dump(pages: Page.all)
end

def greatest_id
render_json_dump(id: Page.maximum(:id))
end

def create
page = Page.new(page_params)
page.save!
@@ -32,7 +36,7 @@ def destroy
private

def page_params
params.require(:page).permit(:title, :body)
params.require(:page).permit(:title, :body, :stylesheet, :path)
end
end
end
6 changes: 6 additions & 0 deletions app/controllers/static_pages/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -8,5 +8,11 @@ def show
page = Page.find(params[:id])
render_json_dump(page: page)
end

def route
normalized_path = params[:path].sub(/^\//, '').sub(/\/$/, '')
page = Page.where(path: normalized_path).first
render_json_dump(page: page)
end
end
end
13 changes: 13 additions & 0 deletions app/models/static_pages/page.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
module StaticPages
class Page < ActiveRecord::Base

def compile_stylesheet(scss)
DiscourseSassCompiler.compile("@import \"theme_variables\";\n" << scss, 'custom')
rescue => e
puts e.backtrace.join("\n") unless Sass::SyntaxError === e
raise e
end

before_save do
self.stylesheet_baked = compile_stylesheet(self.stylesheet) if self.stylesheet
self.path = path.sub(/^\//, '').sub(/\/$/, '') if self.path
end

end
end
16 changes: 11 additions & 5 deletions assets/javascripts/admin/models/page.js.es6
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
import { ajax } from 'discourse/lib/ajax';

export default {
findAll() {
return Discourse.ajax('/pages/admin/pages');
return ajax('/pages/admin/pages');
},

findById(id) {
return Discourse.ajax(`/pages/admin/pages/${id}`);
return ajax(`/pages/admin/pages/${id}`);
},

findGreatestId() {
return ajax('/pages/admin/pages/greatestId')
},

create(model) {
return Discourse.ajax('/pages/admin/pages', {
return ajax('/pages/admin/pages', {
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({ page: model })
});
},

update(model) {
return Discourse.ajax(`/pages/admin/pages/${model.id}`, {
return ajax(`/pages/admin/pages/${model.id}`, {
method: 'PATCH',
contentType: 'application/json',
data: JSON.stringify({ page: model })
})
},

delete(model) {
return Discourse.ajax(`/pages/admin/pages/${model.id}`, {
return ajax(`/pages/admin/pages/${model.id}`, {
method: 'DELETE'
});
}
1 change: 0 additions & 1 deletion assets/javascripts/discourse/admin-pages-route-map.js.es6
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export default {
resource: 'admin.adminPlugins',
path: '/plugins',
map() {
this.route('pages', function () {
this.route('new');
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Page from '../../admin/models/page';

export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
sortProperties: ['updated_at'],
sortAscending: false,

19 changes: 19 additions & 0 deletions assets/javascripts/discourse/helpers/cook.js.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { default as PrettyText } from 'pretty-text/pretty-text';
import { emojiUnescape } from 'discourse/lib/text';

export default Ember.Helper.helper(function ([body]) {
return new Handlebars.SafeString(
emojiUnescape(
new PrettyText(
{
sanitize: false,
features: {
'bold-italics': true,
'auto-link': true,
'newline': true
}
}
).cook(body)
)
);
})
20 changes: 10 additions & 10 deletions assets/javascripts/discourse/initializers/static-pages-menu.js.es6
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import HamburgerMenuComponent from 'discourse/components/hamburger-menu';
import { withPluginApi } from 'discourse/lib/plugin-api';
import Page from '../../discourse/models/page';

export default {
name: 'static-pages-menu',

initialize: function() {
HamburgerMenuComponent.reopen({
didInsertElement() {
Page.findAll()
.then((result) => {
this.set('staticPages', result.pages);
});

this.set('staticPages', [{ title: 'Testing', id: 123 }]);
}
});
withPluginApi('0.1', api => {
Page.findAll().then(result => {
result.pages.forEach(page => {
api.decorateWidget('hamburger-menu:generalLinks', () => (
{ href: '/pages/'+page.id, rawLabel: page.title }
))
})
})
})
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { withPluginApi } from 'discourse/lib/plugin-api';
import { ajax } from 'discourse/lib/ajax';

export default {
name: 'static-pages-routing',

initialize: function () {

withPluginApi('0.1', api => {
const UnknownRoute = api.container.lookupFactory('route:unknown')
UnknownRoute.reopen({

model (params) {
var normalized_path = params.path.replace(/^\//, '').replace(/\/$/, '')
return ajax('/' + normalized_path).then(result => {
if (result.page && result.page.path == normalized_path) {
return result.page
} else {
return ajax("/404-body", { dataType: 'html' });
}
}).catch(() => {
return ajax("/404-body", { dataType: 'html' });
})
},

renderTemplate (controller, model) {
if (model.path) {
this.render('pages/show', { model: model })
} else {
this._super(controller, model)
}
}

})
})
}
};
6 changes: 4 additions & 2 deletions assets/javascripts/discourse/models/page.js.es6
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ajax } from 'discourse/lib/ajax';

export default {
findAll() {
return Discourse.ajax('/pages');
return ajax('/pages');
},

findById(id) {
return Discourse.ajax(`/pages/${id}`);
return ajax(`/pages/${id}`);
}
};
12 changes: 5 additions & 7 deletions assets/javascripts/discourse/pages-route-map.js.es6
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export default {
resource: 'pages',
path: '/pages',
map() {
this.route('show', { path: ':id' });
}
};
export default function () {
this.route('pages', function () {
this.route('show', { path: '/:id' });
})
}
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@ import Page from '../../admin/models/page';
export default Discourse.Route.extend({
actions: {
update() {
const { id, title, body } = this.controller.model;
const { id, title, body, stylesheet, path } = this.controller.model;

Page.update({ id, title, body })
Page.update({ id, title, body, stylesheet, path })
.then(() => {
this.transitionTo('adminPlugins.pages.index');
})
@@ -23,5 +23,10 @@ export default Discourse.Route.extend({
return Page.findById(params.id).then((result) => {
return result.page;
});
},

setupController: function(controller, model) {
controller.set('model', model);
controller.set('pathPlaceholder', `/pages/${model.id}`)
}
});
Original file line number Diff line number Diff line change
@@ -5,9 +5,5 @@ export default Discourse.Route.extend({
return Page.findAll().then((result) => {
return result.pages;
});
},

setupController(controller, model) {
controller.setProperties({ model });
}
});
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@ import Page from '../../admin/models/page';
export default Discourse.Route.extend({
actions: {
create() {
const { title, body } = this.controller.model;
const { title, body, stylesheet, path } = this.controller.model;

Page.create({ title, body })
Page.create({ title, body, stylesheet, path })
.then(() => {
this.transitionTo('adminPlugins.pages.index');
})
@@ -21,5 +21,12 @@ export default Discourse.Route.extend({

model() {
return {};
},

setupController: function(controller, model) {
controller.set('model', model);
Page.findGreatestId().then(result => {
controller.set('pathPlaceholder', `/pages/${result.id + 1}`)
})
}
});
7 changes: 4 additions & 3 deletions assets/javascripts/discourse/routes/pages-show.js.es6
Original file line number Diff line number Diff line change
@@ -7,8 +7,9 @@ export default Discourse.Route.extend({
});
},

setupController(controller, model) {
model.body = new Handlebars.SafeString(Discourse.Markdown.cook(model.body));
controller.setProperties({ model });
redirect(model) {
if (model.path) {
this.replaceWith('unknown', model)
}
}
});
Original file line number Diff line number Diff line change
@@ -6,6 +6,14 @@
{{input type="text" name="title" value=model.title required="true"}}
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2" for="path">
{{i18n 'static_pages.path'}}
</label>
<div class="col-lg-10">
{{input type="text" name="path" value=model.path placeholder=pathPlaceholder}}
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2" for="body">
{{i18n 'static_pages.body'}}
@@ -14,4 +22,12 @@
{{d-editor name="body" value=model.body required="true"}}
</div>
</div>
<input type="hidden" name="id" {{bind-attr value=model.id}} id="id" />
<div class="form-group">
<label class="control-label col-lg-2" for="stylesheet">
{{i18n 'static_pages.stylesheet'}}
</label>
<div class="col-lg-10">
{{ace-editor content=model.stylesheet mode="scss" name="stylesheet"}}
</div>
</div>
<input type="hidden" name="id" value={{model.id}} id="id" />
Original file line number Diff line number Diff line change
@@ -3,25 +3,32 @@
<thead>
<tr>
<th>{{i18n 'static_pages.page'}}</th>
<th>{{i18n 'static_pages.path'}}</th>
<th>{{i18n 'static_pages.created'}}</th>
<th>{{i18n 'static_pages.updated'}}</th>
<th>{{i18n 'static_pages.actions'}}</th>
</tr>
</thead>
<tbody>
{{#each page in model}}
{{#each model as |page|}}
<tr>
<td>
{{page.title}}
</td>
<td>
{{page.created_at}}
{{#if page.path}}
{{#link-to 'unknown' page.path}}{{page.path}}{{/link-to}}
{{else}}
{{#link-to 'pages.show' page.id}}pages/{{page.id}}{{/link-to}}
{{/if}}
</td>
<td>
{{page.updated_at}}
{{age-with-tooltip page.created_at}}
</td>
<td>
{{age-with-tooltip page.updated_at}}
</td>
<td>
{{#link-to 'pages.show' page.id class="btn"}}{{i18n 'static_pages.view'}}{{/link-to}}
{{#link-to 'adminPlugins.pages.edit' page.id class="btn btn-primary"}}{{i18n 'static_pages.edit'}}{{/link-to}}
<button class="btn" {{action 'delete' page}}>{{i18n 'static_pages.delete'}}</button>
</td>
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{{outlet}}
<div class="admin-static-pages">
{{outlet}}
</div>

This file was deleted.

5 changes: 4 additions & 1 deletion assets/javascripts/discourse/templates/pages/show.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<style>
{{model.stylesheet_baked}}
</style>
<div class="static-page">
<h1>{{model.title}}</h1>

{{model.body}}
{{cook model.body}}
</div>
Loading