httpong-rails 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e768a4096ff731c09571d1ffc5b7c866dd08bd6
4
- data.tar.gz: d9244d9511a64e56291227efdb25bd2161d4886d
3
+ metadata.gz: d26719b096610099353d54a4135138fbae73b297
4
+ data.tar.gz: fbedfc1d7014406d4e4b745e080abeb0c8828255
5
5
  SHA512:
6
- metadata.gz: c863b7bbde0375395fdde67d802938dc69cad4bc17898411aac6d58045a9cb56889b8f91104048a0c1c673342b4b244be94d333b978032abacedb69918ffce33
7
- data.tar.gz: 9eed592a3bdb9f344fba9fdddcbd060f0689206240447539ce3494e2f34e187f25ed0675aa9693686656779c5e90cc14c9362589dfa5b9a0c148926f415c6ad6
6
+ metadata.gz: 3592ee6dc7d91dda62a7d25711b6c5ce9ca3b737d516a12e72f4a8be6f5fe3d5c256bc89fb6101b6ce2975f74fa5c8ddc76a96917fd257e0e6d5758da080f237
7
+ data.tar.gz: aad7a2a434fe7161f0d4b3a947daf6b0c971346b6090bad95ceb3b33a68f7e80dfeed315c957cf50dbd4389ab59b03be12aa8c23cc3629eb68c57be225a73a19
data/README.md CHANGED
@@ -2,11 +2,15 @@
2
2
 
3
3
  This library is meant to use with [HTTPong for Javascript][js]
4
4
 
5
- You can put a `scheme.json` or `scheme.cson` in the `/config` folder, and
5
+ You can put a `scheme.json` in the `/config` folder, and
6
6
  that will be used as the default scheme.
7
7
 
8
+ ```ruby
9
+ gem 'httpong-rails'
10
+ ```
11
+
8
12
  ```bash
9
- $ rails generate httpong:install
13
+ $ rails generate httpong
10
14
  ```
11
15
 
12
16
  ```ruby
@@ -18,9 +22,9 @@ end
18
22
 
19
23
  ```html
20
24
  <head>
21
- <!-- other stuff -->
22
- <%= httpong_scheme('animal-farm') %>
23
- <%= httpong_collection('pigs') %>
25
+ <%= httpong_scheme 'animal-farm' %>
26
+ <%= httpong_collection 'pigs', path: '/api/v1/pigs/index', locals: {pigs: @pigs} %>
27
+ <%= httpong_element 'user', path: '/api/v1/users/me', attributes: {'current-user': true} %>
24
28
  </head>
25
29
  ```
26
30
 
@@ -1,6 +1,7 @@
1
1
  require 'httpong'
2
2
  require_relative 'rails/version'
3
3
  require_relative 'rails/helper'
4
+ require_relative 'rails/reloader'
4
5
 
5
6
  module HTTPong
6
7
  module Rails
@@ -2,26 +2,47 @@ module HTTPong
2
2
  module Rails
3
3
  module Helper
4
4
  def httpong_scheme(name_or_scheme = nil)
5
- if name_or_scheme.class == HTTPong::Scheme
6
- scheme = name_or_scheme
7
- elsif name_or_scheme
8
- scheme = HTTPong.get_scheme(name_or_scheme)
9
- else
10
- scheme = HTTPong.default_scheme
11
- end
5
+ scheme = get_scheme_from_name_or_scheme(name_or_scheme)
12
6
  content_tag(:meta, nil, name: 'httpong-scheme', content: scheme.to_json, scheme: scheme.name)
13
- # "<meta name='httpong-scheme' content='#{scheme.to_json}' scheme='#{scheme.name}'/>"
14
7
  end
15
8
 
16
- def httpong_collection(name, path, options = {})
17
- if options[:scheme].class == HTTPong::Scheme
18
- scheme = options[:scheme]
19
- elsif options[:scheme]
20
- scheme = HTTPong.get_scheme(options[:scheme])
9
+ def httpong_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: 'httpong-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 httpong_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: 'httpong-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 == HTTPong::Scheme
40
+ name_or_scheme
41
+ elsif name_or_scheme
42
+ HTTPong.get_scheme(name_or_scheme)
21
43
  else
22
- scheme = HTTPong.default_scheme
44
+ HTTPong.default_scheme
23
45
  end
24
- content_tag(:meta, nil, name: 'httpong-collection', content: raw(render(template: path)), scheme: scheme.name, collection: name)
25
46
  end
26
47
  end
27
48
  end
@@ -0,0 +1,16 @@
1
+ module HTTPong
2
+ module Rails
3
+ class Reloader
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ HTTPong.schemes.each do |scheme|
10
+ scheme.reload
11
+ end
12
+ @app.call(env)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  module HTTPong
2
2
  module Rails
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpong-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hans Otto Wirtz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-04 00:00:00.000000000 Z
11
+ date: 2016-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -78,6 +78,7 @@ files:
78
78
  - lib/generators/httpong_generator.rb
79
79
  - lib/httpong/rails.rb
80
80
  - lib/httpong/rails/helper.rb
81
+ - lib/httpong/rails/reloader.rb
81
82
  - lib/httpong/rails/version.rb
82
83
  - lib/tasks/httpong/rails_tasks.rake
83
84
  homepage: https://github.com/hansottowirtz/httpong-rails
@@ -105,3 +106,4 @@ signing_key:
105
106
  specification_version: 4
106
107
  summary: HTTPong for Rails
107
108
  test_files: []
109
+ has_rdoc: