class Slight::DSL
Public Class Methods
new(io)
click to toggle source
# File lib/slight/dsl.rb, line 91 def initialize(io) @output_buffer = io #@root = page_node.new("root") end
Public Instance Methods
binding_scope()
click to toggle source
# File lib/slight/dsl.rb, line 105 def binding_scope binding end
echo(str)
click to toggle source
# File lib/slight/dsl.rb, line 98 def echo(str); @output_buffer << str; nil; end
method_missing(fun, *param, &block)
click to toggle source
# File lib/slight/dsl.rb, line 100 def method_missing(fun, *param, &block) __dsl__define(fun) self.send(fun, *param, &block) end
puts(str)
click to toggle source
# File lib/slight/dsl.rb, line 96 def puts(str); @output_buffer << html_escape(str); nil; end
resolve_blinding(blinding)
click to toggle source
# File lib/slight/dsl.rb, line 117 def resolve_blinding(blinding) blinding.each do |m| undef_method m end end
resolve_local(var,val)
click to toggle source
# File lib/slight/dsl.rb, line 123 def resolve_local(var,val) self.singleton_class.class_eval do define_method(var.to_sym){ return val } end end
resolve_shortcutA(shortcutA)
click to toggle source
# File lib/slight/dsl.rb, line 109 def resolve_shortcutA(shortcutA) @__dsl__attr_replacements = shortcutA end
resolve_shortcutT(shortcutT)
click to toggle source
# File lib/slight/dsl.rb, line 113 def resolve_shortcutT(shortcutT) @__dsl__tag_replacements = shortcutT end
Private Instance Methods
__dsl__define(tag)
click to toggle source
# File lib/slight/dsl.rb, line 132 def __dsl__define(tag) self.singleton_class.class_eval do define_method(tag){|*at, &block| __dsl__packup(tag.to_s, *at, &block) } end end
__dsl__packup(tag, *at) { || ... }
click to toggle source
# File lib/slight/dsl.rb, line 140 def __dsl__packup(tag, *at) attr_replacements = @__dsl__attr_replacements||{} tag_replacements = @__dsl__tag_replacements||{} attrs=[] if self_close = tag.end_with?("!") then tag = tag[0..-2] end at.each do |var| if var.class == Hash then var.each_pair do |a, v| unless a.to_sym == :_ then at_new = attr_replacements.fetch(a, a) at_new = v.class == String ? "#{at_new}=\"#{v}\"" : "#{at_new}=#{v.to_s}" else at_new = "#{v}" end attrs.push at_new end elsif var.class == String attrs.push "class=\"#{var}\"" end end s_tag = tag_replacements.fetch(tag.to_sym, tag) e_tag = s_tag.split(" ")[0] space = attrs.length > 0 ? " " : "" echo "<#{s_tag}#{space}#{attrs.join(" ")}" if self_close then echo "/>\n" else echo ">\n" puts yield.to_s if block_given? echo "</#{e_tag}>\n" end end