Sha256: 9a5e25401099cf84f29fc251a1b3bca267957593fd65c88123abd6990a21d5ff

Contents?: true

Size: 1.93 KB

Versions: 4

Compression:

Stored size: 1.93 KB

Contents

class Ecrire::Railtie
  module Theme
    extend ActiveSupport::Concern

    included do

      initializer 'ecrire.logs', before: :initialize_logger do |app|
        unless Rails.env.test?
          app.paths.add "log", with: "log/#{Rails.env}.log"
        end
      end

      initializer 'ecrire.locales' do |app|
        config.i18n.railties_load_path.concat(paths['user:locales'].existent)
      end

      initializer 'ecrire.controllers' do |app|
        if paths['user:controllers'].existent.any?
          app.paths['app/controllers'].concat paths['user:controllers'].existent
        end
      end

      initializer 'ecrire.helpers' do |app|
        if paths['user:helpers'].existent.any?
          app.paths['app/helpers'].concat paths['user:helpers'].existent
        end
      end

      initializer 'ecrire.view_paths' do |app|
        ActionController::Base.prepend_view_path paths['user:views'].existent
      end

      initializer 'ecrire.assets' do |app|
        app.config.assets.paths.concat paths['user:assets'].existent
      end

      def paths
        @paths ||= begin
          paths = Rails::Paths::Root.new(root_path)
          paths.add 'user:views', with: 'views'
          paths.add 'user:controllers', with: 'controllers', eager_load: true
          paths.add 'user:assets', with: 'assets', glob: '*'
          paths.add 'user:locales', with: 'locales', glob: '**/*.{rb,yml}'
          paths.add 'user:helpers', with: 'helpers', eager_load: true
          paths.add 'public', with: 'tmp/public'
          paths
        end
      end

      def root_path(file = 'config.ru')
        begin
          pathname = Pathname.pwd

          while !(pathname + file).exist? do
            pathname = pathname.parent
            if pathname.root?
              raise "Could not find #{file}. Type 'ecrire new blog_name' to create a new blog"
              break
            end
          end

          pathname
        end
      end


    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ecrire-0.23.0 lib/ecrire/railtie/theme.rb
ecrire-0.22.1 lib/ecrire/railtie/theme.rb
ecrire-0.21.0 lib/ecrire/railtie/theme.rb
ecrire-0.20.0 lib/ecrire/railtie/theme.rb