Pywebtest Gitbook

Programming Basic စာအုပ်မှာ Python ကို အသုံးပြုပြီးရေးထားတော့ website ပေါ်မှာ python code run အောင် ဘယ်လို လုပ်ထားသလဲ ဆိုပြီး မေးကြတာ တွေ့ပါတယ်။ Python ကို website တွေမှာ run ဖို့ အတွက်ကတော့ brython ကို အသုံးပြုထားပါတယ်။

Gitbook ကို အသုံးပြုထားသည့် စာအုပ်ထဲမှာ ရေးဖို့ကတော့ brython တစ်ခု တည်းမရတော့ပါဘူး။ Editor လေးပါ ပြချင်တာကြောင့် Ace editor နဲ့ တွဲပြီး သုံးထားပါတယ်။ CodeMirror ကို Gitbook မှာ အသုံးပြုလို့ မရပါဘူး။ require js library ကြောင့် conflict ဖြစ်နေပါတယ်။ ဒါကြောင့် Ace ကို အသုံးပြုထားပါတယ်။ Ace Editor မှာ ရေးပြီးတော့ ထဲက content တွေကို brython နဲ့ run ပါတယ်။ ရလာတဲ့ result ကို ပြန်ပြပေးထားပါတယ်။

Github မှာ source code ရှိပါတယ်။ Gitbook ကို အသုံးပြုပြီးတော့ လွယ်လင့် တကူ အသုံးပြုနိုင်အောင် plugin ပြန်ရေးထားပေးပါတယ်။

npm install pywebtest-gitbook

နဲ့ plugin ကို သွင်းပြီးတော့ book.json မှာ

"plugin" : [
    "pywebtest-gitbook"
    ]

plugin ထဲမှာ pywebtest-gitbook ဖြည့်ပေးဖို့ လိုပါတယ်။

စာရေးသည့် အခါမှာတော့

{% pyweb %}helloworld.py{% endpyweb %}

ဆိုပြီး ရေးရင် လက်ရှိ file ရှိတဲ့ နေရာက helloworld.py ကို သွားဖတ်ပြီးတော့ editor လေးနဲ့ ဖော်ပြပေးပါလိမ့်မယ်။

folder နဲ့ ခွဲထားရင်တော့

{% pyweb %}folder_name/helloworld.py{% endpyweb %}

ဆိုပြီး ရေးနိုင်ပါတယ်။

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.