├── .gitignore ├── .rspec ├── Gemfile ├── Gemfile.lock ├── MIT-LICENSE ├── README.md ├── Rakefile ├── app ├── assets │ └── javascripts │ │ └── lazy_render.js ├── controllers │ └── lazy_render │ │ ├── application_controller.rb │ │ └── lazyload_controller.rb └── helpers │ └── lazy_render │ ├── application_helper.rb │ └── lazyload_helper.rb ├── bin └── rails ├── config └── routes.rb ├── lazy_render.gemspec ├── lib ├── lazy_render.rb ├── lazy_render │ ├── engine.rb │ ├── rails │ │ └── routes.rb │ └── version.rb └── tasks │ └── lazy_render_tasks.rake └── spec ├── assets └── images │ └── lazy-render.png ├── controllers └── lazy_render │ └── lazy_render_controller_spec.rb ├── features └── lazy_render_spec.rb ├── helpers └── lazy_render │ └── lazy_render_helper_spec.rb ├── rails_helper.rb ├── spec_helper.rb └── test_app ├── README.rdoc ├── Rakefile ├── app ├── assets │ ├── images │ │ └── .keep │ ├── javascripts │ │ ├── application.js │ │ └── top.js │ └── stylesheets │ │ ├── application.css │ │ └── top.css ├── controllers │ ├── application_controller.rb │ ├── concerns │ │ └── .keep │ ├── lazy_render_controller.rb │ └── top_controller.rb ├── helpers │ ├── application_helper.rb │ └── top_helper.rb ├── mailers │ └── .keep ├── models │ ├── .keep │ └── concerns │ │ └── .keep └── views │ ├── layouts │ └── application.html.erb │ ├── lazy_render │ ├── directory │ │ └── separator.html.erb │ ├── lazy_render_message.erb │ ├── pass_variables.html.erb │ └── with_cache.html.erb │ └── top │ └── index.html.erb ├── bin ├── bundle ├── rails ├── rake └── setup ├── config.ru ├── config ├── application.rb ├── boot.rb ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── assets.rb │ ├── backtrace_silencers.rb │ ├── cookies_serializer.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ ├── mime_types.rb │ ├── session_store.rb │ └── wrap_parameters.rb ├── locales │ └── en.yml ├── routes.rb └── secrets.yml ├── lib └── assets │ └── .keep ├── log └── .keep └── public ├── 404.html ├── 422.html ├── 500.html └── favicon.ico /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle/ 2 | log/*.log 3 | pkg/ 4 | spec/test_app/db/*.sqlite3 5 | spec/test_app/db/*.sqlite3-journal 6 | spec/test_app/log/*.log 7 | spec/test_app/tmp/ 8 | spec/test_app/.sass-cache 9 | .idea 10 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --require spec_helper 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Declare your gem's dependencies in lazy_render.gemspec. 4 | # Bundler will treat runtime dependencies like base dependencies, and 5 | # development dependencies will be added by default to the :development group. 6 | gemspec 7 | 8 | gem 'jquery-rails' 9 | # Declare any dependencies that are still in development here instead of in 10 | # your gemspec. These might include edge Rails or gems from your path or 11 | # Git. Remember to move these dependencies to your gemspec before releasing 12 | # your gem to rubygems.org. 13 | 14 | # To use a debugger 15 | # gem 'byebug', group: [:development, :test] 16 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | lazy_render (0.2.0) 5 | jquery-rails 6 | rails (>= 4.0.0) 7 | 8 | GEM 9 | remote: https://rubygems.org/ 10 | specs: 11 | actionmailer (4.1.7) 12 | actionpack (= 4.1.7) 13 | actionview (= 4.1.7) 14 | mail (~> 2.5, >= 2.5.4) 15 | actionpack (4.1.7) 16 | actionview (= 4.1.7) 17 | activesupport (= 4.1.7) 18 | rack (~> 1.5.2) 19 | rack-test (~> 0.6.2) 20 | actionview (4.1.7) 21 | activesupport (= 4.1.7) 22 | builder (~> 3.1) 23 | erubis (~> 2.7.0) 24 | activemodel (4.1.7) 25 | activesupport (= 4.1.7) 26 | builder (~> 3.1) 27 | activerecord (4.1.7) 28 | activemodel (= 4.1.7) 29 | activesupport (= 4.1.7) 30 | arel (~> 5.0.0) 31 | activesupport (4.1.7) 32 | i18n (~> 0.6, >= 0.6.9) 33 | json (~> 1.7, >= 1.7.7) 34 | minitest (~> 5.1) 35 | thread_safe (~> 0.1) 36 | tzinfo (~> 1.1) 37 | arel (5.0.1.20140414130214) 38 | builder (3.2.2) 39 | capybara (2.4.4) 40 | mime-types (>= 1.16) 41 | nokogiri (>= 1.3.3) 42 | rack (>= 1.0.0) 43 | rack-test (>= 0.5.4) 44 | xpath (~> 2.0) 45 | capybara-webkit (1.3.1) 46 | capybara (>= 2.0.2, < 2.5.0) 47 | json 48 | concurrent-ruby (1.0.1) 49 | diff-lcs (1.2.5) 50 | erubis (2.7.0) 51 | factory_girl (4.5.0) 52 | activesupport (>= 3.0.0) 53 | factory_girl_rails (4.5.0) 54 | factory_girl (~> 4.5.0) 55 | railties (>= 3.0.0) 56 | i18n (0.6.11) 57 | jquery-rails (3.1.2) 58 | railties (>= 3.0, < 5.0) 59 | thor (>= 0.14, < 2.0) 60 | json (1.8.1) 61 | mail (2.6.4) 62 | mime-types (>= 1.16, < 4) 63 | mime-types (2.4.3) 64 | mini_portile (0.6.1) 65 | minitest (5.4.3) 66 | nokogiri (1.6.4.1) 67 | mini_portile (~> 0.6.0) 68 | rack (1.5.2) 69 | rack-test (0.6.2) 70 | rack (>= 1.0) 71 | rails (4.1.7) 72 | actionmailer (= 4.1.7) 73 | actionpack (= 4.1.7) 74 | actionview (= 4.1.7) 75 | activemodel (= 4.1.7) 76 | activerecord (= 4.1.7) 77 | activesupport (= 4.1.7) 78 | bundler (>= 1.3.0, < 2.0) 79 | railties (= 4.1.7) 80 | sprockets-rails (~> 2.0) 81 | railties (4.1.7) 82 | actionpack (= 4.1.7) 83 | activesupport (= 4.1.7) 84 | rake (>= 0.8.7) 85 | thor (>= 0.18.1, < 2.0) 86 | rake (10.3.2) 87 | rspec-core (3.1.7) 88 | rspec-support (~> 3.1.0) 89 | rspec-expectations (3.1.2) 90 | diff-lcs (>= 1.2.0, < 2.0) 91 | rspec-support (~> 3.1.0) 92 | rspec-mocks (3.1.3) 93 | rspec-support (~> 3.1.0) 94 | rspec-rails (3.1.0) 95 | actionpack (>= 3.0) 96 | activesupport (>= 3.0) 97 | railties (>= 3.0) 98 | rspec-core (~> 3.1.0) 99 | rspec-expectations (~> 3.1.0) 100 | rspec-mocks (~> 3.1.0) 101 | rspec-support (~> 3.1.0) 102 | rspec-support (3.1.2) 103 | sprockets (3.6.0) 104 | concurrent-ruby (~> 1.0) 105 | rack (> 1, < 3) 106 | sprockets-rails (2.3.3) 107 | actionpack (>= 3.0) 108 | activesupport (>= 3.0) 109 | sprockets (>= 2.8, < 4.0) 110 | sqlite3 (1.3.10) 111 | thor (0.19.1) 112 | thread_safe (0.3.4) 113 | tzinfo (1.2.2) 114 | thread_safe (~> 0.1) 115 | xpath (2.0.0) 116 | nokogiri (~> 1.3) 117 | 118 | PLATFORMS 119 | ruby 120 | 121 | DEPENDENCIES 122 | capybara 123 | capybara-webkit 124 | factory_girl_rails 125 | jquery-rails 126 | lazy_render! 127 | rspec-rails 128 | sqlite3 129 | 130 | BUNDLED WITH 131 | 1.10.6 132 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 vexus2 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LazyRender 2 | 3 | ![lazy_render](https://raw.githubusercontent.com/vexus2/lazy_render/master/spec/assets/images/lazy-render.png) 4 | 5 | ## What is this? 6 | It delays loading of partial or actions in views. 7 | 8 | ## Installation 9 | 10 | LazyRender works with Rails 4.0 onwards. You can add it to your Gemfile with: 11 | 12 | ``` 13 | gem 'lazy_render' 14 | ``` 15 | 16 | 17 | ## Usage 18 | 19 | ### 1. Route to LazyRender 20 | 21 | add to `routes.rb` 22 | ``` 23 | lazy_render_for 'lazy_render/load', to: 'lazy_render' 24 | ``` 25 | 26 | ### 2. Configuring Javascript 27 | 28 | add to `application.js` 29 | 30 | ``` 31 | //= require jquery 32 | //= require lazy_render 33 | ``` 34 | 35 | ### 3. Configuring Controller 36 | 37 | add to include helper into application_controller 38 | 39 | ``` 40 | class ApplicationController < ActionController::Base 41 | helper LazyRender::LazyloadHelper 42 | end 43 | ``` 44 | 45 | create a controller to run lazy render 46 | 47 | controllers/lazy_render_controller.rb 48 | ``` 49 | class LazyRenderController < LazyRender::LazyloadController 50 | def load 51 | super 52 | end 53 | end 54 | ``` 55 | 56 | and add some action to `LazyRenderController` 57 | 58 | ``` 59 | def sample_action(locals) 60 | @data[:sample_text] = 'Hello LazyRender!' 61 | @data[:pass_value] = locals[:value] 62 | end 63 | ``` 64 | 65 | 66 | ### 4. Configuring View 67 | 68 | create view file under `views/lazy_render/` 69 | 70 | views/lazy_render/sample_action.html.erb 71 | ``` 72 |

This is sample view.

73 |

<%= data[:sample_text] %>

74 |

<%= data[:pass_value] %> 75 | ``` 76 | 77 | 78 | ### 5. Call lazy_render from View 79 | 80 | Call lazy_render from your any views 81 | 82 | ``` 83 | <%= lazy_render :sample_text, locals: { value: 'Sample Text' } %> 84 | ``` 85 | 86 | ``` 87 |

This is sample view.

88 |

Hello LazyRender!

89 |

Sample Text 90 | ``` 91 | 92 | ### lazy_render options 93 | - *locals* : The parameters to passed to action 94 | - *cache* : Time to hold a View to the local storage. Default: 0 95 | - *callback* : To specify the Javascript method that you want to execute after displaying partial. 96 | - *parallel* : I carry it out in parallel without compiling a request in lazy_render. Default: false 97 | 98 | ## Contributing 99 | 100 | 1. Fork it ( https://github.com/vexus2/lazy_render/fork ) 101 | 2. Create your feature branch (`git checkout -b my-new-feature`) 102 | 3. Commit your changes (`git commit -am 'Add some feature'`) 103 | 4. Push to the branch (`git push origin my-new-feature`) 104 | 5. Create a new Pull Request 105 | 106 | 107 | ## Authors 108 | [vexus2](https://github.com/vexus2) 109 | 110 | 111 | ## Thanks to 112 | be inspired by [akiyan](https://github.com/akiyan) 113 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | begin 2 | require 'bundler/setup' 3 | rescue LoadError 4 | puts 'You must `gem install bundler` and `bundle install` to run rake tasks' 5 | end 6 | 7 | require 'rdoc/task' 8 | 9 | RDoc::Task.new(:rdoc) do |rdoc| 10 | rdoc.rdoc_dir = 'rdoc' 11 | rdoc.title = 'LazyRender' 12 | rdoc.options << '--line-numbers' 13 | rdoc.rdoc_files.include('README.rdoc') 14 | rdoc.rdoc_files.include('lib/**/*.rb') 15 | end 16 | 17 | APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__) 18 | load 'rails/tasks/engine.rake' 19 | 20 | 21 | load 'rails/tasks/statistics.rake' 22 | 23 | 24 | 25 | Bundler::GemHelper.install_tasks 26 | 27 | Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f } 28 | 29 | require 'rspec/core' 30 | require 'rspec/core/rake_task' 31 | 32 | desc "Run all specs in spec directory (excluding plugin specs)" 33 | RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare') 34 | task :default => :spec 35 | 36 | -------------------------------------------------------------------------------- /app/assets/javascripts/lazy_render.js: -------------------------------------------------------------------------------- 1 | //= require jquery 2 | 3 | var LazyRender = { 4 | load : function (context) { 5 | var lazy_renders = []; 6 | var lazy_render_elms = []; 7 | $('[class^=js-lazy-render]', context).each(function () { 8 | var param = { 9 | name : $(this).data('lazy-render-name'), 10 | locals : $(this).data('lazy-render-params'), 11 | cache : $(this).data('lazy-render-cache'), 12 | version : $(this).data('lazy-render-version'), 13 | callback : $(this).data('lazy-render-callback'), 14 | parallel : $(this).data('lazy-render-parallel') 15 | }; 16 | if (param['cache']) { 17 | var cache = LazyRender.cache_read(param['name'] + $(this).attr('data-lazy-render-lazy_renders'), param['version']); 18 | if (cache) { 19 | LazyRender.apply(this, param, cache); 20 | return; 21 | } 22 | } 23 | if (param['parallel']) { 24 | LazyRender.request([param], [this]); 25 | } else { 26 | lazy_render_elms[lazy_render_elms.length] = this; 27 | lazy_renders.push(param); 28 | } 29 | }); 30 | if (lazy_renders.length > 0) LazyRender.request(lazy_renders, lazy_render_elms); 31 | }, 32 | request: function(params, positions) { 33 | $.ajax({ 34 | type : 'post', 35 | url : '/lazy_render/load', 36 | data : { 37 | lazy_renders : params, 38 | referrer : document.referrer ? document.referrer : '' 39 | }, 40 | beforeSend : function (jqXHR, settings) { 41 | jqXHR.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content')); 42 | }, 43 | cache : false, 44 | dataType : 'json', 45 | success : function (result) { 46 | $(params).each(function (i, lazy_render) { 47 | LazyRender.apply(positions[i], lazy_render, result[i]); 48 | if (lazy_render['cache']) { 49 | LazyRender.cache_write(result[i], lazy_render['name'] + $(positions[i]).attr('data-lazy-render-lazy_renders'), lazy_render['version'], lazy_render['cache']); 50 | } 51 | }); 52 | } 53 | }); 54 | }, 55 | apply : function (elm, data, html) { 56 | if ($(elm).data('lazy-render-replace') == 'inner') { 57 | $(elm).html(html); 58 | } else { 59 | $(elm).replaceWith(html); 60 | } 61 | if (data['callback']) { 62 | eval(data['callback'] + '(data, elm);'); 63 | } 64 | }, 65 | cache_storage_prefix : 'lazy_render_cache_', 66 | cache_storage_key : function (key) { 67 | return location.protocol + this.cache_storage_prefix + key; 68 | }, 69 | cache_read : function (key, version) { 70 | if (typeof sessionStorage == 'undefined' || typeof JSON == 'undefined') return false; 71 | if (location.search.match('cacheclear=1')) return false; 72 | try { 73 | var cache = JSON.parse(sessionStorage[this.cache_storage_key(key)]); 74 | if (!cache) return false; 75 | var now = new Date / 1e3 | 0; 76 | return cache['expire'] > now && cache['version'] == version ? cache['data'] : false; 77 | }catch (e) { 78 | return false; 79 | } 80 | }, 81 | cache_write : function (data, key, version, lifetimesec) { 82 | if (typeof sessionStorage == 'undefined' || typeof JSON == 'undefined') return false; 83 | sessionStorage[this.cache_storage_key(key)] = JSON.stringify({ 84 | data : data, 85 | version : version, 86 | expire : (new Date / 1e3 | 0) + lifetimesec 87 | }); 88 | return true; 89 | } 90 | }; 91 | 92 | 93 | $(function () { 94 | if ($('[class^=js-lazy-render]').length > 0) { 95 | LazyRender.load(document); 96 | } 97 | }); 98 | -------------------------------------------------------------------------------- /app/controllers/lazy_render/application_controller.rb: -------------------------------------------------------------------------------- 1 | module LazyRender 2 | class ApplicationController < ActionController::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/controllers/lazy_render/lazyload_controller.rb: -------------------------------------------------------------------------------- 1 | require_dependency 'lazy_render/application_controller' 2 | 3 | module LazyRender 4 | class LazyloadController < ApplicationController 5 | protect_from_forgery with: :null_session 6 | 7 | def load 8 | return unless params['lazy_renders'] 9 | result = [] 10 | @data = {} 11 | params['lazy_renders'].values.select { |v| v['name'] && respond_to?(v['name']) }.each do |v| 12 | data = { 13 | name: v['name'], 14 | locals: v['locals'] || {} 15 | } 16 | data[:locals].empty? ? send(data[:name]) : send(data[:name], data[:locals]) 17 | # TODO: Add Benchmark time 18 | html = render_to_string 'lazy_render/' + data[:name].gsub('__', '/'), layout: false, locals: { data: @data || {} } 19 | result << html 20 | end 21 | 22 | render json: result 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /app/helpers/lazy_render/application_helper.rb: -------------------------------------------------------------------------------- 1 | module LazyRender 2 | module ApplicationHelper 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/helpers/lazy_render/lazyload_helper.rb: -------------------------------------------------------------------------------- 1 | module LazyRender 2 | module LazyloadHelper 3 | def lazy_render(name, locals: {}, cache: false, callback: false, parallel: false) 4 | data = { 'lazy-render-name' => name } 5 | data['lazy-render-params'] = locals if locals.instance_of?(Hash) && locals.presence 6 | data['lazy-render-cache'] = cache.to_i if cache 7 | data['lazy-render-callback'] = callback if callback 8 | data['lazy-render-parallel'] = parallel if parallel 9 | content_tag :span, nil, class: "js-lazy-render-#{name}", data: data 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application. 3 | 4 | ENGINE_ROOT = File.expand_path('../..', __FILE__) 5 | ENGINE_PATH = File.expand_path('../../lib/lazy_render/engine', __FILE__) 6 | 7 | # Set up gems listed in the Gemfile. 8 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 9 | require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) 10 | 11 | require 'rails/all' 12 | require 'rails/engine/commands' 13 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | LazyRender::Engine.routes.draw do 2 | end 3 | -------------------------------------------------------------------------------- /lazy_render.gemspec: -------------------------------------------------------------------------------- 1 | $:.push File.expand_path("../lib", __FILE__) 2 | 3 | # Maintain your gem's version: 4 | require "lazy_render/version" 5 | 6 | # Describe your gem and declare its dependencies: 7 | Gem::Specification.new do |s| 8 | s.name = "lazy_render" 9 | s.version = LazyRender::VERSION 10 | s.authors = ["vexus2"] 11 | s.email = ["hikaru.tooyama@gmail.com"] 12 | s.homepage = "http://github.com/vexus2" 13 | s.summary = "Delay load your actions" 14 | s.description = "It delays loading of partial or actions in views." 15 | s.license = "MIT" 16 | 17 | s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"] 18 | 19 | s.test_files = Dir["spec/**/*"] 20 | 21 | s.add_dependency "rails", ">= 4.0.0" 22 | s.add_dependency "jquery-rails" 23 | 24 | s.add_development_dependency 'sqlite3' 25 | s.add_development_dependency 'rspec-rails' 26 | s.add_development_dependency 'capybara' 27 | s.add_development_dependency 'capybara-webkit' 28 | s.add_development_dependency 'factory_girl_rails' 29 | end 30 | -------------------------------------------------------------------------------- /lib/lazy_render.rb: -------------------------------------------------------------------------------- 1 | require 'lazy_render/engine' 2 | 3 | module LazyRender 4 | end 5 | -------------------------------------------------------------------------------- /lib/lazy_render/engine.rb: -------------------------------------------------------------------------------- 1 | require 'lazy_render/rails/routes' 2 | module LazyRender 3 | class Engine < ::Rails::Engine 4 | isolate_namespace LazyRender 5 | 6 | initializer 'lazy_render.lazyload_controller' do |app| 7 | ActiveSupport.on_load :lazyload_controller do 8 | helper LazyRender::LazyloadHelper 9 | end 10 | end 11 | 12 | config.generators do |g| 13 | g.test_framework :rspec 14 | g.fixture_replacement :factory_girl, :dir => 'spec/factories' 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /lib/lazy_render/rails/routes.rb: -------------------------------------------------------------------------------- 1 | require 'active_support/core_ext/object/try' 2 | require 'active_support/core_ext/hash/slice' 3 | 4 | module ActionDispatch::Routing 5 | class Mapper 6 | def lazy_render_for(path, *block) 7 | options = block.extract_options! 8 | match "#{path}", to: "#{options[:to]}#load", via: 'post' 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/lazy_render/version.rb: -------------------------------------------------------------------------------- 1 | module LazyRender 2 | VERSION = '0.2.0' 3 | end 4 | -------------------------------------------------------------------------------- /lib/tasks/lazy_render_tasks.rake: -------------------------------------------------------------------------------- 1 | # desc "Explaining what the task does" 2 | # task :lazy_render do 3 | # # Task goes here 4 | # end 5 | -------------------------------------------------------------------------------- /spec/assets/images/lazy-render.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vexus2/lazy_render/000c114506bf8b6d0d1f7e7b1eda1490a1ed3149/spec/assets/images/lazy-render.png -------------------------------------------------------------------------------- /spec/controllers/lazy_render/lazy_render_controller_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | module LazyRender 4 | RSpec.describe LazyRenderController, :type => :controller do 5 | 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/features/lazy_render_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'LazyRender', :type => :feature, js: true do 4 | before { visit root_path; sleep 1 } 5 | describe 'is show lazy_render messages after secs' do 6 | it { expect(page).to have_content('LazyRender Message') } 7 | it { expect(page).to have_content('value1') } 8 | it { expect(page).to have_content('value2') } 9 | it { expect(page).to have_content('sample text') } 10 | it { expect(page).to have_content('Separated by the directory') } 11 | end 12 | end -------------------------------------------------------------------------------- /spec/helpers/lazy_render/lazy_render_helper_spec.rb: -------------------------------------------------------------------------------- 1 | require 'rails_helper' 2 | 3 | # Specs in this file have access to a helper object that includes 4 | # the LazyloadHelper. For example: 5 | # 6 | # describe LazyloadHelper do 7 | # describe "string concat" do 8 | # it "concats two strings with spaces" do 9 | # expect(helper.concat_strings("this","that")).to eq("this that") 10 | # end 11 | # end 12 | # end 13 | module LazyRender 14 | RSpec.describe LazyloadHelper, :type => :helper do 15 | 16 | describe '#lazy_render' do 17 | it 'return span tag with class and name' do 18 | expect(helper.lazy_render('sample_class')).to eq "" 19 | expect(helper.lazy_render('sample_class', locals: [])).to eq "" 20 | expect(helper.lazy_render('sample_class', locals: 'Sample')).to eq "" 21 | end 22 | it 'return span tag with class and name and locals' do 23 | expect(helper.lazy_render('sample_class', locals: { var1: 'var3', var2: 'var4' })).to eq "" 24 | end 25 | 26 | it 'return span tag with class and name and cache params' do 27 | expect(helper.lazy_render('sample_class', cache: 200)).to eq "" 28 | expect(helper.lazy_render('sample_class', cache: '300')).to eq "" 29 | expect(helper.lazy_render('sample_class', cache: 'abc')).to eq "" 30 | end 31 | 32 | it 'return span tag with class and name and callback method' do 33 | expect(helper.lazy_render('sample_class', callback: 'Activity.start')).to eq "" 34 | end 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /spec/rails_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | ENV["RAILS_ENV"] ||= 'test' 3 | ENV["RAILS_ROOT"] ||= File.dirname(__FILE__) + "../../../spec/test_app" 4 | require 'spec_helper' 5 | require File.expand_path("../test_app/config/environment", __FILE__) 6 | require 'rspec/rails' 7 | require 'capybara-webkit' 8 | # Add additional requires below this line. Rails is not loaded until this point! 9 | 10 | # Requires supporting ruby files with custom matchers and macros, etc, in 11 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are 12 | # run as spec files by default. This means that files in spec/support that end 13 | # in _spec.rb will both be required and run as specs, causing the specs to be 14 | # run twice. It is recommended that you do not name files matching this glob to 15 | # end with _spec.rb. You can configure this pattern with the --pattern 16 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. 17 | # 18 | # The following line is provided for convenience purposes. It has the downside 19 | # of increasing the boot-up time by auto-requiring all files in the support 20 | # directory. Alternatively, in the individual `*_spec.rb` files, manually 21 | # require only the support files necessary. 22 | # 23 | # Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } 24 | 25 | # Checks for pending migrations before tests are run. 26 | # If you are not using ActiveRecord, you can remove this line. 27 | ActiveRecord::Migration.maintain_test_schema! 28 | 29 | ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../') 30 | Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f } 31 | 32 | RSpec.configure do |config| 33 | config.include Rails.application.routes.url_helpers 34 | config.mock_with :rspec 35 | config.use_transactional_fixtures = true 36 | config.infer_base_class_for_anonymous_controllers = false 37 | config.order = "random" 38 | config.include Capybara::DSL 39 | Capybara.javascript_driver = :webkit 40 | end 41 | 42 | RSpec.configure do |config| 43 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 44 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 45 | 46 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 47 | # examples within a transaction, remove the following line or assign false 48 | # instead of true. 49 | config.use_transactional_fixtures = true 50 | 51 | # RSpec Rails can automatically mix in different behaviours to your tests 52 | # based on their file location, for example enabling you to call `get` and 53 | # `post` in specs under `spec/controllers`. 54 | # 55 | # You can disable this behaviour by removing the line below, and instead 56 | # explicitly tag your specs with their type, e.g.: 57 | # 58 | # RSpec.describe UsersController, :type => :controller do 59 | # # ... 60 | # end 61 | # 62 | # The different available types are documented in the features, such as in 63 | # https://relishapp.com/rspec/rspec-rails/docs 64 | config.infer_spec_type_from_file_location! 65 | end 66 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all 2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 3 | # The generated `.rspec` file contains `--require spec_helper` which will cause this 4 | # file to always be loaded, without a need to explicitly require it in any files. 5 | # 6 | # Given that it is always loaded, you are encouraged to keep this file as 7 | # light-weight as possible. Requiring heavyweight dependencies from this file 8 | # will add to the boot time of your test suite on EVERY test run, even for an 9 | # individual file that may not need all of that loaded. Instead, consider making 10 | # a separate helper file that requires the additional dependencies and performs 11 | # the additional setup, and require it from the spec files that actually need it. 12 | # 13 | # The `.rspec` file also contains a few flags that are not defaults but that 14 | # users commonly want. 15 | # 16 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 17 | RSpec.configure do |config| 18 | # rspec-expectations config goes here. You can use an alternate 19 | # assertion/expectation library such as wrong or the stdlib/minitest 20 | # assertions if you prefer. 21 | config.expect_with :rspec do |expectations| 22 | # This option will default to `true` in RSpec 4. It makes the `description` 23 | # and `failure_message` of custom matchers include text for helper methods 24 | # defined using `chain`, e.g.: 25 | # be_bigger_than(2).and_smaller_than(4).description 26 | # # => "be bigger than 2 and smaller than 4" 27 | # ...rather than: 28 | # # => "be bigger than 2" 29 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 30 | end 31 | 32 | # rspec-mocks config goes here. You can use an alternate test double 33 | # library (such as bogus or mocha) by changing the `mock_with` option here. 34 | config.mock_with :rspec do |mocks| 35 | # Prevents you from mocking or stubbing a method that does not exist on 36 | # a real object. This is generally recommended, and will default to 37 | # `true` in RSpec 4. 38 | mocks.verify_partial_doubles = true 39 | end 40 | 41 | # The settings below are suggested to provide a good initial experience 42 | # with RSpec, but feel free to customize to your heart's content. 43 | =begin 44 | # These two settings work together to allow you to limit a spec run 45 | # to individual examples or groups you care about by tagging them with 46 | # `:focus` metadata. When nothing is tagged with `:focus`, all examples 47 | # get run. 48 | config.filter_run :focus 49 | config.run_all_when_everything_filtered = true 50 | 51 | # Limits the available syntax to the non-monkey patched syntax that is recommended. 52 | # For more details, see: 53 | # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax 54 | # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 55 | # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching 56 | config.disable_monkey_patching! 57 | 58 | # Many RSpec users commonly either run the entire suite or an individual 59 | # file, and it's useful to allow more verbose output when running an 60 | # individual spec file. 61 | if config.files_to_run.one? 62 | # Use the documentation formatter for detailed output, 63 | # unless a formatter has already been configured 64 | # (e.g. via a command-line flag). 65 | config.default_formatter = 'doc' 66 | end 67 | 68 | # Print the 10 slowest examples and example groups at the 69 | # end of the spec run, to help surface which specs are running 70 | # particularly slow. 71 | config.profile_examples = 10 72 | 73 | # Run specs in random order to surface order dependencies. If you find an 74 | # order dependency and want to debug it, you can fix the order by providing 75 | # the seed, which is printed after each run. 76 | # --seed 1234 77 | config.order = :random 78 | 79 | # Seed global randomization in this process using the `--seed` CLI option. 80 | # Setting this allows you to use `--seed` to deterministically reproduce 81 | # test failures related to randomization by passing the same `--seed` value 82 | # as the one that triggered the failure. 83 | Kernel.srand config.seed 84 | =end 85 | end 86 | -------------------------------------------------------------------------------- /spec/test_app/README.rdoc: -------------------------------------------------------------------------------- 1 | == README 2 | 3 | This README would normally document whatever steps are necessary to get the 4 | application up and running. 5 | 6 | Things you may want to cover: 7 | 8 | * Ruby version 9 | 10 | * System dependencies 11 | 12 | * Configuration 13 | 14 | * Database creation 15 | 16 | * Database initialization 17 | 18 | * How to run the test suite 19 | 20 | * Services (job queues, cache servers, search engines, etc.) 21 | 22 | * Deployment instructions 23 | 24 | * ... 25 | 26 | 27 | Please feel free to use a different markup language if you do not plan to run 28 | rake doc:app. 29 | -------------------------------------------------------------------------------- /spec/test_app/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /spec/test_app/app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vexus2/lazy_render/000c114506bf8b6d0d1f7e7b1eda1490a1ed3149/spec/test_app/app/assets/images/.keep -------------------------------------------------------------------------------- /spec/test_app/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require jquery 14 | //= require lazy_render 15 | -------------------------------------------------------------------------------- /spec/test_app/app/assets/javascripts/top.js: -------------------------------------------------------------------------------- 1 | // Place all the behaviors and hooks related to the matching controller here. 2 | // All this logic will automatically be available in application.js. 3 | -------------------------------------------------------------------------------- /spec/test_app/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the 9 | * compiled file so the styles you add here take precedence over styles defined in any styles 10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new 11 | * file per style scope. 12 | * 13 | *= require_tree . 14 | *= require_self 15 | */ 16 | -------------------------------------------------------------------------------- /spec/test_app/app/assets/stylesheets/top.css: -------------------------------------------------------------------------------- 1 | /* 2 | Place all the styles related to the matching controller here. 3 | They will automatically be included in application.css. 4 | */ 5 | -------------------------------------------------------------------------------- /spec/test_app/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery with: :exception 3 | end 4 | -------------------------------------------------------------------------------- /spec/test_app/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vexus2/lazy_render/000c114506bf8b6d0d1f7e7b1eda1490a1ed3149/spec/test_app/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /spec/test_app/app/controllers/lazy_render_controller.rb: -------------------------------------------------------------------------------- 1 | class LazyRenderController < LazyRender::LazyloadController 2 | def lazy_render_message 3 | end 4 | 5 | def pass_variables(locals) 6 | @data[:value1] = 'value1' 7 | @data[:value2] = { key: 'value2' } 8 | @data[:value3] = locals[:v] 9 | end 10 | 11 | def directory__separator 12 | end 13 | 14 | def with_cache 15 | end 16 | 17 | def load 18 | super 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /spec/test_app/app/controllers/top_controller.rb: -------------------------------------------------------------------------------- 1 | class TopController < ApplicationController 2 | helper LazyRender::LazyloadHelper 3 | def index 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /spec/test_app/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /spec/test_app/app/helpers/top_helper.rb: -------------------------------------------------------------------------------- 1 | module TopHelper 2 | end 3 | -------------------------------------------------------------------------------- /spec/test_app/app/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vexus2/lazy_render/000c114506bf8b6d0d1f7e7b1eda1490a1ed3149/spec/test_app/app/mailers/.keep -------------------------------------------------------------------------------- /spec/test_app/app/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vexus2/lazy_render/000c114506bf8b6d0d1f7e7b1eda1490a1ed3149/spec/test_app/app/models/.keep -------------------------------------------------------------------------------- /spec/test_app/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vexus2/lazy_render/000c114506bf8b6d0d1f7e7b1eda1490a1ed3149/spec/test_app/app/models/concerns/.keep -------------------------------------------------------------------------------- /spec/test_app/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TestApp 5 | <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 6 | <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spec/test_app/app/views/lazy_render/directory/separator.html.erb: -------------------------------------------------------------------------------- 1 | Separated by the directory -------------------------------------------------------------------------------- /spec/test_app/app/views/lazy_render/lazy_render_message.erb: -------------------------------------------------------------------------------- 1 | LazyRender Message -------------------------------------------------------------------------------- /spec/test_app/app/views/lazy_render/pass_variables.html.erb: -------------------------------------------------------------------------------- 1 | <%= data[:value1] %> 2 | <%= data[:value2] %> 3 | <%= data[:value3] %> 4 | -------------------------------------------------------------------------------- /spec/test_app/app/views/lazy_render/with_cache.html.erb: -------------------------------------------------------------------------------- 1 | message with cache -------------------------------------------------------------------------------- /spec/test_app/app/views/top/index.html.erb: -------------------------------------------------------------------------------- 1 |

