Skip to content

Instantly share code, notes, and snippets.

View lewispb's full-sized avatar

Lewis Buckley lewispb

View GitHub Profile
@greendog
greendog / liquid.rb
Created January 23, 2013 12:54
Create a Liquid Handler for Rails 3.1 Use: require 'action_view/template/handlers/liquid' ActionView::Template.register_template_handler :liquid, ActionView::Template::Handlers::Liquid
class ActionView::Template::Handlers::Liquid
def self.call(template)
"ActionView::Template::Handlers::Liquid.new(self).render(#{template.source.inspect}, local_assigns)"
end
def initialize(view)
@view = view
end
def render(template, local_assigns = {})
##
# Get the context for a search term and highlight the term itself
# text: string containing the search term and additional information
# term: string with the term you're looking for
# words: int for how many words to include total
# padding_left: int for characters to the left of the search term
# padding_right: int for characters to the right of the search term
#
# Only handles the first instance of a given term. Can be modified to take
# character positions denoting the start and stop of term(s).