Sha256: 8841d820d519f31e023aca95ddd6c67932131285180cb491e8cd2560919ea4de

Contents?: true

Size: 1.87 KB

Versions: 1

Compression:

Stored size: 1.87 KB

Contents

require 'rails' unless defined?(::Rails)
require 'action_controller' unless defined?(::ActionController)

class View
  VERSION = '2.0.0'

  def View.version
    View::VERSION
  end

  def View.load_shit!
    @loaded_shit ||= (
      unless defined?(::Rails)
        require 'rails'
      end

      unless defined?(::ActionController)
        require 'action_controller'
      end

      unless defined?(::ActionDispatch::TestRequest)
        require 'action_dispatch/testing/test_request.rb' 
      end

      unless defined?(::ActionDispatch::TestResponse)
        require 'action_dispatch/testing/test_response.rb' 
      end

      true
    )
  end

  def View.controller(&block)
    load_shit!

    controller_class = Class.new(::ActionController::Base) do
      layout false
      helper :all
    end

    default_url_options =
      begin
        require 'rails_default_url_options'
        DefaultUrlOptions
      rescue LoadError
        options[:default_url_options] || {}
      end

    store = ActiveSupport::Cache::MemoryStore.new 
    request = ActionDispatch::TestRequest.new 
    response = ActionDispatch::TestResponse.new 

    controller = controller_class.new()

    controller.perform_caching = false
    controller.cache_store = store 
    controller.request = request 
    controller.response = response 
    #controller.send(:initialize_template_class, response) 
    #controller.send(:assign_shortcuts, request, response) 
    controller.send(:default_url_options).merge!(default_url_options)
    block ? controller.instance_eval(&block) : controller
  end

  def View.render(*args)
    Array(View.controller{ render(*args) }).join.html_safe
  end
end

Rails_view = ::View

__END__
puts View.render(:inline => "<%= Time.now %> <%= link_to :foo, root_path %><%= solid :bar %><%= link_to :chiclet, Chiclet.first %>")
puts View.render(:inline => "* one\n* two\n* three\n", :type => :markdown)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_view-2.0.0 lib/rails_view.rb