LoginSignup
47
38

More than 5 years have passed since last update.

Slimのテンプレートにjavascriptを組み込む

Posted at
sample.slim
doctype html
html
   head
      script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"
      script src="js/animatedtablesorter/tsort.min.js"
      link rel="stylesheet" href="js/animatedtablesorter/style.css" type="text/css"
   body
      javascript:
        $(document).ready(function(){$('table.tableSorter').tableSort();});

      table border=1 class="tableSorter"
        tr
          th ID
          th Thumnail
以下略

scriptへのリンク自体はimgを埋め込む時と同じ感じ。
scriptを直接記入する時はjavascript:の下の行にインデントつけて記述する。

今回はjquery-animated-table-sorterを組み込んでみた。

sinatraでは静的なファイルはpublicディレクトリに格納する。
従ってスクリプトは以下のような配置となる。

├── public
│   └── js
│       └── animatedtablesorter
│           ├── arrow_asc.png
│           ├── arrow_desc.png
│           ├── style.css
│           ├── tsort.js
│           └── tsort.min.js
├── views
│   └── index.slim
│   └── slideshow_list.slim

script src="js/animatedtablesorter/tsort.min.js"
と記載しているようにURL自体にはpublicのディレクトリ名は記入しない。

47
38
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
47
38