Skip to content
Simple comments for your Kemal site
Crystal
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
libs
src
LICENSE
README.md
shard.lock
shard.yml

README.md

Kemal-comments

Simple comments for your Kemal site

screenshot

Installation

Add this to your application's shard.yml:

dependencies:
  kemal-comments:
    github: TyanNN/kemal-comments

Usage

require "kemal"
require "kemal-comments"
require "session"

comms=Comments::Comments.new(name="name") # Optional database name, defaults to comments.db
comms.init_sockets() # Add /get_comments and /add_comments sockets

get "/post/1" do |env|
  env.session["NAME"]="TyanNN" # Before using this you probably should create basic user system with crystal session module
                               # This will use SESSION_LOGIN
  "
  <html>
  <meta charset='utf-8'>
  <link rel='stylesheet' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'>
  <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js'></script>
  <script src='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js'></script> <!-- Include bootstrap -->
  <script>
  #{comms.js(env)} //JS part
  </script>
  <div id='comments'></div> <!--Put this where comments should be -->
  #{comms.update_button(env)} <!-- Update button, can be styled with CSS by changing #update_div and #update_button -->
  #{comms.add_comment_block} <!-- Adding comment block -->
  </html>
  "
end

Kemal.run

or in ecr pattern:

<script>
<%= comms.js(env)%>
//etc.
</script>

There is also some parameters you can change via Comments::PARAMS["name"]:

  • SESSION_SECRET - Secret for session, only useful if CREATE_SESSION is true, defaults to SECRET
  • REDACT_MINUTES - minutes until comments will become not editable, default is 7
  • SUBMIT_BUTTON_TEXT - Text on the submit button
  • COMMENT_PLACEHOLDER - Placeholder in the comment addition textbox
  • ANSWER_BUTTON_TEXT - Text on the answer button
  • NO_TEXT_WARNING - Text, that one will see if comment textbox is empty
  • POST_ID_REGEX - Regular expression used to find post id, defaults to \d+$ (as this is string all \ must be \\ )
  • SESSION_LOGIN - session hash key, where login is stored, default is NAME
  • CREATE_SESSION - should module create session for you with SESSION_SECRET secret, default is true
  • SOCKETS_IP - Your ip, default is 0.0.0.0:3000, you should probably change it to yours

Comment's CSS selector is [class^="comment_"]

Development

All is stored in src/kemal-comments.cr, fill free to fork and make additions

Contributing

  1. Fork it ( https://github.com/TyanNN/kemal-comments/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • TyanNN - creator, maintainer
You can’t perform that action at this time.