Sha256: 86507a867d94597e8e4aa3c20aff3707be71f8920003ff449f58d2e33447e47f

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

require 'middleman-core'

module Middleman
  module Ember
    class << self
      def registered(app, options_hash={}, &block)
        app.send :include, InstanceMethods
        app.set  :ember_variant, :development

        @@options = OpenStruct.new(default_options.merge(options_hash))
        yield @@options if block_given?

        app.after_configuration do
          ember_version = 
            if ember_variant == :production
              "prod."
            else
              ""
            end

          # copy in the relevant version of Ember
          FileUtils.mkdir_p(ember_asset_path)
          FileUtils.cp("#{@@options.ember_path}/ember.#{ember_version}js", ember_asset_path.join("ember.js"))
          # only copy ember_data_path if defined. Allows you to just use Ember.
          if @@options.ember_data_path
            FileUtils.cp("#{@@options.ember_data_path}/ember-data.#{ember_version}js", ember_asset_path.join("ember-data.js")) 
          end
          sprockets.append_path(ember_asset_path)

          # add in Handlebars path
          sprockets.append_path(handlebars_asset_path)
        end
      end

      def ember_options
        @@options
      end

      private

      def default_options
        ember_data_path = defined?(::Ember::Data) ? ::Ember::Data::Source.bundled_path_for("") : nil
        {
          ember_path: ::Ember::Source.bundled_path_for(""),
          ember_data_path: ember_data_path,
          handlebars_path: File.dirname(::Handlebars::Source.bundled_path)
        }
      end
      alias :included :registered
    end

    module InstanceMethods
      def ember_asset_path
        Pathname.new(File.join("#{root}/tmp/middleman-ember"))
      end

      def handlebars_asset_path
        ::Middleman::Ember.ember_options.handlebars_path
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-ember-0.2.0 lib/middleman/ember/extension.rb