Skip to content

Commit

Permalink
Templates: Added :raw format and format changing.
Browse files Browse the repository at this point in the history
Now the render options can specify the format for a template's arguments.  This
allows special templates like syntax highlighting to avoid rendering arguments
entirely (by setting options[:template_formats][:template_name] = :raw) so that
the arguments can be rendered by the template itself without side-effects like
link footnotes.  The :raw format simply returns the original parsed text of
arguments.

Another change in this commit is to remove the :tree option that was added a
few commits ago.  It was a bad idea, although necessary in some cases.  I
think, however, for those cases it is better to monkey-patch something in.
  • Loading branch information
rdblue committed Nov 14, 2010
1 parent 175ce50 commit 4620fde
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/marker/templates.rb
Expand Up @@ -17,12 +17,13 @@ def to_s( options = {} )
end

def render( format, options = {} )
# optionally change the format for argument rendering
if options[:template_formats] and options[:template_formats][target]
format = options[:template_formats][target]
end

ordered, named = arg_list( format, options )
Marker.templates.send(
target, format,
ordered, named,
options.merge( :tree => self )
)
Marker.templates.send( target, format, ordered, named, options )
end

def target
Expand Down Expand Up @@ -50,6 +51,18 @@ def to_arg_list( format, options = {} )
named_params = {}

case format
when :raw
# don't render the text, just return the original value
# this is needed for special templates, like syntax highlighting
to_a.each do |a|
next unless a
value = ( a.val ? a.val.text_value : "" )
if a.name
named_params[a.name.to_s(options)] = value
else
pos_params << value
end
end
when :html
to_a.each do |a|
next unless a
Expand Down Expand Up @@ -110,7 +123,6 @@ def val
# A set of basic templates for rendering
module DefaultTemplates
def self.method_missing( sym, *args )
args.pop # don't print the options hash
"render:#{sym}( #{args.map(&:inspect).join(', ')} )"
end
end
Expand Down

0 comments on commit 4620fde

Please sign in to comment.