crystallix-pages
crystallix-pages
Small library which helps you to create .crweb
files which used by Crystallix (https://github.com/De-Os/crystallix)
Installation
Add this to your shard.yml
:
dependencies:
mysql-interface:
github: De-Os/crystallix-pages
Usage
First of all, add require
and create new CRYSTALLIX::PAGE
:
require "crystallix-pages"
page = CRYSTALLIX::Page.new
After that, you can write anything to the page and headers:
page.add "<html><head><title>Crystallix page</title></head>"
page.add "<body>It works with <pre>#{`crystal -v`}!</pre></body></html>"
# code...
page.header("Content-Language", "en")
# any other code...
After you did all your stuff use close
to echo contents to STDOUT
:
# after all code
page.close
Building
After you did all tests and ready to go, build your executable with
crystal build src/my_page.cr --release --progress -o my_page.crweb
Make sure you got .crweb
and use it in Crystallix!
CGI Variables
You can access CGI Variables using CRYSTALLIX::variable_name
, like:
if CRYSTALLIX::USER_AGENT =~ /chrome/i
page.add "Hello, Chrome!"
else
page.add "Hello, browser!"
end
Supported variables:
CRYSTALLIX::SERVER_NAME
, stringCRYSTALLIX::REDIRECT_STATUS
, stringCRYSTALLIX::SERVER_PROTOCOL
, stringCRYSTALLIX::REQUEST_METHOD
, string, always upcaseCRYSTALLIX::QUERY_STRING
, stringCRYSTALLIX::REMOTE_ADDR
, stringCRYSTALLIX::SERVER_PORT
, integerCRYSTALLIX::CONTENT_TYPE
, stringCRYSTALLIX::CONTENT_LENGTH
, integerCRYSTALLIX::USER_AGENT
(HTTP_USER_AGENT
from CGI), stringCRYSTALLIX::ACCEPT
(HTTP_ACCEPT
from CGI), stringCRYSTALLIX::COOKIES
(HTTP_COOKIES
from CGI), string
Body
Also, you can get body if POST was used:
if CRYSTALLIX::REQUEST_METHOD == "POST"
page.header("Content-Type", ["text/plain", "charset=utf-8"])
page.add "Hey, you're using post! That's your body:\n\n"
page.add CRYSTALLIX::BODY
else
page.add "Use POST method!"
end
Repository
crystallix-pages
Owner
Statistic
- 1
- 0
- 0
- 0
- 0
- over 4 years ago
- August 7, 2020
License
Links
Synced at
Sun, 22 Dec 2024 11:29:04 GMT
Languages