class Undies::Template
Constants
- ESCAPE_HTML
Ripped from Rack v1.3.0 ======================================
> ripped b/c I don't want a dependency on Rack for just this¶ ↑
- ESCAPE_HTML_PATTERN
Public Class Methods
escape_html(string)
click to toggle source
Escape ampersands, brackets and quotes to their HTML/XML entities.
# File lib/undies/template.rb, line 31 def self.escape_html(string) string.to_s.gsub(ESCAPE_HTML_PATTERN){|c| ESCAPE_HTML[c] } end
flush(template)
click to toggle source
have as many methods on the class level as possible to keep from polluting the public instance methods, the instance scope, and to maximize the effectiveness of the Template#method_missing logic
# File lib/undies/template.rb, line 15 def self.flush(template) template.__flush end
new(*args)
click to toggle source
end Rip from Rack v1.3.0 =====================================
# File lib/undies/template.rb, line 36 def initialize(*args) # setup a node stack with the given output obj @_undies_io = if args.last.kind_of?(Undies::IO) args.pop else raise ArgumentError, "please provide an IO object" end # apply any given data to template scope as instance variables (args.last.kind_of?(::Hash) ? args.pop : {}).each do |k, v| self.instance_variable_set("@#{k}", v) end # push a root node onto the IO @_undies_io.push!(RootNode.new(@_undies_io)) if @_undies_io.empty? # if given some source, build it if args.last.kind_of?(Source) # setup a source stack with the given source @_undies_source_stack = SourceStack.new(args.pop) # yield to recursivley render the source stack __yield # flush any elements that need to be built __flush end end