Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Working rest rendering, no error checking

embedded python, no pyobjc
  • Loading branch information...
commit 7e1f600f81c9f7e0bf5ef8019edb1e4212297707 1 parent fa1e4c9
@idan authored
View
4 GeneratePreviewForURL.m
@@ -12,7 +12,9 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
CFURLRef url, CFStringRef contentTypeUTI,
CFDictionaryRef options)
{
- CFDataRef data = (CFDataRef) renderRest((NSURL*) url);
+ // TODO: Fallback to plaintext rendering if rest rendering fails?
+
+ CFDataRef data = (CFDataRef) renderRest((NSURL*) url);
if (data) {
CFDictionaryRef props = (CFDictionaryRef) [NSDictionary dictionary];
View
4 GenerateThumbnailForURL.m
@@ -19,7 +19,9 @@ OSStatus GenerateThumbnailForURL(void *thisInterface,
CFURLRef url, CFStringRef contentTypeUTI,
CFDictionaryRef options, CGSize maxSize)
{
- NSData *data = renderRest((NSURL*) url);
+ // TODO: Fallback to plaintext rendering if rest rendering fails?
+
+ NSData *data = renderRest((NSURL*) url);
if (data) {
NSRect viewRect = NSMakeRect(0.0, 0.0, 600.0, 800.0);
View
55 Info.plist
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UTImportedTypeDeclarations</key>
- <array>
+ <array>
<dict>
<key>UTTypeIdentifier</key>
- <string>net.sourceforge.docutils</string>
- <key>UTTypeReferenceURL</key>
- <string>http://docutils.sourceforge.net</string>
- <key>UTTypeDescription</key>
- <string>ReStructured Text document</string>
- <key>UTTypeIconFile</key>
- <string>public.text.icns</string>
- <key>UTTypeConformsTo</key>
- <array>
+ <string>net.sourceforge.docutils</string>
+ <key>UTTypeReferenceURL</key>
+ <string>http://docutils.sourceforge.net</string>
+ <key>UTTypeDescription</key>
+ <string>ReStructured Text document</string>
+ <key>UTTypeIconFile</key>
+ <string>public.text.icns</string>
+ <key>UTTypeConformsTo</key>
+ <array>
<string>public.text</string>
<string>public.plain-text</string>
</array>
@@ -48,13 +48,13 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
- <string>net.pixane.QLRest</string>
+ <string>net.pixane.qlgenerator.QLRest</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
- <key>CFBundleShortVersionString</key>
- <string>1</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1</string>
<key>CFPlugInDynamicRegisterFunction</key>
<string></string>
<key>CFPlugInDynamicRegistration</key>
@@ -73,22 +73,15 @@
</dict>
<key>CFPlugInUnloadFunction</key>
<string></string>
- <!-- Change following property to <true/> if the generators supports
- multiple concurrent requests -->
- <key>QLSupportsConcurrentRequests</key>
- <false/>
- <!-- Change following property to <true/> if the generators needs
- to be run on main thread -->
- <key>QLNeedsToBeRunInMainThread</key>
- <false/>
- <!-- Change following property to indicate the minimum useful size for a thumbnail the generator
- can produce. If your generator is fast enough, you can remove the minimum size so to appear in lists -->
- <key>QLThumbnailMinimumSize</key>
- <real>17</real>
- <!-- Change following properites to indicate the preview size to use if preview generation takes too long -->
- <key>QLPreviewWidth</key>
- <real>800</real>
- <key>QLPreviewHeight</key>
- <real>600</real>
+ <key>QLSupportsConcurrentRequests</key>
+ <false/>
+ <key>QLNeedsToBeRunInMainThread</key>
+ <false/>
+ <key>QLThumbnailMinimumSize</key>
+ <real>17</real>
+ <key>QLPreviewWidth</key>
+ <real>800</real>
+ <key>QLPreviewHeight</key>
+ <real>600</real>
</dict>
</plist>
View
25 PyRestConverter.py
@@ -1,25 +0,0 @@
-#
-# PyRestConverter.py
-# QLRest
-#
-# Created by Idan Gazit on 20/2/09.
-# Copyright (c) 2009 __MyCompanyName__. All rights reserved.
-#
-
-from Foundation import *
-import objc
-from docutils.core import publish_string
-
-NSObject = objc.lookUpClass(u"NSObject")
-class PyRestConverter(NSObject):
- def __init__(self):
- self = super(PyRestConverter, self).init()
- return self
-
- def restToHtml_(self, rest):
- return publish_string(rest, writer_name='html')
- #restToHtml = objc.accessor(restToHtml)
-
- def foo_(self):
- return u'foo!'
-
View
8 QLRest.xcodeproj/project.pbxproj
@@ -16,7 +16,7 @@
8D576314048677EA00EA77CD /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0AA1909FFE8422F4C02AAC07 /* CoreFoundation.framework */; };
8D5B49A804867FD3000E48DA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8D5B49A704867FD3000E48DA /* InfoPlist.strings */; };
C86B05270671AA6E00DD9006 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C86B05260671AA6E00DD9006 /* CoreServices.framework */; };
- EEC527160F4EDE4200F78FC5 /* PyRestConverter.py in Resources */ = {isa = PBXBuildFile; fileRef = EEC527150F4EDE4200F78FC5 /* PyRestConverter.py */; };
+ EE245D150F530DF600A4E708 /* Python.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE245D140F530DF600A4E708 /* Python.framework */; };
EEC528820F52A16100F78FC5 /* RestConverter.h in Headers */ = {isa = PBXBuildFile; fileRef = EEC528800F52A16100F78FC5 /* RestConverter.h */; };
EEC528830F52A16100F78FC5 /* RestConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = EEC528810F52A16100F78FC5 /* RestConverter.m */; };
F28CFBFD0A3EC0AF000ABFF5 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F28CFBFC0A3EC0AF000ABFF5 /* ApplicationServices.framework */; };
@@ -35,7 +35,7 @@
8D576316048677EA00EA77CD /* QLRest.qlgenerator */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = QLRest.qlgenerator; sourceTree = BUILT_PRODUCTS_DIR; };
8D576317048677EA00EA77CD /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
C86B05260671AA6E00DD9006 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = /System/Library/Frameworks/CoreServices.framework; sourceTree = "<absolute>"; };
- EEC527150F4EDE4200F78FC5 /* PyRestConverter.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = PyRestConverter.py; sourceTree = "<group>"; };
+ EE245D140F530DF600A4E708 /* Python.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Python.framework; path = /System/Library/Frameworks/Python.framework; sourceTree = "<absolute>"; };
EEC528800F52A16100F78FC5 /* RestConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RestConverter.h; sourceTree = "<group>"; };
EEC528810F52A16100F78FC5 /* RestConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RestConverter.m; sourceTree = "<group>"; };
F28CFBFC0A3EC0AF000ABFF5 /* ApplicationServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ApplicationServices.framework; path = /System/Library/Frameworks/ApplicationServices.framework; sourceTree = "<absolute>"; };
@@ -53,6 +53,7 @@
F28CFC030A3EC0C6000ABFF5 /* QuickLook.framework in Frameworks */,
0A80BFB20E21A90900C8BF14 /* Cocoa.framework in Frameworks */,
0A80BFCC0E21B61A00C8BF14 /* WebKit.framework in Frameworks */,
+ EE245D150F530DF600A4E708 /* Python.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -73,6 +74,7 @@
089C1671FE841209C02AAC07 /* External Frameworks and Libraries */ = {
isa = PBXGroup;
children = (
+ EE245D140F530DF600A4E708 /* Python.framework */,
0A80BFCB0E21B61A00C8BF14 /* WebKit.framework */,
0A80BFB10E21A90900C8BF14 /* Cocoa.framework */,
F28CFC020A3EC0C6000ABFF5 /* QuickLook.framework */,
@@ -99,7 +101,6 @@
61E3BCFA0870B4F2002186A0 /* GenerateThumbnailForURL.m */,
2C05A19B06CAA52B00D84F6F /* GeneratePreviewForURL.m */,
08FB77B6FE84183AC02AAC07 /* main.c */,
- EEC527150F4EDE4200F78FC5 /* PyRestConverter.py */,
EEC528800F52A16100F78FC5 /* RestConverter.h */,
EEC528810F52A16100F78FC5 /* RestConverter.m */,
);
@@ -172,7 +173,6 @@
files = (
8D5B49A804867FD3000E48DA /* InfoPlist.strings in Resources */,
4446D0240F41AD4700BAC3F4 /* styles.css in Resources */,
- EEC527160F4EDE4200F78FC5 /* PyRestConverter.py in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
18 RestConverter.h
@@ -1,18 +1,4 @@
-//
-// RestConverter.h
-// QLRest
-//
-// Created by Idan Gazit on 23/2/09.
-// Copyright 2009 __MyCompanyName__. All rights reserved.
-//
+#import <Foundation/Foundation.h>
-#import <Cocoa/Cocoa.h>
+NSData* renderRest(NSURL* url);
-
-@interface RestConverter : NSObject {
- @public
- NSObject pyRestConv;
-}
-
- +(NSData*) renderRest: (NSURL*) url;
-@end
View
57 RestConverter.m
@@ -1,30 +1,35 @@
-//
-// RestConverter.m
-// QLRest
-//
-// Created by Idan Gazit on 23/2/09.
-// Copyright 2009 __MyCompanyName__. All rights reserved.
-//
-
#import "RestConverter.h"
+#import <Python/Python.h>
-@class PyRestConverter;
-
-@interface NSObject (MethodsThatReallyDoExist)
-- (NSString *) foo;
-@end
-
-@implementation RestConverter
- -(void) initialize {
- Class PyRestConverterClass = NSClassFromString(@"PyRestConverter");
- NSObject * pyRestConv;
- pyRestConv = [PyRestConverterClass new];
- }
+NSData* renderRest(NSURL* url) {
- +(NSData*) renderRest: (NSURL*) url {
- NSString *html = [pyRestConv foo];
- return [html dataUsingEncoding:NSUTF8StringEncoding];
- }
+ PyObject *pmodule, *pmethod, *presult;
+ PyTupleObject *pmethodargs;
+ PyDictObject *pmethodnamedargs;
+ char* output;
+ NSString *source = [NSString stringWithContentsOfFile:[url path] encoding:NSUTF8StringEncoding error:nil];
-
-@end
+ Py_Initialize();
+
+ // TODO: there's no exception handling going on here at all.
+ // TODO: Is it possible to make the warnings go away?
+
+ pmethodargs = PyTuple_New(1);
+ pmethodnamedargs = PyDict_New();
+
+ PyTuple_SetItem(pmethodargs, 0, PyString_FromString([source UTF8String]));
+ PyDict_SetItemString(pmethodnamedargs, "writer_name", PyString_FromString("html"));
+ pmodule = PyImport_ImportModule("docutils.core");
+ pmethod = PyObject_GetAttrString(pmodule, "publish_string");
+ presult = PyObject_Call(pmethod, pmethodargs, pmethodnamedargs);
+ if (PyErr_Occurred())
+ PyErr_Print();
+ PyArg_Parse(presult, "s", &output);
+ if (PyErr_Occurred())
+ PyErr_Print();
+
+ Py_Finalize();
+
+ NSString *html = [NSString stringWithUTF8String:output];
+ return [html dataUsingEncoding:NSUTF8StringEncoding];
+}
Please sign in to comment.
Something went wrong with that request. Please try again.