LoginSignup
0
0

More than 5 years have passed since last update.

slim使ってみた

Last updated at Posted at 2015-08-17

参考

環境準備

mkdir views
touch test.rb views/index.slim Gemfile
Gemfile
source "https://rubygems.org"

gem "sinatra"
gem "slim"
bundle install --path=vendor/bundler

ソースの準備

test.rb
require 'sinatra'
require 'slim'

get '/' do
        @arr01 = [0,1,2]
        @has01 = {:id => '1',:value => 'sample' }
        @has02 = [{:id => '1', :value => 'sample1'},
                  {:id => '2', :value => 'sample2'}]
        slim :index
end
views/index.slim
doctype html
html
 head
  title Slim Example
 body
  h1 スリムテスト

  - unless @arr01.empty?
   table
    - for item in @arr01
     tr
      td= item

  - unless @has01.empty?
   table
    tr
     td= @has01[:id]
     td= @has01[:value]

  - unless @has02.empty?
   table
    - for item in @has02
     tr
      td= item[:id]
      td= item[:value]
  • インデントがタグのくくり。

実行

bundle exec ruby test.rb -o 0.0.0.0 -p 3000

aaa.png

HTML2slim

aaa.png

書式

0
0
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
0
0