Ruby Code to HTML

  • Thread starter James Edward Gray II
  • Start date
J

Josef 'Jupp' Schugt

--------------040703020002040507030809
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
I need to HTMLify some Ruby code. Before I go make some crude solution,
I thought I would ask if there is anything out there along these lines.
Any pointers?

Attached is a tiny Rakefile that I use for some Ruby scripts of mine.
It uses vim but converts FONT-burdened HTML into CSS-based one. Style
files are attached as well. Should work on any platform that is
supported by Ruby and vim.

Josef 'Jupp' Schugt

--------------040703020002040507030809
Content-Type: text/plain;
name="Rakefile.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Rakefile.txt"

#!/usr/bin/env ruby

$ext='rb'
$type='ruby'

# Data needed for file generation
$data = {
'anysentis' => {
'link' => 'anysentis',
'refer' => 'anysentis.html',
'title' => 'anysentis.rb - Play \'Disentis\' and \'Trisentis\''
},
'unescapeURL' => {
'link' => 'unescapeURL',
'refer' => 'unescapeURL.html',
'title' => 'unescapeURL - Unobfuscate URLs'
},
'nmapchk' => {
'link' => 'nmapchk',
'refer' => 'nmapchk.html',
'title' => 'nmapchk.rb - Look for new version of Nmap'
},
}

targets = Array.new
$data.each_key { |x|
targets.push "#{x}.#{$ext}.html"
}

task :default => targets

task :clean do
rm_f targets
end

task :untmp do
(Dir["*~"]+Dir['*.html1']).each do |tmpfile|
rm_f tmpfile
end
end

