Created
March 12, 2015 08:46
-
-
Save nowri/3e5f6e2b9a60706a95c7 to your computer and use it in GitHub Desktop.
grunt-jadeでjade名と同名のjsonファイルを読み込む関数
This file contains hidden or 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
| function jadeDataFunc(env){ | |
| return function(dest, srcAr){ //dest が生成するhtml、srcが参照元jadeファイル | |
| var _ = grunt.util._, | |
| regDest = /\/([A-Za-z_0-9-]+?)\.html/, | |
| destName = dest.match(regDest)[1], | |
| dataPath = "src/jade/json/" + destName + ".json", | |
| mergeData, | |
| data; | |
| try { | |
| mergeData = grunt.file.readJSON("src/jade/json/_common.json"); | |
| } catch(e){ | |
| mergeData = {}; | |
| } | |
| mergeData = _.clone(mergeData); | |
| try { | |
| data = grunt.file.readJSON(dataPath); | |
| } catch(e){ | |
| data = {}; | |
| } | |
| _.extend(mergeData.pc, data.pc || {}); | |
| _.extend(mergeData.sp, data.sp || {}); | |
| _.extend(mergeData.common, data.common || {}); | |
| return _.extend(mergeData, { | |
| env:env, | |
| page:destName | |
| }); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment