Class: Rack::MultiPage

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-multipage.rb

Overview

Rack::MultiPage sometimes it’s nice to see the effect of changes on multiple pages at once.

in your development.rb file config.middleware.use Rack::MultiPage, pages: [“/”, “/users/1”, “/login”]

then go to “/multipage” Those pages will be loaded into a series of iframes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, config = {}) ⇒ MultiPage

Returns a new instance of MultiPage.



19
20
21
22
23
24
25
26
27
# File 'lib/rack-multipage.rb', line 19

def initialize (app, config = {})
  @app          = app
  @pages_list   = config.fetch :pages,  []
  @route        = config.fetch :route,  "/multipage"
  @height       = config.fetch :height,  "600"
  @width        = config.fetch :width,  "800"
  @percentage   = config.fetch :width,  "50"

end

Instance Attribute Details

#appObject

Returns the value of attribute app.



13
14
15
# File 'lib/rack-multipage.rb', line 13

def app
  @app
end

#heightObject (readonly)

Returns the value of attribute height.



16
17
18
# File 'lib/rack-multipage.rb', line 16

def height
  @height
end

#pages_listObject (readonly)

Returns the value of attribute pages_list.



14
15
16
# File 'lib/rack-multipage.rb', line 14

def pages_list
  @pages_list
end

#routeObject (readonly)

Returns the value of attribute route.



15
16
17
# File 'lib/rack-multipage.rb', line 15

def route
  @route
end

#widthObject (readonly)

Returns the value of attribute width.



17
18
19
# File 'lib/rack-multipage.rb', line 17

def width
  @width
end

Instance Method Details

#call(env) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/rack-multipage.rb', line 29

def call(env)
  if env["REQUEST_PATH"] == route
    [200, {"Content-Type" => "text/html"}, [template(insides)]]
  else
    app.call(env)
  end
end

#cssObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rack-multipage.rb', line 41

def css
  <<-CSS
  body {
    background-color: #eee;
    padding: 0; margin:0;
  }

  div.pageboxes {
    height: 100%;
    width: 100p%;
  }

  div.pageboxes .page {
    height: #{height}px;
    width:  #{width}px;
    border: solid 1px black;
    background-color: white;
    top: 0;
    -webkit-transform: scale(#{scale}) ;
    -webkit-transform-origin: top left ;
    -webkit-box-shadow: 1px 1px 5px rgba(100,100,100,0.6)
  }

  div.pageboxes .box{
    width: #{width * scale}px;
    height: #{height * scale}px;
    margin-left: 10px;
    margin-top: 10px;
    float: left;
  }

  div.pageboxes .page iframe{
    height: 100%;
    width: 100%;
    border: solid 1px #eee;
    border-radius: 5px;
  }

  CSS
end

#insidesObject



118
119
120
# File 'lib/rack-multipage.rb', line 118

def insides
  page_boxes
end

#page_boxesObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/rack-multipage.rb', line 100

def page_boxes
  output = "<div class='pageboxes'>"
  @pages_list.each {|page|
    output << <<-BOX

    <div class="box">
    <a href="#{page}">#{page}</a>
    <div class="page">
    <iframe src="#{page}"></iframe>
    </div>
    </div>

    BOX
  }
  output << "</div>"
  output
end

#scaleObject



37
38
39
# File 'lib/rack-multipage.rb', line 37

def scale
  (percentage / 100).to_f
end

#template(insides) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rack-multipage.rb', line 82

def template(insides)
  <<-TEMPLATE
  <html>
  <head>
  <style>
  #{css}
  </style>
  </head>
  <body>

  <div id="insides">
  #{insides}
  </div>
  </body>
  </html>
  TEMPLATE
end