Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #26, preview broken

  • Loading branch information...
commit 0e0619ec02652c78a946b151961d398d02365010 1 parent deb40a6
@cgay cgay authored
View
2  dylan/access.dylan
@@ -364,7 +364,7 @@ define tag show-rules in wiki
end tag show-rules;
define named-method can-view-content? in wiki
- (acls-page :: <wiki-dsp>)
+ (page :: <wiki-dsp>)
has-permission?(authenticated-user(), *page*, $view-content)
end;
View
1  dylan/main.dylan
@@ -234,7 +234,6 @@ define function restore-from-text-files
page := make(<wiki-page>,
title: title,
source: source,
- parsed-source: parse-wiki-markup(source, title),
owner: author);
end;
store(*storage*, page, author, comment, standard-meta-data(page, "create"));
View
77 dylan/page.dylan
@@ -15,7 +15,7 @@ define class <wiki-page> (<wiki-object>)
// A sequence of <string>s (of RST source) or <wiki-reference>s.
constant slot page-parsed-source :: <sequence>,
- required-init-keyword: parsed-source:;
+ init-keyword: parsed-source:;
// Comment entered by the user describing the changes for this revision.
constant slot page-comment :: <string>,
@@ -31,13 +31,13 @@ define class <wiki-page> (<wiki-object>)
constant slot page-author :: <wiki-user>,
required-init-keyword: author:;
- // Tags (strings) entered by the author when the page was saved.
- constant slot page-tags :: <sequence>,
- required-init-keyword: tags:;
-
slot page-access-controls :: <acls>,
required-init-keyword: access-controls:;
+ // Tags (strings) entered by the author when the page was saved.
+ constant slot page-tags :: <sequence> = #(),
+ init-keyword: tags:;
+
// e.g. a git commit hash or a revision number
// Filled in by the storage back-end.
slot page-revision :: <string>,
@@ -46,6 +46,36 @@ define class <wiki-page> (<wiki-object>)
end class <wiki-page>;
+/// Provide defaulting and a copy-from argument.
+define method make
+ (class == <wiki-page>,
+ #rest args,
+ #key copy-from :: false-or(<wiki-page>),
+ name, source, parsed-source, comment, owner,
+ author, tags, access-controls, revision)
+ => (page :: <wiki-page>)
+ let p = copy-from;
+ let name = name | (p & p.object-name);
+ let source = source | (p & p.page-source);
+ let owner = owner | (p & p.page-owner) | author;
+ apply(next-method,
+ class,
+ name: name,
+ source: source,
+ parsed-source: parsed-source
+ | (source & parse-wiki-markup(source, name))
+ | (p & p.parsed-source),
+ comment: comment | "",
+ owner: owner,
+ author: author | (p & p.page-author) | owner,
+ tags: tags | (p & p.page-tags) | #(),
+ access-controls: access-controls
+ | (p & p.page-access-controls)
+ | $default-access-controls,
+ args)
+end method make;
+
+
// back compat
define inline function page-title
(page :: <wiki-page>) => (title :: <string>)
@@ -178,14 +208,12 @@ define method save-page
let user = authenticated-user();
let old-page = find-page(title);
let page = make(<wiki-page>,
+ copy-from: old-page,
name: title,
source: source,
- parsed-source: parse-wiki-markup(source, title),
- tags: tags | #(),
+ tags: tags,
comment: comment,
- author: user,
- owner: user,
- access-controls: $default-access-controls);
+ author: user);
update-reference-tables!(page,
iff(old-page,
outbound-references(old-page),
@@ -497,7 +525,8 @@ define method respond-to-post
(wiki-dsp :: <edit-page-page>, #key title :: <string>)
let title = percent-decode(title);
let page = find-or-load-page(title);
- with-query-values (content as source, comment, tags, button)
+ with-query-values (content, comment, tags, button)
+ let source = content | "";
let tags = iff(tags, parse-tags(tags), #[]);
let previewing? = (button = "Preview");
let author = authenticated-user();
@@ -514,25 +543,25 @@ define method respond-to-post
end;
if (previewing? | page-has-errors?())
- set-attribute(page-context(), "previewing?", #t);
- set-attribute(page-context(), "title", title);
- process-template(wiki-dsp);
+ dynamic-bind (*page* = make(<wiki-page>,
+ copy-from: page,
+ name: title,
+ source: source,
+ comment: comment,
+ author: author))
+ let pc = page-context();
+ set-attribute(pc, "previewing?", #t);
+ set-attribute(pc, "title", title);
+ set-attribute(pc, "preview", as-html(source, title));
+ process-template(wiki-dsp);
+ end;
else
- let page = save-page(title, source | "", comment, tags);
+ let page = save-page(title, source, comment, tags);
redirect-to(page);
end;
end;
end method respond-to-post;
-define tag show-page-preview in wiki
- (page :: <edit-page-page>)
- ()
- // TODO: change this to "source"
- let markup = get-query-value("content");
- let title = get-query-value("title");
- output("%s", as-html(markup, title));
-end;
-
//// View Diff
View
6 dylan/rst-parser.dylan
@@ -29,6 +29,12 @@ define method as-html
rst2html(map(as-rst, page.page-parsed-source))
end method as-html;
+define method as-html
+ (source :: <string>, title :: <string>)
+ => (html :: <string>)
+ rst2html(map(as-rst, parse-wiki-markup(source, title)))
+end;
+
/// Parse one unit of wiki markup. Normally that means a page. When
/// one page is included in another, the included page is not part of
View
2  www/dsp/edit-page.dsp
@@ -27,7 +27,7 @@
<div class="preview">
<dsp:if test="can-view-content?">
<dsp:then>
- <wiki:show-page-preview/>
+ <dsp:get name="preview" context="page" raw="true"/>
<%dsp:include url="view-page-tags.dsp"/>
</dsp:then>
<dsp:else>
Please sign in to comment.
Something went wrong with that request. Please try again.