Sha256: 10e37152ad677f7dd46bff77c57c9b3479e4eda979dab94aa926a1723b491dbe

Contents?: true

Size: 1004 Bytes

Versions: 2

Compression:

Stored size: 1004 Bytes

Contents

# original code is Red Shoes class-book.rb by _why
require '../lib/green_shoes'
require 'yaml'

class Book < Shoes
  url '/', :index
  url '/incidents/(\d+)', :incident

  def index
    incident 0
  end

  INCIDENTS = YAML.load_file('./class-book.yaml')

  def table_of_contents
    toc = []
    INCIDENTS.each_with_index do |(title, story), i|
      toc.push "(#{i + 1}) ",
        link(title){visit "/incidents/#{i}"},
        " / "
    end
    toc[0...-1] << "\n"*3
  end

  def incident num
    num = num.to_i
    stack  margin_left: 190 do
      banner "Incident"
      para strong("No. #{num + 1}: #{INCIDENTS[num][0]}")
    end

    flow do
      flow width: 180, margin_left: 10 do
        para *table_of_contents, size: 8
      end

      stack width: 460, margin_left: 10 do
        INCIDENTS[num][1].split(/\n\n+/).each do |p|
          para p
        end
      end
    end
  end
end

Shoes.app width: 640, height: 700, title: "Incidents, a Book"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
green_shoes-0.139.0 samples/sample36.rb
green_shoes-0.138.0 samples/sample36.rb