This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
.gitignore | ||
| |
README.textile | ||
| |
init.rb | ||
| |
lib/ | ||
| |
redclother.rb | ||
| |
test/ |
README.textile
HasMarkup – Syntax Highlighting and Textile Formatting for Your AR Models
HasMarkup is a Ruby on Rails Plugin that adds syntax highlighting and textile formatting capabilities to your ActiveRecord models.
Features:
- Supports all popular languages and several themes thanks to the Ultraviolet library.
- Data is processed once and then cached in the database, which means it’s as fast as it should be.
- Configurable which means it’s probably flexible enough to fit your database schema (if not tell me).
Installation
script/plugin install git://github.com/christianhellsten/has_markup.git
Usage
The schema:
ActiveRecord::Schema.define :version => 0 do
create_table :snippets, :force => true do |t|
t.string :title
t.text :body
t.text :rendered_body
end
end
The options:
HasMarkup can be configured to use other columns than the default body and rendered_body columns. Here’s a list of all available options:
has_markup :language => lambda { |snippet| snippet.language.syntax }, # Either the name of the column where the language is stored or a Proc
:input => :body, # Name of column where content is stored
:output => :rendered_body, # Name of column where rendered content should be stored
# Ultraviolet configuration
:theme => 'active4d', # Default Ultraviolet theme
:language => :language, # Default Ultraviolet syntax, can be a Proc
:line_numbers => false, # Display line numbers, or not.
# RedCloth configuration
:redcloth => [:filter_html, :filter_styles, :filter_ids, :filter_classes] # Textile options, see http://redcloth.rubyforge.org/
The model:
class Snippet < ActiveRecord::Base has_markup validates_presence_of :body end
The controller:
body = <<BODY
<code language="html">
<html>
<body>
<span>hello</span>
</body>
</html>
</code>
BODY
@snippet = Snippet.create(:title => 'A Ruby snippet', :body => body)
The view:
<%= @snippet.rendered_body %>
Questions?
Advanced Usage
See:
- has_markup_test.rb (unit/integration tests)
- snippet.rb and language.rb (model examples)








