rshot 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/rshot/app_delegate.h +11 -0
- data/ext/rshot/app_delegate.m +15 -0
- data/ext/rshot/extconf.rb +5 -0
- data/ext/rshot/rshot.h +26 -0
- data/ext/rshot/rshot.m +56 -0
- data/ext/rshot/ruby.m +52 -0
- metadata +51 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
#include "app_delegate.h"
|
2
|
+
|
3
|
+
@implementation AppDelegate
|
4
|
+
|
5
|
+
- (void)applicationDidFinishLaunching:(NSNotification*)notice
|
6
|
+
{
|
7
|
+
NSLog(@"applicationDidFinishLaunching");
|
8
|
+
}
|
9
|
+
|
10
|
+
- (void)threadStart:(NSApplication*)application
|
11
|
+
{
|
12
|
+
[application run];
|
13
|
+
}
|
14
|
+
|
15
|
+
@end
|
data/ext/rshot/rshot.h
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#include "setjmp.h"
|
2
|
+
#import <Foundation/Foundation.h>
|
3
|
+
#import <AppKit/NSBitmapImageRep.h>
|
4
|
+
#import <WebKit/WebKit.h>
|
5
|
+
#import <WebKit/WebView.h>
|
6
|
+
#import <WebKit/WebFrame.h>
|
7
|
+
#import <WebKit/WebFrameLoadDelegate.h>
|
8
|
+
|
9
|
+
extern jmp_buf RShot_finishedEnv;
|
10
|
+
|
11
|
+
@interface RShot : NSObject
|
12
|
+
{
|
13
|
+
WebView* webView;
|
14
|
+
NSString* path;
|
15
|
+
}
|
16
|
+
|
17
|
+
@property (retain) WebView* webView;
|
18
|
+
@property (retain) NSString* path;
|
19
|
+
|
20
|
+
- (void)renderUrl:(NSString*)url toFile:(NSString*)file;
|
21
|
+
- (void)webView:(WebView*)sender didFinishLoadForFrame:(WebFrame*)frame;
|
22
|
+
- (void)webView:(WebView*)sender didFailProvisionalLoadWithError:(NSError*)error forFrame:(WebFrame*)frame;
|
23
|
+
- (void)webView:(WebView*)sender didFailLoadWithError:(NSError*)error forFrame:(WebFrame*)frame;
|
24
|
+
- (void)dealloc;
|
25
|
+
|
26
|
+
@end
|
data/ext/rshot/rshot.m
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#import "rshot.h"
|
2
|
+
|
3
|
+
@implementation RShot
|
4
|
+
|
5
|
+
@synthesize webView, path;
|
6
|
+
|
7
|
+
- (void)renderUrl:(NSString*)url toFile:(NSString*)file
|
8
|
+
{
|
9
|
+
NSRect rect = NSMakeRect(0, 0, 800, 600);
|
10
|
+
NSWindow* window = [[NSWindow alloc]
|
11
|
+
initWithContentRect: rect
|
12
|
+
styleMask: NSBorderlessWindowMask
|
13
|
+
backing: NSBackingStoreBuffered
|
14
|
+
defer: NO];
|
15
|
+
|
16
|
+
path = file;
|
17
|
+
webView = [[WebView alloc] initWithFrame: rect];
|
18
|
+
[window setContentView: webView];
|
19
|
+
[webView setFrameLoadDelegate: self];
|
20
|
+
[[webView mainFrame] loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: url]]];
|
21
|
+
}
|
22
|
+
|
23
|
+
- (void)webView:(WebView*)sender didFinishLoadForFrame:(WebFrame*)frame
|
24
|
+
{
|
25
|
+
NSBitmapImageRep* bmp;
|
26
|
+
NSView* view = [[[webView mainFrame] frameView] documentView];
|
27
|
+
[[view window] setContentSize: [view bounds].size];
|
28
|
+
[view lockFocus];
|
29
|
+
|
30
|
+
bmp = [[NSBitmapImageRep alloc] initWithFocusedViewRect: [view bounds]];
|
31
|
+
[view unlockFocus];
|
32
|
+
NSLog(@"%@", path);
|
33
|
+
[[bmp representationUsingType: NSPNGFileType properties: nil] writeToFile: path atomically: YES];
|
34
|
+
|
35
|
+
[NSApp stop: self];
|
36
|
+
longjmp(RShot_finishedEnv, 0);
|
37
|
+
}
|
38
|
+
|
39
|
+
- (void)webView:(WebView*)sender didFailProvisionalLoadWithError:(NSError*)error forFrame:(WebFrame*)frame
|
40
|
+
{
|
41
|
+
NSLog(@"Error: %@", [error localizedDescription]);
|
42
|
+
}
|
43
|
+
|
44
|
+
- (void)webView:(WebView*)sender didFailLoadWithError:(NSError*)error forFrame:(WebFrame*)frame
|
45
|
+
{
|
46
|
+
NSLog(@"Error: %@", [error localizedDescription]);
|
47
|
+
}
|
48
|
+
|
49
|
+
- (void)dealloc
|
50
|
+
{
|
51
|
+
[webView release];
|
52
|
+
[path release];
|
53
|
+
[super dealloc];
|
54
|
+
}
|
55
|
+
|
56
|
+
@end
|
data/ext/rshot/ruby.m
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#import <AppKit/AppKit.h>
|
2
|
+
#include "ruby.h"
|
3
|
+
#import "rshot.h"
|
4
|
+
#import "app_delegate.h"
|
5
|
+
|
6
|
+
jmp_buf RShot_finishedEnv;
|
7
|
+
|
8
|
+
static VALUE rb_cRShot = Qundef;
|
9
|
+
static VALUE RShot_alloc(VALUE class);
|
10
|
+
static void RShot_free(void* rshot);
|
11
|
+
static VALUE RShot_render_url(VALUE self, VALUE url, VALUE png);
|
12
|
+
static VALUE RShot_gogogo(VALUE self);
|
13
|
+
static NSAutoreleasePool* pool;
|
14
|
+
static NSThread* app_thread;
|
15
|
+
static AppDelegate* app_delegate;
|
16
|
+
|
17
|
+
void Init_rshot()
|
18
|
+
{
|
19
|
+
pool = [[NSAutoreleasePool alloc] init];
|
20
|
+
[NSApplication sharedApplication];
|
21
|
+
app_delegate = [[AppDelegate alloc] init];
|
22
|
+
[NSApp setDelegate: app_delegate];
|
23
|
+
|
24
|
+
rb_cRShot = rb_define_class("RShot", rb_cObject);
|
25
|
+
rb_define_alloc_func(rb_cRShot, RShot_alloc);
|
26
|
+
rb_define_method(rb_cRShot, "render_url", RShot_render_url, 2);
|
27
|
+
}
|
28
|
+
|
29
|
+
static void RShot_free(void* rshot)
|
30
|
+
{
|
31
|
+
[(RShot*)rshot release];
|
32
|
+
[pool drain];
|
33
|
+
}
|
34
|
+
|
35
|
+
static VALUE RShot_alloc(VALUE class)
|
36
|
+
{
|
37
|
+
RShot* rshot = [[RShot alloc] init];
|
38
|
+
return Data_Wrap_Struct(class, 0, RShot_free, rshot);
|
39
|
+
}
|
40
|
+
|
41
|
+
static VALUE RShot_render_url(VALUE self, VALUE url, VALUE png)
|
42
|
+
{
|
43
|
+
RShot* rshot;
|
44
|
+
NSString* nsurl = [NSString stringWithUTF8String: rb_string_value_cstr(&url)];
|
45
|
+
NSString* nspng = [NSString stringWithUTF8String: rb_string_value_cstr(&png)];
|
46
|
+
Data_Get_Struct(self, RShot, rshot);
|
47
|
+
[rshot renderUrl: nsurl toFile: nspng];
|
48
|
+
if(!setjmp(RShot_finishedEnv)) {
|
49
|
+
[NSApp run];
|
50
|
+
}
|
51
|
+
return Qtrue;
|
52
|
+
}
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rshot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Charlie Somerville
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-26 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email: charlie@charliesomerville.com
|
16
|
+
executables: []
|
17
|
+
extensions:
|
18
|
+
- ext/rshot/extconf.rb
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ext/rshot/app_delegate.m
|
22
|
+
- ext/rshot/rshot.m
|
23
|
+
- ext/rshot/ruby.m
|
24
|
+
- ext/rshot/app_delegate.h
|
25
|
+
- ext/rshot/rshot.h
|
26
|
+
- ext/rshot/extconf.rb
|
27
|
+
homepage: https://github.com/charliesome/RShot
|
28
|
+
licenses: []
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 1.8.10
|
48
|
+
signing_key:
|
49
|
+
specification_version: 3
|
50
|
+
summary: Takes screenshots of web pages
|
51
|
+
test_files: []
|