Sha256: f760c1f1d3c21dfb33c72caff4ee54f0e30ecac152ac375906ff423dad71433e

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module Crystal
  module Plugin
    class Web
      attr_reader :dir
      
      def initialize dir
        @dir = dir
      end
      
      def asset name
        require 'asset_packager'
        AssetPackager.add "#{dir}/config/asset_packages.yml", "#{dir}/public"
        
        crystal.after :environment do
          crystal.ensure_public_symlink name, "#{dir}/public"
        end
      end
      
      def routes
        crystal.after :environment do
          routes_file = "#{dir}/config/routes.rb"
          load routes_file if File.exist? routes_file
        end
      end
      
      def locales
        I18n.load_path += Dir["#{dir}/config/locales/**/*.{rb,yml}"]
      end
      
      def require_paths *relative_paths
        relative_paths = relative_paths.first if relative_paths.first.is_a? Array
        relative_paths.each do |relative_path|
          path = "#{dir}/#{relative_path}"
          $LOAD_PATH << path unless $LOAD_PATH.include? path
        end
      end
      
      def autoload *list
        list = list.first if list.first.is_a? Array
        list.each{|d| autoload_dir "#{dir}/#{d}"}
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
crystal_ext-0.0.4 lib/crystal_ext/plugin/web.rb