Last active
December 23, 2015 06:49
-
-
Save kerotaa/6596364 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
path = require 'path' | |
grunt.registerMultiTask 'template_concat', -> | |
indent = (text, indentStr, width)-> | |
lines = text.split "\n" | |
t = '' | |
for i in [0...width] | |
t += indentStr | |
lines.forEach (line, index)-> | |
lines[index] = t + line | |
lines.join "\n" | |
compile_template = (filepath)-> | |
if !grunt.file.exists filepath | |
grunt.util.error 'File not found: ' + filepath | |
code = grunt.file.read filepath | |
matches = code.match /(\n?[\s\t]*)<%=\s*.+\s*%>/g | |
base_dir = path.dirname(filepath) | |
if matches | |
matches.forEach (value, index, arr)-> | |
m = value.match(/(\n*)([\s\t]*)(<%=\s*(.+)\s*%>)/) | |
n = m[4].replace /\s+$/, '' | |
p = base_dir + '/' + n | |
compile_template.compiled[p] = compile_template.compiled[p] || compile_template(p) | |
code = code.replace(m[2] + m[3], indent(compile_template.compiled[p], m[2], 1)) | |
code | |
compile_template.compiled = {} | |
compiled_code = compile_template this.data | |
grunt.file.write this.target, compiled_code | |
grunt.log.oklns 'succeed: ' + this.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
・色々とおかしかった部分を修正
・インデントを良い感じにしてくれるようにした