code2html 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/README.rdoc +12 -0
- data/bin/code2html +20 -0
- data/lib/htmlclipboard.rb +69 -0
- metadata +72 -0
data/CHANGELOG
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
= Code2Html
|
2
|
+
|
3
|
+
Author:: Ed Botzum (mailto:ed.botzum@siemens.com)
|
4
|
+
Copyright:: Copyright (c) 2010 edbotz
|
5
|
+
License:: GPL
|
6
|
+
Version:: 0.0.1
|
7
|
+
|
8
|
+
Uses CodeRay to read in a source code file, convert it to html
|
9
|
+
and copy it to the clipboard in Windows.
|
10
|
+
|
11
|
+
==TODOS:
|
12
|
+
* Support for the mac.
|
data/bin/code2html
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'coderay'
|
4
|
+
require 'win32/clipboard'
|
5
|
+
require File.join(File.dirname(__FILE__), *%w[../lib/htmlclipboard])
|
6
|
+
|
7
|
+
include Win32
|
8
|
+
|
9
|
+
# gather the file information
|
10
|
+
code_file_name = ARGV[0]
|
11
|
+
code_file = File.new( code_file_name, 'r' )
|
12
|
+
extension = File.extname( code_file_name ).gsub( /\./, '' )
|
13
|
+
out_file_name = File.basename( code_file_name, ".#{extension}" ) << ".html"
|
14
|
+
|
15
|
+
# Convert Extensions for CodeRay
|
16
|
+
extension = 'ruby' if extension == 'rb'
|
17
|
+
|
18
|
+
# Create the html
|
19
|
+
code = CodeRay.scan( code_file.read, extension )
|
20
|
+
Clipboard.set_html_data( code.html( :line_numbers => :inline, :wrap => :page ) )
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#
|
2
|
+
# htmlclipboard.rb
|
3
|
+
# by John Allen
|
4
|
+
# http://johnallen.us/?p=289
|
5
|
+
#
|
6
|
+
module Win32
|
7
|
+
class Clipboard
|
8
|
+
|
9
|
+
@cfHTML = nil
|
10
|
+
|
11
|
+
def self.registerHTML
|
12
|
+
if not @cfHTML
|
13
|
+
@cfHTML = Win32::Clipboard.RegisterClipboardFormat("HTML Format")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
=begin
|
18
|
+
zeroFmt(nbr)
|
19
|
+
-- Takes a number and formats with zero's in front.
|
20
|
+
1234 => "0000001234"
|
21
|
+
23 => "0000000023"
|
22
|
+
=end
|
23
|
+
def self.zeroFmt(nbr)
|
24
|
+
zeros = "0"*10
|
25
|
+
len = nbr.to_s.length # this is the number of digits in the number 2784 => 4
|
26
|
+
return zeros.slice(0..(zeros.length - len - 1)) + nbr.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.set_html_data(clip_data)
|
30
|
+
sDataStart = "<HTML><BODY>\n<!--StartFragment -->"
|
31
|
+
sDataEnd = "<!--EndFragment -->\n</BODY></HTML>"
|
32
|
+
sData = ""
|
33
|
+
#
|
34
|
+
# Clipboard Header: looks like ->
|
35
|
+
# Version: 1.0
|
36
|
+
# StartHTML:0000000000
|
37
|
+
# EndHTML:0000000000
|
38
|
+
# StartFragment:0000000000
|
39
|
+
# EndFragment:0000000000
|
40
|
+
sDataHdr = "Version:1.0\r\nStartHTML:aaaaaaaaaa\r\nEndHTML:bbbbbbbbbb\r\n"
|
41
|
+
sDataHdr += "StartFragment:cccccccccc\r\nEndFragment:dddddddddd\r\n"
|
42
|
+
sData = sDataHdr + sDataStart + clip_data + sDataEnd
|
43
|
+
|
44
|
+
sData = sData.gsub(/aaaaaaaaaa/) { zeroFmt(sDataHdr.length) }
|
45
|
+
sData = sData.gsub(/bbbbbbbbbb/) { zeroFmt(sData.length) }
|
46
|
+
sData = sData.gsub(/cccccccccc/) { zeroFmt(sDataHdr.length + sDataStart.length) }
|
47
|
+
sData = sData.gsub(/dddddddddd/) { zeroFmt(sDataHdr.length + sDataStart.length + clip_data.length) }
|
48
|
+
|
49
|
+
if not @cfHTML
|
50
|
+
self.registerHTML
|
51
|
+
end
|
52
|
+
|
53
|
+
self.open
|
54
|
+
EmptyClipboard()
|
55
|
+
hmem = GlobalAlloc(GHND, sData.length + 10)
|
56
|
+
mem = GlobalLock(hmem)
|
57
|
+
memcpy(mem, sData, sData.length)
|
58
|
+
begin
|
59
|
+
if SetClipboardData(@cfHTML, hmem) == 0
|
60
|
+
raise Error, "SetClipboardData() failed; " + get_last_error
|
61
|
+
end
|
62
|
+
ensure
|
63
|
+
GlobalFree(hmem)
|
64
|
+
self.close
|
65
|
+
end
|
66
|
+
self
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: code2html
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ed Botzum
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-30 00:00:00 -04:00
|
13
|
+
default_executable: opps
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: win32-clipboard
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.5.2
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: contact@edbotz.us
|
27
|
+
executables:
|
28
|
+
- code2html
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
- CHANGELOG
|
34
|
+
files:
|
35
|
+
- lib/htmlclipboard.rb
|
36
|
+
- README.rdoc
|
37
|
+
- CHANGELOG
|
38
|
+
has_rdoc: true
|
39
|
+
homepage:
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --main
|
45
|
+
- README.rdoc
|
46
|
+
- --template
|
47
|
+
- c:/ruby/lib/ruby/gems/1.8/gems/allison-2.0.3/lib/allison
|
48
|
+
- --line-numbers
|
49
|
+
- --inline-source
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Code2Html utility.
|
71
|
+
test_files: []
|
72
|
+
|