Search code examples
ruby-on-railssinatrahandsontable

Sinatra Framework, handsontable


Does anyone know if it's possible to use the handsontable add on with a Sinatra framework? The Gem on rubygems.org mentions Rails only so I wasn't sure if the add on was only made for/intended for Rails.


Solution

  • I would recomend the same as @iceman. Just use the js and css direct.

    Most time I sort the files in two folders on for js and css, you endup with something like:

    yourappolder
       -public
         -js
            -handsontable.full.js
         -css
            -handsontable.full.css
    

    That this folder is named public is convention. From the doc:

    A string specifying the directory where static files should be served from. By default, this is assumed to be a directory named “public” within the root directory (see the :root setting). You can set the public directory explicitly with:

    set :public_folder, '/var/www'
    set :public_folder, Proc.new { File.join(root, "static") }
    

    These files can now directly included in your layout file

    !!!
    %html
      %head
        %title My title
        %link(rel="stylesheet" href="/css/handsontable.full.css")
        %script{:type => "text/javascript", :src => "/js/handsontable.full.js"}
      %body
        = yield
    

    Or you can build a view, where you require you files. And render these view in you layout. (It add a bit more structure)

    To answer your question:

    Should I actually download source and copy to my working directory and point to them in there or just via weblink?

    Have a copy of the used files, just for the case. And use the weblink, because most time it's faster for your user. (They have cdn's)

    If you build a intranet site or want host the css/js yourself, have a look at sinatra-assetpack, this can combine and minify your css/js for a faster download.

    Update: I've been told that handsontable work no without jquery so I updated my answer. If you use a old version of handsontable you should probably load the jquery javascript file (and before the handsontable js file).