Top#index

2 |

Find me in app/views/top/index.html.erb

3 | 4 | <%= lazy_render :lazy_render_message %> 5 | 6 | <%= lazy_render :pass_variables, locals: { v: 'sample text' } %> 7 | 8 | <%= lazy_render :directory__separator %> 9 | 10 | <%= lazy_render :with_cache, cache: 300 %> 11 | 12 | <%= lazy_render :undefined_item %> 13 | -------------------------------------------------------------------------------- /spec/test_app/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /spec/test_app/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../../config/application', __FILE__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /spec/test_app/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /spec/test_app/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | 4 | # path to your application root. 5 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 6 | 7 | Dir.chdir APP_ROOT do 8 | # This script is a starting point to setup your application. 9 | # Add necessary setup steps to this file: 10 | 11 | puts "== Installing dependencies ==" 12 | system "gem install bundler --conservative" 13 | system "bundle check || bundle install" 14 | 15 | # puts "\n== Copying sample files ==" 16 | # unless File.exist?("config/database.yml") 17 | # system "cp config/database.yml.sample config/database.yml" 18 | # end 19 | 20 | puts "\n== Preparing database ==" 21 | system "bin/rake db:setup" 22 | 23 | puts "\n== Removing old logs and tempfiles ==" 24 | system "rm -f log/*" 25 | system "rm -rf tmp/cache" 26 | 27 | puts "\n== Restarting application server ==" 28 | system "touch tmp/restart.txt" 29 | end 30 | -------------------------------------------------------------------------------- /spec/test_app/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /spec/test_app/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | # Pick the frameworks you want: 4 | require "active_record/railtie" 5 | require "action_controller/railtie" 6 | require "action_mailer/railtie" 7 | require "action_view/railtie" 8 | require "sprockets/railtie" 9 | # require "rails/test_unit/railtie" 10 | 11 | Bundler.require(*Rails.groups) 12 | require "lazy_render" 13 | 14 | module TestApp 15 | class Application < Rails::Application 16 | # Settings in config/environments/* take precedence over those specified here. 17 | # Application configuration should go into files in config/initializers 18 | # -- all .rb files in that directory are automatically loaded. 19 | 20 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 21 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 22 | # config.time_zone = 'Central Time (US & Canada)' 23 | 24 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 25 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 26 | # config.i18n.default_locale = :de 27 | 28 | # Do not swallow errors in after_commit/after_rollback callbacks. 29 | # config.active_record.raise_in_transactional_callbacks = true 30 | end 31 | end 32 | 33 | -------------------------------------------------------------------------------- /spec/test_app/config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) 3 | 4 | require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) 5 | $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) 6 | -------------------------------------------------------------------------------- /spec/test_app/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: db/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: db/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: db/production.sqlite3 26 | -------------------------------------------------------------------------------- /spec/test_app/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /spec/test_app/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports and disable caching. 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send. 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger. 20 | config.active_support.deprecation = :log 21 | 22 | # Raise an error on page load if there are pending migrations. 23 | config.active_record.migration_error = :page_load 24 | 25 | # Debug mode disables concatenation and preprocessing of assets. 26 | # This option may cause significant delays in view rendering with a large 27 | # number of complex assets. 28 | config.assets.debug = true 29 | 30 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 31 | # yet still be able to expire them through the digest params. 32 | config.assets.digest = true 33 | 34 | # Adds additional error checking when serving assets at runtime. 35 | # Checks for improperly declared sprockets dependencies. 36 | # Raises helpful error messages. 37 | config.assets.raise_runtime_errors = true 38 | 39 | # Raises error for missing translations 40 | # config.action_view.raise_on_missing_translations = true 41 | end 42 | -------------------------------------------------------------------------------- /spec/test_app/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both threaded web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application 18 | # Add `rack-cache` to your Gemfile before enabling this. 19 | # For large-scale production use, consider using a caching reverse proxy like 20 | # NGINX, varnish or squid. 21 | # config.action_dispatch.rack_cache = true 22 | 23 | # Disable Rails's static asset server (Apache or NGINX will already do this). 24 | config.serve_static_assets = false 25 | 26 | # Compress JavaScripts and CSS. 27 | config.assets.js_compressor = :uglifier 28 | # config.assets.css_compressor = :sass 29 | 30 | # Do not fallback to assets pipeline if a precompiled asset is missed. 31 | config.assets.compile = false 32 | 33 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 34 | # yet still be able to expire them through the digest params. 35 | config.assets.digest = true 36 | 37 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 38 | 39 | # Specifies the header that your server uses for sending files. 40 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 41 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 42 | 43 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 44 | # config.force_ssl = true 45 | 46 | # Decrease the log volume. 47 | # config.log_level = :info 48 | 49 | # Prepend all log lines with the following tags. 50 | # config.log_tags = [ :subdomain, :uuid ] 51 | 52 | # Use a different logger for distributed setups. 53 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 54 | 55 | # Use a different cache store in production. 56 | # config.cache_store = :mem_cache_store 57 | 58 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 59 | # config.action_controller.asset_host = 'http://assets.example.com' 60 | 61 | # Ignore bad email addresses and do not raise email delivery errors. 62 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 63 | # config.action_mailer.raise_delivery_errors = false 64 | 65 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 66 | # the I18n.default_locale when a translation cannot be found). 67 | config.i18n.fallbacks = true 68 | 69 | # Send deprecation notices to registered listeners. 70 | config.active_support.deprecation = :notify 71 | 72 | # Use default logging formatter so that PID and timestamp are not suppressed. 73 | config.log_formatter = ::Logger::Formatter.new 74 | 75 | # Do not dump schema after migrations. 76 | config.active_record.dump_schema_after_migration = false 77 | end 78 | -------------------------------------------------------------------------------- /spec/test_app/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure static asset server for tests with Cache-Control for performance. 16 | config.serve_static_assets = true 17 | config.static_cache_control = 'public, max-age=3600' 18 | 19 | # Show full error reports and disable caching. 20 | config.consider_all_requests_local = true 21 | config.action_controller.perform_caching = false 22 | 23 | # Raise exceptions instead of rendering exception templates. 24 | config.action_dispatch.show_exceptions = false 25 | 26 | # Disable request forgery protection in test environment. 27 | config.action_controller.allow_forgery_protection = false 28 | 29 | # Tell Action Mailer not to deliver emails to the real world. 30 | # The :test delivery method accumulates sent emails in the 31 | # ActionMailer::Base.deliveries array. 32 | config.action_mailer.delivery_method = :test 33 | 34 | # Randomize the order test cases are executed 35 | config.active_support.test_order = :random 36 | 37 | # Print deprecation notices to the stderr. 38 | config.active_support.deprecation = :stderr 39 | 40 | # Raises error for missing translations 41 | # config.action_view.raise_on_missing_translations = true 42 | end 43 | -------------------------------------------------------------------------------- /spec/test_app/config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = '1.0' 5 | 6 | # Add additional assets to the asset load path 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 11 | # Rails.application.config.assets.precompile += %w( search.js ) 12 | -------------------------------------------------------------------------------- /spec/test_app/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /spec/test_app/config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.action_dispatch.cookies_serializer = :json 4 | -------------------------------------------------------------------------------- /spec/test_app/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /spec/test_app/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /spec/test_app/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /spec/test_app/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.session_store :cookie_store, key: '_test_app_session' 4 | -------------------------------------------------------------------------------- /spec/test_app/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters) 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /spec/test_app/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /spec/test_app/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | 3 | root 'top#index' 4 | 5 | lazy_render_for 'lazy_render/load', to: 'lazy_render' 6 | end 7 | -------------------------------------------------------------------------------- /spec/test_app/config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: 625f0b0421a2894364f0ffa59d0984bd5e324f91d927985ae2514382b1e5eda75737661235c5bc56327a3cdf2f07a32231a25783a2a19abb17d2bd48df9d375f 15 | 16 | test: 17 | secret_key_base: fb646fb926f81c3cad7fd2a41bd19157db01ed04309093d2adb65a6492fb0b5d9e95c41c0bc4257294c2442d1d0ec554f1da7397cdf8f73295f6c469f59805e6 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /spec/test_app/lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vexus2/lazy_render/000c114506bf8b6d0d1f7e7b1eda1490a1ed3149/spec/test_app/lib/assets/.keep -------------------------------------------------------------------------------- /spec/test_app/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vexus2/lazy_render/000c114506bf8b6d0d1f7e7b1eda1490a1ed3149/spec/test_app/log/.keep -------------------------------------------------------------------------------- /spec/test_app/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The page you were looking for doesn't exist.

62 |

You may have mistyped the address or the page may have moved.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /spec/test_app/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

The change you wanted was rejected.

62 |

Maybe you tried to change something you didn't have access to.

63 |
64 |

If you are the application owner check the logs for more information.

65 |
66 | 67 | 68 | -------------------------------------------------------------------------------- /spec/test_app/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 6 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |

We're sorry, but something went wrong.

62 |
63 |

If you are the application owner check the logs for more information.

64 |
65 | 66 | 67 | -------------------------------------------------------------------------------- /spec/test_app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vexus2/lazy_render/000c114506bf8b6d0d1f7e7b1eda1490a1ed3149/spec/test_app/public/favicon.ico --------------------------------------------------------------------------------