Class: Rack::MultiPage
- Inherits:
-
Object
- Object
- Rack::MultiPage
- 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
-
#app ⇒ Object
Returns the value of attribute app.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#pages_list ⇒ Object
readonly
Returns the value of attribute pages_list.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #css ⇒ Object
-
#initialize(app, config = {}) ⇒ MultiPage
constructor
A new instance of MultiPage.
- #insides ⇒ Object
- #page_boxes ⇒ Object
- #scale ⇒ Object
- #template(insides) ⇒ Object
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
#app ⇒ Object
Returns the value of attribute app.
13 14 15 |
# File 'lib/rack-multipage.rb', line 13 def app @app end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
16 17 18 |
# File 'lib/rack-multipage.rb', line 16 def height @height end |
#pages_list ⇒ Object (readonly)
Returns the value of attribute pages_list.
14 15 16 |
# File 'lib/rack-multipage.rb', line 14 def pages_list @pages_list end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
15 16 17 |
# File 'lib/rack-multipage.rb', line 15 def route @route end |
#width ⇒ Object (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 |
#css ⇒ Object
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 |
#insides ⇒ Object
118 119 120 |
# File 'lib/rack-multipage.rb', line 118 def insides page_boxes end |
#page_boxes ⇒ Object
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 |
#scale ⇒ Object
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 |