responsive_preview 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a3374938fd932a994f6ba3f497cb4486065ed58568865f63413b09fa2daaebd0
4
+ data.tar.gz: 7f21a9142f05bf54e2fbe0bdb949f65a4ddb989f14a2cfa9e20bd886694514bd
5
+ SHA512:
6
+ metadata.gz: 50a912e977e49e8318dc52598361624b59ceefa25d38cea49e5e97a2852348feb90c307e7c9c2a87affdbe97bc63f3b5406bef3d93750ca2b76bb4ace0236c98
7
+ data.tar.gz: 923ce621004a5c1f7b3cb1d849634eab62fd5e55c609d0bdeaa93a66962a1b5b2b3da77e54944f80c0262e9c106cd01c41cec3f9067b69e550b31732f9092c37
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # ResponsivePreview
2
+
3
+ Rack Middleware gem that injects an iframe around the response for the purpose of testing responsive css at different
4
+ breakpoints.
5
+
6
+ ## Usage
7
+
8
+
9
+ Define when the responsive preview is shown
10
+
11
+ ```ruby
12
+ class MyController < ApplicationController
13
+ def wants_responsive_preview?
14
+ # some condition to decide when to view the page in the responsive preview layout
15
+ end
16
+ end
17
+ ```
18
+
19
+ Provide a responsive preview layout
20
+
21
+ ```ERB
22
+ <!-- app/views/layouts/responsive_preview.html.erb -->
23
+
24
+ <!-- Add some other chrome for switching devices/iframe dimensions -->
25
+ <%= content_tag :iframe, '', srcdoc: yield %>
26
+ <%= responsive_preview_js %>
27
+ ```
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -0,0 +1,4 @@
1
+ /*! srcdoc-polyfill - v1.0.0 - 2017-01-29
2
+ * http://github.com/jugglinmike/srcdoc-polyfill/
3
+ * Copyright (c) 2017 Mike Pennisi; Licensed MIT */
4
+ !function(a,b){var c=window.srcDoc;"function"==typeof define&&define.amd?define(["exports"],function(d){b(d,c),a.srcDoc=d}):"object"==typeof exports?b(exports,c):(a.srcDoc={},b(a.srcDoc,c))}(this,function(a,b){var c,d,e,f=!!("srcdoc"in document.createElement("iframe")),g="Polyfill may not function in the presence of the `sandbox` attribute. Consider using the `force` option.",h=/\ballow-same-origin\b/,i=function(a,b){var c=a.getAttribute("sandbox");"string"!=typeof c||h.test(c)||(b&&b.force?a.removeAttribute("sandbox"):b&&b.force===!1||(e(g),a.setAttribute("data-srcdoc-polyfill",g)))},j={compliant:function(a,b,c){b&&(i(a,c),a.setAttribute("srcdoc",b))},legacy:function(a,b,c){var d;a&&a.getAttribute&&(b?a.setAttribute("srcdoc",b):b=a.getAttribute("srcdoc"),b&&(i(a,c),d="javascript: window.frameElement.getAttribute('srcdoc');",a.contentWindow&&(a.contentWindow.location=d),a.setAttribute("src",d)))}},k=a;if(e=window.console&&window.console.error?function(a){window.console.error("[srcdoc-polyfill] "+a)}:function(){},k.set=j.compliant,k.noConflict=function(){return window.srcDoc=b,k},!f)for(k.set=j.legacy,d=document.getElementsByTagName("iframe"),c=d.length;c--;)k.set(d[c])});
@@ -0,0 +1,7 @@
1
+ module ResponsivePreview
2
+ module ViewHelper
3
+ def responsive_preview_js
4
+ javascript_include_tag('responsive_preview')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ <!-- Overwrite this layout file in the host app -->
2
+ <iframe><%= yield %></iframe>
3
+ <%= responsive_preview_js %>
@@ -0,0 +1,4 @@
1
+ if defined?(Rails)
2
+ require 'responsive_preview/railtie'
3
+ require 'responsive_preview/engine'
4
+ end
@@ -0,0 +1,12 @@
1
+ require 'digest'
2
+
3
+ module ResponsivePreview
4
+ module ControllerExtensions
5
+ module InstanceMethods
6
+ def wants_responsive_preview?
7
+ # Override this method in the host app controllers
8
+ false
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ require 'responsive_preview/controller_extensions'
2
+
3
+ module ResponsivePreview
4
+ class Engine < Rails::Engine
5
+
6
+ initializer 'responsive_preview.load_controller_extensions' do |app|
7
+ ActiveSupport.on_load(:action_controller) do
8
+ include ControllerExtensions::InstanceMethods
9
+ end
10
+ end
11
+
12
+ initializer 'responsive_preview.append_precompile_assets' do |app|
13
+ config.assets.precompile += %w(responsive_preview.js)
14
+ end
15
+
16
+ initializer 'responsive_preview.load_helpers' do
17
+ ActiveSupport.on_load(:action_controller) do
18
+ helper ResponsivePreview::ViewHelper
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module ResponsivePreview
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ request = Rack::Request.new(env)
9
+ status, headers, response = @app.call(env)
10
+ action_controller = env['action_controller.instance']
11
+
12
+ if action_controller&.wants_responsive_preview?
13
+ original_response = Array(response.body).join
14
+ body = action_controller.render_to_string(html: original_response, layout: "responsive_preview")
15
+ headers["Content-Length"] = body.bytesize.to_s
16
+ response = [body]
17
+ end
18
+
19
+ return [status, headers, response]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ require 'responsive_preview/middleware'
2
+
3
+ module ResponsivePreview
4
+ class Railtie < Rails::Railtie
5
+ initializer "responsive_preview.init" do |app|
6
+ app.config.middleware.use ResponsivePreview::Middleware
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module ResponsivePreview
2
+ VERSION = "0.1.2"
3
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: responsive_preview
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Wallace
8
+ - Nicholas Jakobsen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-10-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '4.2'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '4.2'
28
+ description: Rack Middleware that injects an iframe around the response content to
29
+ allow for responsive previewing
30
+ email:
31
+ - hello@combinaut.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - MIT-LICENSE
37
+ - README.md
38
+ - app/assets/javascripts/responsive_preview/index.js
39
+ - app/assets/javascripts/responsive_preview/srcdoc-polyfill.min.js
40
+ - app/helpers/responsive_preview/view_helper.rb
41
+ - app/views/layouts/responsive_preview.html.erb
42
+ - lib/responsive_preview.rb
43
+ - lib/responsive_preview/controller_extensions.rb
44
+ - lib/responsive_preview/engine.rb
45
+ - lib/responsive_preview/middleware.rb
46
+ - lib/responsive_preview/railtie.rb
47
+ - lib/responsive_preview/version.rb
48
+ homepage: http://github.com/combinaut/responsive_preview
49
+ licenses: []
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.7.9
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Rack Middleware that injects an iframe around the response content to allow
71
+ for responsive previewing
72
+ test_files: []