17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/vue/sprockets.rb', line 17
def self.call(input)
source = input[:data]
load_path = input[:load_path]
filename = input[:filename]
path = filename[load_path.length..-1]
if !@root || (path[0..@root.length-1] == @root)
js = source.gsub( /(?<spaces>\s+)template\s*:\s*(?<quote>["`'])(?<code>.*?[^\\])\k<quote>/m ) do |match|
spaces = "#{$1}"
src = $3.gsub("\\n","\n")
src = src.gsub("\\\"","\"")
src = src.gsub("\\\'","\'")
src = src.gsub("\\t","\t")
result = Vue::Compiler.compile(src)
out = spaces + "render :" + toFunction(result[:render]) + ",\n"
out += spaces + "staticRenderFns :[" + (result[:staticRenderFns] || []).map{|f| toFunction(f)}.join(',') + "]"
puts "ERROR: vue/sprockets #{filename} ==>\n#{result[:errors]}" if result[:errors].to_s != ""
puts "TIP: vue/sprockets #{filename} ==>\n#{result[:tips]}" if result[:tips].to_s != ""
out
end
{:data=>js}
else
nil
end
end
|