Sha256: 41a63148de6e28d7a0dee65d73976187aece8f51b616167ab11c739baa5790e2

Contents?: true

Size: 1.56 KB

Versions: 8

Compression:

Stored size: 1.56 KB

Contents

require 'ostruct'
require 'abstract_controller'
require 'action_view'
require 'action_dispatch/http/mime_type'

module Lurker
  class RenderingController < ::AbstractController::Base
    # Include all the concerns we need to make this work
    include AbstractController::Helpers
    include AbstractController::Rendering
    include ActionView::Rendering if defined?(ActionView::Rendering)
    include ActionView::Layouts if defined?(ActionView::Layouts) # Rails 4.1.x
    include AbstractController::Layouts if defined?(AbstractController::Layouts) # Rails 3.2.x, 4.0.x
    include ActionView::Context

    self.view_paths = File.join(File.dirname(__FILE__), "templates")

    # Define additional helpers, this one is for csrf_meta_tag
    helper_method :protect_against_forgery?, :tag_with_anchor

    # override the layout in your subclass if needed.
    layout 'application'

    # we are not in a browser, no need for this
    def protect_against_forgery?
      false
    end

    def tag_with_anchor(tag, content, anchor_slug = nil)
      anchor_slug ||= content.downcase.gsub(' ', '_')
      <<-EOS
      <#{tag} id="#{anchor_slug}">
        <a href="##{anchor_slug}" class="anchor">
          #{content}
        </a>
      </#{tag}>
      EOS
    end

    # so that your flash calls still work
    def flash
      {}
    end

    # and nil request to differentiate between live and offline
    def request
      OpenStruct.new
    end

    # and params will be accessible
    def params
      {}
    end

    # so that your cookies calls still work
    def cookies
      {}
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
lurker-0.6.9 lib/lurker/rendering_controller.rb
lurker-0.6.8 lib/lurker/rendering_controller.rb
lurker-0.6.7 lib/lurker/rendering_controller.rb
lurker-0.6.6 lib/lurker/rendering_controller.rb
lurker-0.6.5 lib/lurker/rendering_controller.rb
lurker-0.6.4 lib/lurker/rendering_controller.rb
lurker-0.6.3 lib/lurker/rendering_controller.rb
lurker-0.6.2 lib/lurker/rendering_controller.rb