From 989a9e5aefe4f92a5398bbf0d89116d7002e4738 Mon Sep 17 00:00:00 2001 From: Anis SAJED Date: Sat, 18 Apr 2015 21:35:56 +0000 Subject: [PATCH 1/2] EJS views --- lib/app.js | 9 +++- lib/config.js | 1 + package.json | 1 + views/404.ejs | 7 +++ views/500.ejs | 8 +++ views/compare.ejs | 25 +++++++++ views/create.ejs | 100 +++++++++++++++++++++++++++++++++++ views/edit.ejs | 129 ++++++++++++++++++++++++++++++++++++++++++++++ views/history.ejs | 40 ++++++++++++++ views/index.ejs | 4 ++ views/layout.ejs | 102 ++++++++++++++++++++++++++++++++++++ views/list.ejs | 42 +++++++++++++++ views/login.ejs | 57 ++++++++++++++++++++ views/preview.ejs | 3 ++ views/search.ejs | 24 +++++++++ views/show.ejs | 68 ++++++++++++++++++++++++ views/syntax.ejs | 69 +++++++++++++++++++++++++ views/welcome.ejs | 8 +++ 18 files changed, 696 insertions(+), 1 deletion(-) create mode 100644 views/404.ejs create mode 100644 views/500.ejs create mode 100644 views/compare.ejs create mode 100644 views/create.ejs create mode 100644 views/edit.ejs create mode 100644 views/history.ejs create mode 100644 views/index.ejs create mode 100644 views/layout.ejs create mode 100644 views/list.ejs create mode 100644 views/login.ejs create mode 100644 views/preview.ejs create mode 100644 views/search.ejs create mode 100644 views/show.ejs create mode 100644 views/syntax.ejs create mode 100644 views/welcome.ejs diff --git a/lib/app.js b/lib/app.js index 6a5f7aa9..355901f9 100644 --- a/lib/app.js +++ b/lib/app.js @@ -128,7 +128,14 @@ module.exports.initialize = function(config) { app.use(expValidator()); app.set('views', __dirname + '/../views'); - app.set('view engine', 'jade'); + + if (config.get("application").EJSViews){ + app.set('view engine', 'ejs'); + app.engine('ejs', require("ejs-mate")); + } + else { + app.set('view engine', 'jade'); + } app.use(function (req, res, next) { diff --git a/lib/config.js b/lib/config.js index 8d005b8f..3e43a113 100644 --- a/lib/config.js +++ b/lib/config.js @@ -57,6 +57,7 @@ module.exports = (function() { git: "git", skipGitCheck: false, loggingMode: 1, + EJSViews: false, pedanticMarkdown: true, staticWhitelist: "/\\.png$/i, /\\.jpg$/i, /\\.gif$/i" }, diff --git a/package.json b/package.json index e2aad03a..54139867 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "gravatar": "^1.1.0", "iconv": "*", "jade": "*", + "ejs-mate": "*", "js-yaml": "^3.1.0", "lodash": "^2.4.1", "marked": "^0.3.2", diff --git a/views/404.ejs b/views/404.ejs new file mode 100644 index 00000000..4f38e900 --- /dev/null +++ b/views/404.ejs @@ -0,0 +1,7 @@ +<% layout('layout') -%> +
+
+

<%= title %>

+

The requested resource is not available

+
+
diff --git a/views/500.ejs b/views/500.ejs new file mode 100644 index 00000000..e9116599 --- /dev/null +++ b/views/500.ejs @@ -0,0 +1,8 @@ +<% layout('layout') -%> +
+
+

<%= title %>

+
<%= error %>
+

<%= message %>

+
+
diff --git a/views/compare.ejs b/views/compare.ejs new file mode 100644 index 00000000..b166d136 --- /dev/null +++ b/views/compare.ejs @@ -0,0 +1,25 @@ +<% layout('layout') -%> +
+

Compare two revisions of:  + <%= page.title %> +

+ + +<% + lines.forEach(function(line){ -%> + + + + + +<% + }); -%> +
<%= line.ldln %><%= line.rdln %><%= line.text %>
+
diff --git a/views/create.ejs b/views/create.ejs new file mode 100644 index 00000000..cfca7617 --- /dev/null +++ b/views/create.ejs @@ -0,0 +1,100 @@ +<% layout('layout') -%> +<% var str = ""; +if (hasFeature('markitup')){ + str = str + '\ + \n\ + \n\ + \n'; +} +if (hasFeature('codemirror')){ + str = str + '\ + \n\ + \n'; +} +block('styles').append(str) %> + +
+<% + var errors = locals.errors; + if ((typeof(errors) != 'undefined' && Object.keys(errors).length > 0)){ %> +
+
    + <% errors.forEach(function(v){ -%> +
  • <%= v.msg || v %>
  • +<% }) -%> +
+
+<% + } -%> +

Create a new page

+
+ +
+ +
+
+ +
+
+ +   + Cancel +
+
+
+ + + +<% var str = ""; +if (hasFeature('markitup')){ + str = str + '\ + \n\ + \n\ + \n\ + \n\ + ' +} +if (hasFeature('codemirror')){ + str = str + '\ + \n\ + ' +} +block('scripts').append(str) %> diff --git a/views/edit.ejs b/views/edit.ejs new file mode 100644 index 00000000..8aec9d0a --- /dev/null +++ b/views/edit.ejs @@ -0,0 +1,129 @@ +<% layout('layout') -%> +<% var style = ""; +if (hasFeature('markitup')){ + style = style + '\ + \n\ + \n\ + \n'; +} +if (hasFeature('codemirror')){ + style = style + '\ + \n\ + \n'; +} +block('styles').append(style); + +var tools = '\ + \n'; + +block('tools').append(tools) -%> +
+<% + var errors = locals.errors; + if (typeof(errors) != 'undefined' && Object.keys(errors).length > 0){ -%> +
+
    + <% errors.forEach(function(v){ -%> +
  • <%= v.msg || v %>
  • + <% }) -%> +
+
+<% + } + + var warning = locals.warning; + if (typeof(warning) != 'undefined'){ -%> +
+ <%- warning %> +
+<% + } -%> +

Edit page

+
+
+ + +
+
+ +
+
+ +
+
+ +   + Cancel +
+
+
+ + +<% var scripts = ""; +if (hasFeature('markitup')){ + scripts = scripts + '\ + \n\ + \n\ + \n\ + \n\ + \n'; +} + +if (hasFeature('codemirror')){ + scripts = scripts + '\ + \n\ + \n'; +} + +block('scripts').append(scripts) -%> diff --git a/views/history.ejs b/views/history.ejs new file mode 100644 index 00000000..2a00e45c --- /dev/null +++ b/views/history.ejs @@ -0,0 +1,40 @@ +<% layout('layout'); + +var tools = '\ + \n'; + +block('tools').append(tools); %> + +
+

Revisions of:  + <%= page.title %> +

+

+ +

+ +<% + items.forEach(function(item){ -%> + + + + + + + +<% + }); -%> +
+<% if (item.email) { -%> + +   +<% }; -%> + <%= item.author %> + <%= item.relDate %><%= item.subject %>
+
diff --git a/views/index.ejs b/views/index.ejs new file mode 100644 index 00000000..3e18769c --- /dev/null +++ b/views/index.ejs @@ -0,0 +1,4 @@ +<% layout('layout') -%> +
+

Welcome to <%= title %>

+
diff --git a/views/layout.ejs b/views/layout.ejs new file mode 100644 index 00000000..ea0ce4e9 --- /dev/null +++ b/views/layout.ejs @@ -0,0 +1,102 @@ +<% /*# TODO trouver comment require mixins/form.jade */ -%> + + + + + + + <%= title%> + + + + + +<%- block('styles').toString() -%> +<% + if (hasCustomStyle()){ -%> + +<% + } -%> + + +<% var term_ph = (typeof term == "undefined" ? "" : term) -%> + + +
+<%- block('tools').toString() -%> +
+ +
+
+<% if (hasSidebar()) { -%> +
+
+<%- _sidebar -%> +
+
+<% } + else { -%> +
+<% } -%> +
+<%- body -%> +
+
+<% if (hasFooter()) { -%> +
+
+ +
+
+<% } -%> +
+ + + + + + +<%- block('scripts').toString() %> +<% + if (hasCustomScript()) { -%> + +<% + } -%> + + diff --git a/views/list.ejs b/views/list.ejs new file mode 100644 index 00000000..a27aadfe --- /dev/null +++ b/views/list.ejs @@ -0,0 +1,42 @@ +<% layout('layout') -%> + +
+

Document list – Most recent updates shown first

+ + +
diff --git a/views/login.ejs b/views/login.ejs new file mode 100644 index 00000000..3bee610f --- /dev/null +++ b/views/login.ejs @@ -0,0 +1,57 @@ +<% layout('layout'); -%> +
+

Choose your authentication method

+<% +if (auth.google.enabled){ -%> +

Google login

+<% +} + +if (auth.github.enabled){ -%> +

Github login

+<% +} + +if (auth.google.enabled || auth.github.enabled){ -%> +

Cancel

+<% +} + +var errors = locals.errors; +if (typeof(errors) != 'undefined' && Object.keys(errors).length > 0){ %> +
+
    +<% errors.forEach(function(v){ -%> +
  • <%= v.msg || v %>
  • +<% }) -%> +
+
+<% +} + +if (auth.alone.enabled){ -%> +

+

Authenticate locally

+

+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+  or cancel +
+
+
+<% +} -%> +
diff --git a/views/preview.ejs b/views/preview.ejs new file mode 100644 index 00000000..5a4ba040 --- /dev/null +++ b/views/preview.ejs @@ -0,0 +1,3 @@ +
+ <%- content %> +
diff --git a/views/search.ejs b/views/search.ejs new file mode 100644 index 00000000..8589a39f --- /dev/null +++ b/views/search.ejs @@ -0,0 +1,24 @@ +<% layout('layout') -%> + +
+<% + var warning = locals.warning; + if (typeof(warning) != 'undefined'){ %> +
+ <%- warning %> +
+<% + } -%> +

Search results for <%= term %>

+
+<% + matches.forEach(function(match){ -%> +
+ + <%= match.line %> +
+
<%= match.text %>
+<% + }) -%> +
+
diff --git a/views/show.ejs b/views/show.ejs new file mode 100644 index 00000000..ab779146 --- /dev/null +++ b/views/show.ejs @@ -0,0 +1,68 @@ +<% layout('layout'); + +var tools = '\ + \n'; + +block('tools').append(tools) -%> + +
+<% +var notice = locals.notice; +if (typeof(notice) != 'undefined') { %> +
+ <%- notice %> +
+<% +} + +var warning = locals.warning; +if (typeof(warning) != 'undefined'){ %> +
+ <%- warning %> +
+<% +} -%> + +<%- content %> + + + diff --git a/views/syntax.ejs b/views/syntax.ejs new file mode 100644 index 00000000..85db0b75 --- /dev/null +++ b/views/syntax.ejs @@ -0,0 +1,69 @@ +
+
+
+

Format Text

+

Headers

+
# This is an <h1> tag
+## This is an <h2> tag
+###### This is an <h6> tag
+

Text styles

+
*This text will be italic*
+_This will also be italic_
+**This text will be bold**
+__This will also be bold__
+*You **can** combine them*
+
+
+

Lists

+

Unordered

+
* Item 1
+* Item 2
+* Item 2a
+* Item 2b
+

Ordered

+
1. Item 1
+2. Item 2
+3. Item 3
+  * Item 3a
+  * Item 3b
+
+
+

Miscellaneous

+

Images

+
![GitHub Logo](/images/logo.png)
+Format: ![Alt Text](url)
+

Links

+
|http://github.com - automatic!
+[GitHub](http://github.com)
+

Blockquotes

+
As Kanye West said:
+> We're living the future so
+> the present is our past.
+
+
+
+

Code Examples in Markdown

+
+

Syntax highlighting with GFM

+
```javascript
+function fancyAlert(arg) {
+ if(arg) {
+   $.facebox({div:'#foo'})
+ }
+}
+```
+
+
+

Or, indent your code 4 spaces

+
Here is a Python code example
+without syntax highlighting:
+def foo:
+if not bar:
+ return true
+
+
+

Inline code for comments

+
I think you should use an
+`<addr>` element here instead.
+
+
diff --git a/views/welcome.ejs b/views/welcome.ejs new file mode 100644 index 00000000..b1da0c7b --- /dev/null +++ b/views/welcome.ejs @@ -0,0 +1,8 @@ +<% layout('layout') -%> +
+
+

Welcome to the wiki

+

This page doesn't (yet) exist. You should first login and then you'll be redirected to the editor so that you can create the front page.

+

Login and start adding content!

+
+
From 0c626947e9c443dcfa3ccc70120ef3cefa77448a Mon Sep 17 00:00:00 2001 From: Anis SAJED Date: Sat, 18 Apr 2015 21:51:27 +0000 Subject: [PATCH 2/2] improving readability --- lib/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config.js b/lib/config.js index 3e43a113..d624663e 100644 --- a/lib/config.js +++ b/lib/config.js @@ -57,7 +57,7 @@ module.exports = (function() { git: "git", skipGitCheck: false, loggingMode: 1, - EJSViews: false, + EJSViews: false, pedanticMarkdown: true, staticWhitelist: "/\\.png$/i, /\\.jpg$/i, /\\.gif$/i" },