ljax_rails 0.0.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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/MIT_LICENSE +22 -0
- data/README.md +27 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/ljax_rails.js.coffee +11 -0
- data/lib/ljax_rails.rb +24 -0
- data/lib/ljax_rails/action_dispatch_monkey.rb +5 -0
- data/lib/ljax_rails/action_view_monkey.rb +22 -0
- data/lib/ljax_rails/application_controller_ljax_filter.rb +12 -0
- data/ljax_rails.gemspec +22 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c8fd90181ed09aaff3cd7570d689cc63d0d6ab86
|
4
|
+
data.tar.gz: 254da859df28e68454ba0a26b5bef19344ecfe08
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cbbb9d511cebcd08931f7eddd0fadb3ac6478f8b5699922435f77c9b59a41066d7ce30dafc9a51d9efe0a3a9874af7d3ddc7f5bc3fa25753b3f1f09935e0843e
|
7
|
+
data.tar.gz: a906250f13b9d2b7bf26bb48556fdd672ebcc154438dd090b6caa27bb35098782e0ec33fc7ad5a54274a5ae9141ca7cf90ef53942e32511cfd5f4dc0ee48638c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT_LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Akira Matsuda
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# LJAX
|
2
|
+
|
3
|
+
Lazy-load AJAX on Rails
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Bundle `ljax_rails` gem:
|
8
|
+
|
9
|
+
gem 'ljax_rails'
|
10
|
+
|
11
|
+
Then add this to your app/assets/javascripts/application.js (or whatever bundle you use):
|
12
|
+
|
13
|
+
//=require ljax_rails
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Add `remote: true` option to your `render :partial` call, then the partial will be lazily rendered in a separate HTTP request.
|
18
|
+
|
19
|
+
<%= render 'users', remote: true %>
|
20
|
+
|
21
|
+
Also, you can give `remote_url` option for specifying request target URL.
|
22
|
+
|
23
|
+
<%= render 'sidebar', remote: true, remote_url: '/shared/sidebar' %>
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Send me your PRs!
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
$ ->
|
2
|
+
$('.ljax-container').each (index, container) =>
|
3
|
+
$.ajax
|
4
|
+
type: 'GET'
|
5
|
+
dataType: 'text'
|
6
|
+
url: $(container).data('remote-url')
|
7
|
+
headers: {'X-LJAX': 'true', 'X-LJAX-Container': container.id, 'X-LJAX-Partial': $(container).data('ljax-partial')}
|
8
|
+
success: (data, status, xhr) ->
|
9
|
+
$("##{container.id}").replaceWith data
|
10
|
+
error: (data, status, xhr) ->
|
11
|
+
console.log "error: #{data}"
|
data/lib/ljax_rails.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module LjaxRails
|
2
|
+
VERSION = Gem.loaded_specs['ljax_rails'].version.to_s
|
3
|
+
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
initializer 'ljax_rails.add_controller' do
|
6
|
+
ActiveSupport.on_load :action_controller do
|
7
|
+
require_relative 'ljax_rails/action_dispatch_monkey'
|
8
|
+
require_relative 'ljax_rails/action_view_monkey'
|
9
|
+
require_relative 'ljax_rails/application_controller_ljax_filter'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.encryptor
|
15
|
+
@encryption_key ||= begin
|
16
|
+
key = if Rails.application.config.respond_to? :secret_key_base
|
17
|
+
Rails.application.config.secret_key_base || Rails.application.config.secret_token
|
18
|
+
else
|
19
|
+
Rails.application.config.secret_token
|
20
|
+
end
|
21
|
+
ActiveSupport::MessageEncryptor.new key
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module LjaxRails
|
4
|
+
module LjaxRenderer
|
5
|
+
def render_partial(context, options, &block)
|
6
|
+
if options[:locals] && options[:locals].delete(:remote)
|
7
|
+
partial = options.delete :partial
|
8
|
+
encrypted_partial = LjaxRails.encryptor.encrypt_and_sign partial
|
9
|
+
|
10
|
+
url = options[:locals].delete :remote_url
|
11
|
+
id = "ljax-#{SecureRandom.uuid}"
|
12
|
+
loading = block.call if block
|
13
|
+
|
14
|
+
%Q!<div id="#{id}" class="ljax-container" data-ljax-partial="#{encrypted_partial}"#{%Q( data-remote-url="#{url}") if url}>#{loading}</div>!.html_safe
|
15
|
+
else
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
ActionView::Renderer.send :prepend, LjaxRails::LjaxRenderer
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module LjaxRails::LjaxActionProcessor
|
2
|
+
def default_render(*)
|
3
|
+
if request.ljax?
|
4
|
+
partial = LjaxRails.encryptor.decrypt_and_verify request.headers['X-LJAX-Partial']
|
5
|
+
render partial: partial
|
6
|
+
else
|
7
|
+
super
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
ActionController::Base.send :prepend, LjaxRails::LjaxActionProcessor
|
data/ljax_rails.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ljax_rails"
|
7
|
+
spec.version = '0.0.1'
|
8
|
+
spec.authors = ["Akira Matsuda"]
|
9
|
+
spec.email = ["ronnie@dio.jp"]
|
10
|
+
spec.description = '"LJAX" (= Lazy load Ajax) on Rails'
|
11
|
+
spec.summary = '"LJAX" (= Lazy load Ajax) on Rails'
|
12
|
+
spec.homepage = 'https://github.com/amatsuda/ljax_rails'
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ljax_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Akira Matsuda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: '"LJAX" (= Lazy load Ajax) on Rails'
|
42
|
+
email:
|
43
|
+
- ronnie@dio.jp
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- MIT_LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- app/assets/javascripts/ljax_rails.js.coffee
|
54
|
+
- lib/ljax_rails.rb
|
55
|
+
- lib/ljax_rails/action_dispatch_monkey.rb
|
56
|
+
- lib/ljax_rails/action_view_monkey.rb
|
57
|
+
- lib/ljax_rails/application_controller_ljax_filter.rb
|
58
|
+
- ljax_rails.gemspec
|
59
|
+
homepage: https://github.com/amatsuda/ljax_rails
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.0.3
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: '"LJAX" (= Lazy load Ajax) on Rails'
|
83
|
+
test_files: []
|
84
|
+
has_rdoc:
|