class Rack::MultiPage
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.
Attributes
app[RW]
height[R]
pages_list[R]
percentage[R]
route[R]
width[R]
Public Class Methods
new(app, config = {})
click to toggle source
# File lib/rack-multipage.rb, line 20 def initialize (app, config = {}) @app = app @pages_list = config.fetch :pages, [] @route = config.fetch :route, "/multipage" @width = config.fetch :width, 800 @height = config.fetch :height, 600 @percentage = config.fetch :percentage, 50 end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack-multipage.rb, line 30 def call(env) if env["REQUEST_PATH"] == route [200, {"Content-Type" => "text/html"}, [template(insides)]] else app.call(env) end end
css()
click to toggle source
# File lib/rack-multipage.rb, line 42 def css <<-CSS body { background-color: #ccc; padding: 0; margin:0; } div.pageboxes { height: 100%; width: 100%; } 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
insides()
click to toggle source
# File lib/rack-multipage.rb, line 119 def insides page_boxes end
page_boxes()
click to toggle source
# File lib/rack-multipage.rb, line 101 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
scale()
click to toggle source
# File lib/rack-multipage.rb, line 38 def scale percentage / 100.0 end
template(insides)
click to toggle source
# File lib/rack-multipage.rb, line 83 def template(insides) <<-TEMPLATE <html> <head> <style> #{css} </style> </head> <body> <div id="insides"> #{insides} </div> </body> </html> TEMPLATE end