Sha256: 2ed2730c6065fdcab11074a50f3aa2b144800a94cac54ac0bcce3902e0466e35

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

methods = Hash.public_instance_methods(true)
unless methods.include?(:extractable_options?)
  Hash.send(:define_method, :extractable_options?, proc do
    instance_of?(Hash)
  end)
end

unless methods.include?(:symbolize_keys!)
  Hash.send(:define_method, :symbolize_keys!, proc do
    keys.each do |key|
      next unless key.respond_to?(:to_sym)
      self[key.to_sym] = delete(key)
    end
    self
  end)
end

methods = Array.public_instance_methods(true)
unless methods.include?(:extract_options!)
  Array.send(:define_method, :extract_options!, proc do
    if last.is_a?(Hash) && last.extractable_options?
      pop
    else
      {}
    end
  end)
end

module WrapIt
  #
  # Non rails render implementation
  #
  module Renderer
    def self.included(base)
      base == Base || fail(
        TypeError,
        "#{self.class.name} can be included only into WrapIt::Base"
      )
    end

    protected

    def empty_html
      ''
    end

    def capture(text = nil)
      block_given? ? yield : text
    end

    def concat(text)
      @buffer ||= empty_html
      @buffer << text
    end

    def output_buffer
      @buffer
    end

    def content_tag(tag, body, options = {})
      arr = [tag]
      options.each { |o, v| arr << "#{o}=\"#{v.to_s}\"" }
      "<#{arr.join(' ')}>#{body}</#{tag}>"
    end

    def html_safe(text)
      text
    end

    def html_safe?(text)
      true
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
wrap_it-1.0.2 lib/wrap_it/no_rails.rb
wrap_it-1.0.1 lib/wrap_it/no_rails.rb
wrap_it-1.0.0 lib/wrap_it/no_rails.rb
wrap_it-0.2.0 lib/wrap_it/no_rails.rb
wrap_it-0.1.5 lib/wrap_it/no_rails.rb
wrap_it-0.1.4 lib/wrap_it/no_rails.rb