elpong-rails 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +31 -0
- data/Rakefile +11 -0
- data/lib/elpong/rails.rb +10 -0
- data/lib/elpong/rails/helper.rb +49 -0
- data/lib/elpong/rails/reloader.rb +16 -0
- data/lib/elpong/rails/version.rb +5 -0
- data/lib/generators/elpong_generator.rb +15 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c1d51243ca69f2f13d48c1b71d46315906dd21a
|
4
|
+
data.tar.gz: b24e5aaaf399b733ef5aca652510d8699e21a222
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 05edb05e6b20678ac68db73cb8b1b5a24e722d44140d6e899d5af95f4f92f825da4d6192087157814fe605b561c6e6dff7b10631d4672062a11477192efbb28c
|
7
|
+
data.tar.gz: 07d094e797966b5ccd514e0ac9e53a5ffbc55733e7426855d2988d649487f0fe2522e1922a1ec4ec93961ae47f29afdbb8ec0bd93509f4944ff75c1a559a059a
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Hans Otto Wirtz
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Elpong for Rails
|
2
|
+
|
3
|
+
This library is meant for use with [Elpong for Javascript][js]
|
4
|
+
|
5
|
+
You can put a `scheme.json` in the `/config` folder, and
|
6
|
+
that will be used as the default scheme.
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'elpong-rails'
|
10
|
+
```
|
11
|
+
|
12
|
+
```bash
|
13
|
+
$ rails generate elpong
|
14
|
+
```
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
class ApplicationController < ActionController::Base
|
18
|
+
helper Elpong::Rails::Helper
|
19
|
+
# this provides methods like elpong_scheme and elpong_collection
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
```html
|
24
|
+
<head>
|
25
|
+
<%= elpong_scheme 'animal-farm' %>
|
26
|
+
<%= elpong_collection 'pigs', path: '/api/v1/pigs/index', locals: {pigs: @pigs} %>
|
27
|
+
<%= elpong_element 'user', path: '/api/v1/users/me', attributes: {'current-user': true} %>
|
28
|
+
</head>
|
29
|
+
```
|
30
|
+
|
31
|
+
[js]: https://github.com/hansottowirtz/elpong-js
|
data/Rakefile
ADDED
data/lib/elpong/rails.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Elpong
|
2
|
+
module Rails
|
3
|
+
module Helper
|
4
|
+
def elpong_scheme(name_or_scheme = nil)
|
5
|
+
scheme = get_scheme_from_name_or_scheme(name_or_scheme)
|
6
|
+
content_tag(:meta, nil, name: 'elpong-scheme', content: scheme.to_json, scheme: scheme.name)
|
7
|
+
end
|
8
|
+
|
9
|
+
def elpong_collection(name, options = {})
|
10
|
+
scheme = get_scheme_from_name_or_scheme(options[:scheme])
|
11
|
+
# options[:locals] ||=
|
12
|
+
throw new StandardError('No path') if !options[:path]
|
13
|
+
attributes = {
|
14
|
+
name: 'elpong-collection',
|
15
|
+
content: h( render(template: options[:path], locals: options[:locals] || {}) ),
|
16
|
+
scheme: scheme.name,
|
17
|
+
collection: name
|
18
|
+
}
|
19
|
+
content_tag(:meta, nil, attributes)
|
20
|
+
end
|
21
|
+
|
22
|
+
def elpong_element(singular_name, options = {})
|
23
|
+
scheme = get_scheme_from_name_or_scheme(options[:scheme])
|
24
|
+
throw new StandardError('No path') if !options[:path]
|
25
|
+
attributes = {
|
26
|
+
name: 'elpong-element',
|
27
|
+
content: h( render(template: options[:path], locals: options[:locals] || {}) ),
|
28
|
+
scheme: scheme.name,
|
29
|
+
collection: singular_name.pluralize
|
30
|
+
}
|
31
|
+
options[:attributes].each do |name, value|
|
32
|
+
attributes[name] = value
|
33
|
+
end
|
34
|
+
content_tag(:meta, nil, attributes)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def get_scheme_from_name_or_scheme(name_or_scheme)
|
39
|
+
if name_or_scheme.class == Elpong::Scheme
|
40
|
+
name_or_scheme
|
41
|
+
elsif name_or_scheme
|
42
|
+
Elpong.get_scheme(name_or_scheme)
|
43
|
+
else
|
44
|
+
Elpong.default_scheme
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class ElpongGenerator < Rails::Generators::Base
|
2
|
+
desc 'This generator creates an initializer file at config/initializers'
|
3
|
+
def create_initializer_file
|
4
|
+
create_file 'config/initializers/elpong.rb', <<-'RUBY' # no interpolation of Rails.root
|
5
|
+
scheme = Elpong::Scheme.new("#{Rails.root}/config/scheme.json")
|
6
|
+
|
7
|
+
if Rails.env.development?
|
8
|
+
listener = Listen.to("#{Rails.root}/config", only: /^scheme.json$/) do
|
9
|
+
scheme.reload
|
10
|
+
end
|
11
|
+
listener.start
|
12
|
+
end
|
13
|
+
RUBY
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elpong-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hans Otto Wirtz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: elpong
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.2.1
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.2'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.2.1
|
47
|
+
description:
|
48
|
+
email:
|
49
|
+
- hansottowirtz@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- lib/elpong/rails.rb
|
58
|
+
- lib/elpong/rails/helper.rb
|
59
|
+
- lib/elpong/rails/reloader.rb
|
60
|
+
- lib/elpong/rails/version.rb
|
61
|
+
- lib/generators/elpong_generator.rb
|
62
|
+
homepage: https://github.com/hansottowirtz/elpong-rails
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.6.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Elpong for Rails
|
86
|
+
test_files: []
|
87
|
+
has_rdoc:
|