Sha256: 96b2f93af572f9c02f66769a070e8869a808d02e0250425e93db652febb4c1bd

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

require 'rails/railtie'

module Cell
  class Railtie < Rails::Railtie
    require 'cell/rails'
    config.cells = ActiveSupport::OrderedOptions.new

    initializer('cells.attach_router') do |app|
      ViewModel.class_eval do
        include app.routes.url_helpers # TODO: i hate this, make it better in Rails.
      end
    end

    initializer 'cells.template_engine' do |app|
      ViewModel.template_engine = app.config.app_generators.rails.fetch(:template_engine, 'erb').to_s
    end

    # ruthlessly stolen from the zurb-foundation gem.
    initializer 'cells.update_asset_paths' do |app|
      Array(app.config.cells.with_assets).each do |cell_class|
        # puts "@@@@@ #{cell_class.camelize.constantize.prefixes}"
        app.config.assets.paths += cell_class.camelize.constantize.prefixes # Song::Cell.prefixes
      end
    end

    initializer('cells.rails_extensions') do |app|
      ActiveSupport.on_load(:action_controller) do
        self.class_eval do
          include ::Cell::RailsExtensions::ActionController
        end
      end

      ActiveSupport.on_load(:action_view) do |app|
        self.class_eval do
          include ::Cell::RailsExtensions::ActionView
        end

        #include assert helpers (image_path, font_path, ect)
        ViewModel.class_eval do
          include ActionView::Helpers::AssetTagHelper
        end
      end

      # set VM#cache_store, etc.
      ViewModel.send(:include, RailsExtensions::ViewModel)

      if defined?(ActionView)
        # always include those helpers so we can override the shitty parts.
        ViewModel.send(:include, ActionView::Helpers::UrlHelper)
        ViewModel.send(:include, ActionView::Helpers::FormTagHelper)
      end
    end

    initializer('cells.development') do |app|
      if Rails.env == "development"
        require "cell/development"
        ViewModel.send(:include, Development)
      end
    end

    rake_tasks do
      load 'tasks/cells.rake'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cells-4.0.0.beta5 lib/cell/railtie.rb