All Projects → chamnap → Liquid Rails

chamnap / Liquid Rails

Licence: mit
Renders liquid templates with layout and partial support

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Liquid Rails

Graphjin
GraphJin - Build APIs in 5 minutes with GraphQL. An instant GraphQL to SQL compiler.
Stars: ✭ 1,264 (+1289.01%)
Mutual labels:  rails
Covid Volunteers
Organizing and matching volunteers with COVID-19 projects
Stars: ✭ 87 (-4.4%)
Mutual labels:  rails
Gorailsyourself
A suite of useful functions needed when porting/mixing Go/Rails code.
Stars: ✭ 89 (-2.2%)
Mutual labels:  rails
Chaskiq
A full featured Live Chat, Support & Marketing platform, alternative to Intercom, Drift, Crisp, etc ...
Stars: ✭ 1,263 (+1287.91%)
Mutual labels:  rails
Site
Stars: ✭ 86 (-5.49%)
Mutual labels:  liquid
Instuigram
🎓 Learning Ruby on Rails through building the Instagram Application.
Stars: ✭ 88 (-3.3%)
Mutual labels:  rails
Thredded
The best Rails forums engine ever.
Stars: ✭ 1,263 (+1287.91%)
Mutual labels:  rails
Activeadmin
The administration framework for Ruby on Rails applications.
Stars: ✭ 9,096 (+9895.6%)
Mutual labels:  rails
Csso Rails
CSS Optimizer(csso) ruby wrapper for Rails Asset pipeline
Stars: ✭ 86 (-5.49%)
Mutual labels:  rails
Jquery Slick Rails
Integrates Slick carousel, a jQuery plugin, into your Rails app.
Stars: ✭ 89 (-2.2%)
Mutual labels:  rails
Rails React Boilerplate
Ruby on Rails, React, Webpack 4 boilerplate app.
Stars: ✭ 86 (-5.49%)
Mutual labels:  rails
Pager Api
Easy API pagination for Rails
Stars: ✭ 86 (-5.49%)
Mutual labels:  rails
Errdo
A simple plugin to handle, log, and customize production errors in Rails applications
Stars: ✭ 88 (-3.3%)
Mutual labels:  rails
Stimulus reflex expo
StimulusReflex demos
Stars: ✭ 85 (-6.59%)
Mutual labels:  rails
Reactchat
A chat app built with React.js and ActionCable in Ruby on Rails 5.1
Stars: ✭ 90 (-1.1%)
Mutual labels:  rails
Rails Security Checklist
🔑 Community-driven Rails Security Checklist (see our GitHub Issues for the newest checks that aren't yet in the README)
Stars: ✭ 1,265 (+1290.11%)
Mutual labels:  rails
Simpleadmin Rails
SimpleAdmin - Dashboard for modern website without wasting time
Stars: ✭ 87 (-4.4%)
Mutual labels:  rails
Javlibrary Rails
Elegant way to build your own javlibrary database.
Stars: ✭ 91 (+0%)
Mutual labels:  rails
Translate enum
Easily Translate Enums in Rails
Stars: ✭ 90 (-1.1%)
Mutual labels:  rails
Muvee
μv: (mew-vee) Netflix, for your home. WIP
Stars: ✭ 89 (-2.2%)
Mutual labels:  rails

Build StatusCoverage StatusGem Version

Liquid-Rails

It allows you to render .liquid templates with layout and partial support. It also provides filters, tags, drops class to be used inside your liquid template.

Installation

Add this line to your application's Gemfile:

gem 'liquid-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install liquid-rails

Usage

In order to render with layout, in your layout file app/views/layouts/application.liquid, put this:

{{ content_for_layout }}
# It will render app/views/home/_partial.liquid when the current controller is `HomeController`.
{% include 'partial' %}

# It will render app/views/shared/_partial.liquid.
{% include 'shared/partial' %}

Template Rendering

By default, Liquid-Rails makes all instance variables from controller available to liquid template. To limit only some instance variables, do this inside your controller:

def liquid_assigns
  { 'listing' => current_listing, 'content_for_header' => content_for_header, 'current_account' => current_account }
end

By default, Liquid-Rails makes all your helper methods inside your rails app available to liquid template. To limit only some helpers, do this inside your controller:

def liquid_filters
  []
end

You can render liquid templates from other template engines, eg. erb, haml, ...

= render 'shared/partial.liquid'

Filter

Filters are simple methods that modify the output of numbers, strings, variables and objects. They are placed within an output tag {{ }} and are separated with a pipe character |.

Currently, Liquid-Rails adds only the followings:

  1. AssetTagFilter
  2. AssetUrlFilter
  3. DateFilter
  4. NumberFilter
  5. SanitizeFilter
  6. TextFilter
  7. TranslateFilter
  8. UrlFilter
  9. MiscFilter

Tag

Liquid tags are the programming logic that tells templates what to do. Tags are wrapped in: {% %}.

Currently, Liquid-Rails adds only the followings:

  1. csrf_meta_tags
  2. google_analytics_tag
  3. javascript_tag
  4. paginate
  5. content_for

Drop Class

Drops let you provide the user with custom functionality. They are very much like a standard Ruby class, but have all unused and potentially dangerous methods removed. From the user's perspective a drop acts very much like a Hash, though methods are accessed with dot-notation as well as element selection. A drop method cannot be invoked with arguments. Drops are called just-in-time, thus allowing you to lazily load objects.

Given two models, a Post(title: string, body: text) and a Comment(name:string, body:text, post_id:integer), you will have two drops:

class PostDrop < Liquid::Rails::Drop
  attributes :id, :title, :body

  has_many :comments
end

and

class CommentDrop < Liquid::Rails::Drop
  attributes :id, :name, :body

  belongs_to :post
end

Check out more examples.

It works for any ORMs. The PORO should include Liquid::Rails::Droppable. That's all you need to do to have your POROs supported.

RSpec

In spec_helper.rb, you'll need to require the matchers:

require 'liquid-rails/matchers'

Example:

describe PostDrop do
  it { should have_attribute(:id) }
  it { should have_attribute(:title) }
  it { should have_attribute(:body) }
  it { should have_many(:comments) }
end
describe CommentDrop do
  it { should have_attribute(:id) }
  it { should have_attribute(:name) }
  it { should have_attribute(:body) }
  it { should belongs_to(:post) }
end

Contributors

Authors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].