class Jcompiler::Provider def initialize @context = nil end def object!(arg_name = nil, &block) pre_context = context context = [] srcs, subst_src = if arg_name [block.call(nil), "#{block.parameters[0][1]}=#{arg_name};"] else [block.call, ''] end context = pre_context %{"{\#{#{subst_src}[#{srcs.join(',')}].join(',')}}"} end def array!(arg_name, &block) item_name = block.parameters[0][1].to_s src = block.call(nil) %{"[\#{#{arg_name}.map { |#{item_name}| #{src} }.join(',')}]"} end def integer!(i) %{"#{i}"} end def method_missing(name, *args, &block) context << %{"\\"#{name}\\":3"} end private attr_accessor :context end