pagehook-rails 0.0.13 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -11
- data/lib/generators/pagehook/install/install_generator.rb +17 -4
- data/lib/generators/pagehook/install/templates/global.js +4 -0
- data/lib/generators/pagehook/install/templates/global.ts +4 -0
- data/lib/generators/pagehook/install/templates/pagehook_rails.js +12 -7
- data/lib/generators/pagehook/install/templates/pagehook_rails.ts +22 -0
- data/lib/generators/pagehook/pagehook_generator.rb +4 -4
- data/lib/generators/pagehook/templates/hook.js.erb +2 -2
- data/lib/generators/pagehook/templates/hook.ts.erb +4 -0
- data/lib/pagehook-rails/engine.rb +1 -1
- data/lib/pagehook-rails/version.rb +1 -1
- metadata +12 -11
- data/app/assets/javascripts/pagehook_rails/pagehook.js +0 -82
- data/lib/generators/pagehook/install/templates/pagehook_rails.coffee +0 -7
- data/lib/generators/pagehook/templates/hook.coffee.erb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1233e455124a9255cf37b940682d2df66e7eafc0e76ebd683f4eeebb0ef8623
|
4
|
+
data.tar.gz: 7ae8e6be99a95183bbb6879accb037f898f8eb0aa9614283c430a30144d6fedc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85584053052956a9daea5450062c42d6f4086f6919411a648c0aa9db484e6d56d671f7e268b2221fc5ed23ad4eef03bd07f51053ae79ec6dcd30953e7ba804c5
|
7
|
+
data.tar.gz: ac5cc2da3288405507820c6825c14675a771b40ffd4d9d2e8925252166bc9fef26f5e2efeb4ab18951bc8c078b13be25993d636f0336e0c1df28d6e02f8a9878
|
data/README.md
CHANGED
@@ -15,9 +15,7 @@ And then execute:
|
|
15
15
|
|
16
16
|
$ bundle
|
17
17
|
$ rails g pagehook:install
|
18
|
-
# Or `rails g pagehook:install --lang
|
19
|
-
|
20
|
-
If you use turbolinks, you should load `pagehook_rails` after `turbolinks` in `app/assets/javascripts/application.js`.
|
18
|
+
# Or `rails g pagehook:install --lang js` if you dont use TypeScript
|
21
19
|
|
22
20
|
|
23
21
|
View helper
|
@@ -25,7 +23,7 @@ View helper
|
|
25
23
|
|
26
24
|
`pagehook` view helper method generates "trigger element".
|
27
25
|
|
28
|
-
<%= pagehook("articles/index", id: 123) %>
|
26
|
+
<%= pagehook("articles/index", {id: 123}) %>
|
29
27
|
|
30
28
|
This generates following HTML.
|
31
29
|
|
@@ -38,15 +36,14 @@ Generator
|
|
38
36
|
`rails g pagehook path/to/view` generates hook definition template.
|
39
37
|
|
40
38
|
$ rails g pagehook articles/index
|
41
|
-
create app/
|
42
|
-
$ cat app/
|
43
|
-
|
44
|
-
Pagehook.register("articles/index",
|
45
|
-
|
39
|
+
create app/javascript/pagehook/articles/index.ts
|
40
|
+
$ cat app/javascript/pagehook/articles/index.ts
|
41
|
+
import Pagehook from "pagehook"
|
42
|
+
Pagehook.register("articles/index", (data: any) => {
|
43
|
+
console.log(data);
|
46
44
|
});
|
47
45
|
|
48
|
-
|
49
|
-
You can also do `rails g pagehook path/to/view --lang coffee` to generate .coffee rather than .js.
|
46
|
+
You can also do `rails g pagehook path/to/view --lang js` to generate .js rather than .ts.
|
50
47
|
|
51
48
|
|
52
49
|
Contributing
|
@@ -1,17 +1,30 @@
|
|
1
1
|
module Pagehook
|
2
2
|
class InstallGenerator < Rails::Generators::Base
|
3
3
|
source_root File.expand_path("../templates", __FILE__)
|
4
|
-
class_option :lang, type: :string, default: "
|
4
|
+
class_option :lang, type: :string, default: "ts"
|
5
|
+
|
6
|
+
def install
|
7
|
+
run "yarn add pagehook@^0.1.4"
|
8
|
+
end
|
5
9
|
|
6
10
|
def copy_loader
|
7
11
|
case options[:lang].downcase
|
8
|
-
when "coffee", "coffeescript"
|
9
|
-
copy_file "pagehook_rails.coffee", "app/assets/javascripts/pagehook_rails.coffee"
|
10
12
|
when "js", "javascript"
|
11
|
-
copy_file "pagehook_rails.js", "app/
|
13
|
+
copy_file "pagehook_rails.js", "app/javascript/pagehook_rails.js"
|
14
|
+
copy_file "global.js", "app/javascript/pagehook/global.js"
|
15
|
+
when "ts", "typescript"
|
16
|
+
copy_file "pagehook_rails.ts", "app/javascript/pagehook_rails.ts"
|
17
|
+
copy_file "global.ts", "app/javascript/pagehook/global.ts"
|
12
18
|
else
|
13
19
|
raise "Unknown language: #{lang}"
|
14
20
|
end
|
21
|
+
|
22
|
+
case
|
23
|
+
when File.exists?("app/javascript/packs/application.ts")
|
24
|
+
append_file_with_newline "app/javascript/packs/application.ts", %(\nimport "../pagehook_rails")
|
25
|
+
when File.exists?("app/javascript/packs/application.js")
|
26
|
+
append_file_with_newline "app/javascript/packs/application.js", %(\nimport "../pagehook_rails")
|
27
|
+
end
|
15
28
|
end
|
16
29
|
end
|
17
30
|
end
|
@@ -1,8 +1,13 @@
|
|
1
|
-
//= require pagehook_rails/pagehook
|
2
1
|
// Register event handler
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
import Pagehook from "pagehook";
|
3
|
+
document.addEventListener("DOMContentLoaded", Pagehook.handler);
|
4
|
+
|
5
|
+
const requireHook = require.context(
|
6
|
+
"./pagehook",
|
7
|
+
true, // Whether or not to look in subfolders
|
8
|
+
/[a-z0-9_]+\.(js|ts)$/u,
|
9
|
+
);
|
10
|
+
|
11
|
+
requireHook.keys().forEach((fileName) => {
|
12
|
+
requireHook(fileName);
|
13
|
+
});
|
@@ -0,0 +1,22 @@
|
|
1
|
+
// Register event handler
|
2
|
+
import Pagehook from "pagehook";
|
3
|
+
document.addEventListener("DOMContentLoaded", Pagehook.handler);
|
4
|
+
|
5
|
+
// Require all hooks in ./pagehook
|
6
|
+
interface RequireHook {
|
7
|
+
(fileName: string): object | {default: object};
|
8
|
+
keys: () => string[];
|
9
|
+
}
|
10
|
+
interface NodeRequireWithContext extends NodeRequire {
|
11
|
+
context: (a: string, b: boolean, c: RegExp) => RequireHook;
|
12
|
+
}
|
13
|
+
|
14
|
+
const requireHook = (require as NodeRequireWithContext).context(
|
15
|
+
"./pagehook",
|
16
|
+
true, // Whether or not to look in subfolders
|
17
|
+
/[a-z0-9_]+\.(js|ts)$/u,
|
18
|
+
);
|
19
|
+
|
20
|
+
requireHook.keys().forEach((fileName: string) => {
|
21
|
+
requireHook(fileName);
|
22
|
+
});
|
@@ -1,13 +1,13 @@
|
|
1
1
|
class PagehookGenerator < Rails::Generators::NamedBase
|
2
2
|
source_root File.expand_path("../templates", __FILE__)
|
3
|
-
class_option :lang, type: :string, default: "
|
3
|
+
class_option :lang, type: :string, default: "ts"
|
4
4
|
|
5
5
|
def generate_script
|
6
6
|
case options[:lang].downcase
|
7
|
-
when "coffee", "coffeescript"
|
8
|
-
template "hook.coffee.erb", "app/assets/javascripts/pagehook/#{view_path}.coffee"
|
9
7
|
when "js", "javascript"
|
10
|
-
template "hook.js.erb", "app/
|
8
|
+
template "hook.js.erb", "app/javascript/pagehook/#{view_path}.js"
|
9
|
+
when "ts", "typescript"
|
10
|
+
template "hook.ts.erb", "app/javascript/pagehook/#{view_path}.ts"
|
11
11
|
else
|
12
12
|
raise "Unknown language: #{lang}"
|
13
13
|
end
|
@@ -3,7 +3,7 @@ module PagehookRails
|
|
3
3
|
isolate_namespace PagehookRails
|
4
4
|
|
5
5
|
initializer "pagehook-rails.action_controller" do |app|
|
6
|
-
|
6
|
+
Rails.application.reloader.to_prepare do
|
7
7
|
ActionController::Base.helper PagehookRails::PagehookHelper
|
8
8
|
end
|
9
9
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagehook-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- labocho
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: loofah
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,21 +118,22 @@ files:
|
|
118
118
|
- MIT-LICENSE
|
119
119
|
- README.md
|
120
120
|
- Rakefile
|
121
|
-
- app/assets/javascripts/pagehook_rails/pagehook.js
|
122
121
|
- app/helpers/pagehook_rails/pagehook_helper.rb
|
123
122
|
- lib/generators/pagehook/install/install_generator.rb
|
124
|
-
- lib/generators/pagehook/install/templates/
|
123
|
+
- lib/generators/pagehook/install/templates/global.js
|
124
|
+
- lib/generators/pagehook/install/templates/global.ts
|
125
125
|
- lib/generators/pagehook/install/templates/pagehook_rails.js
|
126
|
+
- lib/generators/pagehook/install/templates/pagehook_rails.ts
|
126
127
|
- lib/generators/pagehook/pagehook_generator.rb
|
127
|
-
- lib/generators/pagehook/templates/hook.coffee.erb
|
128
128
|
- lib/generators/pagehook/templates/hook.js.erb
|
129
|
+
- lib/generators/pagehook/templates/hook.ts.erb
|
129
130
|
- lib/pagehook-rails.rb
|
130
131
|
- lib/pagehook-rails/engine.rb
|
131
132
|
- lib/pagehook-rails/version.rb
|
132
133
|
homepage: https://github.com/labocho/pagehook-rails
|
133
134
|
licenses: []
|
134
135
|
metadata: {}
|
135
|
-
post_install_message:
|
136
|
+
post_install_message:
|
136
137
|
rdoc_options: []
|
137
138
|
require_paths:
|
138
139
|
- lib
|
@@ -147,8 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
148
|
- !ruby/object:Gem::Version
|
148
149
|
version: '0'
|
149
150
|
requirements: []
|
150
|
-
rubygems_version: 3.
|
151
|
-
signing_key:
|
151
|
+
rubygems_version: 3.3.3
|
152
|
+
signing_key:
|
152
153
|
specification_version: 4
|
153
154
|
summary: Rails plugin integrates Pagehook (https://github.com/labocho/pagehook)
|
154
155
|
test_files: []
|
@@ -1,82 +0,0 @@
|
|
1
|
-
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.Pagehook=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2
|
-
"use strict";
|
3
|
-
|
4
|
-
// constructor
|
5
|
-
var Pagehook = function() {
|
6
|
-
this.definitions = {};
|
7
|
-
this.handler = this.handlerUnbound.bind(this);
|
8
|
-
};
|
9
|
-
|
10
|
-
// constant
|
11
|
-
Pagehook.GLOBAL_HOOK_NAME = "@global";
|
12
|
-
Pagehook.ATTRIBUTE_NAME = "data-pagehook";
|
13
|
-
|
14
|
-
// static methods
|
15
|
-
Pagehook.register = function(name_or_map, func) {
|
16
|
-
this.instance.register(name_or_map, func);
|
17
|
-
};
|
18
|
-
|
19
|
-
Pagehook.dispatch = function(name, arg) {
|
20
|
-
this.instance.dispatch(name, arg);
|
21
|
-
};
|
22
|
-
|
23
|
-
// Pagehook.register "name", (arg)-> ...
|
24
|
-
// // or
|
25
|
-
// Pagehoook.register
|
26
|
-
// name: (arg)->
|
27
|
-
Pagehook.prototype.register = function(name_or_map, func) {
|
28
|
-
var name;
|
29
|
-
|
30
|
-
if (typeof(name_or_map) === "string") {
|
31
|
-
if (!this.definitions[name_or_map]) {
|
32
|
-
this.definitions[name_or_map] = [];
|
33
|
-
}
|
34
|
-
this.definitions[name_or_map].push(func);
|
35
|
-
} else {
|
36
|
-
for (name in name_or_map) {
|
37
|
-
this.register(name, name_or_map[name]);
|
38
|
-
}
|
39
|
-
}
|
40
|
-
};
|
41
|
-
|
42
|
-
// Pagehook.dispatch("name", {foo: 1, bar: 2})
|
43
|
-
Pagehook.prototype.dispatch = function(name, arg) {
|
44
|
-
if (this.definitions[name]) {
|
45
|
-
this.definitions[name].forEach(function(func) {
|
46
|
-
func(arg);
|
47
|
-
});
|
48
|
-
} else {
|
49
|
-
if (name !== Pagehook.GLOBAL_HOOK_NAME) {
|
50
|
-
console.log("Pagehook for " + name + " is undefined");
|
51
|
-
}
|
52
|
-
}
|
53
|
-
};
|
54
|
-
|
55
|
-
// Event handler for DOMContentLoaded or turbolinks:load (turbolinks)
|
56
|
-
// Use `handler` property instead of this
|
57
|
-
Pagehook.prototype.handlerUnbound = function() {
|
58
|
-
var elements, i, e, name, arg;
|
59
|
-
|
60
|
-
this.dispatch(Pagehook.GLOBAL_HOOK_NAME);
|
61
|
-
|
62
|
-
elements = document.querySelectorAll("[" + Pagehook.ATTRIBUTE_NAME + "]");
|
63
|
-
for (i = 0; i < elements.length; i++) {
|
64
|
-
e = elements[i];
|
65
|
-
name = e.getAttribute(Pagehook.ATTRIBUTE_NAME);
|
66
|
-
arg = this.isBlank(e.textContent) ? undefined : JSON.parse(e.textContent);
|
67
|
-
this.dispatch(name, arg);
|
68
|
-
}
|
69
|
-
};
|
70
|
-
|
71
|
-
Pagehook.prototype.isBlank = function(string) {
|
72
|
-
return !!(string.match(/^\s*$/));
|
73
|
-
};
|
74
|
-
|
75
|
-
// instanciate singleton object
|
76
|
-
Pagehook.instance = new Pagehook();
|
77
|
-
Pagehook.handler = Pagehook.instance.handler;
|
78
|
-
|
79
|
-
module.exports = Pagehook;
|
80
|
-
|
81
|
-
},{}]},{},[1])(1)
|
82
|
-
});
|
@@ -1,7 +0,0 @@
|
|
1
|
-
#= require pagehook_rails/pagehook
|
2
|
-
# Register event handler
|
3
|
-
if typeof(Turbolinks) == "undefined"
|
4
|
-
document.addEventListener("DOMContentLoaded", Pagehook.handler)
|
5
|
-
else
|
6
|
-
document.addEventListener("turbolinks:load", Pagehook.handler)
|
7
|
-
document.addEventListener("page:load", Pagehook.handler)
|