rocco command acts like documented
This commit is contained in:
parent
50fb900e5e
commit
4a0dfe7421
16
bin/rocco
16
bin/rocco
@ -22,13 +22,9 @@ rescue LoadError
|
|||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
rocco =
|
ARGV.each do |filename|
|
||||||
Rocco.new(ARGV[0]) do
|
rocco = Rocco.new(filename)
|
||||||
if $stdin.tty?
|
dest = File.basename(filename, '.rb') + '.html'
|
||||||
File.read(ARGV[0])
|
warn "rocco: #{filename} -> #{dest}"
|
||||||
else
|
File.open(dest, 'wb') { |fd| fd.write(rocco.to_html) }
|
||||||
$stdin.read
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
$stdout.write(rocco.to_html)
|
|
||||||
|
15
lib/rocco.rb
15
lib/rocco.rb
@ -30,9 +30,20 @@
|
|||||||
|
|
||||||
#### Prerequisites
|
#### Prerequisites
|
||||||
|
|
||||||
# The RDiscount library is required for Markdown processing.
|
# The [rdiscount](http://github.com/rtomayko/rdiscount) library is
|
||||||
|
# required for Markdown processing.
|
||||||
require 'rdiscount'
|
require 'rdiscount'
|
||||||
|
|
||||||
|
# We use [{{ mustache }}](http://defunkt.github.com/mustache/) for
|
||||||
|
# templating.
|
||||||
|
require 'mustache'
|
||||||
|
|
||||||
|
# Code is run through [Pygments](http://pygments.org/) for syntax
|
||||||
|
# highlighting. Fail fast if we can't find the `pygmentize` program.
|
||||||
|
if ! ENV['PATH'].split(':').any? { |dir| File.exist?("#{dir}/pygmentize") }
|
||||||
|
fail "Pygments is required for syntax highlighting"
|
||||||
|
end
|
||||||
|
|
||||||
#### Public Interface
|
#### Public Interface
|
||||||
|
|
||||||
# `Rocco.new` takes a source `filename` and an optional `block`.
|
# `Rocco.new` takes a source `filename` and an optional `block`.
|
||||||
@ -48,7 +59,7 @@ class Rocco
|
|||||||
else
|
else
|
||||||
File.read(filename)
|
File.read(filename)
|
||||||
end
|
end
|
||||||
# Jump right into parsing and highlighting.
|
# Parsing and highlighting
|
||||||
@sections = highlight(parse(@data))
|
@sections = highlight(parse(@data))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user