4bcbdc54c9
This switches the Metasploit Framework to a Rails 3 backend. If you run into new problems (especially around Active Record or your postgresql gem) you should try first updating your Ruby installation to 1.9.3 and use a more recent 'pg' gem. If that fails, we'd love to see your bug report (just drop all the detail you can into an issue on GitHub). In the meantime, you can checkout the rails2 branch, which was branched from master immediately before this cutover. Squashed commit of the following: commit 5802ec851580341c6717dfea529027c12678d35f Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 23:30:12 2012 -0500 Enable MSF_BUNDLE_GEMS mode by default (set to N/F/0 to disable) commit 8102f98dce9eb0c73c4374e40dce09af7b51d060 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 23:30:03 2012 -0500 Add a method to expand win32 file paths commit bda6479d154cf75572dd5de8b66bfde661a55de9 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 18:53:44 2012 -0500 Fix 1.8.x compatibility commit 101ce4eb17bfdf755ef8c0a5198174668b6cd6fd Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 18:40:59 2012 -0500 Use verbose instead of stringio commit 5db467ffb593488285576d183b1662093e454b3e Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 18:30:06 2012 -0500 Hide the iconv warning, were stuck with it due to EBCDIC support commit 63b9cb20eb6a61daf4effb4c8d2761c16ff0c4e0 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 18:29:58 2012 -0500 Dont use GEM_HOME by default commit ca49271c22c314a4465fff934334df18c704cbc0 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 18:23:34 2012 -0500 Move Gemfile to root (there be dragons, lets find them) and catch failed bundler loads commit 34af04076a068e9f60c5526045ddbba5fca359fd Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 18:18:29 2012 -0500 Fallback to bundler when not running inside of a installer env commit ed1066a4f3f12fae7d4afc03eb1ab70ffe2f9cf3 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 16:26:55 2012 -0500 Remove a mess of gems that were not actually required commit 21290a73926809e9049a59359449168f740d13d2 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 15:59:10 2012 -0500 Hack around a gem() call that is well-intentioned but an obstacle in this case commit 8e414a8bfab9641c81088d22f73033be5b37a700 Author: Tod Beardsley <todb@metasploit.com> Date: Sun Apr 15 15:06:08 2012 -0500 Ruby, come on. Ducktype this. Please. Use interpolated strings to get the to_s behavior you don't get with just plussing. commit 0fa92c58750f8f84edbecfaab72cd2da5062743f Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 15:05:42 2012 -0500 Add new eventmachine/thin gems commit 819d5e7d45e0a16741d3852df3ed110b4d7abc44 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 15:01:18 2012 -0500 Purge (reimport in a second) commit ea6f3f6c434537ca15b6c6674e31081e27ce7f86 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 14:54:42 2012 -0500 Cleanup uncessary .so files (ext vs lib) commit d219330a3cc563e9da9f01fade016c9ed8cda21c Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 14:53:02 2012 -0500 PG gems built against the older installation environment commit d6e590cfa331ae7b25313ff1471c6148a6b36f3b Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 14:06:35 2012 -0500 Rename to include the version commit a893de222b97ce1222a55324f1811b0262aae2d0 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 13:56:47 2012 -0500 Detect older installation environments and load the arch-lib directories into the search path commit 6444bba0a421921e2ebe2df2323277a586f9736f Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 13:49:25 2012 -0500 Merge in windows gems commit 95efbcfde220917bc7ee08e6083d7b383240d185 Author: Tod Beardsley <todb@metasploit.com> Date: Sun Apr 15 13:49:33 2012 -0500 Report_vuln shouldn't use :include in finder find_or_create_by doesn't take :include as a param. commit c5f99eb87f0874ef7d32fa42828841c9a714b787 Author: David Maloney <DMaloney@rapid7.com> Date: Sun Apr 15 12:44:09 2012 -0500 One more msised Mdm namespace issue commit 2184e2bbc3dd9b0993e8f21d2811a65a0c694d68 Author: David Maloney <DMaloney@rapid7.com> Date: Sun Apr 15 12:33:41 2012 -0500 Fixes some mroe Mdm namespace confusion Fixes #6626 commit 10cee17f391f398bb2be3409137ff7348c7a66ee Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 03:40:44 2012 -0500 Add robots gem (required by webscan) commit 327e674c83850101364c9cca8f8d16da1de3dfb5 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 03:39:05 2012 -0500 Fix missing error checks commit a5a24641866e47e611d7636a3f19ba3b3ed10ac5 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 01:15:37 2012 -0500 Reorder requires and add a method for injecting a new migration path commit 250a5fa5ae8cb05807af022aa4168907772c15f8 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 00:56:09 2012 -0500 Remove missing constant (use string) and add gemcache cleaner commit 37ad6063fce0a41dddedb857fa49aa2c4834a508 Merge: d47ee82 |
||
---|---|---|
.. | ||
bin | ||
lib | ||
test | ||
COPYING | ||
Gemfile | ||
README.md | ||
Rakefile | ||
TEMPLATES.md | ||
tilt.gemspec |
README.md
Tilt
Tilt is a thin interface over a bunch of different Ruby template engines in an attempt to make their usage as generic possible. This is useful for web frameworks, static site generators, and other systems that support multiple template engines but don't want to code for each of them individually.
The following features are supported for all template engines (assuming the feature is relevant to the engine):
- Custom template evaluation scopes / bindings
- Ability to pass locals to template evaluation
- Support for passing a block to template evaluation for "yield"
- Backtraces with correct filenames and line numbers
- Template file caching and reloading
- Fast, method-based template source compilation
The primary goal is to get all of the things listed above right for all template engines included in the distribution.
Support for these template engines is included with the package:
ENGINE FILE EXTENSIONS REQUIRED LIBRARIES
-------------------------- ----------------------- ----------------------------
ERB .erb, .rhtml none (included ruby stdlib)
Interpolated String .str none (included ruby core)
Erubis .erb, .rhtml, .erubis erubis
Haml .haml haml
Sass .sass haml (< 3.1) or sass (>= 3.1)
Scss .scss haml (< 3.1) or sass (>= 3.1)
Less CSS .less less
Builder .builder builder
Liquid .liquid liquid
RDiscount .markdown, .mkd, .md rdiscount
Redcarpet .markdown, .mkd, .md redcarpet
BlueCloth .markdown, .mkd, .md bluecloth
Kramdown .markdown, .mkd, .md kramdown
Maruku .markdown, .mkd, .md maruku
RedCloth .textile redcloth
RDoc .rdoc rdoc
Radius .radius radius
Markaby .mab markaby
Nokogiri .nokogiri nokogiri
CoffeeScript .coffee coffee-script (+ javascript)
Creole (Wiki markup) .wiki, .creole creole
WikiCloth (Wiki markup) .wiki, .mediawiki, .mw wikicloth
Yajl .yajl yajl-ruby
These template engines ship with their own Tilt integration:
ENGINE FILE EXTENSIONS REQUIRED LIBRARIES
-------------------------- ----------------- ----------------------------
Slim .slim slim (>= 0.7)
Embedded JavaScript sprockets
Embedded CoffeeScript sprockets
JST sprockets
See TEMPLATES.md for detailed information on template engine options and supported features.
Basic Usage
Instant gratification:
require 'erb'
require 'tilt'
template = Tilt.new('templates/foo.erb')
=> #<Tilt::ERBTemplate @file="templates/foo.rb" ...>
output = template.render
=> "Hello world!"
It's recommended that calling programs explicitly require template engine libraries (like 'erb' above) at load time. Tilt attempts to lazy require the template engine library the first time a template is created but this is prone to error in threaded environments.
The Tilt
module contains generic implementation classes for all supported
template engines. Each template class adheres to the same interface for
creation and rendering. In the instant gratification example, we let Tilt
determine the template implementation class based on the filename, but
Tilt::Template
implementations can also be used directly:
template = Tilt::HamlTemplate.new('templates/foo.haml')
output = template.render
The render
method takes an optional evaluation scope and locals hash
arguments. Here, the template is evaluated within the context of the
Person
object with locals x
and y
:
template = Tilt::ERBTemplate.new('templates/foo.erb')
joe = Person.find('joe')
output = template.render(joe, :x => 35, :y => 42)
If no scope is provided, the template is evaluated within the context of an
object created with Object.new
.
A single Template
instance's render
method may be called multiple times
with different scope and locals arguments. Continuing the previous example,
we render the same compiled template but this time in jane's scope:
jane = Person.find('jane')
output = template.render(jane, :x => 22, :y => nil)
Blocks can be passed to render
for templates that support running
arbitrary ruby code (usually with some form of yield
). For instance,
assuming the following in foo.erb
:
Hey <%= yield %>!
The block passed to render
is called on yield
:
template = Tilt::ERBTemplate.new('foo.erb')
template.render { 'Joe' }
# => "Hey Joe!"
Template Mappings
The Tilt
module includes methods for associating template implementation
classes with filename patterns and for locating/instantiating template
classes based on those associations.
The Tilt::register
method associates a filename pattern with a specific
template implementation. To use ERB for files ending in a .bar
extension:
>> Tilt.register Tilt::ERBTemplate, 'bar'
>> Tilt.new('views/foo.bar')
=> #<Tilt::ERBTemplate @file="views/foo.bar" ...>
Retrieving the template class for a file or file extension:
>> Tilt['foo.bar']
=> Tilt::ERBTemplate
>> Tilt['haml']
=> Tilt::HamlTemplate
It's also possible to register template file mappings that are more specific
than a file extension. To use Erubis for bar.erb
but ERB for all other .erb
files:
>> Tilt.register Tilt::ErubisTemplate, 'bar.erb'
>> Tilt.new('views/foo.erb')
=> Tilt::ERBTemplate
>> Tilt.new('views/bar.erb')
=> Tilt::ErubisTemplate
The template class is determined by searching for a series of decreasingly
specific name patterns. When creating a new template with
Tilt.new('views/foo.html.erb')
, we check for the following template
mappings:
views/foo.html.erb
foo.html.erb
html.erb
erb
Fallback mode
If there are more than one template class registered for a file extension, Tilt will automatically try to load the version that works on your machine:
- If any of the template engines has been loaded already: Use that one.
- If not, it will try to initialize each of the classes with an empty template.
- Tilt will use the first that doesn't raise an exception.
- If however all of them failed, Tilt will raise the exception of the first template engine, since that was the most preferred one.
Template classes that were registered last would be tried first. Because the Markdown extensions are registered like this:
Tilt.register Tilt::BlueClothTemplate, 'md'
Tilt.register Tilt::RDiscountTemplate, 'md'
Tilt will first try RDiscount and then BlueCloth. You could say that RDiscount has a higher priority than BlueCloth.
The fallback mode works nicely when you just need to render an ERB or Markdown template, but if you depend on a specific implementation, you should use #prefer:
# Prefer BlueCloth for all its registered extensions (markdown, mkd, md)
Tilt.prefer Tilt::BlueClothTemplate
# Prefer Erubis for .erb only:
Tilt.prefer Tilt::ErubisTemplate, 'erb'
When a file extension has a preferred template class, Tilt will always use that class, even if it raises an exception.
Template Compilation
Tilt compiles generated Ruby source code produced by template engines and reuses it on subsequent template invocations. Benchmarks show this yields a 5x-10x performance increase over evaluating the Ruby source on each invocation.
Template compilation is currently supported for these template engines: StringTemplate, ERB, Erubis, Haml, Nokogiri, Builder and Yajl.
LICENSE
Tilt is Copyright (c) 2010 Ryan Tomayko and
distributed under the MIT license. See the COPYING
file for more info.