Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a _guard method to the renderer that can be used to protect blo…

…cks of

text from processing by remaining filters. Right now only the textile filter is
guarded against.
  • Loading branch information...
commit 8f2cde7f1bcdeb716fbc5cb6cbe2ddf22e1a332f 1 parent c3d3102
@TwP TwP authored
View
6 lib/webby/helpers/coderay_helper.rb
@@ -53,10 +53,8 @@ def coderay( *args, &block )
out << ::CodeRay.scan(text, lang).html(cr_opts)
out << '</pre></div>'
- if @_cursor.remaining_filters.include? 'textile'
- out.insert 0, "<notextile>\n"
- out << "\n</notextile>"
- end
+ # put some guards around the output (specifically for textile)
+ out = _guard(out)
concat_erb(out, block.binding)
return
View
8 lib/webby/helpers/graphviz_helper.rb
@@ -119,12 +119,8 @@ def graphviz( *args, &block )
IO.popen(cmd, 'w') {|io| io.write text}
GraphvizHelper.error_check(err)
- # see if we need to put some guards around the output
- # (specifically for textile)
- if @_cursor.remaining_filters.include? 'textile'
- out.insert 0, "<notextile>\n"
- out << "\n</notextile>"
- end
+ # put some guards around the output (specifically for textile)
+ out = _guard(out)
concat_erb(out, block.binding)
return
View
6 lib/webby/helpers/tex_img_helper.rb
@@ -116,10 +116,8 @@ def tex2img( *args, &block )
end
out << " />\n"
- if @_cursor.remaining_filters.include? 'textile'
- out.insert 0, "<notextile>\n"
- out << "\n</notextile>"
- end
+ # put some guards around the output (specifically for textile)
+ out = _guard(out)
concat_erb(out, block.binding)
return
View
6 lib/webby/helpers/ultraviolet_helper.rb
@@ -47,10 +47,8 @@ def uv( *args, &block )
out << Uv.parse(text, "xhtml", lang, line_numbers, theme)
out << '</div>'
- if @_cursor.remaining_filters.include? 'textile'
- out.insert 0, "<notextile>\n"
- out << "\n</notextile>"
- end
+ # put some guards around the output (specifically for textile)
+ out = _guard(out)
concat_erb(out, block.binding)
return
View
52 lib/webby/renderer.rb
@@ -94,17 +94,7 @@ def render_page
# Webby::Resources::DB#find method for more information.
#
def render_partial( part, opts = {} )
- part = case part
- when String
- fn = '_' + part
- p = Resources.partials.find(
- :filename => fn, :in_directory => @page.dir ) rescue nil
- p ||= Resources.partials.find(:filename => fn)
- raise ::Webby::Error, "could not find partial '#{part}'" if p.nil?
- p
- when ::Webby::Resources::Partial
- part
- else raise ::Webby::Error, "expecting a partial or a partial name" end
+ part = _find_partial(part)
_track_rendering(part.path) {
_configure_locals(opts[:locals])
@@ -143,9 +133,6 @@ def get_binding
@_bindings.last
end
-
- private
-
# call-seq:
# _layout_page => string
#
@@ -261,6 +248,43 @@ def _configure_locals( locals )
end
end
+ # Attempts to locate a partial by name. The search starts in the directory
+ # of the current page being rendered. If the partial is not found in the
+ # current directory, the search starts again at the root of the content
+ # folder.
+ #
+ # Raies a Webby::Error if the partial could not be found.
+ #
+ def _find_partial( part )
+ case part
+ when String
+ fn = '_' + part
+ p = Resources.partials.find(
+ :filename => fn, :in_directory => @page.dir ) rescue nil
+ p ||= Resources.partials.find(:filename => fn)
+ raise ::Webby::Error, "could not find partial '#{part}'" if p.nil?
+ p
+ when ::Webby::Resources::Partial
+ part
+ else raise ::Webby::Error, "expecting a partial or a partial name" end
+ end
+
+ # This method will put filter guards around the given input string. This
+ # will protect the string from being processed by any remaining filters
+ # (specifically the textile filter).
+ #
+ # The string is returned unchanged if there are no remaining filters to
+ # guard against.
+ #
+ def _guard( str )
+ return str unless @_cursor
+
+ if @_cursor.remaining_filters.include? 'textile'
+ str = "<notextile>\n%s\n</notextile>" % str
+ end
+ str
+ end
+
# Returns the binding in the scope of this Renderer object.
#
def _binding() binding end
View
2  lib/webby/resources/partial.rb
@@ -8,7 +8,7 @@ module Webby::Resources
# correspond directly to an output file.
#
# Partials can contain YAML meta-data at the top of the file. This
-# information is only used to determin the filters to apply to the
+# information is only used to determine the filters to apply to the
# partial. If there is no meta-data, then the partial text is used "as is"
# without any processing by the Webby rendering engine.
#
View
10 lib/webby/resources/resource.rb
@@ -69,6 +69,16 @@ def <=>( other )
end
# call-seq:
+ # resource[key] => value or nil
+ #
+ # Returns the value associated with the given meta-data key. Key is
+ # usually a string.
+ #
+ def []( key )
+ @mdata[key]
+ end
+
+ # call-seq:
# method_missing( symbol [, *args, &block] ) => result
#
# Invoked by Ruby when a message is sent to the resource that it cannot
Please sign in to comment.
Something went wrong with that request. Please try again.