Sha256: 4ed6bda83c912c2a5289e0f72ea8121aac2f6411c319578dec97ac9a7109fbf9

Contents?: true

Size: 1.2 KB

Versions: 16

Compression:

Stored size: 1.2 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 ||= "if (!window) { var window = {}; }\n#{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

16 entries across 16 versions & 3 rubygems

Version Path
handlebars_assets-0.23.9 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.23.8 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.23.7 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.23.6 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.23.5 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.23.4 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.23.3 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.23.2 lib/handlebars_assets/handlebars.rb
arcabouco-0.2.13 vendor/bundle/gems/handlebars_assets-0.23.1/lib/handlebars_assets/handlebars.rb
handlebars_assets-0.23.1 lib/handlebars_assets/handlebars.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/handlebars_assets-0.23.0/lib/handlebars_assets/handlebars.rb
handlebars_assets-0.23.0 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.22.0 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.21.0 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.20.2 lib/handlebars_assets/handlebars.rb
handlebars_assets-0.20.1 lib/handlebars_assets/handlebars.rb