Skip to content

Commit

Permalink
Refactored HTML templates to use new layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaz committed Feb 21, 2011
1 parent 0d41271 commit 593ea57
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 84 deletions.
11 changes: 11 additions & 0 deletions Application/GBApplicationSettingsProvider.h
Expand Up @@ -334,10 +334,21 @@
/// @name Application-wide HTML helpers
///---------------------------------------------------------------------------------------

/** Returns a new string containing HTML representation of the given Markdown string.
The resulting string is not escaped!
@param markdown Markdown source string to convert.
@return Returns converted string.
@see stringByEscapingHTML:
*/
- (NSString *)stringByConvertingMarkdown:(NSString *)markdown;

/** Returns a new string by escaping the given HTML.
@param string HTML string to escape.
@return Returns escaped HTML string.
@see stringByConvertingMarkdown:
*/
- (NSString *)stringByEscapingHTML:(NSString *)string;

Expand Down
16 changes: 16 additions & 0 deletions Application/GBApplicationSettingsProvider.m
Expand Up @@ -6,6 +6,7 @@
// Copyright (C) 2010, Gentle Bytes. All rights reserved.
//

#include "mkdio.h"
#import <objc/runtime.h>
#import "RegexKitLite.h"
#import "GBDataObjects.h"
Expand Down Expand Up @@ -147,6 +148,21 @@ - (void)replaceAllOccurencesOfPlaceholderStringsInSettingsValues {

#pragma mark Common HTML handling

- (NSString *)stringByConvertingMarkdown:(NSString *)markdown {
NSString *result = nil;
MMIOT *document = mkd_string((char *)[markdown cStringUsingEncoding:NSUTF8StringEncoding], (int)[markdown length], 0);
mkd_compile(document, 0);
char *html = NULL;
int size = mkd_document(document, &html);
if (size <= 0) {
GBLogWarn(@"Failed converting markdown '%@' to HTML!", [markdown normalizedDescription]);
} else {
result = [NSString stringWithCString:html encoding:NSASCIIStringEncoding];
}
mkd_cleanup(document);
return result;
}

- (NSString *)stringByEscapingHTML:(NSString *)string {
// Copied directly from GRMustache's GRMustacheVariableElement.m...
NSMutableString *result = [NSMutableString stringWithCapacity:5 + ceilf(string.length * 1.1)];
Expand Down
106 changes: 106 additions & 0 deletions Libraries/Discount/mkdio.h
@@ -0,0 +1,106 @@
#ifndef _MKDIO_D
#define _MKDIO_D

#include <stdio.h>

typedef void MMIOT;

typedef unsigned int mkd_flag_t;

/* line builder for markdown()
*/
MMIOT *mkd_in(FILE*,mkd_flag_t); /* assemble input from a file */
MMIOT *mkd_string(char*,int,mkd_flag_t); /* assemble input from a buffer */

void mkd_basename(MMIOT*,char*);

void mkd_initialize();
void mkd_with_html5_tags();
void mkd_shlib_destructor();

/* compilation, debugging, cleanup
*/
int mkd_compile(MMIOT*, mkd_flag_t);
int mkd_cleanup(MMIOT*);

/* markup functions
*/
int mkd_dump(MMIOT*, FILE*, int, char*);
int markdown(MMIOT*, FILE*, mkd_flag_t);
int mkd_line(char *, int, char **, mkd_flag_t);
typedef int (*mkd_sta_function_t)(const int,const void*);
void mkd_string_to_anchor(char *, int, mkd_sta_function_t, void*, int);
int mkd_xhtmlpage(MMIOT*,int,FILE*);

/* header block access
*/
char* mkd_doc_title(MMIOT*);
char* mkd_doc_author(MMIOT*);
char* mkd_doc_date(MMIOT*);

/* compiled data access
*/
int mkd_document(MMIOT*, char**);
int mkd_toc(MMIOT*, char**);
int mkd_css(MMIOT*, char **);
int mkd_xml(char *, int, char **);

/* write-to-file functions
*/
int mkd_generatehtml(MMIOT*,FILE*);
int mkd_generatetoc(MMIOT*,FILE*);
int mkd_generatexml(char *, int,FILE*);
int mkd_generatecss(MMIOT*,FILE*);
#define mkd_style mkd_generatecss
int mkd_generateline(char *, int, FILE*, mkd_flag_t);
#define mkd_text mkd_generateline

/* url generator callbacks
*/
typedef char * (*mkd_callback_t)(const char*, const int, void*);
typedef void (*mkd_free_t)(char*, void*);

void mkd_e_url(void *, mkd_callback_t);
void mkd_e_flags(void *, mkd_callback_t);
void mkd_e_free(void *, mkd_free_t );
void mkd_e_data(void *, void *);

/* version#.
*/
extern char markdown_version[];
void mkd_mmiot_flags(FILE *, MMIOT *, int);
void mkd_flags_are(FILE*, mkd_flag_t, int);


/* special flags for markdown() and mkd_text()
*/
#define MKD_NOLINKS 0x00000001 /* don't do link processing, block <a> tags */
#define MKD_NOIMAGE 0x00000002 /* don't do image processing, block <img> */
#define MKD_NOPANTS 0x00000004 /* don't run smartypants() */
#define MKD_NOHTML 0x00000008 /* don't allow raw html through AT ALL */
#define MKD_STRICT 0x00000010 /* disable SUPERSCRIPT, RELAXED_EMPHASIS */
#define MKD_TAGTEXT 0x00000020 /* process text inside an html tag; no
* <em>, no <bold>, no html or [] expansion */
#define MKD_NO_EXT 0x00000040 /* don't allow pseudo-protocols */
#define MKD_CDATA 0x00000080 /* generate code for xml ![CDATA[...]] */
#define MKD_NOSUPERSCRIPT 0x00000100 /* no A^B */
#define MKD_NORELAXED 0x00000200 /* emphasis happens /everywhere/ */
#define MKD_NOTABLES 0x00000400 /* disallow tables */
#define MKD_NOSTRIKETHROUGH 0x00000800 /* forbid ~~strikethrough~~ */
#define MKD_TOC 0x00001000 /* do table-of-contents processing */
#define MKD_1_COMPAT 0x00002000 /* compatibility with MarkdownTest_1.0 */
#define MKD_AUTOLINK 0x00004000 /* make http://foo.com link even without <>s */
#define MKD_SAFELINK 0x00008000 /* paranoid check for link protocol */
#define MKD_NOHEADER 0x00010000 /* don't process header blocks */
#define MKD_TABSTOP 0x00020000 /* expand tabs to 4 spaces */
#define MKD_NODIVQUOTE 0x00040000 /* forbid >%class% blocks */
#define MKD_NOALPHALIST 0x00080000 /* forbid alphabetic lists */
#define MKD_NODLIST 0x00100000 /* forbid definition lists */
#define MKD_EXTRA_FOOTNOTE 0x00200000 /* enable markdown extra-style footnotes */
#define MKD_EMBED MKD_NOLINKS|MKD_NOIMAGE|MKD_TAGTEXT

/* special flags for mkd_in() and mkd_string()
*/


#endif/*_MKDIO_D*/
Binary file added Libraries/libmarkdown.a
Binary file not shown.
37 changes: 37 additions & 0 deletions Model/GBComment.h
Expand Up @@ -115,6 +115,43 @@
*/
@property (assign) BOOL isCopied;

/** Specifies whether the comment has short description or not.
@see hasLongDescription
*/
@property (readonly) BOOL hasShortDescription;

/** Specifies whether the comment has long description or not.
@see hasShortDescription
*/
@property (readonly) BOOL hasLongDescription;

/** Specifies whether the `methodParameters` contains at least one object or not.
@see hasMethodExceptions
@see hasMethodResult
*/
@property (readonly) BOOL hasMethodParameters;

/** Specifies whether the `methodExceptions` contains at least one object or not.
@see hasMethodParameters
@see hasMethodResult
*/
@property (readonly) BOOL hasMethodExceptions;

/** Specifies whether the `methodResult` contains at least one object or not.
@see hasMethodParameters
@see hasMethodExceptions
*/
@property (readonly) BOOL hasMethodResult;

/** Specifies whether the `relatedItems` contains at least one object or not.
*/
@property (readonly) BOOL hasRelatedItems;

///---------------------------------------------------------------------------------------
/// @name Input values
///---------------------------------------------------------------------------------------
Expand Down
24 changes: 24 additions & 0 deletions Model/GBComment.m
Expand Up @@ -48,6 +48,30 @@ - (NSString *)debugDescription {

#pragma mark Properties

- (BOOL)hasShortDescription {
return self.shortDescription != nil;
}

- (BOOL)hasLongDescription {
return [self.longDescription.components count] > 0;
}

- (BOOL)hasMethodParameters {
return [self.methodParameters count] > 0;
}

- (BOOL)hasMethodExceptions {
return [self.methodExceptions count] > 0;
}

- (BOOL)hasMethodResult {
return [self.methodResult.components count] > 0;
}

- (BOOL)hasRelatedItems {
return [self.relatedItems.components count] > 0;
}

@synthesize isCopied;
@synthesize sourceInfo;
@synthesize stringValue;
Expand Down
3 changes: 2 additions & 1 deletion Model/GBCommentComponent.m
Expand Up @@ -6,6 +6,7 @@
// Copyright 2011 Gentle Bytes. All rights reserved.
//

#import "GBApplicationSettingsProvider.h"
#import "GBCommentComponent.h"

@implementation GBCommentComponent
Expand All @@ -28,7 +29,7 @@ + (id)componentWithStringValue:(NSString *)value sourceInfo:(GBSourceInfo *)info
- (NSString *)htmlValue {
if (!self.settings) return self.markdownValue;
if (_htmlValue) return _htmlValue;
_htmlValue = self.markdownValue;
_htmlValue = [self.settings stringByConvertingMarkdown:self.markdownValue];
return _htmlValue;
}

Expand Down
17 changes: 15 additions & 2 deletions Templates/html/css/styles.css
Expand Up @@ -29,6 +29,10 @@ li {
margin-bottom: 10px;
}

p:first-child {
margin-top: 0.5em;
}

a {
text-decoration: none;
color: #36C;
Expand Down Expand Up @@ -363,14 +367,14 @@ li#jumpto_button select {
border: 1px solid #5088C5;
background-color: #F0F3F7;
margin-bottom: 0.5em;
padding: 0.3em 0.8em;
padding: 0em 0.8em;
}

.bug {
border: 1px solid #000;
background-color: #ffffcc;
margin-bottom: 0.5em;
padding: 0.3em 0.8em;
padding: 0em 0.8em;
}

/* @end */
Expand Down Expand Up @@ -435,6 +439,10 @@ span.tooltip span.tooltip {
text-align: left;
}

span.tooltip span.tooltip p {
margin: 0.1em 0.3em;
}

span.tooltip:hover span.tooltip {
display: block;
position: absolute;
Expand Down Expand Up @@ -496,6 +504,11 @@ span.tooltip:hover span.tooltip {
margin-bottom: 3px;
}

.see-also-section p {
margin-top: 0;
margin-bottom: 0;
}

.declared-in-ref {
color: #666;
}
Expand Down
28 changes: 5 additions & 23 deletions Templates/html/document-template.html
Expand Up @@ -12,35 +12,17 @@
<article>
<a title="{{page/title}}" name="top"></a>
<div id="container">
{{#object/comment}}{{>GBComment}}{{/object/comment}}
{{#object/comment}}{{#longDescription}}{{>GBCommentComponentsList}}{{/longDescription}}{{/object/comment}}
</div>
</article>
</body>
</html>


Section GBComment
{{#paragraphs}}
<p>{{>GBCommentParagraph}}</p>
{{/paragraphs}}
Section GBCommentComponentsList
{{#components}}{{>GBCommentComponent}}{{/components}}
EndSection

Section GBCommentParagraph
{{#paragraphItems}}{{>GBParagraphItem}}{{/paragraphItems}}
EndSection

Section GBParagraphItem
{{#isTextItem}}{{&stringValue}}{{/isTextItem}}{{#isOrderedListItem}}<ol>{{>GBParagraphListItem}}</ol>{{/isOrderedListItem}}{{#isUnorderedListItem}}<ul>{{>GBParagraphListItem}}</ul>{{/isUnorderedListItem}}{{#isWarningSpecialItem}}<p class="warning">{{>GBParagraphSpecialItem}}</p>{{/isWarningSpecialItem}}{{#isBugSpecialItem}}<p class="bug">{{>GBParagraphSpecialItem}}</p>{{/isBugSpecialItem}}{{#isExampleSpecialItem}}<pre>{{>GBParagraphSpecialItem}}</pre>{{/isExampleSpecialItem}}{{#isBoldDecoratorItem}}<strong>{{>GBParagraphDecoratorItem}}</strong>{{/isBoldDecoratorItem}}{{#isItalicsDecoratorItem}}<em>{{>GBParagraphDecoratorItem}}</em>{{/isItalicsDecoratorItem}}{{#isCodeDecoratorItem}}<code>{{>GBParagraphDecoratorItem}}</code>{{/isCodeDecoratorItem}}{{#isLinkItem}}<a href="{{&href}}">{{&stringValue}}</a>{{/isLinkItem}}
EndSection

Section GBParagraphListItem
{{#listItems}}<li>{{>GBCommentParagraph}}</li>{{/listItems}}
EndSection

Section GBParagraphSpecialItem
{{#specialItemDescription}}{{>GBCommentParagraph}}{{/specialItemDescription}}
EndSection

Section GBParagraphDecoratorItem
{{#decoratedItems}}{{>GBParagraphItem}}{{/decoratedItems}}
Section GBCommentComponent
{{&htmlValue}}
EndSection

0 comments on commit 593ea57

Please sign in to comment.