post-massage-rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTE1MjM4YzE2MTUyNzE3NzU2N2RkYTU5N2RhNjZkMjg5OWM4OTg5Zg==
5
+ data.tar.gz: !binary |-
6
+ YTczMWY4ODVlYjIzY2UxMzE4MTM4Y2RmOWNjZmM3NTZlOTE1ZjZjOA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MzliM2E3MGJhYjhiMGQ1ZmI1MzYwNDFkYWRhYmYxMWVlMjlmZWI2NmEwODQ0
10
+ OTY5MzI3YWExZjAwYmVhN2M1M2Y1OWIyNjY0MjhkNzg2NWEzY2E1MjdlMTAy
11
+ NzE0NDcwNzc4ZTUyMWU0MjYyMjcwNWU3ZjEwOTAzNTJkNzMxNjQ=
12
+ data.tar.gz: !binary |-
13
+ MTZiMzMyYTI5NTk5OTY1OGI5MTE4OTlkODU1NWI0YzNlODhlYzdlODU1MWJh
14
+ ODVjZjAzN2U2ZjJkNWFjMjkzMTM1MTEzMGQzMzM4NzBmYWZmZWQ2MTBiMTQx
15
+ OTc3Y2FhMDkwMDRjYjM0MjA3ODAyODJhNTNjZTVjYTdjNjExOWY=
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 1.0.0 (6 August 2016)
2
+
3
+ - well, I started.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,9 @@
1
+ Thanks for helping with the massage!
2
+
3
+ ## Updating PostMassage
4
+
5
+ If PostMassage scripts changed, run rake rake update_post_massage open an issue and submit a pull request
6
+
7
+ ## Tests
8
+
9
+ PostMassage has its own tests. Not much to test here.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
data/Gemfile.lock ADDED
@@ -0,0 +1,71 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ post-massage-rails (1.0.0)
5
+ railties (>= 3.0, < 5.0)
6
+ thor (>= 0.14, < 2.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionpack (4.2.7)
12
+ actionview (= 4.2.7)
13
+ activesupport (= 4.2.7)
14
+ rack (~> 1.6)
15
+ rack-test (~> 0.6.2)
16
+ rails-dom-testing (~> 1.0, >= 1.0.5)
17
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
+ actionview (4.2.7)
19
+ activesupport (= 4.2.7)
20
+ builder (~> 3.1)
21
+ erubis (~> 2.7.0)
22
+ rails-dom-testing (~> 1.0, >= 1.0.5)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
+ activesupport (4.2.7)
25
+ i18n (~> 0.7)
26
+ json (~> 1.7, >= 1.7.7)
27
+ minitest (~> 5.1)
28
+ thread_safe (~> 0.3, >= 0.3.4)
29
+ tzinfo (~> 1.1)
30
+ builder (3.2.2)
31
+ erubis (2.7.0)
32
+ i18n (0.7.0)
33
+ json (1.8.3)
34
+ loofah (2.0.3)
35
+ nokogiri (>= 1.5.9)
36
+ mini_portile2 (2.1.0)
37
+ minitest (5.9.0)
38
+ nokogiri (1.6.8)
39
+ mini_portile2 (~> 2.1.0)
40
+ pkg-config (~> 1.1.7)
41
+ pkg-config (1.1.7)
42
+ rack (1.6.4)
43
+ rack-test (0.6.3)
44
+ rack (>= 1.0)
45
+ rails-deprecated_sanitizer (1.0.3)
46
+ activesupport (>= 4.2.0.alpha)
47
+ rails-dom-testing (1.0.7)
48
+ activesupport (>= 4.2.0.beta, < 5.0)
49
+ nokogiri (~> 1.6.0)
50
+ rails-deprecated_sanitizer (>= 1.0.1)
51
+ rails-html-sanitizer (1.0.3)
52
+ loofah (~> 2.0)
53
+ railties (4.2.7)
54
+ actionpack (= 4.2.7)
55
+ activesupport (= 4.2.7)
56
+ rake (>= 0.8.7)
57
+ thor (>= 0.18.1, < 2.0)
58
+ rake (11.2.2)
59
+ thor (0.19.1)
60
+ thread_safe (0.3.5)
61
+ tzinfo (1.2.2)
62
+ thread_safe (~> 0.1)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ post-massage-rails!
69
+
70
+ BUNDLED WITH
71
+ 1.12.5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2016 Tyler Kasten
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # post-massage-rails
2
+
3
+ post-massage! For Rails!
4
+
5
+ This gem provides:
6
+
7
+ * post-massage
8
+
9
+ See [VERSIONS.md](VERSIONS.md) to see which versions of post-massage-rails bundle which versions of post-massage.
10
+
11
+ ## Versions
12
+
13
+ ```
14
+ patch version bump = updates to post-massage-rails, and patch-level updates to post-massage
15
+ minor version bump = minor-level updates to post-massage
16
+ major version bump = major-level updates to post-massage and updates to rails which may be backwards-incompatible
17
+ ```
18
+
19
+ ## Installation
20
+
21
+ Gemfile
22
+
23
+ ```ruby
24
+ gem "post-massage-rails"
25
+ ```
26
+
27
+ And run `bundle install`. The rest of the installation depends on whether the asset pipeline is being used.
28
+
29
+ ### Rails 3.1 or greater (with asset pipeline *enabled*)
30
+
31
+ The post-massage files will be added to the asset pipeline and available for you to use. add these lines to `app/assets/javascripts/application.js`:
32
+
33
+ ```js
34
+ //= require post-massage
35
+ ```
36
+
37
+ ### Rails 3.0 (or greater with asset pipeline *disabled*)
38
+
39
+ This gem adds a single generator: `post-massage:install`. Running the generator will copy PostMassage to the `public/javascripts` directory.
40
+
41
+ This gem will also hook into the Rails configuration process, adding PostMassage to the javascript files included by the `javascript_include_tag(:defaults)` call. While this gem contains the minified and un-minified versions of PostMassage, only the minified versions will be included in the `:defaults` when Rails is run in `production` or `test` mode (un-minified versions will be included when Rails is run in `development` mode).
42
+
43
+ To invoke the generator, run:
44
+
45
+ ```sh
46
+ rails generate post-massage:install
47
+ ```
48
+
49
+ You're done!
50
+
51
+ ## Contributing
52
+
53
+ Feel free to open an issue ticket if you find something that could be improved.
54
+
55
+ ## Acknowledgements
56
+
57
+ This gem's structure and technique for wrapping a JS library into a rails friendly package is based entirely on jquery-rails. Many thanks are due to all of [the jquery-rails contributors](https://github.com/rails/jquery-rails/graphs/contributors).
58
+
59
+ Copyright Tyler Kasten, released under the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ # Check if versions are correct between VERSION constants and .js files
5
+ #
6
+ task :release => [:guard_version]
7
+
8
+ task :guard_version do
9
+ def check_version(file, pattern, constant)
10
+ body = File.read("vendor/assets/javascripts/#{file}")
11
+ match = body.match(pattern) or abort "Version check failed: no pattern matched in #{file}"
12
+ file_version = body.match(pattern)[1]
13
+ constant_version = PostMassage::Rails.const_get(constant)
14
+
15
+ unless constant_version == file_version
16
+ abort "PostMassage::Rails::#{constant} was #{constant_version} but it should be #{file_version}"
17
+ end
18
+ end
19
+
20
+ check_version('post-massage.js', /Version: ([\S]+)/, 'POST_MASSAGE_VERSION')
21
+ end
22
+
23
+ task :update_post_massage do
24
+ puts "Downloading post-massage.js"
25
+ puts `curl -o vendor/assets/javascripts/post-massage.js https://raw.githubusercontent.com/tkasten/postMassage/master/src/post-massage.js`
26
+
27
+ puts "Updating version.rb"
28
+ version = false
29
+ File.foreach('vendor/assets/javascripts/post-massage.js') do |line|
30
+ version = line.match(/Version: ([\S]+)/)
31
+ version = version && version[1]
32
+ break if version
33
+ end
34
+
35
+ version_path = 'lib/post_massage/rails/version.rb'
36
+ lines = IO.readlines(version_path).map do |line|
37
+ line.gsub(/POST_MASSAGE_VERSION = "([\d\.]+)"/, "POST_MASSAGE_VERSION = \"#{version}\"")
38
+ end
39
+ File.open(version_path, 'w') do |file|
40
+ file.puts lines
41
+ end
42
+
43
+ puts "\e[32mDone!\e[0m"
44
+ end
data/VERSIONS.md ADDED
@@ -0,0 +1,5 @@
1
+ # Bundled Versions
2
+
3
+ | Gem | post-massage |
4
+ |--------|----------------|
5
+ | 1.0.0 | 1.0.5 |
@@ -0,0 +1,36 @@
1
+ require 'rails'
2
+
3
+ # Supply generator for Rails 3.0.x or if asset pipeline is not enabled
4
+ if ::Rails.version < "3.1" || !::Rails.application.config.assets.enabled
5
+ module PostMassage
6
+ module Generators
7
+ class InstallGenerator < ::Rails::Generators::Base
8
+
9
+ desc "This generator installs PostMassage #{PostMassage::Rails::POST_MASSAGE_VERSION}"
10
+ source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
11
+
12
+ def copy_post_massage
13
+ say_status("copying", "PostMassage (#{PostMassage::Rails::POST_MASSAGE_VERSION})", :green)
14
+ copy_file "post-massage.js", "public/javascripts/post-massage.js"
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ else
21
+ module PostMassage
22
+ module Generators
23
+ class InstallGenerator < ::Rails::Generators::Base
24
+ desc "Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps"
25
+
26
+ def do_nothing
27
+ say_status("deprecated", "You are using Rails 3.1 with the asset pipeline enabled, so this generator is not needed.")
28
+ say_status("", "The necessary files are already in your asset pipeline.")
29
+ say_status("", "Just add `//= require post-massage` to your app/assets/javascripts/application.js")
30
+ say_status("", "If you do not want the asset pipeline enabled, you may turn it off in application.rb and re-run this generator.")
31
+ # ok, nothing
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1 @@
1
+ require 'post_massage/rails'
@@ -0,0 +1,7 @@
1
+ require 'post_massage/rails/engine' if ::Rails.version >= '3.1'
2
+ require 'post_massage/rails/version'
3
+
4
+ module PostMassage
5
+ module Rails
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module PostMassage
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module PostMassage
2
+ module Rails
3
+ VERSION = "1.0.0"
4
+ POST_MASSAGE_VERSION = "1.0.5"
5
+ end
6
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/post_massage/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "post-massage-rails"
6
+ s.version = PostMassage::Rails::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Tyler Kasten"]
9
+ s.email = ["tyler.kasten@gmail.com"]
10
+ s.homepage = "https://github.com/tkasten/post-massage-rails"
11
+ s.summary = "Use PostMassage with Rails 3+"
12
+ s.description = "This gem provides PostMassage for your Rails 3+ application."
13
+ s.license = "MIT"
14
+
15
+ s.required_rubygems_version = ">= 1.3.6"
16
+
17
+ s.add_dependency "railties", ">= 3.0", "< 5.0"
18
+ s.add_dependency "thor", ">= 0.14", "< 2.0"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
22
+ s.require_path = 'lib'
23
+ end
@@ -0,0 +1,111 @@
1
+ /*
2
+ * File: post-massage.js
3
+ * Version: 1.0.5
4
+ * Desc: A stupid simple postMessage wrapper for bi-directional communication between windows
5
+ * Doc: https://github.com/tkasten/postMassage
6
+ * Author: Tyler Kasten tyler.kasten@gmail.com
7
+ */
8
+
9
+ var PostMassage = function(opts){
10
+ this.namespace = opts.namespace || 'pmb',
11
+ this.tx_origin = opts.tx_origin || '*'
12
+ this.rx_origin = opts.rx_origin || /.*/
13
+ this.window = opts.window || parent,
14
+ this.methods = opts.methods || {}
15
+ this.logging = opts.logging || false
16
+ this.addListener = opts.addListener === false ? false : true
17
+
18
+ this.call = function(method, data, callback){
19
+ /***************************************************************************
20
+ * Messages passed using postMessage() are wrapped in an object
21
+ * that contains a namespace to avoid collisions with other people
22
+ * also using postMessage() concurrently. The structure is as follows:
23
+ *
24
+ * {
25
+ * 'myConfiguredNamespace':{
26
+ * method:
27
+ * data:
28
+ * callback:
29
+ * }
30
+ * }
31
+ *
32
+ * method: the name of the method to be dispatched in the other window's
33
+ * listening PostMassage object.
34
+ *
35
+ * data: the data your shipping to the other side's method
36
+ *
37
+ * callback (optional): the value returned from the above 'method' will be
38
+ * passed to this method on this window's listening
39
+ * PostMassage object. The typical
40
+ * use case is to get back the value of the method
41
+ * you called in the remote window (the receiving
42
+ * PostMassage is instructed to send it back to
43
+ * you via this named callback.)
44
+ ***************************************************************************/
45
+ msg = {}
46
+ msg[this.namespace] = {
47
+ method: method,
48
+ data: data,
49
+ callback: callback
50
+ }
51
+ // IE9 (of course) calls toString on the message object. So stringify it first.
52
+ msg = JSON.stringify(msg)
53
+ this.window.postMessage(msg, this.tx_origin)
54
+ },
55
+
56
+ this.bind = function(method, functionObj){
57
+ this.methods[method] = functionObj
58
+ },
59
+
60
+ this.log = function(msg){
61
+ this.logging && console.log('PostMassage: ' + msg)
62
+ }
63
+
64
+ this.buildRxEventListener = function(){
65
+ var self = this
66
+ var listener = function(event){
67
+ try{
68
+ var msg = JSON.parse(event.data);
69
+ }catch(e){
70
+ self.log('ignoring non-JSON encoded string message');
71
+ return;
72
+ }
73
+ if(msg[self.namespace]){
74
+ if(self.rx_origin.exec(event.origin)){
75
+ var method = msg[self.namespace].method,
76
+ data = msg[self.namespace].data,
77
+ callback = msg[self.namespace].callback
78
+ if(self.methods[method]){
79
+ var value = self.methods[method](data, event)
80
+ if(callback){
81
+ self.call(callback, value)
82
+ }
83
+ }else{
84
+ self.log('received a message but has no method named `' + method + '` registered')
85
+ }
86
+ }else{
87
+ self.log('received a message namespaced to `' + self.namespace + '` but its origin `' + event.origin + '` didnt match ' + self.rx_origin)
88
+ }
89
+ }else{
90
+ self.log('ignoring message from different namespace')
91
+ }
92
+ }
93
+ return listener
94
+ }
95
+
96
+ if(this.addListener){
97
+ window.addEventListener("message", this.buildRxEventListener(), false)
98
+ }
99
+ }
100
+
101
+ function factory(){
102
+ return PostMassage
103
+ }
104
+
105
+ if (typeof define === 'function' && define.amd) {
106
+ define([],factory)
107
+ } else if (typeof module === 'object' && typeof module.exports === 'object') { //Node for browserfy
108
+ module.exports = factory()
109
+ } else {
110
+ window.PostMassage = window.PostMassage || factory()
111
+ }
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: post-massage-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Kasten
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: thor
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0.14'
40
+ - - <
41
+ - !ruby/object:Gem::Version
42
+ version: '2.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0.14'
50
+ - - <
51
+ - !ruby/object:Gem::Version
52
+ version: '2.0'
53
+ description: This gem provides PostMassage for your Rails 3+ application.
54
+ email:
55
+ - tyler.kasten@gmail.com
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - CHANGELOG.md
61
+ - CONTRIBUTING.md
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - VERSIONS.md
68
+ - lib/generators/post_massage/install/install_generator.rb
69
+ - lib/post-massage-rails.rb
70
+ - lib/post_massage/rails.rb
71
+ - lib/post_massage/rails/engine.rb
72
+ - lib/post_massage/rails/version.rb
73
+ - post-massage-rails.gemspec
74
+ - vendor/assets/javascripts/post-massage.js
75
+ homepage: https://github.com/tkasten/post-massage-rails
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: 1.3.6
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.8
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Use PostMassage with Rails 3+
99
+ test_files: []