phandoc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/phandoc.rb +71 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6f9584d9dab58847b233d613f1b5bd6eae594fd3
|
4
|
+
data.tar.gz: 52e0fa7dc5442f75e31fd1078086150ab3520001
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ac0b614ada0092d9f85cddc66480a547c8eadbe354ea868e1dd1f112cbb6eb2a512edf5fad96f535f3376cb1c4d0aa6aa651e4b2340cc008bc8a93406648a668
|
7
|
+
data.tar.gz: 7606d9be8880759725d8d044a856087adff5571be542ca951e36f994b8a0def4c33752dae78f19ef516948d0b44d5452d2ad348e0ff193bb71d55534d111dc23
|
data/lib/phandoc.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'phantomjs'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
class Phandoc
|
5
|
+
def initialize(html)
|
6
|
+
@html = html
|
7
|
+
end
|
8
|
+
|
9
|
+
def execute(code)
|
10
|
+
result = []
|
11
|
+
|
12
|
+
html_file = Tempfile.new('phantom_html')
|
13
|
+
js_file = Tempfile.new('phantom_js')
|
14
|
+
script_file = Tempfile.new('phantom_script')
|
15
|
+
|
16
|
+
begin
|
17
|
+
html_file.write(@html)
|
18
|
+
html_file.flush
|
19
|
+
|
20
|
+
js_file.write(code)
|
21
|
+
js_file.flush
|
22
|
+
|
23
|
+
script_file.write <<-JAVASCRIPT
|
24
|
+
var fs = require('fs');
|
25
|
+
var htmlContent = fs.read('#{html_file.path}');
|
26
|
+
var jsContent = fs.read('#{js_file.path}');
|
27
|
+
|
28
|
+
var webpage = require('webpage');
|
29
|
+
var page = webpage.create();
|
30
|
+
|
31
|
+
page.content = htmlContent;
|
32
|
+
|
33
|
+
var output = page.evaluate(function(script) {
|
34
|
+
return eval(script);
|
35
|
+
}, jsContent);
|
36
|
+
|
37
|
+
console.log(output);
|
38
|
+
console.log(page.content.replace(/^/mg, '[:PHANDOC_SOURCE:] '));
|
39
|
+
|
40
|
+
phantom.exit();
|
41
|
+
JAVASCRIPT
|
42
|
+
script_file.flush
|
43
|
+
|
44
|
+
html = []
|
45
|
+
Phantomjs.run(script_file.path) do |line|
|
46
|
+
if line.start_with?('[:PHANDOC_SOURCE:] ')
|
47
|
+
html << line.sub(/(^\[:PHANDOC_SOURCE:\] |\n$)/, '')
|
48
|
+
else
|
49
|
+
result << line.sub(/\n$/, '')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
@html = html.join("\n")
|
54
|
+
ensure
|
55
|
+
html_file.close
|
56
|
+
html_file.unlink
|
57
|
+
|
58
|
+
js_file.close
|
59
|
+
js_file.unlink
|
60
|
+
|
61
|
+
script_file.close
|
62
|
+
script_file.unlink
|
63
|
+
end
|
64
|
+
|
65
|
+
result.join("\n")
|
66
|
+
end
|
67
|
+
|
68
|
+
def html
|
69
|
+
@html
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phandoc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- greatghoul
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: phantomjs
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Javascript + DOM in your ruby, based on PhantomJS.
|
28
|
+
email: greatghoul@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/phandoc.rb
|
34
|
+
homepage: https://github.com/greatghoul/phandoc
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.2.2
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Javascript + DOM in your ruby, based on PhantomJS.
|
58
|
+
test_files: []
|