Sha256: d25dbb08441a824f7891f8299628abe606807a8fbd2af5291c1d4e771140dd30

Contents?: true

Size: 1.29 KB

Versions: 18

Compression:

Stored size: 1.29 KB

Contents

require 'oxymoron/concern'

module Oxymoron
  class Engine < ::Rails::Engine
    initializer 'oxymoron.dependent_on_routes', after: "sprockets.environment" do
      Rails.application.config.after_initialize do

        if Config.rewrite_form_for
          ActionView::Base.send :include, ActionViewExtensions::FormHelperRewrite
        end

        ActionView::Base.send :include, ActionViewExtensions::FormHelper

        module ActionView::Helpers
          class FormBuilder
            include ActionViewExtensions::FormBuilder
          end
        end

        Config.oxymoron_js_path ||= Rails.root.join('app', 'assets', 'javascripts')
        routes_watch unless Rails.env.production?
        write_assets
      end
    end

    initializer 'oxymoron.csrf' do |app|
      ActiveSupport.on_load(:action_controller) do
        include ::Oxymoron::Concern
      end
    end

    private
      def routes_watch
        oxymoron_reloader = ActiveSupport::FileUpdateChecker.new(Dir["#{Rails.root}/config/routes.rb"]) do
          write_assets
        end

        ActionDispatch::Reloader.to_prepare do
          oxymoron_reloader.execute_if_updated
        end
      end

      def write_assets
        File.write(File.join(Config.oxymoron_js_path, "oxymoron.js"), Oxymoron.generate("oxymoron.js.erb"))
      end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
oxymoron-1.1.9 lib/oxymoron/engine.rb
oxymoron-1.1.8 lib/oxymoron/engine.rb
oxymoron-1.1.7 lib/oxymoron/engine.rb
oxymoron-1.1.6 lib/oxymoron/engine.rb
oxymoron-1.1.5 lib/oxymoron/engine.rb
oxymoron-1.1.4 lib/oxymoron/engine.rb
oxymoron-1.1.3 lib/oxymoron/engine.rb
oxymoron-1.1.2 lib/oxymoron/engine.rb
oxymoron-1.1.1 lib/oxymoron/engine.rb
oxymoron-1.1.0 lib/oxymoron/engine.rb
oxymoron-1.0.10 lib/oxymoron/engine.rb
oxymoron-1.0.9 lib/oxymoron/engine.rb
oxymoron-1.0.8 lib/oxymoron/engine.rb
oxymoron-1.0.7 lib/oxymoron/engine.rb
oxymoron-1.0.6 lib/oxymoron/engine.rb
oxymoron-1.0.5 lib/oxymoron/engine.rb
oxymoron-1.0.4 lib/oxymoron/engine.rb
oxymoron-1.0.3 lib/oxymoron/engine.rb