diff options
author | murphy <murphy@rubychan.de> | 2005-10-29 16:09:17 +0000 |
---|---|---|
committer | murphy <murphy@rubychan.de> | 2005-10-29 16:09:17 +0000 |
commit | 39ff12b40e0b8b3a892aea63eddfae87531f5d10 (patch) | |
tree | c94d1a334bf3f11896af65abb1aeda4de9b1e000 | |
parent | 20cc0418476d2f27276fbf4cfe42fd884092befd (diff) | |
download | coderay-39ff12b40e0b8b3a892aea63eddfae87531f5d10.tar.gz |
Version 0.4.6!
coderay.rb: Added highlight functions
new demo/demo_highlight.rb
encoders/helpers/html_output.rb: Improved stylesheet method
Rakefile: smarter progress info on uploading
-rw-r--r-- | Rakefile | 6 | ||||
-rw-r--r-- | demo/demo_highlight.rb | 14 | ||||
-rw-r--r-- | lib/coderay.rb | 24 | ||||
-rw-r--r-- | lib/coderay/encoders/helpers/html_output.rb | 14 |
4 files changed, 53 insertions, 5 deletions
@@ -176,7 +176,11 @@ def uploader_for ftp proc do |l, *r|
r = r.first || l
raise 'File %s not found!' % l unless File.exist? l
- g 'Uploading %s to %s...' % [l, r]
+ if l == r
+ g 'Uploading %s...' % [l]
+ else
+ g 'Uploading %s to %s...' % [l, r]
+ end
ftp.putbinaryfile l, r
gd
end
diff --git a/demo/demo_highlight.rb b/demo/demo_highlight.rb new file mode 100644 index 0000000..846efa4 --- /dev/null +++ b/demo/demo_highlight.rb @@ -0,0 +1,14 @@ +require 'coderay'
+
+puts CodeRay.highlight('puts "Hello, World!"', :ruby)
+
+output = CodeRay.highlight_file($0, :line_numbers => :table)
+puts <<HTML
+<html>
+<head>
+#{output.stylesheet true}
+<body>
+#{output}
+</body>
+</html>
+HTML
diff --git a/lib/coderay.rb b/lib/coderay.rb index 9a18a32..5e9f3f8 100644 --- a/lib/coderay.rb +++ b/lib/coderay.rb @@ -128,7 +128,7 @@ # The scanning methods provide more flexibility; we recommend to use these. module CodeRay - Version = '0.4.4' + Version = '0.4.6' require 'coderay/tokens' require 'coderay/scanner' @@ -201,6 +201,16 @@ module CodeRay encoder(format, options).encode code, lang, options end + # Highlight a string into a HTML <div>. + # + # CSS styles use classes, so you have to include a stylesheet + # in your output. + # + # See encode. + def highlight code, lang, options = { :css => :class }, format = :div + encode code, lang, format, options + end + # Encode pre-scanned Tokens. # Use this together with CodeRay.scan: # @@ -223,10 +233,20 @@ module CodeRay # require 'coderay' # page = CodeRay.encode_file 'some_c_code.c', :html def encode_file filename, format, options = {} - tokens = scan_file filename, auto, get_scanner_options(options) + tokens = scan_file filename, :auto, get_scanner_options(options) encode_tokens tokens, format, options end + # Highlight a file into a HTML <div>. + # + # CSS styles use classes, so you have to include a stylesheet + # in your output. + # + # See encode. + def highlight_file filename, options = { :css => :class }, format = :div + encode_file filename, format, options + end + # Finds the Encoder class for +format+ and creates an instance, passing # +options+ to it. # diff --git a/lib/coderay/encoders/helpers/html_output.rb b/lib/coderay/encoders/helpers/html_output.rb index 2ff5c19..c6012f7 100644 --- a/lib/coderay/encoders/helpers/html_output.rb +++ b/lib/coderay/encoders/helpers/html_output.rb @@ -35,8 +35,14 @@ module CodeRay warn "The Output module is intended to extend instances of String, not #{o.class}." unless o.respond_to? :to_str
end
- def stylesheet
- CSS::DEFAULT_STYLESHEET
+ def stylesheet in_tag = false
+ ss = CSS::DEFAULT_STYLESHEET
+ ss = <<-CSS if in_tag
+<style type="text/css">
+#{ss}
+</style>
+ CSS
+ ss
end
def page_template_for_css css = :default
@@ -174,6 +180,10 @@ module CodeRay clone.numerize!(*args)
end
+ def stylesheet in_tag = false
+ Output.stylesheet in_tag
+ end
+
class Template < String
def self.wrap! str, template, target
|