class Wedge::HTML::DSL
Attributes
scope[RW]
Public Class Methods
html(&block)
click to toggle source
fix: opal bug. for some reason this can't be in the class << self block.
# File lib/wedge/html.rb, line 85 def self.html &block DSL.scope!(scope).new(nil, nil, &block) end
new(tag, *args, &block)
click to toggle source
# File lib/wedge/html.rb, line 42 def initialize(tag, *args, &block) @tag = tag @content = args.find { |a| a.instance_of? String } @attributes = args.find { |a| a.instance_of? Hash } @attr_string = [] self.instance_eval &block if block_given? end
scope!(scope)
click to toggle source
# File lib/wedge/html.rb, line 92 def scope! scope klass = Class.new(self) klass.instance_variable_set(:@scope, scope) klass end
Public Instance Methods
children()
click to toggle source
# File lib/wedge/html.rb, line 59 def children @children ||= [] end
method_missing(tag, *args, &block)
click to toggle source
# File lib/wedge/html.rb, line 70 def method_missing(tag, *args, &block) if !TAGS.include?(tag.to_s) && scope.respond_to?(tag, true) scope.send(tag, *args, &block) else child = DSL.scope!(scope).new(tag.to_s, *args, &block) children << child child end end
scope()
click to toggle source
# File lib/wedge/html.rb, line 80 def scope self.class.scope end
to_html()
click to toggle source
# File lib/wedge/html.rb, line 50 def to_html if @tag @attr_string << " #{@attributes.map {|k,v| "#{k}=#{v.to_s.inspect}" }.join(" ")}" if @attributes "<#{@tag}#{@attr_string.join}>#{@content}#{children.map(&:to_html).join}</#{@tag}>" else "#{@content}#{children.map(&:to_html).join}" end end