-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add filter registration system, break out existing filters into sep…
…arate files under filters/ * bin/webby loads webby from relative path * SITE defaults in a single place (the library's webby.rb vs webby.rb AND setup.rb); to be overridden in project Rakefile * Support automatically loading vendor/webby when loading rake in projects * Support automatically loading vendor/filters when loading rake in projects * Very little documentation and no testing; YMMV
- Loading branch information
Bruce Williams
committed
Dec 8, 2007
1 parent
2f58e71
commit bb25f47
Showing
14 changed files
with
172 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,6 @@ | ||
#!/usr/bin/env ruby | ||
|
||
begin | ||
require 'rubygems' | ||
require 'webby' | ||
rescue LoadError | ||
path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
raise if $:.include? path | ||
$: << path | ||
retry | ||
end | ||
|
||
require File.dirname(__FILE__) << "/../lib/webby" | ||
::Webby::Main.run ARGV | ||
|
||
# EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
|
||
module Webby | ||
|
||
module Filters | ||
|
||
class << self | ||
|
||
# Register a handler for a filter | ||
def register(filter, &block) | ||
handlers[filter.to_s] = block | ||
end | ||
|
||
# Process input through filters | ||
def process(renderer, page, input) | ||
# Start a new cursor for this page | ||
Cursor.new(renderer, page).start_for(input) | ||
end | ||
|
||
# Access a filter handler | ||
def [](name) | ||
handlers[name] | ||
end | ||
|
||
####### | ||
private | ||
####### | ||
|
||
# The registered filter handlers | ||
def handlers | ||
@handlers ||= {} | ||
end | ||
|
||
# Instances of this class handle processing a set of filters | ||
# for a given renderer and page. | ||
# Note: The instance is passed as the second argument to filters | ||
# that require two parameters and can be used to access | ||
# information on the renderer, page, or filters being | ||
# processed. | ||
class Cursor | ||
|
||
attr_reader :renderer, :page, :filters, :log | ||
def initialize(renderer, page) | ||
@renderer, @page = renderer, page | ||
@filters = Array(page.filter) | ||
@log = Logging::Logger[self] | ||
@processed = 0 | ||
end | ||
|
||
def start_for(input) | ||
filters.inject(input) do |result, filter| | ||
handler = Filters[filter] | ||
args = [result, self][0, handler.arity] | ||
handle(filter, handler, *args) | ||
end | ||
end | ||
|
||
# The list of filters yet to be processed | ||
def remaining_filters | ||
filters[@processed..-1] | ||
end | ||
|
||
# The name of the current filter | ||
def current_filter | ||
filters[@processed] | ||
end | ||
|
||
####### | ||
private | ||
####### | ||
|
||
# Process arguments through a single filter | ||
def handle(filter, handler, *args) | ||
result = handler.call(*args) | ||
@processed += 1 | ||
result | ||
rescue NameError => e | ||
log.fatal "Name error in filter `#{filter}' (missing dependency?): #{e.message}" | ||
exit 1 | ||
rescue => e | ||
log.fatal "Error in filter `#{filter}': #{e.message}" | ||
exit 1 | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Render text via ERB using the built in ERB library. | ||
Webby::Filters.register :erb do |input, cursor| | ||
@page = cursor.page | ||
@content = cursor.renderer.content | ||
ERB.new(input, nil, '-').result(binding) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Render text via the Haml library | ||
Webby::Filters.register :haml do |input, cursor| | ||
opts = cursor.page.haml_options || {} | ||
opts[:locals] ||= {} | ||
opts[:locals].merge!(:page => cursor.renderer.page, :pages => cursor.renderer.pages) | ||
Haml::Engine.new(input, opts).to_html | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Render text via markdown using the BlueCloth library. | ||
Webby::Filters.register :markdown do |input| | ||
BlueCloth.new(input).to_html | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Render text via the Sass library (part of Haml) | ||
Webby::Filters.register :sass do |input, cursor| | ||
opts = cursor.page.sass_options || {} | ||
Sass::Engine.new(input, opts).render | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Render text via textile using the RedCloth library. | ||
Webby::Filters.register :textile do |input| | ||
RedCloth.new(input).to_html | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.