Sha256: 80d070251a72cb9dc59a7979d8649f3a2bc194ab590ac0bae35c689a15a38beb

Contents?: true

Size: 1.16 KB

Versions: 15

Compression:

Stored size: 1.16 KB

Contents

# Based on https://github.com/josh/ruby-coffee-script
require 'execjs'
require 'pathname'

module HandlebarsAssets
  class Handlebars
    class << self

      def precompile(*args)
        context.call('Handlebars.precompile', *args)
      end

      protected

      attr_writer :source

      def append_patch(patch_file)
        self.source += patch_source(patch_file)
      end

      def apply_patches_to_source
        if HandlebarsAssets::Config.patch_files.any?
          HandlebarsAssets::Config.patch_files.each do |patch_file|
            append_patch(patch_file)
          end
        end
        source
      end

      def context
        @context ||= ExecJS.compile(apply_patches_to_source)
      end

      def source
        @source ||= path.read
      end

      def patch_path
        @patch_path ||= Pathname(HandlebarsAssets::Config.patch_path)
      end

      def patch_source(patch_file)
        patch_path.join(patch_file).read
      end

      def path
        @path ||= assets_path.join(HandlebarsAssets::Config.compiler)
      end

      def assets_path
        @assets_path ||= Pathname(HandlebarsAssets::Config.compiler_path)
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
handlebars_assets-0.19.2 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.19.1 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.19 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.18 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.17.2 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.17.1 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.17 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.16 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.15 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.14.1 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.13.0 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.12.3 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.12.2 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.12.1 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.12.0 lib/handlebars_assets/handlebars.rb