class Sprockets::Vue::Script

Constants

SCRIPT_COMPILES
SCRIPT_REGEX
TEMPLATE_REGEX

Public Class Methods

cache_key() click to toggle source
# File lib/sprockets/vue/script.rb, line 49
def cache_key
  [
    self.name,
    VERSION,
  ].freeze
end
call(input) click to toggle source
# File lib/sprockets/vue/script.rb, line 19
def call(input)
  data = input[:data]
  name = input[:name]
  input[:cache].fetch([cache_key, input[:source_path], data]) do
    script = SCRIPT_REGEX.match(data)
    template = TEMPLATE_REGEX.match(data)
    output = []
    map = nil
    if script
      result = SCRIPT_COMPILES[script[:lang]].call(script[:content], input)
      
      map = result['sourceMap']

      output << "'object' != typeof VComponents && (this.VComponents = {});
        var module = { exports: null };
        #{result['js']}; VComponents['#{name}'] = module.exports;"
    end

    if template
      output << "VComponents['#{name.sub(/\.tpl$/, "")}'].template = '#{j template[:content]}';"
    end

    { data: "#{warp(output.join)}", map: map }
  end
end
warp(s) click to toggle source
# File lib/sprockets/vue/script.rb, line 45
def warp(s)
  "(function(){#{s}}).call(this);"
end