Coder Social home page Coder Social logo

lazy_render's Introduction

LazyRender

lazy_render

What is this?

It delays loading of partial or actions in views.

Installation

LazyRender works with Rails 4.0 onwards. You can add it to your Gemfile with:

gem 'lazy_render'

Usage

1. Route to LazyRender

add to routes.rb

  lazy_render_for 'lazy_render/load', to: 'lazy_render'

2. Configuring Javascript

add to application.js

//= require jquery
//= require lazy_render

3. Configuring Controller

add to include helper into application_controller

class ApplicationController < ActionController::Base
  helper LazyRender::LazyloadHelper
end

create a controller to run lazy render

controllers/lazy_render_controller.rb

class LazyRenderController < LazyRender::LazyloadController
  def load
    super
  end
end

and add some action to LazyRenderController

def sample_action(locals)
  @data[:sample_text] = 'Hello LazyRender!'
  @data[:pass_value] = locals[:value]
end

4. Configuring View

create view file under views/lazy_render/

views/lazy_render/sample_action.html.erb

<h2>This is sample view.</h2>
<p><%= data[:sample_text] %></p>
<h3><%= data[:pass_value] %></3>

5. Call lazy_render from View

Call lazy_render from your any views

<%= lazy_render :sample_text, locals: { value: 'Sample Text' } %>
<h2>This is sample view.</h2>
<p>Hello LazyRender!</p>
<h3>Sample Text</3>

lazy_render options

  • locals : The parameters to passed to action
  • cache : Time to hold a View to the local storage. Default: 0
  • callback : To specify the Javascript method that you want to execute after displaying partial.
  • parallel : I carry it out in parallel without compiling a request in lazy_render. Default: false

Contributing

  1. Fork it ( https://github.com/vexus2/lazy_render/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Authors

vexus2

Thanks to

be inspired by akiyan

lazy_render's People

Contributors

vexus2 avatar hagiyat avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.