Ruby Slim
http://slim-lang.com/
ruby slim+gulp+jsonを組み合わせて、自動的にslimファイルを生成を行いたいと考えております。
下記ファイルでgulpでjsonデータを渡しているのですが、エラー表示があり、生成されません。
エラーは文字コードですが、そちらも合わせて解決していただけますでしょうか?
また、gulp-slimによるjsonデータの引き渡し方をご教授ください。
エラー
Error: Slim error in file (.../template.slim):
command.rb:62:in `block in set_opts': incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string) (Encoding::CompatibilityError)
template.slim
slim
1- # coding: utf-8 2- data = jsonData; 3doctype html 4html[lang="ja"] 5 head 6 meta[charset="UTF-8"] 7 | <meta name="description" content=" 8 = data.description 9 | "> 10 title 11 = data.title 12 body 13 | タイトルは 14 = data.title 15 | ディスクリプションは 16 = data.description
json File
json
1{ 2 "pages": [ 3 { 4 "id": "hoge1", 5 "name": "ページ名", 6 "content": [ 7 { 8 "title": "ポラーノの広場1", 9 "text": "あのイーハトーヴォのすきとおった風、夏でも底に冷たさをもつ青いそら、うつくしい森で飾られたモリーオ市、郊外のぎらぎらひかる草の波。 " 10 } 11 ] 12 }, 13 { 14 "id": "hoge2", 15 "name": "ページ名", 16 "content": [ 17 { 18 "title": "ポラーノの広場2", 19 "text": "あのイーハトーヴォのすきとおった風、夏でも底に冷たさをもつ青いそら、うつくしい森で飾られたモリーオ市、郊外のぎらぎらひかる草の波。 " 20 } 21 ] 22 }, 23 { 24 "id": "hoge3", 25 "name": "ページ名", 26 "content": [ 27 { 28 "title": "ポラーノの広場3", 29 "text": "あのイーハトーヴォのすきとおった風、夏でも底に冷たさをもつ青いそら、うつくしい森で飾られたモリーオ市、郊外のぎらぎらひかる草の波。 " 30 } 31 ] 32 } 33 ] 34}
gulp file
gulp
1gulp.task('create',function(){ 2 3 var json_file = './config.json'; 4 var json = JSON.parse(fs.readFileSync(json_file,"utf-8")); 5 var pages = json.pages; 6 7 for (var i = 0; i < pages.length; i++) { 8 gulp.src("./template.slim") 9 .pipe(slim({ 10 data: pages, 11 options: "encoding='utf-8'" 12 })) 13 .pipe(rename(pages[i].id+".slim")) 14 .pipe(convertEncoding({to: "utf-8"})) 15 .pipe(gulp.dest("./slim/")); 16 } 17});
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。