arya / tm_syntax_highlighting

A Rails plugin that provides helpers to highlight code with pretty TextMate-style highlighting.

This URL has Read+Write access

Arya Asemanfar (author)
Wed Apr 30 14:07:59 -0700 2008
commit  b96d5955b9254c27b06f7882172716123d90feee
tree    1abeb92082ffadfb3666cbe8e4470f56df63a1ea
parent  a08adffc971a2f78dd1c419c9c4221523bd434d9
name age message
file MIT-LICENSE Wed Apr 30 13:38:28 -0700 2008 first commit [Arya Asemanfar]
file README Wed Apr 30 14:01:44 -0700 2008 added usage for generator to readme [Arya Asemanfar]
file Rakefile Loading commit data...
directory generators/
file init.rb Wed Apr 30 13:38:28 -0700 2008 first commit [Arya Asemanfar]
file install.rb Wed Apr 30 14:07:59 -0700 2008 readme outputted on install [Arya Asemanfar]
directory lib/ Wed Apr 30 13:38:28 -0700 2008 first commit [Arya Asemanfar]
directory test/ Wed Apr 30 13:38:28 -0700 2008 first commit [Arya Asemanfar]
file uninstall.rb Wed Apr 30 13:38:28 -0700 2008 first commit [Arya Asemanfar]
README
TmSyntaxHighlighting
====================
** NOTE: You must install ultraviolet *before* installing this plugin. Follow the instructions below.

This plugin allows you to add TextMate themed syntax highlighting to your views.

It requires the Ultraviolet gem, which requires TextPow, which requires oniguruma (both the gem and the system library).


Oniguruma is a regular expression library used by TextPow in order to properly parse TextMate syntax/language files.
It's relatively easy to install, here is the URL for the library:
  http://www.geocities.jp/kosako3/oniguruma/

Then you need to do
  $ gem install ultraviolet  
which should install ultraviolet, textpow, and oniguruma.

Lastly, in order for this plugin to properly copy the syntax CSS files from ultraviolet, ultraviolet must already be 
installed. In other words, you need to install ultraviolet before installing this plugin.

The plugin comes with a generator for the stylesheets for the different themes.
  
  # to see a list of themes
  $ script/generate syntax_css list
  
  # to copy all the themes to public/stylesheets/syntax
  $ script/generate syntax_css all
  
  # to copy a single theme to public/stylesheets/syntax
  $ script/generate syntax_css theme_name
  
Example
=======

The plugin adds 2 view helper methods: code and syntax_css

code (helper method) usage
==========================

  code(some_ruby_code, :theme => "twilight", :lang => "ruby", :line_numbers => true)
  
lang and line_numbers are optional. lang will default to plain_text and line_numbers will default to true.
It is *HIGHLY* recommended that you fragment_cache or some other type of caching for code fragments (TextPow and/or 
Ultraviolet have some speed issues).

theme can be an array, and one will be chosen at random.

you can set defaults in an initializer:

  # config/initializers/tm_syntax_config.rb
  TmSyntaxHighlighting.defaults = {:theme => "sunburst", :line_numbers => true, :lang => "ruby"}
  
again, theme can be an array and will be chosen at random.


syntax_css (helper_method) usage
================================
lastly, the syntax_css method will include the stylesheet tags for the themes

you can call it with a theme name

  syntax_css("twilight")
  
or if you call it with no options, it will include all the css files for the themes used in this request

  code(some_ruby_code, :theme => "twilight")
  code(some_more_ruby_code, :theme => "sunburst")
  ...
  syntax_css # yields stylesheet tags for both twilight and sunburst