rule '.html' => ['.txt'] do |t|
generic_name = t.source.sub(/\.#{$ext}\.txt$/,'')
run_vimscript(t.source, $type)
File::eek:pen(t.name, 'w') {|f| f.puts header(generic_name)}
sh "cat tmp >> #{t.name}"
File::eek:pen(t.name, 'a') {|f| f.puts footer(generic_name)}
rm_f 'tmp'
end

def header(generic_name)
return <<-EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=us-ascii">
<link REL="stylesheet" TYPE="text/css" HREF="../../default.css">
<link REL="stylesheet" TYPE="text/css" HREF="../../vim.css">
<title>deusxmachina &gt; Programs &gt; #{$data[generic_name]["link"]} &gt; Source</title>
</head>
<body>

<hr class="off">

<p class="nav">
<a href="../../index.html">deusxmachina</a> &gt; <a href="../index.html">Software by me</a> &gt; <a href="#{$data[generic_name]['refer']}">#{$data[generic_name]["link"]}</a> &gt; Source
</p>

<hr class="off">

<h1 class="subject">#{$data[generic_name]["title"]}</h1>

EOF
end

def footer(generic_name)
return <<-EOF

<hr class="off">

<p class="nav">
<a href="../../index.html">deusxmachina</a> &gt; <a href="../index.html">Software by me</a> &gt; <a href="#{$data[generic_name]['refer']}">#{$data[generic_name]["link"]}</a> &gt; Source
</p>

<hr class="off">

<p class="mod">
Last modified: #{Time::now.strftime("%Y-%m-%d")}
</p>

</body>

</html>
EOF
end

def run_vimscript(infile, type)
File.open('vimscript', 'w') {|f|
f.puts ':colorscheme peachpuff'
f.puts ":set syntax=#{type}"
f.puts ':runtime! syntax/2html.vim'
f.puts ':1,7d'
f.puts ':$-1,$d'
f.puts ':%s/<\/font>/<\/span>/g'
f.puts ':%s/<font color="#406090">/<span class="comment">/g'
f.puts ':%s/<font color="#c00058">/<span class="constant">/g'
f.puts ':%s/<font color="#6a5acd">/<span class="special">/g'
f.puts ':%s/<font color="#008b8b">/<span class="identifier">/g'
f.puts ':%s/<font color="#cd00cd">/<span class="preproc">/g'
f.puts ':%s/<font color="#a52a2a"><b>/<span class="statement">/g'
f.puts ':%s/<font color="#2e8b57"><b>/<span class="type">/g'
f.puts ':%s/<font color="#ffdab9">/<span class="ignore">/g'
f.puts ':%s/<span style="background-color: #ff0000"><font color="#ffffff"><b>/<span class="error">/g'
f.puts ':%s/<span style="background-color: #ffff00"><font color="#0000ff">/<span class="todo">/g'
f.puts ':%s/<\/span><\/span>/<\/span>/g'
f.puts ':%s/<\/b>//g'
f.puts ":w! tmp"
f.puts ':q'
f.puts ':q'
}
sh "gvim --nofork -s vimscript #{infile}"
rm_f 'vimscript'
end

--------------040703020002040507030809
Content-Type: text/css;
name="default.css"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="default.css"

/******************************************************************************
*
* Permission to copy this stylesheet is granted but please communicate any
* improvements you make to jupp(a)gmx.de
*
*****************************************************************************/

/* Body stuff */

body {
background-color: #DDDDDD;
background-image: url(img/bg.png);
font-family: arial,helvetica,sans-serif;
font-size: medium;
}

/* Headline stuff */

h1,h2,h3,h4,h5 {
font-style: normal;
font-weight: bold;
}
h1 {
font-size: xx-large;
font-variant: small-caps;
}
h1.subject {
color: #000099;
}
h2 {
font-size: xx-large;
}
h3 {
font-size: x-large;
}
h4 {
font-size: large;
}
h5 {
font-size: medium;
}
h6 {
font-size: medium;
font-weight: normal;
font-style: oblique;
}

/* Anchor stuff */

a {
font-weight: bold;
padding-bottom: 0.1em;
padding-left: 0.3em;
padding-right: 0.3em;
padding-top: 0.1em;
text-decoration: none;
}
a:active {
border-color: #FF0000;
}
a.ext:before {
content: url(img/ext.png);
margin-right: 0.2em;
vertical-align: baseline;
}
a:hover {
background-color: #FFFF66;
border-color: #000000;
}
a:link {
border-style: none;
border-width: thin;
color: #000099;
}
a:visited {
border-style: none;
border-width: thin;
color: #660066;
}

/* List stuff */

dl {
padding-left: 2em;
}
dt {
font-weight: bold;
}
dd {
padding-bottom: 1em;
}
ul li {
list-style-image: url(img/box.png);
margin-bottom: 1em;
vertical-align: baseline;
}
ul li.lnk {
list-style-image: url(img/ext.png);
margin-bottom: 1em;
vertical-align: baseline;
}
ul li.src {
list-style-image: url(img/floppy.png);
margin-bottom: 1em;
vertical-align: baseline;
}
ul li.syn {
list-style-image: url(img/eye.png);
margin-bottom: 1em;
vertical-align: baseline;
}
ul.links li {
list-style-image: url(img/ext.png);
vertical-align: baseline;
}

/* Pre-formatted stuff */

pre {
background-color: #CCCCCC;
background-image: url(img/codebg.png);
border-style: solid;
border-width: medium;
font-family: courier new,courier,monospace;
padding: 1em;
}

/* Paragraph stuff */

p.mod {
font-size: small;
}
p.nav {
background-color: #CCCCCC;
background-image: url(img/navbg.png);
border-style: solid;
border-width: thin;
padding: 0.5em;
}
p.thumb {
padding: 0.2em;
}

/* Modifiers */

/*
* Elements of class "off" are only visible in browsers WITHOUT CSS support.
*/
off {
display: none;
}

/*
* Elements of class "ruby" display in white on ruby.
*/
ruby {
background-color: #993300;
background-image: url(img/rubybg.png);
border-style: solid;
border-width: thin;
color: #FFFFFF;
font-weight: bold;
padding: 0.5em;

}
man {
background-color: #CCCCCC;
background-image: url(img/codebg.png);
border-style: solid;
border-width: medium;
padding: 1em;
}

--------------040703020002040507030809
Content-Type: text/css;
name="vim.css"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="vim.css"

/******************************************************************************
*
* Permission to copy this stylesheet is granted but please communicate any
* improvements you make to jupp(a)gmx.de
*
*****************************************************************************/

comment {
color: #666666;
}
constant {
color: #000099;
font-weight: bold;
}
special {
color: #0000FF;
font-weight: bold;
}
identifier {
color: #000000;
font-weight: bold;
}
preproc {
color: #006666;
font-weight: bold;
}
type {
color: #990000;
font-weight: bold;
}
statement {
color: #990000;
font-weight: bold;
}
ignore {
display: none;
}
error {
color: #FFFFFF;
background: #FF0000;
font-weight: bold;
}
todo {
color: #0000FF;
background: #FFFF00;
}

--------------040703020002040507030809--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top