Sha256: 0067bfe328e7c5a8926a7b5d9fe3272d7b7ca124df3a55ca6a14ae093c499177

Contents?: true

Size: 1.92 KB

Versions: 13

Compression:

Stored size: 1.92 KB

Contents

require "ende/version"

# TODO add csrf extensions to autoloadpaths
require "ende/csrf_extensions"

module Ende
  class Railtie < Rails::Railtie
    config.to_prepare do
      current_dir = Pathname.new(__FILE__).parent.parent

      assets      = Ende.assets

      assets.paths << current_dir.join('lib', 'assets', 'javascripts').to_s
      assets.paths << current_dir.join('lib', 'assets', 'stylesheets').to_s
      assets.paths << current_dir.join('lib', 'assets', 'components' ).to_s

      assets.paths << current_dir.join('vendor', 'assets', 'javascripts').to_s
      assets.paths << current_dir.join('vendor', 'assets', 'stylesheets').to_s
      assets.paths << current_dir.join('vendor', 'assets', 'components' ).to_s

    end

    # Check if devise exists and extend devise controllers to send
    # authenticity (csrf) token
    # TODO move each extension to its own folder
    initializer :csrf_extensions do |app|
      app.config.to_prepare do
        # TODO map devise configurations and seek for show route for
        # each defined resource
        if defined? UsersController
          UsersController.class_eval do
            include ::CsrfExtensions
            after_filter :add_new_csrf_token, only: :show
          end
        end

        Devise::SessionsController.class_eval do
          include ::CsrfExtensions
          after_filter :add_new_csrf_token, only: [:create, :destroy]
        end

        Devise::RegistrationsController.class_eval do
          include ::CsrfExtensions
          after_filter :add_new_csrf_token, only: [:create]
        end
      end
    end
  end

  def Ende.load_widget_extensions
    current_dir = Pathname.new(__FILE__).parent.parent
    Dir.glob(current_dir.join 'lib', 'assets', '**', '*.rb').each do |extension|
      require extension
    end
  end

  def Ende.assets
    assets = Railtie.config.assets rescue nil
    assets or Rails.application.config.assets
  end
end

Ende.load_widget_extensions

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ende-0.3.3 lib/ende.rb
ende-0.3.2 lib/ende.rb
ende-0.3.1 lib/ende.rb
ende-0.3.0 lib/ende.rb
ende-0.2.21 lib/ende.rb
ende-0.2.20 lib/ende.rb
ende-0.2.19 lib/ende.rb
ende-0.2.18 lib/ende.rb
ende-0.2.17 lib/ende.rb
ende-0.2.16 lib/ende.rb
ende-0.2.15 lib/ende.rb
ende-0.2.14 lib/ende.rb
ende-0.2.13 lib/ende.rb